diff options
| author | tv <tv@krebsco.de> | 2026-11-19 17:44:03 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 19:26:01 +0100 |
| commit | 59e889254b1fda2dcc8e3e6d596635d1b77f589f (patch) | |
| tree | 2412dd262e7ae729498eb3300912395b601cd0b6 /src/transport/paths.rs | |
| parent | 180aba9ff89a4a294e284aa281d96adbcfe1b85b (diff) | |
transport: wire versions spoken side by side
A build speaks wire versions OLDEST to VERSION and writes each node the
newest both speak (wire::choose), as the node's SPEAKS says; the oldest
until it says. The identity layer keeps that per address (Book::speaks):
a SPEAKS from an address sets it for the address, and for every address
of the node proven there, and a new address of a node takes it over.
Paths encodes each message for an address in its version
(Transport::encode_in; Transport::encode is the newest).
So that two nodes know what the other speaks once they have proven
themselves to each other, before any other message goes between them, a
SPEAKS goes ahead of every WHO and ME, and WHO and ME are read in every
version from 52 on (wire::PROOFS): their tags and layout never change.
Without that, a node whose oldest version is past the other's couldn't
read its proofs, and the two would never get to the handshake that says
what each speaks. A SPEAKS naming no version this build speaks is logged
as a message of another version is, naming the node to upgrade, the
versions as ranges.
A 0.0.1 node takes a SPEAKS from an address not yet proven for any other
message from there: it drops it, and asks WHO.
This build speaks 52 alone, so nothing it sends changes but the SPEAKS
ahead of the proofs. A release adding a version encodes and decodes the
older ones from their own, frozen, types.
Diffstat (limited to 'src/transport/paths.rs')
| -rw-r--r-- | src/transport/paths.rs | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/transport/paths.rs b/src/transport/paths.rs index f425216..e2d9ec9 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -58,7 +58,7 @@ use crate::clock::{Clock, UnixMillis}; use crate::locks::MutexExt; use crate::transport::stats::{PathCounts, PathInfo, PathsStats, TransportStats}; use crate::transport::traffic::Traffic; -use crate::transport::{Connection, EncodedMessage, ParsedMessage, Transport}; +use crate::transport::{Connection, EncodedMessage, ParsedMessage, Transport, wire}; /// Whether to drop what comes from or goes to an address (the debug firewall, /// `transport::firewall`; the identity layer knows which node is where). @@ -67,6 +67,12 @@ pub(crate) trait Gate: Send + Sync { fn blocks_outbound(&self, address: &str) -> bool; } +/// The wire version to write at an address (`transport::wire`): the newest the node there +/// and this build both speak, as the identity layer heard from it. +pub(crate) trait Versions: Send + Sync { + fn version_at(&self, address: &str) -> u8; +} + /// Called with the sender's address, the message and its `payload_len`. pub(crate) type PathHandler = dyn Fn(String, ParsedMessage, usize) -> std::pin::Pin<Box<dyn Future<Output = Result<()>> + Send>> + Send @@ -547,6 +553,8 @@ pub(crate) struct Paths { traffic: Option<Arc<Traffic>>, /// The debug firewall, if any. gate: Option<Weak<dyn Gate>>, + /// What each address speaks; without, every address is written `wire::OLDEST`. + versions: Option<Weak<dyn Versions>>, /// The node's wall clock, which its PONGs say the time by. clock: Arc<Clock>, /// A std mutex: never held across an await. @@ -555,12 +563,14 @@ pub(crate) struct Paths { impl Paths { /// Over `transports`, by scheme, in order of preference; its own PINGs and PONGs - /// counted in `traffic`, the firewall through `gate`, PONGs stamped by `clock`; - /// paths pinged every `keepalive` at least (`Table::probe_every`). + /// counted in `traffic`, the firewall through `gate`, each address written the wire + /// version `versions` says, PONGs stamped by `clock`; paths pinged every `keepalive` + /// at least (`Table::probe_every`). pub(crate) fn new( transports: Vec<(&'static str, Arc<dyn Transport>)>, traffic: Option<Arc<Traffic>>, gate: Option<Weak<dyn Gate>>, + versions: Option<Weak<dyn Versions>>, clock: Arc<Clock>, keepalive: Duration, ) -> Self { @@ -571,6 +581,7 @@ impl Paths { .collect(), traffic, gate, + versions, clock, table: Mutex::new(Table::new(keepalive)), } @@ -580,6 +591,15 @@ impl Paths { self.gate.as_ref()?.upgrade() } + /// The wire version to write at `address` (`Versions`): the oldest this build speaks, + /// until its node says what it speaks. + pub(crate) fn version_at(&self, address: &str) -> u8 { + self.versions + .as_ref() + .and_then(Weak::upgrade) + .map_or(wire::OLDEST, |versions| versions.version_at(address)) + } + /// The transport `address` is on, and the transport identity at it /// (`Transport::locate`, which notes where that is if the address says); None if no /// transport of ours has its scheme, or it isn't one of that transport's. @@ -825,13 +845,16 @@ impl Paths { Err(anyhow!("{}", failures.join("; "))) } - /// `message` encoded for `address`: `peer` and `address` of the result are - /// `address`, and it keeps the message (to encode it for another address). + /// `message` encoded for `address`, in the wire version it speaks (`version_at`): + /// `peer` and `address` of the result are `address`, and it keeps the message (to + /// encode it for another address). pub(crate) fn encode(&self, address: &str, message: &ParsedMessage) -> Result<EncodedMessage> { let (link, target) = self .split(address) .with_context(|| format!("no transport for {address}"))?; - let mut encoded = link.inner.encode(&target, message)?; + let mut encoded = link + .inner + .encode_in(&target, message, self.version_at(address))?; encoded.peer = address.to_owned(); encoded.address = address.to_owned(); encoded.message = Some(Arc::new(message.clone())); @@ -1195,6 +1218,7 @@ mod tests { ], None, None, + None, Arc::default(), Duration::ZERO, )) @@ -1608,6 +1632,7 @@ mod tests { vec![("sim", net.transport("b") as Arc<dyn Transport>)], None, Some(Arc::downgrade(&gate)), + None, Arc::default(), Duration::ZERO, )); @@ -1615,6 +1640,7 @@ mod tests { vec![("sim", net.transport("a") as Arc<dyn Transport>)], None, None, + None, Arc::default(), Duration::ZERO, )); @@ -1673,8 +1699,13 @@ mod tests { async fn resolve_seed(&self, seed: &str) -> Result<String> { Ok(seed.to_owned()) } - fn encode(&self, peer: &str, message: &ParsedMessage) -> Result<EncodedMessage> { - (crate::transport::sim::WIRE.encode)(peer, message) + fn encode_in( + &self, + peer: &str, + message: &ParsedMessage, + version: u8, + ) -> Result<EncodedMessage> { + (crate::transport::sim::WIRE.encode)(peer, message, version) } async fn send_encoded(&self, _message: &EncodedMessage) -> Result<()> { Err(anyhow!("broken")) @@ -1713,6 +1744,7 @@ mod tests { ], None, None, + None, Arc::default(), Duration::ZERO, ); @@ -1720,6 +1752,7 @@ mod tests { vec![("sim", net.transport("b") as Arc<dyn Transport>)], None, None, + None, Arc::default(), Duration::ZERO, )); |
