From c3fde0fdd410902125f006f0a7d77ca030cb9061 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 7 Nov 2026 22:35:21 +0100 Subject: signatures: on their own (SIGNATURES) Signatures no sync message took go on their own within a second, to each peer not sent them yet (wire version bumped). Auth plan M5. --- src/transport/mod.rs | 16 ++++++++++++++++ src/transport/traffic.rs | 6 ++++++ src/transport/wire.rs | 13 +++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/transport') diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 35e1e5f..a1fb9d5 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -252,6 +252,19 @@ pub(crate) enum ParsedMessage { NeighbourReply(NeighbourAnswer), /// Tells the recipient we are neighbours no more (`swarm::hyparview`). Disconnect(NeighbourAnswer), + /// Signatures of changes, sent on their own (`swarm::signatures`). + Signatures(SignaturesMessage), +} + +/// SIGNATURES: signatures of changes no sync message took (`swarm::signatures`). +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct SignaturesMessage { + #[serde(with = "crate::transport::wire::codec::epoch")] + pub(crate) epoch: Epoch, + /// See `SyncEnvelope::epoch_seq`. + pub(crate) epoch_seq: u32, + /// As `SyncEnvelope::signatures`. + pub(crate) signatures: serde_bytes::ByteBuf, } /// A node's proof that it holds the key of its node ID (`identity`), sending from its @@ -399,6 +412,7 @@ pub(crate) enum MessageKind { Neighbour, NeighbourReply, Disconnect, + Signatures, } impl ParsedMessage { @@ -421,6 +435,7 @@ impl ParsedMessage { ParsedMessage::Neighbour(_) => MessageKind::Neighbour, ParsedMessage::NeighbourReply(_) => MessageKind::NeighbourReply, ParsedMessage::Disconnect(_) => MessageKind::Disconnect, + ParsedMessage::Signatures(_) => MessageKind::Signatures, } } @@ -446,6 +461,7 @@ impl ParsedMessage { ParsedMessage::NeighbourReply(answer) | ParsedMessage::Disconnect(answer) => { Some((answer.epoch, answer.epoch_seq)) } + ParsedMessage::Signatures(message) => Some((message.epoch, message.epoch_seq)), ParsedMessage::Who(_) | ParsedMessage::Me(_) | ParsedMessage::Ping(_) diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs index 13ca9fa..180d3b5 100644 --- a/src/transport/traffic.rs +++ b/src/transport/traffic.rs @@ -57,6 +57,8 @@ pub(crate) struct ByKind { pub(crate) plumtree: Counter, /// NEIGHBOUR, NEIGHBOUR_REPLY and DISCONNECT (`swarm::hyparview`). pub(crate) hyparview: Counter, + /// SIGNATURES (`swarm::signatures`). + pub(crate) signatures: Counter, } impl ByKind { @@ -73,6 +75,7 @@ impl ByKind { MessageKind::Probe, MessageKind::Prune, MessageKind::Neighbour, + MessageKind::Signatures, ] { let theirs = *other.get(kind); self.get_mut(kind).absorb(theirs); @@ -94,6 +97,7 @@ impl ByKind { MessageKind::Neighbour | MessageKind::NeighbourReply | MessageKind::Disconnect => { &self.hyparview } + MessageKind::Signatures => &self.signatures, } } @@ -112,6 +116,7 @@ impl ByKind { MessageKind::Neighbour | MessageKind::NeighbourReply | MessageKind::Disconnect => { &mut self.hyparview } + MessageKind::Signatures => &mut self.signatures, } } } @@ -321,6 +326,7 @@ fn names(kind: MessageKind) -> (&'static str, &'static str) { MessageKind::Neighbour => ("NEIGHBOUR", "hyparview"), MessageKind::NeighbourReply => ("NEIGHBOUR_REPLY", "hyparview"), MessageKind::Disconnect => ("DISCONNECT", "hyparview"), + MessageKind::Signatures => ("SIGNATURES", "signatures"), } } diff --git a/src/transport/wire.rs b/src/transport/wire.rs index 97f8819..88b2916 100644 --- a/src/transport/wire.rs +++ b/src/transport/wire.rs @@ -14,7 +14,7 @@ use super::{EncodedMessage, MessageKind, ParsedMessage}; /// The wire format's version, the first byte of every payload. Bump it with every change /// to a message type or a codec (`golden_bytes` fails then). -pub(crate) const VERSION: u8 = 40; +pub(crate) const VERSION: u8 = 41; /// What the second byte of a payload says. fn tag(kind: MessageKind) -> u8 { @@ -36,6 +36,7 @@ fn tag(kind: MessageKind) -> u8 { MessageKind::Neighbour => 16, MessageKind::NeighbourReply => 17, MessageKind::Disconnect => 18, + MessageKind::Signatures => 19, } } @@ -97,6 +98,7 @@ pub(crate) fn encode(message: &ParsedMessage) -> Result, WireError> { ParsedMessage::NeighbourReply(answer) | ParsedMessage::Disconnect(answer) => { rmp_serde::encode::write(&mut payload, answer)? } + ParsedMessage::Signatures(message) => rmp_serde::encode::write(&mut payload, message)?, } Ok(payload) } @@ -176,6 +178,8 @@ pub(crate) fn decode(payload: &[u8]) -> Result { ParsedMessage::NeighbourReply(rmp_serde::from_slice(body)?) } else if is(MessageKind::Disconnect) { ParsedMessage::Disconnect(rmp_serde::from_slice(body)?) + } else if is(MessageKind::Signatures) { + ParsedMessage::Signatures(rmp_serde::from_slice(body)?) } else { return Err(WireError::UnknownKind(kind)); }) @@ -535,6 +539,11 @@ pub(crate) fn samples() -> Vec { epoch_seq: 1, agreed: false, }), + ParsedMessage::Signatures(crate::transport::SignaturesMessage { + epoch, + epoch_seq: 1, + signatures: serde_bytes::ByteBuf::from(vec![9; 96]), + }), ] } @@ -566,7 +575,7 @@ mod tests { #[test] fn every_kind_round_trips() { let samples = samples(); - assert_eq!(samples.len(), 17, "a kind is missing from `samples`"); + assert_eq!(samples.len(), 18, "a kind is missing from `samples`"); for message in samples { let bytes = encode(&message).unwrap(); let decoded = decode(&bytes).unwrap(); -- cgit v1.3.1