From 276f936fc8730504666fbf1c3c5b2942f9be9016 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 23 Oct 2026 22:12:20 +0200 Subject: enrich keepalive content Add ready and syncs_with_you flags as well as actual heads, so the peer - ready: same meaning as in the sync message - syncs_with_you: sender counts recipient as member and in same epoch - heads: allows to tell who's behind or if both sides have changes --- src/state.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index 23892a9..72013b9 100644 --- a/src/state.rs +++ b/src/state.rs @@ -121,8 +121,11 @@ pub(crate) struct PeerState { /// Epoch the peer advertised in its most recent message. pub(crate) epoch: Option, - /// Whether the peer was ready according to its most recent sync message. + /// Whether the peer was ready according to its most recent sync message or keepalive. pub(crate) reports_ready: Option, + + /// Whether the peer said, in its most recent keepalive, that it would sync with us. + pub(crate) syncs_with_us: Option, } /// One Automerge sync with a peer, from a reset to the next. Everything a reset must @@ -326,6 +329,7 @@ impl PeerState { last_resync_at: None, epoch: None, reports_ready: None, + syncs_with_us: None, } } @@ -431,8 +435,8 @@ impl PeerState { /// Self-healing check on PING/PONG. Returns true if a re-handshake should start. pub(crate) fn needs_heal( &mut self, - local: &transport::HeadsDigest, - remote: &transport::HeadsDigest, + local: &transport::HeadsSummary, + remote: &transport::HeadsSummary, timing: &Timing, now: Instant, ) -> bool { @@ -792,11 +796,11 @@ impl AppState { } } - let keepalive = crate::swarm::peer::local_keepalive(self).await; for id in announce { + let keepalive = crate::swarm::peer::local_keepalive(self, id).await; if let Err(error) = self .transport - .send_message(id, &transport::ParsedMessage::Ping(keepalive.clone())) + .send_message(id, &transport::ParsedMessage::Ping(keepalive)) .await { debug!(peer = %id, error = %format!("{error:#}"), "Epoch announcement failed"); -- cgit v1.3.1