diff options
author | Florian Klink <flokli@flokli.de> | 2024-04-07T21·52+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-04-08T07·02+0000 |
commit | fd749070e29bd3856e5923136ea97260d933e3db (patch) | |
tree | 7207bb9576ec9ac872439444a04cb4de8be93af2 /users/picnoir/tvix-daemon | |
parent | 71a3855f0990cbdadfa5ff109db62912e5f3e320 (diff) |
refactor(tvix/nix-compat/wire): move magic bytes to worker_protocol r/7874
`primitive.rs` implements reading and writing primitive (fixed-length) types in the wire format, used in the the nix daemon protocol and NAR format. Move worker-protocol specific magic bytes to worker_protocol.rs (and possibly further split there once needed) Change-Id: If681c01e9460294619f1d000229b81f0ac745810 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11377 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: picnoir picnoir <picnoir@alternativebit.fr>
Diffstat (limited to 'users/picnoir/tvix-daemon')
-rw-r--r-- | users/picnoir/tvix-daemon/src/main.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/users/picnoir/tvix-daemon/src/main.rs b/users/picnoir/tvix-daemon/src/main.rs index d18ff2471309..46cb813e3e38 100644 --- a/users/picnoir/tvix-daemon/src/main.rs +++ b/users/picnoir/tvix-daemon/src/main.rs @@ -127,15 +127,17 @@ where let mut magic_hello = vec![0; 8]; conn.read_exact(&mut magic_hello).await?; debug!("Hello read"); - if magic_hello != primitive::MAGIC_HELLO { + if magic_hello != worker_protocol::MAGIC_HELLO { Err(anyhow!( "Invalid client hello received: {:?}, expected {:?}", magic_hello, - primitive::MAGIC_HELLO + worker_protocol::MAGIC_HELLO )) } else { - conn.write_all(&primitive::MAGIC_HELLO_RESPONSE).await?; - conn.write_all(&primitive::PROTOCOL_VERSION).await?; + conn.write_all(&worker_protocol::MAGIC_HELLO_RESPONSE[..]) + .await?; + conn.write_all(&worker_protocol::PROTOCOL_VERSION[..]) + .await?; conn.flush().await?; debug!("Hello responded"); let client_version = primitive::read_u64(&mut conn).await?; @@ -192,16 +194,16 @@ where #[cfg(test)] mod integration_tests { - use nix_compat::wire::primitive; + use nix_compat::wire::worker_protocol; #[tokio::test] async fn test_init_handshake() { let mut test_conn = tokio_test::io::Builder::new() - .read(&primitive::MAGIC_HELLO) - .write(&primitive::MAGIC_HELLO_RESPONSE) - .write(&primitive::PROTOCOL_VERSION) + .read(&worker_protocol::MAGIC_HELLO) + .write(&worker_protocol::MAGIC_HELLO_RESPONSE) + .write(&worker_protocol::PROTOCOL_VERSION) // Let's say the client is in sync with the daemon // protocol-wise - .read(&primitive::PROTOCOL_VERSION) + .read(&worker_protocol::PROTOCOL_VERSION) // cpu affinity .read(&vec![0; 8]) // reservespace |