umsh_node/
transport.rs

1use umsh_core::PublicKey;
2use umsh_mac::SendOptions;
3
4use crate::ticket::SendProgressTicket;
5
6/// A context through which UMSH frames can be sent.
7///
8/// Both `LocalNode` and `BoundChannel` implement this trait, allowing
9/// generic code over the transport context.
10///
11/// **Important:** `Transport` is a *context* abstraction, not a *security*
12/// abstraction. `LocalNode::send()` produces a unicast frame (destination-
13/// encrypted, only the recipient can decrypt). `BoundChannel::send()`
14/// produces a blind unicast frame (channel-encrypted — any node with the
15/// channel key can decrypt). Generic code over `Transport` must not assume
16/// identical delivery or privacy properties.
17pub trait Transport {
18    type Error;
19
20    /// Send a payload to a specific destination.
21    ///
22    /// - On `LocalNode`: unicast (destination-encrypted)
23    /// - On `BoundChannel`: blind unicast (channel-encrypted)
24    async fn send(
25        &self,
26        to: &PublicKey,
27        payload: &[u8],
28        options: &SendOptions,
29    ) -> Result<SendProgressTicket, Self::Error>;
30
31    /// Send a payload to all reachable nodes in this transport's scope.
32    ///
33    /// - On `LocalNode`: broadcast (unauthenticated)
34    /// - On `BoundChannel`: multicast (channel-encrypted)
35    async fn send_all(
36        &self,
37        payload: &[u8],
38        options: &SendOptions,
39    ) -> Result<SendProgressTicket, Self::Error>;
40}
41
42/// The node a transport context sends through.
43///
44/// Bookkeeping that belongs to the node rather than the carriage—pending
45/// pings, per-peer subscriptions, the MAC's clock and route cache—lives on
46/// [`LocalNode`](crate::LocalNode) whichever way a frame goes out. Reaching it
47/// through this trait is what lets one implementation of ping, identity
48/// requests, and peer subscriptions serve both a plain unicast peer and one
49/// bound to a channel.
50///
51/// Sealed: implemented for `LocalNode` and `BoundChannel` only.
52pub trait NodeAccess: sealed::Sealed {
53    type Backend: crate::mac::MacBackend;
54
55    fn local_node(&self) -> &crate::node::LocalNode<Self::Backend>;
56}
57
58pub(crate) mod sealed {
59    pub trait Sealed {}
60}