Duck typed Protocol showing what a clock must do.
- uuid: bytes
- default_ts: SerializableType
Return the current timestamp.
Update the clock and return the current time stamp.
Return True iff ts1 > ts2.
Return True if not ts1 > ts2 and not ts2 > ts1.
Return 1 if ts1 is later than ts2; -1 if ts2 is later than ts1; and 0 if they are concurrent/incomparable.
Pack the clock into bytes.
Unpack a clock from bytes.
Duck typed Protocol showing what CRDTs must do.
- clock: ClockProtocol
Pack the data and metadata into a bytes string.
Unpack the data bytes string into an instance.
Return the eventually consistent data view.
Apply an update and return self (monad pattern). Should call self.invoke_listeners after validating the state_update.
Returns any checksums for the underlying data to detect desynchronization due to message failure.
history(/, *, update_class: Type[StateUpdateProtocol] = None, until_ts: Any = None, from_ts: Any = None) -> tuple[StateUpdateProtocol]:
Returns a concise history of StateUpdates that will converge to the underlying data. Useful for resynchronization by replaying all updates from divergent nodes.
get_merkle_history(update_class: Type[StateUpdateProtocol]) -> list[bytes, list[bytes], dict[bytes, bytes]]:
Get a Merklized history for the StateUpdates of the form [root, [content_id for update in self.history()], { content_id: packed for update in self.history()}] where packed is the result of update.pack() and content_id is the sha256 of the packed update.
Accept a history of form [root, leaves] from another node. Return the leaves that need to be resolved and merged for synchronization.
Adds a listener that is called on each update.
Removes a listener if it was previously added.
Invokes all event listeners, passing them the state_update.
Returns the int index of the item in the list returned by read(). Should raise a ValueError if the item is not present.
append(item: SerializableType, writer: SerializableType, update_class: Type[StateUpdateProtocol]) -> StateUpdateProtocol:
Creates, applies, and returns an update_class that appends the item to the end of the list returned by read().
remove(index: int, writer: SerializableType, update_class: Type[StateUpdateProtocol]) -> StateUpdateProtocol:
Creates, applies, and returns an update_class that removes the item at the index in the list returned by read(). Should raise ValueError if the index is out of bounds.
Duck type protocol for values that can be written to a LWWRegister, included in a GSet or ORSet, or be used as the key for a LWWMap. Can also be packed, unpacked, and compared.
- value: Any
Data type must be hashable.
Data type must be comparable.
Data type must be comparable.
Data type must be comparable.
Data type must be comparable.
Data type must be comparable.
Data type must be comparable.
Package value into bytes.
Unpack value from bytes.
- clock_uuid: bytes
- ts: Any
- data: Hashable
Initialize the instance.
Pack the instance into bytes.
Unpack an instance from bytes.