diff options
Diffstat (limited to 'src/transport/wire.rs')
| -rw-r--r-- | src/transport/wire.rs | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/src/transport/wire.rs b/src/transport/wire.rs index abaa408..0b661dd 100644 --- a/src/transport/wire.rs +++ b/src/transport/wire.rs @@ -135,9 +135,9 @@ pub(crate) fn encode(message: &ParsedMessage) -> Result<Vec<u8>, WireError> { const MAX_OTHER_VERSIONS: usize = 1024; /// Senders whose messages are of another wire version (`WireError::Version`): each -/// logged once, at warn level, so two builds that don't speak to each other say so, -/// instead of silently retrying their HELLOs for good. Bounded: anyone can send us -/// anything. +/// logged once, at warn level, so two builds that don't speak to each other say so, and +/// which of them to upgrade, instead of silently retrying their HELLOs for good. Bounded: +/// anyone can send us anything. #[derive(Default)] pub(crate) struct OtherVersions(std::sync::Mutex<std::collections::HashSet<String>>); @@ -155,13 +155,36 @@ impl OtherVersions { tracing::warn!( from = %super::Addressed(scheme, &sender), version, - ours = VERSION, - "Peer speaks another wire version (another build); ignoring its messages" + oldest = OLDEST, + newest = VERSION, + "Peer speaks another wire version: {}; ignoring its messages", + other_build(version) ); } } } +/// Of a peer whose messages are of wire `version`, which this build doesn't speak, what +/// an operator does: upgrade this node where the peer's build is newer, the peer's where +/// it is older. +fn other_build(version: u8) -> String { + let ours = if OLDEST == VERSION { + VERSION.to_string() + } else { + format!("{OLDEST} to {VERSION}") + }; + if version > VERSION { + format!( + "a newer build (wire version {version}; this one speaks {ours}): upgrade this node \ + to talk with it" + ) + } else { + format!( + "an older build (wire version {version}; this one speaks {ours}): upgrade that node" + ) + } +} + pub(crate) fn decode(payload: &[u8]) -> Result<ParsedMessage, WireError> { let (&version, payload) = payload.split_first().ok_or(WireError::Empty)?; if version == SPEAKS { @@ -616,6 +639,20 @@ mod tests { assert!(other.0.lock().unwrap().len() <= MAX_OTHER_VERSIONS); } + /// The warning says which build is the older, the one to upgrade, and both versions. + #[test] + fn the_older_build_is_named() { + let newer = other_build(VERSION + 1); + assert!(newer.contains("upgrade this node"), "{newer}"); + assert!( + newer.contains(&format!("wire version {}", VERSION + 1)), + "{newer}" + ); + assert!(newer.contains(&format!("speaks {VERSION}")), "{newer}"); + let older = other_build(OLDEST - 1); + assert!(older.contains("upgrade that node"), "{older}"); + } + /// Every kind decodes to what was encoded: re-encoded, the same bytes. #[test] fn every_kind_round_trips() { |
