Skip to content

Commit

Permalink
Start factoring out the serve protocol for Hydra to share
Browse files Browse the repository at this point in the history
Hydra uses the lock argument differently than Nix, so we un-hard-code
it.

The parent commit is chosen such that this should work for 2.6 and
master alike.
  • Loading branch information
Ericson2314 committed Feb 28, 2022
1 parent b592359 commit e06061e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "pool.hh"
#include "remote-store.hh"
#include "serve-protocol.hh"
#include "serve-protocol-impl.hh"
#include "store-api.hh"
#include "path-with-outputs.hh"
#include "worker-protocol.hh"
Expand Down Expand Up @@ -31,12 +32,9 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
// the documentation
const Setting<int> logFD{(StoreConfig*) this, -1, "log-fd", "file descriptor to which SSH's stderr is connected"};

struct Connection
struct Connection : public serve_proto::BasicConnection
{
std::unique_ptr<SSHMaster::Connection> sshConn;
FdSink to;
FdSource from;
int remoteVersion;
bool good = true;
};

Expand Down Expand Up @@ -353,15 +351,8 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
SubstituteFlag maybeSubstitute = NoSubstitute) override
{
auto conn(connections->get());

conn->to
<< cmdQueryValidPaths
<< false // lock
<< maybeSubstitute;
worker_proto::write(*this, conn->to, paths);
conn->to.flush();

return worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
return serve_proto::queryValidPaths(*conn, *this,
false, paths, maybeSubstitute);
}

void connect() override
Expand Down
24 changes: 24 additions & 0 deletions src/libstore/serve-protocol-impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "serve-protocol-impl.hh"

#include "remote-store.hh"

namespace nix {
namespace serve_proto {

StorePathSet queryValidPaths(
BasicConnection & conn, const Store & remoteStore,
bool lock, const StorePathSet & paths,
SubstituteFlag maybeSubstitute)
{
conn.to
<< cmdQueryValidPaths
<< lock
<< maybeSubstitute;
worker_proto::write(remoteStore, conn.to, paths);
conn.to.flush();

return worker_proto::read(remoteStore, conn.from, Phantom<StorePathSet> {});
}

}
}
25 changes: 25 additions & 0 deletions src/libstore/serve-protocol-impl.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "serialise.hh"

#include "store-api.hh"
#include "serve-protocol.hh"
#include "worker-protocol.hh"

namespace nix {
namespace serve_proto {

struct BasicConnection
{
FdSink to;
FdSource from;
int remoteVersion;
};

StorePathSet queryValidPaths(
BasicConnection & conn, const Store & remoteStore,
bool lock, const StorePathSet & paths,
SubstituteFlag maybeSubstitute);

}
}

0 comments on commit e06061e

Please sign in to comment.