diff options
| author | tv <tv@krebsco.de> | 2026-10-29 05:34:25 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-29 05:34:25 +0100 |
| commit | bd21360f874f6e3d002c0840d7f8722e4fa649e9 (patch) | |
| tree | 51fde8bd8e39594bdca5d65dec60835537a52aa1 /src/transport/mod.rs | |
| parent | badd492779e401b5ef4719c14291bcf86df8c80d (diff) | |
libp2p: add punching stats
Diffstat (limited to 'src/transport/mod.rs')
| -rw-r--r-- | src/transport/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/transport/mod.rs b/src/transport/mod.rs index fb13ad9..40fdfc0 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -361,11 +361,24 @@ pub(crate) struct Destination { pub(crate) proven: bool, /// The transport's connection to it, if the transport has connections. pub(crate) connection: Option<Connection>, + /// While it is connected only through a relay: how hole punching went. + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) punching: Option<Punching>, /// Every address it proved itself at, best first, as the paths layer measures them /// (`transport::paths`). pub(crate) paths: Vec<stats::PathInfo>, } +/// Hole punching to a peer connected only through a relay (libp2p), once a punch failed. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct Punching { + /// Punches that failed in a row. + pub(crate) failed: usize, + /// When it is tried again, in seconds from now (0: due). + pub(crate) next_in_secs: u64, +} + /// How a transport with connections (libp2p) is connected to a peer. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "camelCase")] @@ -712,6 +725,13 @@ pub(crate) trait Transport: Send + Sync { None } + /// How hole punching to `target` went, if a punch failed and it is still connected + /// only through a relay (libp2p). By default never. + fn punching(&self, target: &str) -> Option<Punching> { + let _ = target; + None + } + /// The smoothed round-trip time of the path messages to `peer` go over, if /// measured (`transport::paths`). By default none. fn rtt(&self, peer: &str) -> Option<std::time::Duration> { |
