From 08cc27cc20d88d1df034e5cb384bdfe694ef5295 Mon Sep 17 00:00:00 2001 From: Picnoir Date: Thu, 21 Mar 2024 16:12:18 +0100 Subject: feat(tvix/nix-compat): introduce write_worker_trust_level This is used by the nix client to determine whether or not the daemon trust it. The trust conditions check are daemon-specific, hence not part of nix-compat. Change-Id: Icbcba2f7f1fd58f67e7da72d22a264f5a3f3619d Reviewed-on: https://cl.tvl.fyi/c/depot/+/11231 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/wire/worker_protocol.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tvix/nix-compat/src') diff --git a/tvix/nix-compat/src/wire/worker_protocol.rs b/tvix/nix-compat/src/wire/worker_protocol.rs index 82f227c72362..3d891068eab7 100644 --- a/tvix/nix-compat/src/wire/worker_protocol.rs +++ b/tvix/nix-compat/src/wire/worker_protocol.rs @@ -81,3 +81,25 @@ pub async fn write_op(w: &mut W, op: &Operation) -> st ))?; w.write_u64(op).await } + +#[derive(Debug, PartialEq)] +pub enum Trust { + Trusted, + NotTrusted, +} + +/// Write the worker [Trust] level to the wire. +/// +/// Cpp Nix has a legacy third option: u8 0. This option is meant to +/// be used as a backward compatible measure. Since we're not +/// targetting protocol versions pre-dating the trust notion, we +/// decided not to implement it here. +pub async fn write_worker_trust_level(conn: &mut W, t: Trust) -> std::io::Result<()> +where + W: AsyncReadExt + AsyncWriteExt + Unpin + std::fmt::Debug, +{ + match t { + Trust::Trusted => primitive::write_u64(conn, 1).await, + Trust::NotTrusted => primitive::write_u64(conn, 2).await, + } +} -- cgit 1.4.1