MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / append_frozen_page

Function append_frozen_page

libatomic/src/daemon/provenance_core.rs:235–282  ·  view source on GitHub ↗

Reassemble only complete envelopes, advancing the cursor after a successful page. Retrying an RPC cannot append its bytes twice. Ported verbatim from the legacy owner client (owner.rs `append_frozen_page`).

(
    envelopes: &mut Vec<Vec<u8>>,
    partial: &mut Vec<u8>,
    cursor: &mut FrozenProvenanceCursor,
    cutoff: u64,
    page: FrozenProvenancePage,
)

Source from the content-addressed store, hash-verified

233/// Ported verbatim from the legacy owner client (owner.rs
234/// `append_frozen_page`).
235pub fn append_frozen_page(
236 envelopes: &mut Vec<Vec<u8>>,
237 partial: &mut Vec<u8>,
238 cursor: &mut FrozenProvenanceCursor,
239 cutoff: u64,
240 page: FrozenProvenancePage,
241) -> Result<(), String> {
242 let end = FrozenProvenanceCursor {
243 seq: cutoff,
244 offset: 0,
245 };
246 if page.next <= *cursor || page.next > end {
247 return Err("invalid frozen journal page continuation".to_string());
248 }
249 let mut position = *cursor;
250 for fragment in page.fragments {
251 // Legacy journal records can leave sequence gaps, but never inside an envelope.
252 if fragment.cursor.seq >= cutoff
253 || fragment.cursor < position
254 || (fragment.cursor != position
255 && (position.offset != 0 || fragment.cursor.offset != 0))
256 || (!fragment.complete && fragment.bytes.is_empty())
257 {
258 return Err("invalid frozen journal fragment cursor".to_string());
259 }
260 partial.extend_from_slice(&fragment.bytes);
261 position = if fragment.complete {
262 envelopes.push(std::mem::take(partial));
263 FrozenProvenanceCursor {
264 seq: fragment.cursor.seq + 1,
265 offset: 0,
266 }
267 } else {
268 FrozenProvenanceCursor {
269 seq: fragment.cursor.seq,
270 offset: partial.len(),
271 }
272 };
273 }
274 if page.next < position
275 || (page.next != position && (position.offset != 0 || page.next.offset != 0))
276 || (page.next == end && !partial.is_empty())
277 {
278 return Err("incomplete frozen journal page".to_string());
279 }
280 *cursor = page.next;
281 Ok(())
282}
283
284/// Load the whole frozen journal by paging through it with strict
285/// continuity validation. This is the in-process counterpart of the wire

Callers 1

load_frozen_envelopesFunction · 0.70

Calls 3

is_emptyMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected