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// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Allow excluding test code from coverage measurements on nightly
8#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
9// Pull in the README as the package doc
10#![doc = include_str!("../README.md")]
11
12pub mod memory;
13pub mod protocol;
14pub mod transport;
15
16// The crates whose types appear in this crate's API, re-exported so consumers
17// can name them at the exact versions this crate was compiled against
18pub use darkbio_cobs as cobs;
19pub use darkbio_crypto as crypto;
20pub use darkbio_trust as trust;
21pub use prost;
22
23/// Version of the wire crate compiled into this process. It's mostly a debug
24/// utility to help detect protocol version mismatches without having to guess
25/// who compiled what into where.
26pub const VERSION: &str = env!("CARGO_PKG_VERSION");
27
28use std::fmt;
29use std::sync::atomic::{AtomicU64, Ordering};
30
31/// Labels a session or a message in log lines and nothing else. Sessions get
32/// a process-local number the peer never sees. The type derives no equality
33/// or hashing and exposes no number, so nothing can route or match on it.
34#[derive(Clone, Copy, Debug, Default)]
35pub(crate) struct LogId(u64);
36
37impl From<u64> for LogId {
38    fn from(id: u64) -> Self {
39        Self(id)
40    }
41}
42
43impl fmt::Display for LogId {
44    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45        self.0.fmt(f)
46    }
47}
48
49/// Numbers the sessions of every client and server in the process, so log
50/// lines can be followed from a session's establishment to its end.
51static SESSIONS: AtomicU64 = AtomicU64::new(0);
52
53/// Allocates the next session label, starting from one.
54pub(crate) fn next_log_id() -> LogId {
55    LogId(SESSIONS.fetch_add(1, Ordering::Relaxed) + 1)
56}
57
58#[cfg(test)]
59#[cfg_attr(coverage_nightly, coverage(off))]
60mod testing;