diff options
Diffstat (limited to 'src/transport/identity.rs')
| -rw-r--r-- | src/transport/identity.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/transport/identity.rs b/src/transport/identity.rs index dd3950b..5857fb0 100644 --- a/src/transport/identity.rs +++ b/src/transport/identity.rs @@ -95,7 +95,7 @@ pub(crate) struct IdentityTransport { } struct Shared { - paths: Paths, + paths: Arc<Paths>, key: Arc<NodeKey>, node_id: String, /// WHO and ME are counted here, under the address (`traffic`). @@ -214,11 +214,12 @@ impl IdentityTransport { traffic: Arc<Traffic>, ) -> Self { let node_id = config.key.id(); - let paths = Paths::new( + let paths = Arc::new(Paths::new( std::iter::once((config.scheme, transport)) .chain(config.more) .collect(), - ); + Some(Arc::clone(&traffic)), + )); Self { shared: Arc::new(Shared { paths, @@ -443,20 +444,20 @@ impl Transport for IdentityTransport { self.shared.paths.transports() } - /// The address `encode` picks, and the transport's connection there. + /// The address `encode` picks, the transport's connection there, and every path + /// to `peer` as paths measures it, best first. fn destination(&self, peer: &str) -> Option<Destination> { - let address = self.shared.destination(peer)?; - let proven = self - .shared - .lock() - .proven - .get(peer) - .is_some_and(|addresses| addresses.contains(&address)); + let proven = self.shared.proven_at(peer); + let (address, is_proven) = match proven.first() { + Some(address) => (address.clone(), true), + None => (self.shared.hinted_at(peer).into_iter().next()?, false), + }; let connection = self.shared.paths.connection(&address); Some(Destination { address, - proven, + proven: is_proven, connection, + paths: self.shared.paths.info(&proven), }) } |
