From 63b34dfa41e1595145507a88901e332bf4bd3b14 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 7 Nov 2026 22:35:21 +0100 Subject: signatures: kept in the document file A node's signatures are saved with its document (--document-file) and loaded with it. Auth plan M5. --- src/swarm/document_file.rs | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/swarm/document_file.rs') diff --git a/src/swarm/document_file.rs b/src/swarm/document_file.rs index e9deca0..e066e27 100644 --- a/src/swarm/document_file.rs +++ b/src/swarm/document_file.rs @@ -40,29 +40,45 @@ pub(crate) async fn flush(state: &AppState) { return; } let own = state.remake.own_actors(); - let (epoch, heads) = { + let (epoch, heads, signatures) = { let replica = state.doc.read().await; - (replica.epoch, replica.heads().to_vec()) + ( + replica.epoch, + replica.heads().to_vec(), + replica.signatures.count(), + ) }; - match file.due(epoch, own.len(), &heads) { + match file.due(epoch, own.len(), &heads, Some(signatures)) { Due::Rewrite(reason) => { - let (epoch, copy) = { + let (epoch, copy, signatures) = { let replica = state.doc.read().await; - (replica.epoch, replica.doc.clone()) + ( + replica.epoch, + replica.doc.clone(), + replica.signatures.since(0), + ) }; - file.rewrite(epoch, copy, own, reason).await; + file.rewrite(epoch, copy, signatures, own, reason).await; } - Due::Append { epoch, since } => { - let (heads, increment) = { + Due::Append { + epoch, + since, + signatures, + } => { + let (heads, increment, signatures) = { let replica = state.doc.read().await; // Switched since: the next flush rewrites the file instead. if replica.epoch != epoch { return; } let heads = replica.heads().to_vec(); - (heads, crate::document::save_since(&replica.doc, &since)) + ( + heads, + crate::document::save_since(&replica.doc, &since), + replica.signatures.since(signatures), + ) }; - file.append(since, heads, increment).await; + file.append(since, heads, increment, signatures).await; } Due::Nothing => {} } @@ -90,10 +106,12 @@ async fn flush_before_rejoin( let Some(actors) = file.actors() else { return; }; + // Its signatures aren't kept: those of the document after the rejoin are. if let Due::Append { epoch: written, since, - } = file.due(epoch, actors, &heads) + .. + } = file.due(epoch, actors, &heads, None) && written == epoch { let since_then = since.clone(); @@ -105,6 +123,6 @@ async fn flush_before_rejoin( }) .await .expect("document read task panicked"); - file.append(since, heads, increment).await; + file.append(since, heads, increment, Vec::new()).await; } } -- cgit v1.3.1