diff options
| author | tv <tv@krebsco.de> | 2026-11-29 04:05:41 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 04:08:47 +0000 |
| commit | 2a475153b715c954935ae46d3773ffbf3d007f03 (patch) | |
| tree | 8ebe8a5d6cdaf9869822f95fe2ac7eca0c10cf7f /src/swarm/relay.rs | |
| parent | 2ae7562083f5f96490f90e9398762cf6a024d51e (diff) | |
document: where a document stands, and a peer, is the document's to compare
document::passing: a Mark, where a document stood, by which what
changed since and the node's own units since are told (changed_since,
own_since: the change publisher, the sync worker); and of where a peer
says it stands, what the document lacks, whether the peer holds what
the document held, a pull of what is lacking, and what it has counting
as sent no more (lacking, peer_holds, pull, heard: the relay,
keepalives). The published stamp gives its summary and its mark.
Diffstat (limited to 'src/swarm/relay.rs')
| -rw-r--r-- | src/swarm/relay.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs index 560a41e..76428f0 100644 --- a/src/swarm/relay.rs +++ b/src/swarm/relay.rs @@ -274,11 +274,10 @@ async fn unreached( 1 => senders.iter().next().cloned(), _ => None, }; - let (epoch, heads) = { + let (epoch, ours, stood) = { let stamp = state.stamp.borrow(); - (stamp.epoch, stamp.heads.to_vec()) + (stamp.epoch, stamp.summary(), stamp.mark()) }; - let ours = HeadsSummary::of(heads.clone()); // What each neighbour said it has. let mut said = Vec::new(); for (peer, peer_state) in state.peers_snapshot().await { @@ -305,7 +304,7 @@ async fn unreached( .filter(|(_, last)| { !last.as_ref().is_some_and(|theirs| { *theirs == ours - || crate::document::changes::covers(&replica.doc, theirs.listed(), &heads) + || crate::document::passing::peer_holds(&replica.doc, theirs, &stood) }) }) .map(|(peer, _)| peer) @@ -326,7 +325,7 @@ pub(crate) struct Pulling { /// Whether we lack any of `heads` (with a digest, any of the sample it lists). pub(crate) async fn lacks(state: &AppState, heads: &HeadsSummary) -> bool { let replica = state.doc.read().await; - !crate::document::changes::missing(&replica.doc, heads.listed()).is_empty() + !crate::document::passing::lacking(&replica.doc, heads).is_empty() } /// A STATUS from `peer` (a keepalive's, or an announcement): if it has heads we lack, @@ -337,14 +336,12 @@ pub(crate) async fn lacks(state: &AppState, heads: &HeadsSummary) -> bool { /// was missed. One wait per peer: a STATUS that comes meanwhile is the one judged at the /// end (`PeerState::pull_pending`). pub(crate) async fn pull_after_grace(state: &AppState, peer: &str, remote: &transport::Status) { - if HeadsSummary::of(state.stamp.borrow().heads.to_vec()) != remote.heads { + if state.stamp.borrow().summary() != remote.heads { let missing = { let replica = state.doc.read().await; - crate::document::changes::missing(&replica.doc, remote.heads.listed()) + crate::document::passing::lacking(&replica.doc, &remote.heads) }; if !missing.is_empty() { - let missing: Vec<crate::document::UnitId> = - missing.into_iter().map(Into::into).collect(); state.dissemination().announced(peer, &missing); let grace = state .lock_rtt() @@ -372,7 +369,7 @@ pub(crate) async fn pull_if_behind( return false; } // The common case, the same heads, needs only the published heads. - let ours = HeadsSummary::of(state.stamp.borrow().heads.to_vec()); + let ours = state.stamp.borrow().summary(); if ours == remote.heads { return false; } @@ -380,17 +377,11 @@ pub(crate) async fn pull_if_behind( // have all of it, a later keepalive lists others. let missing = { let replica = state.doc.read().await; - crate::document::changes::missing(&replica.doc, remote.heads.listed()) + crate::document::passing::lacking(&replica.doc, &remote.heads) }; if missing.is_empty() { return false; } - // All heads, when we know them; otherwise those we lack. - let theirs = match remote.heads.heads() { - Some(heads) => heads.to_vec(), - None => missing, - }; - let Some(peer_state) = state.get_peer_state(peer).await else { return false; }; @@ -420,7 +411,7 @@ pub(crate) async fn pull_if_behind( } // Automerge asks for whatever these heads need that we don't have. - peer_state.lock().await.sync.pull_from(theirs); + crate::document::passing::pull(&mut peer_state.lock().await.sync, &remote.heads, missing); state.stats.pull_started(); debug!(peer = %peer, "Neighbour has changes we lack; pulling"); state.request_sync(peer); |
