From b5f756c3f623c41830aa6129a0fd63bd3f99a7ba Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 27 Oct 2026 05:02:39 +0100 Subject: add transport stats --- src/transport/mod.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/transport/mod.rs') diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 3f77306..10a8ae5 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -18,6 +18,7 @@ pub(crate) mod mycelium; pub(crate) mod p2p; #[cfg(test)] pub(crate) mod sim; +pub(crate) mod stats; pub(crate) mod traffic; pub(crate) mod wire; @@ -330,6 +331,37 @@ pub(crate) struct ListedPeer { pub(crate) addresses: Vec, } +/// Where messages to a peer go now (`Transport::destination`). +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct Destination { + /// As the identity layer keeps it: `:`. + pub(crate) address: String, + /// The peer proved itself there; else it is only said to be there, and sends wait + /// for its proof. + pub(crate) proven: bool, + /// The transport's connection to it, if the transport has connections. + pub(crate) connection: Option, +} + +/// How a transport with connections (libp2p) is connected to a peer. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub(crate) enum Connection { + Direct, + /// Only through a relay. + Relayed, +} + +impl Connection { + pub(crate) fn as_str(self) -> &'static str { + match self { + Self::Direct => "direct", + Self::Relayed => "relayed", + } + } +} + #[derive(Clone, Serialize, Deserialize)] pub(crate) struct HelloReply { pub(crate) swarm_id: String, @@ -584,6 +616,25 @@ pub(crate) trait Transport: Send + Sync { let _ = (peer, addresses); } + /// Where messages to `peer` go now. None if nowhere, and by default, for a + /// transport whose identities are addresses (`peer` is where they go). + fn destination(&self, peer: &str) -> Option { + let _ = peer; + None + } + + /// How this node is connected to `target` (a transport identity), if it is. By + /// default not at all, for a transport without connections (Mycelium). + fn connection(&self, target: &str) -> Option { + let _ = target; + None + } + + /// Figures about the transport itself (`stats`). By default none. + fn stats(&self) -> stats::TransportStats { + stats::TransportStats::default() + } + /// Resolves a seed (anything that leads to a node, e.g. an address) to that node's /// identity, as `local_id` gives it on that node. async fn resolve_seed(&self, seed: &str) -> Result; -- cgit v1.3.1