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
13use std::fmt;
14use std::sync::atomic::{AtomicU64, Ordering};
15
16/// Labels a session or a message in log lines and nothing else. Sessions get
17/// a process-local number the peer never sees. The type derives no equality
18/// or hashing and exposes no number, so nothing can route or match on it.
19#[derive(Clone, Copy, Debug, Default)]
20pub(crate) struct LogId(u64);
21
22impl From<u64> for LogId {
23    fn from(id: u64) -> Self {
24        Self(id)
25    }
26}
27
28impl fmt::Display for LogId {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        self.0.fmt(f)
31    }
32}
33
34/// Numbers the sessions of every client and server in the process, so log
35/// lines can be followed from a session's establishment to its end.
36static SESSIONS: AtomicU64 = AtomicU64::new(0);
37
38/// Allocates the next session label, starting from one.
39pub(crate) fn next_log_id() -> LogId {
40    LogId(SESSIONS.fetch_add(1, Ordering::Relaxed) + 1)
41}
42
43#[cfg(test)]
44#[cfg_attr(coverage_nightly, coverage(off))]
45mod testing;