Skip to main content

Log

Struct Log 

Source
pub struct Log<S: Statements = Memory, H: History = MemoryHistory<<S as Statements>::Error>> { /* private fields */ }
Expand description

A replica’s copy of a space’s log: the changes it has accepted, with their sealed payloads and wrapped keys as far as it has them, the changes waiting for their parents, the changes it rejected for good, the wrapped record keys of secret statements, the wrapped keys of blobs, and the state that the accepted changes build.

A change is accepted on its header alone, and its operations are applied once its payload and key are there too, in whatever order they arrive.

The log keeps the space’s hybrid logical clock, so the caller passes the wall clock time to every call that makes or receives a change.

The ordinary statements of the state are kept in a storage S, and the accepted changes in a history H: in memory, or on disk, where reading and writing may fail. The log then keeps the error, and refuses to make or take changes until it is built again, as it no longer matches its storage.

Implementations§

Source§

impl<S: Statements, H: History<Error = S::Error>> Log<S, H>

Source

pub fn followed(&self, keys: &SpaceKeys) -> Result<Followed, LogError>

What a space needs of this log, a group’s, to follow it: the governing changes that the replica can read, in their order, and those each builds on.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn follow( &mut self, groups: Vec<Followed>, keys: &SpaceKeys, ) -> Result<(), LogError>

Follows the groups in this space, as the replica’s copies of their logs say (Log::followed): their changes take effect here at the anchors that name them. The groups it followed before and leaves out are no longer followed. Decides again which changes count, if the groups’ changes are not those it followed before.

The log keeps what it follows in memory alone: a program follows the groups again each time it opens the space, before it takes or makes changes there, and again whenever a group’s log changes, as a space that follows none decides without them.

§Errors

Returns LogError::Storage if the history cannot be read or written.

Source

pub fn review( &self, id: ChangeId, keys: &SpaceKeys, ) -> Result<Option<Review>, LogError>

What an admin reviews of a change that was set aside, if the replica has it: the member whose replica made it, in a space with members, by the counting listings among the governing changes it builds on; its payload, if the replica can read it; and whether accepting it would make it count: an ordinary change, which no rule but those that acceptance lifts sets aside. In a space with members, it must be readable here, so that an admin reviews what it does, and the role that its author’s member had by the governing changes it builds on must allow it, as an AI agent’s must have been allowed there: acceptance lifts only what a lowered role, a removal or a revocation set aside. What an AI agent’s change purges or seals is never accepted, nor what writes a value plainly that its author knew to be secret.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn builds_on_all( &self, change: ChangeId, others: &[ChangeId], ) -> Result<bool, LogError>

Whether every one of others is change or one of its ancestors: the history is walked once, down to the shallowest of them.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn removals_of( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<Vec<ChangeId>, LogError>

In a space with members, the counting governing changes that end a key’s replica there, if they do: the latest that give its member the role none, by which they left or were removed, while that is the member’s role now; and, for an AI agent’s key, the latest that say the space allows no AI agents, while it allows none. Ordered by ID; empty elsewhere.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn is_removed( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether a key’s replica is ended in a space with members, as Log::removals_of says: its member left or was removed, or it is an AI agent’s and the space allows none. It changes nothing there after, and no replica gives it keys.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn removals(&self, keys: &SpaceKeys) -> Result<Vec<ChangeId>, LogError>

In a space with members, every counting governing change that ends replicas there: that gives a member the role none, and, where a counting listing is an AI agent’s, that says the space allows no AI agents. A key is written with only if its making builds on each (technical design). Ordered by ID; empty elsewhere.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn groups(&self, keys: &SpaceKeys) -> Result<Vec<SpaceGroup>, LogError>

The groups that the space’s governing changes add, each with its record there, the group and its first change, the statement that adds it, its role now, and whether it is in the space: whether, by every group change that the counting anchors name, the group agrees to that addition and has not withdrawn. Empty in a space without members.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn listed_through_groups( &self, keys: &SpaceKeys, ) -> Result<Vec<VerifyingKey>, LogError>

The keys that the groups in the space list now, by every group change that its counting anchors name, but AI agents’ and revoked ones: replicas that count as listed there, which a replica syncs with and gives keys to.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn claims(&self, keys: &SpaceKeys) -> Result<Vec<Claim>, LogError>

The claims to the admin role that count in a space with members, in their order, with when another member first saw each, when each takes effect and is settled, and whether a rejection voids it. Empty elsewhere.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn key_role( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<Option<Role>, LogError>

The role that a key’s changes have in a space with members now, as its counting governing changes give it: through its listing’s member, directly or through groups; Role::None for a key that no counting listing names, or whose member left or was removed. None for a space without members. Neither a claim, which takes effect by the wall clock, nor a revocation is taken into account.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn group_member_of( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<Option<(SpaceId, EntityId)>, LogError>

For a key that a group the space follows lists, at any level, the group and the key’s member there, by which history names the key’s changes: the first path’s that gives it a role now, by every group change that the counting anchors name, or else the first group’s by ID that lists it. None for any other key.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn group_member_roles( &self, keys: &SpaceKeys, ) -> Result<BTreeMap<EntityId, Role>, LogError>

The members of the groups that the space follows, at any level, whose keys those groups give a role in the space now, each with the highest role that one of their keys has now; empty for a space that follows no group.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn group_members_of( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<Vec<(SpaceId, EntityId)>, LogError>

Each group that the space follows, at any level, that lists a key now, with the key’s member there, but for AI agents’ keys.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn anchored( &self, keys: &SpaceKeys, ) -> Result<BTreeMap<SpaceId, BTreeSet<ChangeId>>, LogError>

Each group’s changes that the space’s counting anchors name, with every one they build on: a replica that changed a group, or holds a change of it that none of these holds, anchors it.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn author_was_a_member( &self, id: ChangeId, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether a change’s author was, by the governing changes it builds on, a replica that a counting change listed and none revoked, and in a space with members a replica of a member whose role there was not none: as a change that counts was. A key made by such a replica is given out, whatever later sets its making aside, so that what was written with it stays readable (technical design). An AI agent’s replica makes no key.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn governing_statements( &self, keys: &SpaceKeys, ) -> Result<Vec<GoverningStatement>, LogError>

The statements of the governing changes that the replica can read, in the order of their changes, by timestamp and then by ID, each with its change, whether that counts, and its author: what says who the replicas are. Retractions are left out, as revoking is the only way out.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn listings_by_code( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<Vec<RecoveryListing>, LogError>

The listings of key by a recovery code, in the counting governing changes that list it and that it made itself, as a device that recovered with a code lists itself: what it shows a peer that does not know it yet (Sync).

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn roster(&self, keys: &SpaceKeys) -> Result<Roster, LogError>

Who the replicas of the space are, as its governing changes that count say.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn with_ancestors( &self, of: &[ChangeId], ) -> Result<BTreeSet<ChangeId>, LogError>

The changes of, and every accepted change that one of them builds on.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn purged_by(&self) -> Result<PurgedBy, LogError>

Which purge keeps each purged item purged, of the changes, secret statements and sealed blobs that counting purges destroyed: the first that purges it and that no counting change that restores it builds on. A copy that waits counts its wait by it (technical design).

§Errors

Returns LogError::Storage if the history cannot be read.

Source§

impl Log

Source

pub fn new(space: SpaceId, clock: Clock) -> Self

Returns an empty log of a space, with the space’s clock, and its state and history in memory.

Source§

impl<S: Statements> Log<S, MemoryHistory<S::Error>>

Source

pub fn with_storage(space: SpaceId, clock: Clock, storage: S) -> Self

Returns an empty log of a space, with the space’s clock, whose state is kept in storage, and its history in memory. The storage may hold the operations of changes already: those that Log::restore says it covers.

Source§

impl<S: Statements, H: History<Error = S::Error>> Log<S, H>

Source

pub fn with_history( space: SpaceId, clock: Clock, storage: S, history: H, ) -> Self

Returns a log of a space, with the space’s clock, whose state is kept in storage and whose accepted changes are kept in history.

Source

pub fn reset(&mut self, clock: Clock)

Empties the log, as Log::with_history makes it, but keeps its storage, the fields that are secret and the limit on waiting changes, with the space’s clock clock: to take back its changes again, after the storage was made again or a failure left the log out of step with it. Its history is emptied, and opened secrets are forgotten.

Source

pub fn storage_error(&mut self) -> Option<S::Error>

Why reading or writing the storage or the history failed, if it did and this was not asked before. The log keeps refusing changes, as it no longer matches its storage.

Source

pub fn storage_mut(&mut self) -> &mut S

The storage of the state, to begin and end transactions, for example.

Source

pub fn history_mut(&mut self) -> &mut H

The history, to begin and end transactions, for example.

Source

pub const fn history(&self) -> &H

The history.

Source

pub fn expect_governed(&mut self)

Has the space’s first change govern it, as it does in every space of NibKeep: a change without parents that does not govern the space is rejected from now on, whatever came before it, so that every replica decides the same of it.

Source

pub fn expect_roots(&mut self, roots: impl IntoIterator<Item = ChangeId>)

Takes as the space’s first change only one of roots, as a replica told by another that it trusts which change founded the space does: any other change without parents is refused, without being rejected, so that the real one is taken when it comes. With no roots, it takes none until it is told one.

Source

pub fn expect_roots_too(&mut self, roots: impl IntoIterator<Item = ChangeId>)

Takes as the space’s first change one of roots too, besides those it was told of before, as Log::expect_roots says: when several sources that it trusts each name the change that founded the space. If it was told of none, it takes only one of roots; with no roots, it then takes none until it is told one, as when a source it trusts cannot be read.

Source

pub fn limit_waiting(&mut self, limit: usize)

Limits how many changes may wait for their parents, which is 100,000 unless set.

Source

pub fn keep_destroyed(&mut self, keeping: bool)

Keeps what purges destroy, as it was, in Destroyed::kept, for a replica that waits before purging, which keeps it apart for a while: or no longer.

Source

pub fn set_secret_fields(&mut self, fields: impl IntoIterator<Item = FieldName>)

Sets the fields whose values are secret, as the space’s types mark them. New statements of these fields are sealed with record keys of their own.

Source

pub const fn space(&self) -> SpaceId

The space.

Source

pub const fn clock(&self) -> &Clock

The space’s clock, to save across restarts.

Source

pub fn commit( &mut self, author: &SigningKey, keys: &SpaceKeys, operations: Vec<Operation>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Parcel, LogError>

Makes a change of operations, signed by author, its key wrapped with the newest of keys, and applies it. Statements of secret fields are sealed, their record keys wrapped with the newest secrets key, and what they supersede retracted in the ordinary layer. Statements of the fields that govern the space make a change of their own (Kind::Governing), wrapped with the space’s first key, which every replica holds; one that revokes a replica or sets a role builds on no governing change whose payload this replica has not read. Returns the change with its payload and key, for other replicas.

§Errors

Returns an error, and leaves the log unchanged, if a secret value is to be written without a secrets key, if statements that govern the space come with others, if keys lack the space’s first key for a governing change, or if the clock has run out of timestamps.

Source

pub fn governs(&self, operation: &Operation) -> Result<bool, S::Error>

Whether an operation governs the space (Kind::Governing): sets a field that governs it, or retracts or replaces a statement of such a field that the state holds. A change that governs the space holds nothing else: no retraction of secret statements, as no statement that governs is secret.

§Errors

Returns an error if the storage of the state cannot be read.

Source

pub fn receive( &mut self, parcel: Parcel, keys: &SpaceKeys, wall_millis: u64, ) -> Result<Received, LogError>

Receives a change from another replica, with its payload and key if they came with it. Accepts it if its parents are all accepted, together with the waiting changes it completes; otherwise the change waits for its parents. An accepted change’s operations are applied once its payload and key are there. A payload or key that is not the change’s is dropped, and the change waits for the right one. The clock takes a change’s timestamp into account only once the change is accepted.

§Errors

Returns an error, and leaves the log unchanged, if the change belongs to another space, its signature is not valid, it would govern the space and do something else too, its timestamp is too far ahead of the wall clock, or too many changes wait already. Returns an error, and remembers the change as rejected for good, if the change is not later than its parents, purges what it does not build on or what governs the space, or one of its parents was rejected.

Source

pub fn restore( &mut self, parcel: Parcel, keys: &SpaceKeys, covered: bool, ) -> Result<Received, LogError>

Receives a change that this replica accepted or kept waiting before, from its own storage: like Log::receive, without the checks that were made when the change first arrived and need not be made again: its signature, which is slow to check, and its timestamp against the wall clock. Log::forged checks the signatures. covered says whether the storage holds the change’s operations already: if so, applying them leaves the storage as it is, and they are not among those that Log::take_applied gives.

§Errors

Returns the errors of Log::receive, other than the signature’s and the clock’s.

Source

pub fn receive_payload( &mut self, id: ChangeId, payload: SealedPayload, keys: &SpaceKeys, ) -> Result<bool, LogError>

Receives the sealed payload of a change that the log holds, and applies the change’s operations if it is accepted and its key is there too. Returns whether the log kept the payload, which it does unless it had it already.

§Errors

Returns an error if the log does not hold the change, or the payload is not the change’s.

Source

pub fn receive_change_key( &mut self, id: ChangeId, key: WrappedChangeKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Receives a wrapped key of a change that the log holds, and applies the change’s operations if it is accepted and its payload is there too. A replica that cannot open the key yet keeps a few. Returns whether the log kept the key.

§Errors

Returns an error if the log does not hold the change, or keys hold the space key the key needs and it is not the change’s.

Source

pub fn open_changes(&mut self, keys: &SpaceKeys) -> Result<(), LogError>

Applies the operations of every accepted change that keys let the log read now, for example after the replica received an older space key.

§Errors

Returns LogError::Storage if reading or writing the storage failed.

Source

pub fn open_changes_of( &mut self, changes: impl IntoIterator<Item = ChangeId>, keys: &SpaceKeys, ) -> Result<(), LogError>

Applies the operations of these accepted changes, if they are pending and keys let the log read them now.

§Errors

Returns LogError::Storage if reading or writing the storage failed.

Source

pub fn forged(&self) -> Result<Vec<Forged<S::Error>>, S::Error>

The changes, accepted or waiting, whose signatures are not valid, or that the history cannot read, with why, ordered by ID: none, unless the storage that the log read them from was damaged or tampered with. One that cannot be read does not keep the others from being checked.

§Errors

Returns an error if the history cannot list its changes.

Source

pub fn take_applied(&mut self) -> Vec<(ChangeId, Payload)>

The decrypted payloads of the changes whose operations the last call that makes or takes changes, payloads or keys applied, in the order it applied them, without those that the storage covered; each call forgets those of the one before.

Source

pub fn take_destroyed(&mut self) -> Destroyed

What the purges that the last call that makes or takes changes, payloads or keys acted on destroyed: only those of changes that count, also of one that came to count then. Each call forgets what the one before destroyed.

Source

pub fn payload( &self, id: ChangeId, keys: &SpaceKeys, ) -> Result<Option<Payload>, LogError>

The payload of an accepted change, decrypted with keys, if the log has the payload and a key for it.

§Errors

Returns an error if keys lack the space key that the change’s key was wrapped with, or the payload does not open or does not have the form of a payload, or the history cannot be read.

Source

pub fn sealed_payload( &self, id: ChangeId, ) -> Result<Option<SealedPayload>, S::Error>

The sealed payload that the log has for a change, accepted or waiting.

§Errors

Returns an error if the history cannot be read.

Source

pub fn change_keys_of( &self, id: ChangeId, ) -> Result<Vec<WrappedChangeKey>, S::Error>

The wrapped keys that the log has for a change, accepted or waiting: one that it knows to be good, or a few that it cannot check yet.

§Errors

Returns an error if the history cannot be read.

Source

pub fn parcel(&self, id: ChangeId) -> Result<Option<Parcel>, S::Error>

An accepted or waiting change, with its sealed payload and wrapped keys as far as the log has them.

§Errors

Returns an error if the history cannot be read.

Source

pub fn parcels(&self) -> Result<Vec<Parcel>, S::Error>

The accepted changes with their sealed payloads and wrapped keys, ordered by ID, for other replicas.

§Errors

Returns an error if the history cannot be read.

Source

pub fn summaries(&self) -> Result<Vec<Summary>, S::Error>

Every accepted change in short, for reconciling with another replica, ordered by ID.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_complete(&self, id: ChangeId) -> Result<bool, S::Error>

Whether the operations of an accepted change are applied, or its payload found not to have the form it must: whether it adds nothing more.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_set_aside(&self, id: ChangeId) -> Result<bool, S::Error>

Whether an accepted change is set aside: kept and passed on, but not applied, as its author is not listed, or was revoked by a replica that did not have it.

§Errors

Returns an error if the history cannot be read.

Source

pub fn set_aside_changes(&self) -> Result<Vec<ChangeId>, S::Error>

The accepted changes that are set aside, ordered by ID.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_governed(&self, keys: &SpaceKeys) -> Result<bool, LogError>

Whether the space’s first change governs it, so that only the changes of the keys it lists count.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn root(&self) -> Result<Option<ChangeId>, S::Error>

The space’s first change, if it governs the space.

§Errors

Returns an error if the history cannot be read.

Source

pub fn revocations_of( &self, key: Option<&VerifyingKey>, keys: &SpaceKeys, ) -> Result<Vec<ChangeId>, LogError>

The counting changes that revoke a key, ordered by ID, or every counting revocation if key is None.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn revocations(&self, keys: &SpaceKeys) -> Result<Vec<ChangeId>, LogError>

Every counting change that revokes a replica, ordered by ID.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn is_revoked( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether a key is revoked by a change that counts.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn may_revoke_back( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether a revoked key would stay if it revoked back the keys that revoked it, as of two that revoke each other: a replica takes from it what it made without knowing of its revocation, where that revocation of its own may be, and sends it nothing (Sync).

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn is_listed( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether a governing change that counts lists a key, or the space’s first change does not govern it.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn has_members(&self, keys: &SpaceKeys) -> Result<bool, LogError>

Whether the space has members: whether its first change gives a role, as that of every space other than a user’s personal one does. Only the listings that the listed keys signed count there (nibkeep_governance::Listing).

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn member_roles( &self, keys: &SpaceKeys, ) -> Result<BTreeMap<EntityId, Role>, LogError>

The members of a space with members, each with the role that the counting governing changes give them now: the lowest of those that no other of them builds on. Empty for a space without members.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn allows_ai_agents(&self, keys: &SpaceKeys) -> Result<bool, LogError>

Whether a space with members allows AI agents now, as its counting governing changes say: an AI agent’s listing counts there only where they allow them. false for a space without members, which has no admins to allow them.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn is_ai_agent( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether a key is an AI agent’s: whether the governing change that first listed it marks its replica as one (Log). Its changes then count only if they write what an AI agent may, and purge, seal and govern nothing.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn standing_choice( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<Option<(u64, bool)>, LogError>

The choice of the device whose key is key that stands in a space with members, of those that counting changes state: its number and whether it holds the space; none if none states one, or the space has no members, where choices count for nothing (technical design).

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn holds_space( &self, key: &VerifyingKey, keys: &SpaceKeys, ) -> Result<bool, LogError>

Whether the device whose key is key holds the space by its choices: whether its choice that stands holds it, or none does, as Log::standing_choice finds it.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn is_ancestor_of( &self, ancestor: ChangeId, of: ChangeId, ) -> Result<bool, LogError>

Whether the accepted change ancestor is of or one of its ancestors.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn wrapped_keys_of(&self, statement: StatementId) -> &[WrappedKey]

The wrapped record keys this replica has for a statement.

Source

pub fn receive_wrapped_key( &mut self, statement: StatementId, wrapped: WrappedKey, keys: &SpaceKeys, ) -> Result<(), LogError>

Receives a wrapped record key of a secret statement from another replica, and opens the statement if keys hold the secrets key. A key for a purged statement is ignored.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn wrapped_keys(&self) -> impl Iterator<Item = (StatementId, &WrappedKey)>

The wrapped record keys this replica has, for other replicas.

Source

pub fn unlock_secrets(&mut self, keys: &SpaceKeys) -> Result<(), LogError>

Opens every sealed statement that keys and the wrapped record keys allow, after the person has confirmed.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn lock_secrets(&mut self)

Forgets the sealed statements this replica has opened, and the secret blob keys, so that the log holds no secret values until they are unlocked again.

Source

pub fn restore_purged( &mut self, author: &SigningKey, keys: &SpaceKeys, restores: Restores, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Parcel, LogError>

Restores what purges destroyed, as restores names it: makes a change that restores it, signed by author, and takes it in. What it names is no longer purged, unless a purge that the change does not build on purges it too: a change waits for its payload and key again, and a statement or a blob for its wrapped key, which a replica that kept them gives back, as Destroyed::restored says (technical design: copies that wait). The change holds nothing else, and counts only where its author may purge what it restores.

§Errors

Returns LogError::InvalidPurge if it would restore nothing, or what this replica’s history does not hold; LogError::CannotRestore if the change would not count, as the author’s role does not allow it, in which case nothing is made; and another error if the clock has run out of timestamps.

Source

pub fn purge( &mut self, author: &SigningKey, keys: &SpaceKeys, statements: impl IntoIterator<Item = StatementId>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Parcel, LogError>

Purges statements: makes a change that destroys, everywhere, the record key of each secret one, and the key and payload of the change that asserted each other one, stating again everything else that those changes held. What a purged statement replaced stays replaced, so purging never brings back an older value.

§Errors

Returns an error if a statement is not one that this replica can purge: unknown, or asserted in a change that governs the space or whose payload it cannot read; or if the clock has run out of timestamps.

Source

pub fn purge_with_blobs( &mut self, author: &SigningKey, keys: &SpaceKeys, statements: impl IntoIterator<Item = StatementId>, (contents, of_secrets): (&[Hash], bool), wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Parcel, LogError>

Purges statements as Log::purge does, and in the same change the blobs with the content hashes contents: every key of the kind secret says that this replica has opened for them, secret blob keys or ordinary ones, as Log::purge_blob destroys them. Content that the replica has no such key for adds nothing.

§Errors

As Log::purge.

Source

pub fn changes_to_purge( &self, statements: impl IntoIterator<Item = StatementId>, keys: &SpaceKeys, ) -> Result<BTreeSet<ChangeId>, LogError>

The changes that purging these statements purges: every change that asserts one of them, which Log::purge purges and states again without them. Secret statements are purged through their record keys alone, and add none.

§Errors

Returns LogError::CannotPurge if a statement is not one that this replica can purge: unknown, or asserted in a change that governs the space or whose payload it cannot read; and LogError::Storage if the state or the history cannot be read.

Source

pub fn purged_changes(&self) -> Result<Vec<ChangeId>, S::Error>

The changes that were purged, ordered by ID.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_change_purged(&self, id: ChangeId) -> Result<bool, S::Error>

Whether a change was purged: its key and payload destroyed.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_purged(&self, statement: StatementId) -> Result<bool, S::Error>

Whether a secret statement was purged.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_sealed(&self, statement: StatementId) -> Result<bool, S::Error>

Whether a statement is secret: held sealed in an accepted change, whether or not this replica has opened it.

§Errors

Returns an error if the history cannot be read.

Source

pub fn add_blob_key( &mut self, content: Hash, sealed: Hash, key: Key, keys: &SpaceKeys, rng: &mut impl CryptoRng, ) -> Result<(), LogError>

Adds the key of a blob that this replica sealed, wrapped with the newest space key, so that the replica can read the blob and pass the key on. The key of a purged sealed blob is ignored.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn add_secret_blob_key( &mut self, content: Hash, sealed: Hash, key: Key, keys: &SpaceKeys, rng: &mut impl CryptoRng, ) -> Result<(), LogError>

Adds the key of a blob of a secret field that this replica sealed, wrapped with the newest secrets key inside the newest space key, so that only a replica that holds the secrets can read the blob, and every replica can pass the key on. The key of a purged sealed blob is ignored.

§Errors

Returns LogError::SecretsLocked if keys hold no secrets key, and LogError::Storage if the history cannot be read.

Source

pub fn sealed_with_secret_keys(&self) -> impl Iterator<Item = &Hash>

The sealed blobs with a wrapped key in the form of a secret blob key: those whose keys unlocking the secrets may open or drop.

Source

pub fn is_secret_blob(&self, sealed: &Hash) -> bool

Whether the opened key of a sealed blob is a secret blob key: one of a blob of a secret field, which only a replica that holds the secrets opens.

Source

pub fn receive_blob_key( &mut self, sealed: Hash, wrapped: WrappedBlobKey, keys: &SpaceKeys, ) -> Result<(), LogError>

Receives a wrapped blob key from another replica, and opens it if keys hold the space key it needs, and for a secret blob key the secrets key too. A wrapped key that does not open with the keys it names is dropped, and a key of a purged sealed blob is ignored. One whose space key the replica holds is kept even when the replica keeps the most it does for one blob, in place of one whose space key it lacks, so that wrapped keys it cannot check never crowd out a good one; a secret blob key that waits for the secrets is never replaced, as it may be the good one. A secret blob key that opens takes the place of an ordinary key opened for the same sealed blob: only a replica that holds the secrets can make one, and any replica of the space an ordinary one.

§Errors

Returns LogError::Storage if the history cannot be read.

Source

pub fn open_blob_keys(&mut self, keys: &SpaceKeys)

Opens the wrapped blob keys that keys allow, for example after the replica received an older space key, or unlocked its secrets.

Source

pub fn wrapped_blob_keys_of(&self, sealed: &Hash) -> &[WrappedBlobKey]

The wrapped keys this replica has for a sealed blob.

Source

pub fn content_of_sealed(&self, sealed: &Hash) -> Option<Hash>

The content that the key this replica opened for a sealed blob says it seals, if it opened one.

Source

pub fn wrapped_blob_keys( &self, ) -> impl Iterator<Item = (&Hash, &WrappedBlobKey)>

The wrapped blob keys this replica has, by sealed hash, for other replicas.

Source

pub fn blob_keys(&self, content: &Hash) -> impl Iterator<Item = (&Hash, &Key)>

The keys this replica has opened for the content with the hash content, by the sealed hash of the blob each key seals. There are several when replicas sealed the same content before they learned of each other’s keys.

The content hash is what the wrapped keys claim, which only reading the whole sealed blob checks. These keys are therefore for reading, never for sealing other content.

Source

pub fn purge_blob( &mut self, author: &SigningKey, keys: &SpaceKeys, content: &Hash, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Parcel, LogError>

Purges a blob: makes a change that destroys, everywhere, every key that this replica has opened for the content with the hash content.

§Errors

Returns an error if the replica has no key for the content, or if the clock has run out of timestamps.

Source

pub fn is_blob_purged(&self, sealed: &Hash) -> Result<bool, S::Error>

Whether the key of a sealed blob was destroyed.

§Errors

Returns an error if the history cannot be read.

Source

pub fn purged_blobs(&self) -> Result<Vec<Hash>, S::Error>

The sealed hashes of the blobs whose keys were destroyed.

§Errors

Returns an error if the history cannot be read.

Source

pub fn blobs(&self) -> impl Iterator<Item = &Hash>

The content hashes of the blobs whose keys this replica has opened.

Source

pub const fn state(&self) -> &SpaceState<S>

The current state of the space, with the secret values this replica has opened.

Source

pub fn state_as_of(&self, millis: u64) -> State<AsOf<'_, Layers<S>>>

The state of the space as of a wall clock time: the result of the changes whose timestamps are at most millis, with the secret values this replica has opened. It is a view of the state, which knows when each statement was recorded and superseded.

Source

pub fn heads(&self) -> Result<BTreeSet<ChangeId>, S::Error>

The changes that no other change names as a parent.

§Errors

Returns an error if the history cannot be read.

Source

pub fn change(&self, id: ChangeId) -> Result<Option<Change>, S::Error>

An accepted change.

§Errors

Returns an error if the history cannot be read.

Source

pub fn changes(&self) -> Result<Vec<Change>, S::Error>

The accepted changes, ordered by ID.

§Errors

Returns an error if the history cannot be read.

Source

pub fn contains(&self, id: ChangeId) -> Result<bool, S::Error>

Whether the log has a change, accepted or waiting.

§Errors

Returns an error if the history cannot be read.

Source

pub fn is_awaited(&self, id: ChangeId) -> bool

Whether waiting changes wait for a change: accepting it may accept them too, whatever they do.

Source

pub const fn rejected(&self) -> &BTreeMap<ChangeId, LogError>

The changes rejected for good, with the reason. Another replica need not send them again.

Source

pub fn kept(&self) -> Result<usize, S::Error>

How many changes the log keeps, accepted or waiting.

§Errors

Returns an error if the history cannot be read.

Source

pub fn missing(&self) -> Result<BTreeSet<ChangeId>, S::Error>

The changes that waiting changes need and that the log does not have.

§Errors

Returns an error if the history cannot be read.

Source

pub fn author_of( &self, statement: StatementId, ) -> Result<Option<VerifyingKey>, S::Error>

The replica that first asserted a statement, if this replica can read the statement.

§Errors

Returns an error if the storage of the state or the history cannot be read.

Source

pub fn rebuild(&mut self, fresh: S, keys: &SpaceKeys) -> Result<(), LogError>

Builds the state again in fresh, an empty storage, from the operations of every change that adds them, after a purge took some away, and opens again the secret statements that keys open. The operations that the state took in are not among those that Log::take_applied gives.

§Errors

Returns LogError::Storage if the history cannot be read, or the storage written, also if that failed before: a fresh storage does not mend the history, which only Log::reset empties.

Source

pub fn resume_clock(&mut self, latest: Timestamp)

Resumes the space’s clock from the latest time of the changes that the history holds, as a log that reads its history from disk does not take them back one by one.

Source

pub fn reapply( &mut self, id: ChangeId, keys: &SpaceKeys, ) -> Result<(), LogError>

Applies again the operations of an accepted change whose history says they are applied, to a storage of the state that lacks them, such as one that a crash left behind the history, or one made anew. Nothing is decided again: what was applied is applied. They are among those that Log::take_applied gives.

§Errors

Returns LogError::Storage if the history cannot be read or the storage written, and an error if the payload no longer opens with keys.

Source

pub const fn is_stale(&self) -> bool

Whether a purge left the state stale, to be built again by the caller.

Source

pub fn take_stale(&mut self) -> bool

Whether a purge left the state stale, which the caller then builds again, as it is in storage that the log cannot make anew; the log forgets that it was.

Trait Implementations§

Source§

impl<S: Debug + Statements, H: Debug + History> Debug for Log<S, H>
where S::Error: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S = Memory, H = MemoryHistory<<S as Statements>::Error>> !Freeze for Log<S, H>

§

impl<S = Memory, H = MemoryHistory<<S as Statements>::Error>> !RefUnwindSafe for Log<S, H>

§

impl<S = Memory, H = MemoryHistory<<S as Statements>::Error>> !Sync for Log<S, H>

§

impl<S, H> Forget for Log<S, H>

§

impl<S, H> Move for Log<S, H>

§

impl<S, H> Send for Log<S, H>
where H: Send, State<Layers<S>>: Send, RefCell<Option<<S as Statements>::Error>>: Send,

§

impl<S, H> Unpin for Log<S, H>
where H: Unpin, State<Layers<S>>: Unpin, RefCell<Option<<S as Statements>::Error>>: Unpin,

§

impl<S, H> UnsafeUnpin for Log<S, H>

§

impl<S, H> UnwindSafe for Log<S, H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.