diff options
| author | tv <tv@krebsco.de> | 2026-11-07 22:35:21 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-07 22:35:21 +0100 |
| commit | 63b34dfa41e1595145507a88901e332bf4bd3b14 (patch) | |
| tree | e33955ead52d4155a2c5cb5b1abaa3cb7e83f8a6 /src/swarm/document_file.rs | |
| parent | c9b05d33f57b7efd69301b56725614a0d9938599 (diff) | |
signatures: kept in the document file
A node's signatures are saved with its document (--document-file) and
loaded with it.
Auth plan M5.
Diffstat (limited to 'src/swarm/document_file.rs')
| -rw-r--r-- | src/swarm/document_file.rs | 42 |
1 files changed, 30 insertions, 12 deletions
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; } } |
