-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start factoring out the serve protocol for Hydra to share
Factor out `ServeProto::BasicClientConnection` for Hydra to share - `handshake` Separate error handling logic a good bit and make (I hope!) more robust. - `queryValidPaths`: Hydra uses the lock argument differently than Nix, so we un-hard-code it. - `buildDerivationRequest`: Just the request half, as Hydra does some things between requesting and responding.
- Loading branch information
1 parent
4e8483d
commit e6d7ee3
Showing
5 changed files
with
161 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "serve-protocol-impl.hh" | ||
#include "build-result.hh" | ||
#include "derivations.hh" | ||
|
||
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, | ||
SubstituteFlag maybeSubstitute) | ||
{ | ||
to | ||
<< ServeProto::Command::QueryValidPaths | ||
<< lock | ||
<< maybeSubstitute; | ||
write(store, *this, paths); | ||
to.flush(); | ||
|
||
return Serialise<StorePathSet>::read(store, *this); | ||
} | ||
|
||
|
||
void ServeProto::BasicClientConnection::buildDerivationRequest( | ||
const Store & store, | ||
const StorePath & drvPath, const BasicDerivation & drv, | ||
const ServeProto::BuildOptions & options) | ||
{ | ||
to | ||
<< ServeProto::Command::BuildDerivation | ||
<< store.printStorePath(drvPath); | ||
writeDerivation(to, store, drv); | ||
|
||
ServeProto::write(store, *this, options); | ||
|
||
to.flush(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters