Skip to main content

qualia_core_db/net/peer/fabric/
carrier.rs

1//! Path classes and carrier kinds. Adding a carrier must not enlarge disclosure.
2
3use crate::net::peer::connectivity::policy::Disclosure;
4
5/// How packets would reach the counterpart.
6#[repr(u8)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum PathClass {
9    /// Access-network IP would be observable to the counterpart.
10    DirectV6 = 1,
11    DirectV4 = 2,
12    /// Bound/relayed forwarding. The access relay still sees the client source.
13    Relayed = 3,
14    /// Browser WebTransport / WSS to an approved gateway.
15    BrowserGateway = 4,
16    /// Sealed store-and-forward. No live Internet path.
17    Offline = 5,
18}
19
20/// Preferred or compatibility engine. Selection is policy, not a socket grant.
21#[repr(u8)]
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum CarrierKind {
24    NativeQdnf = 1,
25    QuicMasque = 2,
26    Http2Capsule = 3,
27    WireGuardIceWss = 4,
28    Browser = 5,
29    OfflineDurable = 6,
30    /// Nym decentralized mixnet overlay. Zero IP disclosure, operates over Sphinx packets.
31    NymMixnet = 7,
32}
33
34impl PathClass {
35    /// `PathClass::discloses_peer_ip`.
36    pub const fn discloses_peer_ip(self) -> bool {
37        matches!(self, Self::DirectV6 | Self::DirectV4)
38    }
39
40    /// `true` when `live_network`.
41    pub const fn is_live_network(self) -> bool {
42        !matches!(self, Self::Offline)
43    }
44}
45
46/// First filter: a prohibited class never enters scoring.
47pub const fn prohibited(disclosure: Disclosure, class: PathClass) -> bool {
48    match disclosure {
49        Disclosure::DirectPermitted => false,
50        Disclosure::ApprovedRelaysOnly | Disclosure::QualifiedMultiHop => class.discloses_peer_ip(),
51        Disclosure::Isolated => class.is_live_network(),
52    }
53}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn relay_only_forbids_direct_classes() {
61        assert!(prohibited(
62            Disclosure::ApprovedRelaysOnly,
63            PathClass::DirectV6
64        ));
65        assert!(prohibited(
66            Disclosure::ApprovedRelaysOnly,
67            PathClass::DirectV4
68        ));
69        assert!(!prohibited(
70            Disclosure::ApprovedRelaysOnly,
71            PathClass::Relayed
72        ));
73    }
74
75    #[test]
76    fn isolated_forbids_live_paths() {
77        assert!(prohibited(Disclosure::Isolated, PathClass::Relayed));
78        assert!(!prohibited(Disclosure::Isolated, PathClass::Offline));
79    }
80}