mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 22:32:26 +00:00
Factor our ServeProto::BasicServerConnection::handshake
We'll need this for unit testing. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
4a5ca576da
commit
e960b28230
@ -22,6 +22,18 @@ ServeProto::Version ServeProto::BasicClientConnection::handshake(
|
||||
return remoteVersion;
|
||||
}
|
||||
|
||||
ServeProto::Version ServeProto::BasicServerConnection::handshake(
|
||||
BufferedSink & to,
|
||||
Source & from,
|
||||
ServeProto::Version localVersion)
|
||||
{
|
||||
unsigned int magic = readInt(from);
|
||||
if (magic != SERVE_MAGIC_1) throw Error("protocol mismatch");
|
||||
to << SERVE_MAGIC_2 << localVersion;
|
||||
to.flush();
|
||||
return readInt(from);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet ServeProto::BasicClientConnection::queryValidPaths(
|
||||
const Store & store,
|
||||
|
@ -132,4 +132,26 @@ struct ServeProto::BasicClientConnection
|
||||
const ServeProto::BuildOptions & options);
|
||||
};
|
||||
|
||||
struct ServeProto::BasicServerConnection
|
||||
{
|
||||
/**
|
||||
* Establishes connection, negotiating version.
|
||||
*
|
||||
* @return the version provided by the other side of the
|
||||
* connection.
|
||||
*
|
||||
* @param to Taken by reference to allow for various error handling
|
||||
* mechanisms.
|
||||
*
|
||||
* @param from Taken by reference to allow for various error
|
||||
* handling mechanisms.
|
||||
*
|
||||
* @param localVersion Our version which is sent over
|
||||
*/
|
||||
static ServeProto::Version handshake(
|
||||
BufferedSink & to,
|
||||
Source & from,
|
||||
ServeProto::Version localVersion);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ struct ServeProto
|
||||
* @todo remove once Hydra uses Store abstraction consistently.
|
||||
*/
|
||||
struct BasicClientConnection;
|
||||
struct BasicServerConnection;
|
||||
|
||||
/**
|
||||
* Data type for canonical pairs of serialisers for the serve protocol.
|
||||
|
@ -828,11 +828,9 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||
FdSink out(STDOUT_FILENO);
|
||||
|
||||
/* Exchange the greeting. */
|
||||
unsigned int magic = readInt(in);
|
||||
if (magic != SERVE_MAGIC_1) throw Error("protocol mismatch");
|
||||
out << SERVE_MAGIC_2 << SERVE_PROTOCOL_VERSION;
|
||||
out.flush();
|
||||
ServeProto::Version clientVersion = readInt(in);
|
||||
ServeProto::Version clientVersion =
|
||||
ServeProto::BasicServerConnection::handshake(
|
||||
out, in, SERVE_PROTOCOL_VERSION);
|
||||
|
||||
ServeProto::ReadConn rconn {
|
||||
.from = in,
|
||||
|
Loading…
Reference in New Issue
Block a user