feat(tvix/nix-compat/nix_daemon/version): add ProtocolVersion

This provides a nice wrapper struct to deal with versions.

Change-Id: I6acc03bc9f8d84a0583196073b52776c45d3fe92
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11454
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: picnoir picnoir <picnoir@alternativebit.fr>
This commit is contained in:
Florian Klink 2024-04-18 12:36:08 +03:00 committed by clbot
parent 2c884b8bd2
commit cf86a098cf
5 changed files with 160 additions and 27 deletions

View file

@ -3,8 +3,8 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio_listener::{self, SystemOptions, UserOptions};
use tracing::{debug, error, info, instrument, Level};
use nix_compat::wire;
use nix_compat::worker_protocol::{self, server_handshake_client, ClientSettings, Trust};
use nix_compat::{wire, ProtocolVersion};
#[derive(Parser, Debug)]
struct Cli {
@ -55,7 +55,7 @@ async fn main() {
#[derive(Debug)]
struct ClientConnection<R: AsyncReadExt + AsyncWriteExt + Unpin> {
pub conn: R,
pub version_minor: u64,
pub version: ProtocolVersion,
pub client_settings: Option<ClientSettings>,
}
@ -70,7 +70,7 @@ where
Ok(client_protocol_version) => {
let mut client_connection = ClientConnection {
conn,
version_minor: client_protocol_version,
version: client_protocol_version,
client_settings: None,
};
debug!("Client hanshake succeeded");
@ -106,8 +106,7 @@ async fn op_set_options<R>(conn: &mut ClientConnection<R>) -> std::io::Result<Cl
where
R: AsyncReadExt + AsyncWriteExt + Unpin + std::fmt::Debug,
{
let settings =
worker_protocol::read_client_settings(&mut conn.conn, conn.version_minor).await?;
let settings = worker_protocol::read_client_settings(&mut conn.conn, conn.version).await?;
// The client expects us to send some logs when we're processing
// the settings. Sending STDERR_LAST signal we're done processing.
wire::write_u64(&mut conn.conn, worker_protocol::STDERR_LAST).await?;