1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 19:41:48 +02:00

Factor out ServeProto::BasicClientConnection::handshake Hydra to share

This commit is contained in:
John Ericson 2022-02-20 19:24:07 +00:00
parent 4580bed3e4
commit 4a5ca576da
3 changed files with 43 additions and 9 deletions

View file

@ -4,6 +4,25 @@
namespace nix {
ServeProto::Version ServeProto::BasicClientConnection::handshake(
BufferedSink & to,
Source & from,
ServeProto::Version localVersion,
std::string_view host)
{
to << SERVE_MAGIC_1 << localVersion;
to.flush();
unsigned int magic = readInt(from);
if (magic != SERVE_MAGIC_2)
throw Error("'nix-store --serve' protocol mismatch from '%s'", host);
auto remoteVersion = readInt(from);
if (GET_PROTOCOL_MAJOR(remoteVersion) != 0x200)
throw Error("unsupported 'nix-store --serve' protocol version on '%s'", host);
return remoteVersion;
}
StorePathSet ServeProto::BasicClientConnection::queryValidPaths(
const Store & store,
bool lock, const StorePathSet & paths,