barrel_p2p_crdt_wire (barrel_p2p v0.1.0)

View Source

Summary

Functions

Keep only the entries that pass valid_entry/2. Guards the top-level argument: a non-map payload (a malformed broadcast can deliver any term) returns #{} rather than letting maps:filter crash. The helper never crashes the caller on any peer-supplied term.

Validate, absorb the incoming clock, and merge into Local. Returns {Merged, Accepted}: Merged is the new local OR-Map and Accepted is the validated sub-map of incoming entries - the keys that changed, so the caller can update its projection and emit events without rescanning the whole map. A non-map Incoming is a no-op: {Local, #{}}. Works identically for a delta and a full-sync snapshot.

Wrapper-only validity: the entry shape absorb_clock/merge require (a value with a non-empty dot map keyed by {node(), HLC}, or a tombstone carrying an HLC). Accepts any leaf value.

Wrapper validity plus an application leaf-value check.

Types

leaf_validator/0

-type leaf_validator() :: fun((term()) -> boolean()).

Functions

accept(Map, LeafFun)

-spec accept(term(), leaf_validator()) -> barrel_p2p_ormap:ormap().

Keep only the entries that pass valid_entry/2. Guards the top-level argument: a non-map payload (a malformed broadcast can deliver any term) returns #{} rather than letting maps:filter crash. The helper never crashes the caller on any peer-supplied term.

ingest(Local, Incoming, LeafFun)

Validate, absorb the incoming clock, and merge into Local. Returns {Merged, Accepted}: Merged is the new local OR-Map and Accepted is the validated sub-map of incoming entries - the keys that changed, so the caller can update its projection and emit events without rescanning the whole map. A non-map Incoming is a no-op: {Local, #{}}. Works identically for a delta and a full-sync snapshot.

valid_entry(Entry)

-spec valid_entry(term()) -> boolean().

Wrapper-only validity: the entry shape absorb_clock/merge require (a value with a non-empty dot map keyed by {node(), HLC}, or a tombstone carrying an HLC). Accepts any leaf value.

valid_entry(Entry, LeafFun)

-spec valid_entry(term(), leaf_validator()) -> boolean().

Wrapper validity plus an application leaf-value check.