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 | |
| 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')
| -rw-r--r-- | src/swarm/bootstrap.rs | 17 | ||||
| -rw-r--r-- | src/swarm/document_file.rs | 42 |
2 files changed, 43 insertions, 16 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index 446b846..10ad412 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -241,6 +241,8 @@ pub(crate) struct StartingDocument { pub(crate) origin: Origin, /// The actors this node wrote with before (from the document file). pub(crate) earlier_actors: Vec<ActorId>, + /// The signatures of its changes (from the document file). + pub(crate) signatures: Vec<(crate::document::ChangeHash, [u8; 64])>, } /// What `--recover-from` and `--document-file` say about where to start. @@ -289,7 +291,7 @@ pub(crate) fn starting_document( Some(path) => Some(load_backup(path, files)?), }; - let (doc, origin, earlier_actors) = match (backup, from_file) { + let (doc, origin, earlier_actors, signatures) = match (backup, from_file) { (Some(_), Some(_)) if !force.allows("replaceDocumentFile") => { bail!( "recover-from would replace the document in the document file; add --force replaceDocumentFile to recover the backup anyway" @@ -301,9 +303,14 @@ pub(crate) fn starting_document( "Recovering the backup instead of the document file's document (--force replaceDocumentFile)" ); } - (backup, Origin::Backup, Vec::new()) + (backup, Origin::Backup, Vec::new(), Vec::new()) } - (None, Some(loaded)) => (loaded.doc, Origin::DocumentFile, loaded.actors), + (None, Some(loaded)) => ( + loaded.doc, + Origin::DocumentFile, + loaded.actors, + loaded.signatures, + ), (None, None) => return Ok(None), }; if options.genesis && origin == Origin::DocumentFile { @@ -311,7 +318,8 @@ pub(crate) fn starting_document( "The document file holds a document of a swarm, and genesis would start a new one; move the file away to start a new swarm" ); } - let starting = identify(doc, origin, earlier_actors)?; + let mut starting = identify(doc, origin, earlier_actors)?; + starting.signatures = signatures; if let Some(remembered) = options.remembered.filter(|id| *id != starting.swarm_id) { let what = origin.describe(); @@ -347,6 +355,7 @@ fn identify( swarm_id, origin, earlier_actors, + signatures: Vec::new(), }) } 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; } } |
