mirror of
https://github.com/NixOS/nix
synced 2025-07-02 05:11:47 +02:00
It is unused in Nix currently, but will be used in Hydra. This reflects what Hydra does in https://github.com/NixOS/hydra/pull/1387. We may probably to use it more widely for better SSH store performance, but this needs to be subject to more testing before we do that.
83 lines
2 KiB
C++
83 lines
2 KiB
C++
#pragma once
|
|
///@file
|
|
|
|
#include "sync.hh"
|
|
#include "processes.hh"
|
|
#include "file-system.hh"
|
|
|
|
namespace nix {
|
|
|
|
class SSHMaster
|
|
{
|
|
private:
|
|
|
|
const std::string host;
|
|
bool fakeSSH;
|
|
const std::string keyFile;
|
|
/**
|
|
* Raw bytes, not Base64 encoding.
|
|
*/
|
|
const std::string sshPublicHostKey;
|
|
const bool useMaster;
|
|
const bool compress;
|
|
const Descriptor logFD;
|
|
|
|
struct State
|
|
{
|
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
|
Pid sshMaster;
|
|
#endif
|
|
std::unique_ptr<AutoDelete> tmpDir;
|
|
Path socketPath;
|
|
};
|
|
|
|
Sync<State> state_;
|
|
|
|
void addCommonSSHOpts(Strings & args);
|
|
bool isMasterRunning();
|
|
|
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
|
Path startMaster();
|
|
#endif
|
|
|
|
public:
|
|
|
|
SSHMaster(
|
|
std::string_view host,
|
|
std::string_view keyFile,
|
|
std::string_view sshPublicHostKey,
|
|
bool useMaster, bool compress, Descriptor logFD = INVALID_DESCRIPTOR);
|
|
|
|
struct Connection
|
|
{
|
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
|
Pid sshPid;
|
|
#endif
|
|
AutoCloseFD out, in;
|
|
|
|
/**
|
|
* Try to set the buffer size in both directions to the
|
|
* designated amount, if possible. If not possible, does
|
|
* nothing.
|
|
*
|
|
* Current implementation is to use `fcntl` with `F_SETPIPE_SZ`,
|
|
* which is Linux-only. For this implementation, `size` must
|
|
* convertable to an `int`. In other words, it must be within
|
|
* `[0, INT_MAX]`.
|
|
*/
|
|
void trySetBufferSize(size_t size);
|
|
};
|
|
|
|
/**
|
|
* @param command The command (arg vector) to execute.
|
|
*
|
|
* @param extraSshArgs Extra arguments to pass to SSH (not the command to
|
|
* execute). Will not be used when "fake SSHing" to the local
|
|
* machine.
|
|
*/
|
|
std::unique_ptr<Connection> startCommand(
|
|
Strings && command,
|
|
Strings && extraSshArgs = {});
|
|
};
|
|
|
|
}
|