fix(tvix/nix_compat): Fix nix-daemon handshake

Existing handshake behavior assumed that the server version is always
at least as new as the client. Meaning that the client's version was
always picked the handshake details as well as for further communication

This change removes that assumption and correctly uses
min(server_version, client_version).

Change-Id: Ia5dad4613dd5f69a0aeb6c9d86982f1f36fe1a4c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12722
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vova Kryachko 2024-11-02 17:15:07 +00:00 committed by Vladimir Kryachko
parent 4ec9a4b7df
commit aecf0641a4
2 changed files with 66 additions and 11 deletions

View file

@ -67,14 +67,14 @@ where
R: AsyncReadExt + AsyncWriteExt + Unpin + std::fmt::Debug,
{
match server_handshake_client(&mut conn, "2.18.2", Trust::Trusted).await {
Ok(client_protocol_version) => {
Ok(picked_protocol_version) => {
let mut client_connection = ClientConnection {
conn,
version: client_protocol_version,
version: picked_protocol_version,
client_settings: None,
};
debug!("Client hanshake succeeded");
debug!(client_protocol_version = ?client_protocol_version);
debug!(picked_protocol_version = ?picked_protocol_version);
// TODO: implement logging. For now, we'll just send
// STDERR_LAST, which is good enough to get Nix respond to
// us.