From 59e889254b1fda2dcc8e3e6d596635d1b77f589f Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 17:44:03 +0000 Subject: 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. --- src/transport/sim.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/transport/sim.rs') diff --git a/src/transport/sim.rs b/src/transport/sim.rs index 40a1f7d..5d55e32 100644 --- a/src/transport/sim.rs +++ b/src/transport/sim.rs @@ -327,7 +327,7 @@ impl SimNet { /// net. For messages a real node wouldn't send at that moment, e.g. one sent long /// ago and delivered late. pub(crate) async fn inject(&self, from: &str, to: &str, message: &ParsedMessage) -> Result<()> { - let encoded = (self.codec.encode)(to, message)?; + let encoded = (self.codec.encode)(to, message, super::wire::VERSION)?; let (handled_tx, handled_rx) = oneshot::channel(); let delivery = Delivery { from: from.to_owned(), @@ -368,7 +368,7 @@ pub(crate) struct SimTransport { /// around it (Mycelium's: `mycelium::CODEC`), so a whole swarm runs on that envelope. #[derive(Clone, Copy)] pub(crate) struct Codec { - pub(crate) encode: fn(&str, &ParsedMessage) -> Result, + pub(crate) encode: fn(&str, &ParsedMessage, u8) -> Result, pub(crate) decode: fn(&[u8]) -> Result, } @@ -378,8 +378,8 @@ pub(crate) const WIRE: Codec = Codec { decode: wire_decode, }; -fn wire_encode(peer: &str, message: &ParsedMessage) -> Result { - super::wire::encoded(peer, message) +fn wire_encode(peer: &str, message: &ParsedMessage, version: u8) -> Result { + super::wire::encoded_in(peer, message, version) } fn wire_decode(body: &[u8]) -> Result { @@ -410,8 +410,13 @@ impl Transport for SimTransport { } } - fn encode(&self, peer: &str, message: &ParsedMessage) -> Result { - (self.net.codec.encode)(peer, message) + fn encode_in( + &self, + peer: &str, + message: &ParsedMessage, + version: u8, + ) -> Result { + (self.net.codec.encode)(peer, message, version) } /// Always accepted: the net loses messages silently, like Mycelium once it has -- cgit v1.3.1