Skip to content

Commit e06061e

Browse files
committed
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.
1 parent b592359 commit e06061e

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

src/libstore/legacy-ssh-store.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "pool.hh"
33
#include "remote-store.hh"
44
#include "serve-protocol.hh"
5+
#include "serve-protocol-impl.hh"
56
#include "store-api.hh"
67
#include "path-with-outputs.hh"
78
#include "worker-protocol.hh"
@@ -31,12 +32,9 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
3132
// the documentation
3233
const Setting<int> logFD{(StoreConfig*) this, -1, "log-fd", "file descriptor to which SSH's stderr is connected"};
3334

34-
struct Connection
35+
struct Connection : public serve_proto::BasicConnection
3536
{
3637
std::unique_ptr<SSHMaster::Connection> sshConn;
37-
FdSink to;
38-
FdSource from;
39-
int remoteVersion;
4038
bool good = true;
4139
};
4240

@@ -353,15 +351,8 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
353351
SubstituteFlag maybeSubstitute = NoSubstitute) override
354352
{
355353
auto conn(connections->get());
356-
357-
conn->to
358-
<< cmdQueryValidPaths
359-
<< false // lock
360-
<< maybeSubstitute;
361-
worker_proto::write(*this, conn->to, paths);
362-
conn->to.flush();
363-
364-
return worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
354+
return serve_proto::queryValidPaths(*conn, *this,
355+
false, paths, maybeSubstitute);
365356
}
366357

367358
void connect() override
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "serve-protocol-impl.hh"
2+
3+
#include "remote-store.hh"
4+
5+
namespace nix {
6+
namespace serve_proto {
7+
8+
StorePathSet queryValidPaths(
9+
BasicConnection & conn, const Store & remoteStore,
10+
bool lock, const StorePathSet & paths,
11+
SubstituteFlag maybeSubstitute)
12+
{
13+
conn.to
14+
<< cmdQueryValidPaths
15+
<< lock
16+
<< maybeSubstitute;
17+
worker_proto::write(remoteStore, conn.to, paths);
18+
conn.to.flush();
19+
20+
return worker_proto::read(remoteStore, conn.from, Phantom<StorePathSet> {});
21+
}
22+
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include "serialise.hh"
4+
5+
#include "store-api.hh"
6+
#include "serve-protocol.hh"
7+
#include "worker-protocol.hh"
8+
9+
namespace nix {
10+
namespace serve_proto {
11+
12+
struct BasicConnection
13+
{
14+
FdSink to;
15+
FdSource from;
16+
int remoteVersion;
17+
};
18+
19+
StorePathSet queryValidPaths(
20+
BasicConnection & conn, const Store & remoteStore,
21+
bool lock, const StorePathSet & paths,
22+
SubstituteFlag maybeSubstitute);
23+
24+
}
25+
}

0 commit comments

Comments
 (0)