diff options
| author | tv <tv@krebsco.de> | 2026-11-29 03:51:14 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 03:51:14 +0000 |
| commit | facc05316e2b350d7b7bbd7dfd0c013cc167f341 (patch) | |
| tree | 91950b531d24cca374d9f77bf37944c1619797fb /src/document | |
| parent | 66f5cefd1801e2421169adf27d676ea8190e61de (diff) | |
document: taking changes fetched as a blob is the document's
document::passing::take_bulk: the changes a peer offered as a blob,
fetched, judged and applied with their signatures, and all the heads
offered held after. swarm::sync keeps the fetch, the epoch check, and
what is counted and noted of the peer.
Diffstat (limited to 'src/document')
| -rw-r--r-- | src/document/passing.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/document/passing.rs b/src/document/passing.rs index 381b5c7..f745d42 100644 --- a/src/document/passing.rs +++ b/src/document/passing.rs @@ -370,3 +370,79 @@ pub(crate) fn settle( level: level && session.have_all_theirs(&replica.doc), } } + +/// What taking changes fetched as a blob did (`take_bulk`). +pub(crate) struct Bulk { + /// The document's heads before. + pub(crate) heads_before: Vec<ChangeHash>, + /// How many heads it has now, and whether they changed. + pub(crate) heads: usize, + pub(crate) changed: bool, + /// Where asked, and the heads changed: when each change that came was made. + pub(crate) times: Vec<i64>, +} + +/// Takes `bytes`, the changes a peer offered as a blob up to the heads `to`, fetched, +/// into the document `replica` holds, with the `signatures` that came for them: judged +/// as a message's are (`take`), and all of `to` held after, or it fails. With the fresh +/// actor the node writes as from now on, where they carried a change of its actor that +/// it didn't make, failed or not. +pub(crate) fn take_bulk( + replica: &mut Replica, + bytes: &[u8], + signatures: Vec<(ChangeHash, [u8; 64])>, + to: &[ChangeHash], + screening: &std::sync::Mutex<super::screen::Screening>, + timed: bool, +) -> (Option<super::ActorId>, anyhow::Result<Bulk>) { + let heads_before = replica.heads().to_vec(); + let fresh_actor = { + // Its signatures wait for its changes (`Signatures::offer`), each checked as they + // are judged (`screen`), whether this document has a policy yet or not. + let (epoch, epoch_seq) = (replica.epoch, replica.epoch_seq); + let replica = &mut *replica; + replica.signatures.offer(&replica.doc, signatures); + match super::screen::apply_bytes( + &mut replica.doc, + epoch, + epoch_seq, + bytes, + screening, + Some(&mut replica.signatures), + &mut super::PatchLog::inactive(), + ) { + Ok(outcome) => outcome.fresh_actor, + Err(error) => return (None, Err(error)), + } + }; + replica.refresh_heads(); + // Signatures waiting for what it brought (`Signatures::offer`). + { + let replica = &mut *replica; + replica.signatures.offer(&replica.doc, Vec::new()); + } + let missing = super::changes::missing(&replica.doc, to).len(); + if missing > 0 { + return ( + fresh_actor, + Err(anyhow::anyhow!( + "{missing} of the offered heads are still missing after loading" + )), + ); + } + let changed = replica.heads() != heads_before.as_slice(); + let times = if changed && timed { + super::changes::commit_times(&replica.doc, &heads_before) + } else { + Vec::new() + }; + ( + fresh_actor, + Ok(Bulk { + heads: replica.heads().len(), + changed, + times, + heads_before, + }), + ) +} |
