aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/identity.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 03:37:29 +0100
committertv <tv@krebsco.de>2026-10-31 03:37:29 +0100
commit0e13c368f6214dabe99c987a98a990d4e4e0b3c8 (patch)
tree773f49a89ebe1a8fe5ef63cbe17915a95a693250 /src/transport/identity.rs
parent059c9c0a8b6749d382bc9a27a6830373f5064777 (diff)
looking at paths doesn't change them
Diffstat (limited to 'src/transport/identity.rs')
-rw-r--r--src/transport/identity.rs37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/transport/identity.rs b/src/transport/identity.rs
index 886f601..7ce8832 100644
--- a/src/transport/identity.rs
+++ b/src/transport/identity.rs
@@ -453,24 +453,25 @@ impl Shared {
}
/// Where to send to `peer`: an address it proved itself at, else one it is said to
- /// be at; the most preferred transport's first.
- fn destination(&self, peer: &str) -> Option<String> {
- self.proven_at(peer)
+ /// be at; the most preferred transport's first. `sending` as `Paths::rank` has it:
+ /// for a message about to go, or only a look.
+ fn destination(&self, peer: &str, sending: bool) -> Option<String> {
+ self.proven_at(peer, sending)
.into_iter()
.next()
- .or_else(|| self.hinted_at(peer).into_iter().next())
+ .or_else(|| self.hinted_at(peer, sending).into_iter().next())
}
/// The addresses `peer` proved itself at, best first (`Paths::rank`).
- fn proven_at(&self, peer: &str) -> Vec<String> {
+ fn proven_at(&self, peer: &str, sending: bool) -> Vec<String> {
let proven = self.lock().proven.get(peer).cloned().unwrap_or_default();
- self.paths.rank(&proven)
+ self.paths.rank(&proven, sending)
}
/// Where `peer` is said to be, best first.
- fn hinted_at(&self, peer: &str) -> Vec<String> {
+ fn hinted_at(&self, peer: &str, sending: bool) -> Vec<String> {
let hints = self.lock().hints.get(peer).cloned().unwrap_or_default();
- self.paths.rank(&hints)
+ self.paths.rank(&hints, sending)
}
}
@@ -551,7 +552,7 @@ impl Transport for IdentityTransport {
}
fn can_reach(&self, peer: &str) -> bool {
- self.shared.destination(peer).is_some()
+ self.shared.destination(peer, false).is_some()
}
fn transports(&self) -> Vec<String> {
@@ -566,10 +567,13 @@ impl Transport for IdentityTransport {
/// 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 proven = self.shared.proven_at(peer);
+ let proven = self.shared.proven_at(peer, false);
let (address, is_proven) = match proven.first() {
Some(address) => (address.clone(), true),
- None => (self.shared.hinted_at(peer).into_iter().next()?, false),
+ None => (
+ self.shared.hinted_at(peer, false).into_iter().next()?,
+ false,
+ ),
};
let connection = self.shared.paths.connection(&address);
let punching = match connection {
@@ -592,7 +596,7 @@ impl Transport for IdentityTransport {
/// The best path's, where messages to `peer` go.
fn rtt(&self, peer: &str) -> Option<Duration> {
- let address = self.shared.proven_at(peer).into_iter().next()?;
+ let address = self.shared.proven_at(peer, false).into_iter().next()?;
self.shared.paths.rtt(&address)
}
@@ -620,7 +624,7 @@ impl Transport for IdentityTransport {
/// first that does), asked WHO.
async fn resolve_seed(&self, seed: &str) -> Result<String> {
if identity::is_node_id(seed) {
- if self.shared.destination(seed).is_some() {
+ if self.shared.destination(seed, false).is_some() {
return Ok(seed.to_owned());
}
bail!("a node ID alone doesn't say where that node is; give its address");
@@ -656,9 +660,10 @@ impl Transport for IdentityTransport {
}
/// For the address `destination` picks (a send there is refused until `peer`
- /// proved itself there, `send_encoded`).
+ /// proved itself there, `send_encoded`). Only a look at the choice: the send makes
+ /// it (encoding again for another path if it changes).
fn encode(&self, peer: &str, message: &ParsedMessage) -> Result<EncodedMessage> {
- let Some(address) = self.shared.destination(peer) else {
+ let Some(address) = self.shared.destination(peer, false) else {
bail!("no address known for {peer} on this node's transports");
};
let mut encoded = self.shared.paths.encode(&address, message)?;
@@ -669,7 +674,7 @@ impl Transport for IdentityTransport {
/// To the addresses `peer` proved itself at, best first, the next when a send
/// fails (`Paths::send_first`); refused if it proved itself nowhere yet.
async fn send_encoded(&self, message: &EncodedMessage) -> Result<()> {
- let proven = self.shared.proven_at(&message.peer);
+ let proven = self.shared.proven_at(&message.peer, true);
if !proven.is_empty() {
self.shared.ask_other_paths(&message.peer);
}