2017-03-03 20:05:50 +02:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2017-03-03 20:05:50 +02:00
|
|
|
|
2017-03-03 20:28:27 +02:00
|
|
|
#include "sync.hh"
|
2023-10-25 07:43:36 +03:00
|
|
|
#include "processes.hh"
|
|
|
|
#include "file-system.hh"
|
2017-03-03 20:05:50 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
class SSHMaster
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2017-03-03 20:28:27 +02:00
|
|
|
const std::string host;
|
2018-08-03 19:12:28 +03:00
|
|
|
bool fakeSSH;
|
2017-03-03 20:28:27 +02:00
|
|
|
const std::string keyFile;
|
2021-02-25 03:52:22 +02:00
|
|
|
const std::string sshPublicHostKey;
|
2017-03-03 20:28:27 +02:00
|
|
|
const bool useMaster;
|
|
|
|
const bool compress;
|
2017-05-02 13:01:46 +03:00
|
|
|
const int logFD;
|
2017-03-03 20:28:27 +02:00
|
|
|
|
|
|
|
struct State
|
|
|
|
{
|
2023-09-03 00:35:16 +03:00
|
|
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
2017-03-03 20:28:27 +02:00
|
|
|
Pid sshMaster;
|
2023-09-03 00:35:16 +03:00
|
|
|
#endif
|
2017-03-03 20:28:27 +02:00
|
|
|
std::unique_ptr<AutoDelete> tmpDir;
|
|
|
|
Path socketPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
Sync<State> state_;
|
2017-03-03 20:05:50 +02:00
|
|
|
|
2017-03-21 15:35:50 +02:00
|
|
|
void addCommonSSHOpts(Strings & args);
|
2023-05-16 15:48:04 +03:00
|
|
|
bool isMasterRunning();
|
2017-03-21 15:35:50 +02:00
|
|
|
|
2023-09-03 00:35:16 +03:00
|
|
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
|
|
|
Path startMaster();
|
|
|
|
#endif
|
|
|
|
|
2017-03-03 20:05:50 +02:00
|
|
|
public:
|
|
|
|
|
2024-01-25 17:31:52 +02:00
|
|
|
SSHMaster(
|
|
|
|
std::string_view host,
|
|
|
|
std::string_view keyFile,
|
|
|
|
std::string_view sshPublicHostKey,
|
|
|
|
bool useMaster, bool compress, int logFD = -1);
|
2017-03-03 20:05:50 +02:00
|
|
|
|
|
|
|
struct Connection
|
|
|
|
{
|
2023-09-03 00:35:16 +03:00
|
|
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
2017-03-03 20:05:50 +02:00
|
|
|
Pid sshPid;
|
2023-09-03 00:35:16 +03:00
|
|
|
#endif
|
2017-03-03 20:05:50 +02:00
|
|
|
AutoCloseFD out, in;
|
|
|
|
};
|
|
|
|
|
2024-01-22 22:50:00 +02:00
|
|
|
/**
|
|
|
|
* @param command The command (arg vector) to execute.
|
|
|
|
*
|
|
|
|
* @param extraSShArgs Extra args 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 = {});
|
2017-03-03 20:05:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|