diff options
| author | tv <tv@krebsco.de> | 2026-10-30 15:24:41 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-30 15:24:41 +0100 |
| commit | bff42bf27f58bacb8bce58458dea7da74cda2c05 (patch) | |
| tree | f06e584a2237f84007533b964144d45fedd21924 | |
| parent | 4250d9843133d38c7ace1a1b510265a15ebaa0fd (diff) | |
allow dead Connection unless a transport needs it
| -rw-r--r-- | docs/openapi.yaml | 2 | ||||
| -rw-r--r-- | src/transport/mod.rs | 6 | ||||
| -rw-r--r-- | src/transport/tor.rs | 9 |
3 files changed, 15 insertions, 2 deletions
diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 6de726c..1d9a5e9 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1148,7 +1148,7 @@ components: connection: type: [string, 'null'] enum: [direct, relayed, null] - description: The libp2p connection to it; null if none, or on a transport without connections (Mycelium). + description: 'The connection to it: libp2p''s direct or through a relay, Tor''s always direct (an onion circuit, no relay of ours); null if none, or on a transport without connections (Mycelium).' punching: type: object description: 'While it is connected only through a relay and a hole punch failed: how often in a row, and when the next try is (after 1, 5, then every 30 minutes). Absent otherwise.' diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 40fdfc0..b10c799 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -382,9 +382,13 @@ pub(crate) struct Punching { /// How a transport with connections (libp2p) is connected to a peer. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "camelCase")] +// Only libp2p and Tor have connections; without both (the cargo features) nothing makes +// one. +#[cfg_attr(not(any(feature = "libp2p", feature = "tor")), allow(dead_code))] pub(crate) enum Connection { + /// libp2p's to the peer itself; Tor's always (an onion circuit). Direct, - /// Only through a relay. + /// Only through a relay (libp2p). Relayed, } diff --git a/src/transport/tor.rs b/src/transport/tor.rs index 39e0f31..2cf3249 100644 --- a/src/transport/tor.rs +++ b/src/transport/tor.rs @@ -544,6 +544,15 @@ impl Transport for TorTransport { parse_location(target) } + /// Direct while a connection to its onion service is open: an onion circuit, with no + /// relay of ours in between. + fn connection(&self, target: &str) -> Option<crate::transport::Connection> { + let location = parse_location(target)?; + lock(&self.shared.connections) + .contains_key(&location) + .then_some(crate::transport::Connection::Direct) + } + /// An onion service is its own transport identity: nothing to find out. async fn resolve_seed(&self, seed: &str) -> Result<String> { let location = parse_location(seed) |
