about summary refs log tree commit diff
path: root/users/picnoir/tvix-daemon/src/main.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-04-08T08·31+0300
committerclbot <clbot@tvl.fyi>2024-04-08T08·40+0000
commitc05f90e611c9e0e74fbedeff97cf6ca768264d64 (patch)
treee4a19ed322bf9bd031db6ebf226bb138beadfb41 /users/picnoir/tvix-daemon/src/main.rs
parentfd749070e29bd3856e5923136ea97260d933e3db (diff)
refactor(tvix/nix-compat/wire): express magics as u64 r/7875
This allows using read_u64, write_u64, which is a bit easier to juggle
with.

Also, update names to align with the nix codebase, which makes it easier
to spot both the constant name as well as the value.
Leave the ASCII interpretation as a comment afterwards.

Change-Id: I0b9ab187acd22807e2785b0722aa4300dab37c51
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11378
Tested-by: BuildkiteCI
Reviewed-by: picnoir picnoir <picnoir@alternativebit.fr>
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to '')
-rw-r--r--users/picnoir/tvix-daemon/src/main.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/users/picnoir/tvix-daemon/src/main.rs b/users/picnoir/tvix-daemon/src/main.rs
index 46cb813e3e..398c8af01f 100644
--- a/users/picnoir/tvix-daemon/src/main.rs
+++ b/users/picnoir/tvix-daemon/src/main.rs
@@ -124,20 +124,17 @@ async fn perform_init_handshake<'a, R: 'a>(
 where
     &'a mut R: AsyncReadExt + AsyncWriteExt + Unpin + std::fmt::Debug,
 {
-    let mut magic_hello = vec![0; 8];
-    conn.read_exact(&mut magic_hello).await?;
+    let worker_magic_1 = primitive::read_u64(&mut conn).await?;
     debug!("Hello read");
-    if magic_hello != worker_protocol::MAGIC_HELLO {
+    if worker_magic_1 != worker_protocol::WORKER_MAGIC_1 {
         Err(anyhow!(
             "Invalid client hello received: {:?}, expected {:?}",
-            magic_hello,
-            worker_protocol::MAGIC_HELLO
+            worker_magic_1,
+            worker_protocol::WORKER_MAGIC_1
         ))
     } else {
-        conn.write_all(&worker_protocol::MAGIC_HELLO_RESPONSE[..])
-            .await?;
-        conn.write_all(&worker_protocol::PROTOCOL_VERSION[..])
-            .await?;
+        primitive::write_u64(&mut conn, worker_protocol::WORKER_MAGIC_2).await?;
+        primitive::write_u64(&mut conn, worker_protocol::PROTOCOL_VERSION).await?;
         conn.flush().await?;
         debug!("Hello responded");
         let client_version = primitive::read_u64(&mut conn).await?;
@@ -198,12 +195,12 @@ mod integration_tests {
     #[tokio::test]
     async fn test_init_handshake() {
         let mut test_conn = tokio_test::io::Builder::new()
-            .read(&worker_protocol::MAGIC_HELLO)
-            .write(&worker_protocol::MAGIC_HELLO_RESPONSE)
-            .write(&worker_protocol::PROTOCOL_VERSION)
+            .read(&worker_protocol::WORKER_MAGIC_1.to_le_bytes())
+            .write(&worker_protocol::WORKER_MAGIC_2.to_le_bytes())
+            .write(&worker_protocol::PROTOCOL_VERSION.to_le_bytes())
             // Let's say the client is in sync with the daemon
             // protocol-wise
-            .read(&worker_protocol::PROTOCOL_VERSION)
+            .read(&worker_protocol::PROTOCOL_VERSION.to_le_bytes())
             // cpu affinity
             .read(&vec![0; 8])
             // reservespace