Skip to content

Commit

Permalink
feat: add user@address:port support
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Apr 25, 2020
1 parent c9d0cf7 commit 356b8ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/libstore/ssh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace nix {

SSHMaster::SSHMaster(const std::string & host, const std::string & keyFile, bool useMaster, bool compress, int logFD)
: host(host)
, fakeSSH(host == "localhost")
, keyFile(keyFile)
SSHMaster::SSHMaster(const std::string & hostNport, const std::string & keyFile, bool useMaster, bool compress, int logFD)
: keyFile(keyFile)
, useMaster(useMaster && !fakeSSH)
, compress(compress)
, logFD(logFD)
{
auto res = tokenizeString<std::vector<string>>(hostNport, ":");
port = res.size() > 1 ? atoi(res[1].c_str()) : 0; // if we have a port, parse that
host = res[0];

fakeSSH = host == "localhost" && !port;

if (host == "" || hasPrefix(host, "-"))
throw Error("invalid SSH host name '%s'", host);
}
Expand All @@ -22,6 +26,8 @@ void SSHMaster::addCommonSSHOpts(Strings & args)
args.insert(args.end(), {"-i", keyFile});
if (compress)
args.push_back("-C");
if (port != 0)
args.insert(args.end(), {"-p", std::to_string(port)});
}

std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string & command)
Expand Down
3 changes: 2 additions & 1 deletion src/libstore/ssh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class SSHMaster
{
private:

const std::string host;
std::string host;
bool fakeSSH;
const std::string keyFile;
const bool useMaster;
const bool compress;
const int logFD;
int port;

struct State
{
Expand Down

0 comments on commit 356b8ba

Please sign in to comment.