From e06061e4e92d37cade77769c44091f6ada1cf298 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 20 Feb 2022 19:24:07 +0000 Subject: [PATCH] Start factoring out the serve protocol for Hydra to share 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. --- src/libstore/legacy-ssh-store.cc | 17 ++++------------- src/libstore/serve-protocol-impl.cc | 24 ++++++++++++++++++++++++ src/libstore/serve-protocol-impl.hh | 25 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/libstore/serve-protocol-impl.cc create mode 100644 src/libstore/serve-protocol-impl.hh diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 6b3daae7f14..b1797ac3fbb 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -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" @@ -31,12 +32,9 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor // the documentation const Setting 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 sshConn; - FdSink to; - FdSource from; - int remoteVersion; bool good = true; }; @@ -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 {}); + return serve_proto::queryValidPaths(*conn, *this, + false, paths, maybeSubstitute); } void connect() override diff --git a/src/libstore/serve-protocol-impl.cc b/src/libstore/serve-protocol-impl.cc new file mode 100644 index 00000000000..636d0ce1c87 --- /dev/null +++ b/src/libstore/serve-protocol-impl.cc @@ -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 {}); +} + +} +} diff --git a/src/libstore/serve-protocol-impl.hh b/src/libstore/serve-protocol-impl.hh new file mode 100644 index 00000000000..f0f78c9c0c8 --- /dev/null +++ b/src/libstore/serve-protocol-impl.hh @@ -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); + +} +}