From a1460b0a2861d5bb34ba25d409b234468f269e4e Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 03:19:28 +0200 Subject: use nonce in handshake To prevent stale hello replies to cause joins and thus stale sessions, each run gets a random ID, which used as nonce in the handshake. --- src/transport/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/transport/mod.rs') diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 83c4e8d..e8d654d 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -12,6 +12,9 @@ pub use crate::document::replica::Epoch; pub mod firewall; pub mod mycelium; +/// Random identifier of one run of a node (from start to exit). +pub type RunId = [u8; 16]; + /// Most heads listed in a keepalive; more are sent as a digest. A head takes 34 bytes on /// the wire, so 32 of them keep a keepalive within one Mycelium chunk (1300 bytes; see /// the size test in `mycelium`). There are rarely more heads than nodes that wrote @@ -120,6 +123,8 @@ pub struct HelloRequest { pub auth: Vec, /// The sender is ready (same meaning as `SyncEnvelope::ready`). pub ready: bool, + /// Random per run of the sender; the reply echoes it. + pub run_id: RunId, } #[derive(Debug, Clone)] @@ -131,6 +136,9 @@ pub struct HelloReply { pub auth: Vec, /// The sender is ready. pub ready: bool, + /// The `run_id` of the HELLO answered. A reply to a HELLO from an earlier run of the + /// recipient (delivered late, or queued while it was down) is ignored. + pub run_id: RunId, } #[derive(Debug, Clone)] -- cgit v1.3.1