diff options
author | Picnoir <picnoir@alternativebit.fr> | 2024-03-21T15·12+0100 |
---|---|---|
committer | picnoir picnoir <picnoir@alternativebit.fr> | 2024-04-03T11·32+0000 |
commit | 08cc27cc20d88d1df034e5cb384bdfe694ef5295 (patch) | |
tree | 754190ac9807b0cfda97b6b223d218bd53f2dd9e /tvix/nix-compat/src/wire/worker_protocol.rs | |
parent | 017ff431fe0b3c860e4ddb45e54bbd8b3b2b459d (diff) |
feat(tvix/nix-compat): introduce write_worker_trust_level r/7844
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 <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/wire/worker_protocol.rs')
-rw-r--r-- | tvix/nix-compat/src/wire/worker_protocol.rs | 22 |
1 files changed, 22 insertions, 0 deletions
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: AsyncWriteExt + Unpin>(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<W>(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, + } +} |