Skip to main content

darkbio_wire/
lib.rs

1// wire-rs: encrypted protocol between Ark and host
2// Copyright 2025 Dark Bio AG. All rights reserved.
3
4// Allow excluding test code from coverage measurements on nightly
5#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
6// Pull in the README as the package doc
7#![doc = include_str!("../README.md")]
8
9pub mod memory;
10pub mod protocol;
11pub mod transport;
12
13// The crates whose types appear in this crate's API, re-exported so consumers
14// can name them at the exact versions this crate was compiled against
15pub use darkbio_cobs as cobs;
16pub use darkbio_crypto as crypto;
17pub use darkbio_trust as trust;
18pub use prost;
19
20use std::fmt;
21use std::sync::atomic::{AtomicU64, Ordering};
22
23/// Labels a session or a message in log lines and nothing else. Sessions get
24/// a process-local number the peer never sees. The type derives no equality
25/// or hashing and exposes no number, so nothing can route or match on it.
26#[derive(Clone, Copy, Debug, Default)]
27pub(crate) struct LogId(u64);
28
29impl From<u64> for LogId {
30    fn from(id: u64) -> Self {
31        Self(id)
32    }
33}
34
35impl fmt::Display for LogId {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        self.0.fmt(f)
38    }
39}
40
41/// Numbers the sessions of every client and server in the process, so log
42/// lines can be followed from a session's establishment to its end.
43static SESSIONS: AtomicU64 = AtomicU64::new(0);
44
45/// Allocates the next session label, starting from one.
46pub(crate) fn next_log_id() -> LogId {
47    LogId(SESSIONS.fetch_add(1, Ordering::Relaxed) + 1)
48}
49
50#[cfg(test)]
51#[cfg_attr(coverage_nightly, coverage(off))]
52mod testing;