aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/relay.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/relay.rs')
-rw-r--r--src/swarm/relay.rs27
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);