diff options
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/peer.rs | 10 | ||||
| -rw-r--r-- | src/swarm/sync.rs | 11 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/swarm/peer.rs b/src/swarm/peer.rs index 836a967..1e8b91d 100644 --- a/src/swarm/peer.rs +++ b/src/swarm/peer.rs @@ -13,7 +13,7 @@ use tracing::{debug, info, instrument, trace, warn}; use crate::document::replica::{Epoch, EpochRelation}; use crate::document::store::{self, StoreError}; -use crate::state::{AppState, HelloState, Liveness, PeerState, Standing}; +use crate::state::{AppState, HelloState, Liveness, PeerState, SessionCause, Standing}; use crate::swarm::sync::{SyncEvent, handle_sync}; use crate::transport::{self, ParsedMessage}; @@ -503,7 +503,7 @@ async fn establish_peer( // Duplicate replies (caused by our own retries) don't reset again. if peer_state.hello_state != HelloState::Established { peer_state.hello_state = HelloState::Established; - peer_state.reset_sync(); + peer_state.reset_sync(SessionCause::HandshakeComplete); info!(peer = %peer, "Handshake complete; sync state reset"); } @@ -539,7 +539,7 @@ async fn observe_peer_epoch(state: &AppState, peer: &str, remote: Epoch) -> bool // The peer switched documents; our sync state describes its old one. Count // the restart as sync activity, so the keepalive heal doesn't re-handshake // (resetting both sides again) while this fresh sync is under way. - peer_state.reset_sync(); + peer_state.reset_sync(SessionCause::PeerEpochChanged); peer_state.last_sync_rx = Some(Instant::now()); } previous @@ -623,7 +623,7 @@ async fn admit(state: &AppState, peer: &str, message: &ParsedMessage) -> bool { } peer_state.standing = Standing::Stranger; peer_state.hello_state = HelloState::NotSent; - peer_state.reset_sync(); + peer_state.reset_sync(SessionCause::KeyRejected); } // The one place an operator can see why a node can't join: rate limited, // since anyone can send us handshakes. @@ -690,7 +690,7 @@ pub(crate) async fn handle_message( { let peer_state_mutex = state.get_or_create_peer_state(&peer).await; let mut peer_state = peer_state_mutex.lock().await; - peer_state.reset_sync(); + peer_state.reset_sync(SessionCause::PeerHello); peer_state.reply_owed = true; } diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 1335361..dc2e665 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -63,7 +63,8 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str, retry_delivery: bool }; if !retry_delivery { - if let Some(wait) = peer_state.sync.opening_wait(Instant::now()) { + let now = Instant::now(); + if let Some(wait) = peer_state.sync.opening_wait(now) { trace!( wait_ms = wait.as_millis(), "Leaving the opening sync message to the peer" @@ -76,6 +77,14 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str, retry_delivery: bool }); return Ok(()); } + if peer_state.sync.opening_overdue(now) { + debug!( + cause = ?peer_state.sync.cause, + reply_owed = peer_state.reply_owed, + likely = peer_state.sync.cause.missing_opening_hint(), + "The peer didn't open the sync within the grace period; opening ourselves" + ); + } } swarm_id.clone() |
