aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-29 04:05:41 +0000
committertv <tv@krebsco.de>2026-11-29 04:08:47 +0000
commit2a475153b715c954935ae46d3773ffbf3d007f03 (patch)
tree8ebe8a5d6cdaf9869822f95fe2ac7eca0c10cf7f /src/swarm/sync.rs
parent2ae7562083f5f96490f90e9398762cf6a024d51e (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/sync.rs')
-rw-r--r--src/swarm/sync.rs20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index bb99547..65a02ea 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -427,7 +427,7 @@ pub(crate) async fn handle_sync(
{
let mut peer_state = peer_state_mutex.lock().await;
peer_state.reports_ready = Some(from_ready);
- peer_state.last_heads = Some((epoch, transport::HeadsSummary::of(spec.to.clone())));
+ peer_state.last_heads = Some((epoch, spec.stands()));
peer_state.last_sync_rx = Some(Instant::now());
peer_state.sync.answered_by_offer();
}
@@ -509,7 +509,7 @@ pub(crate) async fn handle_sync(
peer_state.reports_ready = Some(from_ready);
// What it says it has (`swarm::relay::unreached`).
peer_state.last_heads =
- Some((epoch, transport::HeadsSummary::of(message.heads().to_vec())));
+ Some((epoch, message.stands()));
let (taken, took) = crate::document::passing::take(
&mut peer_state.sync,
&mut replica,
@@ -855,19 +855,9 @@ async fn download_and_apply_delta(
/// document was replaced (an epoch switch, a rejoin: its heads are no longer ours).
async fn own_changes(
state: &AppState,
- seen_heads: &mut Vec<crate::document::ChangeHash>,
+ seen: &mut crate::document::passing::Mark,
) -> Option<Vec<crate::document::UnitId>> {
- let replica = state.doc.read().await;
- let before = std::mem::replace(seen_heads, replica.heads().to_vec());
- if !crate::document::changes::holds_all(&replica.doc, &before) {
- return None;
- }
- let since = crate::document::changes::since(&replica.doc, &before);
- since
- .authors
- .into_iter()
- .find(|(author, _)| author == state.local_id())
- .map(|(_, hashes)| hashes.into_iter().map(Into::into).collect())
+ crate::document::passing::own_since(&*state.doc.read().await, seen, state.local_id())
}
pub(crate) async fn run_sync_worker(state: AppState, mut rx: mpsc::UnboundedReceiver<SyncEvent>) {
@@ -875,7 +865,7 @@ pub(crate) async fn run_sync_worker(state: AppState, mut rx: mpsc::UnboundedRece
let mut document_dirty = false;
// The heads as of the last document change looked at: what came since, and which of
// it is ours (`own_changes`).
- let mut seen_heads = state.doc.read().await.heads().to_vec();
+ let mut seen_heads = crate::document::passing::mark(&*state.doc.read().await);
info!("Starting the sync worker");