Skip to main content

Library

Struct Library 

Source
pub struct Library { /* private fields */ }
Expand description

A library, opened: its replica’s keys unlocked, and its spaces open.

Implementations§

Source§

impl Library

Source

pub fn device_marks(&self, device: EntityId) -> Result<DeviceMarks, NodeError>

How the person marked one of their devices, in the personal space: as an archive node or an everyday device, and whether it is kept away from home.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn set_device_marks( &mut self, device: EntityId, marks: DeviceMarks, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Marks one of the person’s devices, in the personal space: as an archive node or an everyday device, as kept away from home or not, and with how many bytes of files it keeps as an everyday device, or the default. Its replicas tell the others so at their next syncs (technical design: where the copies are).

§Errors

Returns NodeError::WhichDevice if device is no device of the personal space, and another error if the change cannot be saved.

Source

pub fn copies_of( &self, space: SpaceId, file: EntityId, wall_millis: u64, ) -> Result<Vec<FileCopy>, NodeError>

The disks that hold a copy of a file of a space, and how each holds it, as of wall_millis: this replica’s, as it holds the file now, and the others’ as their accounts say; a sealed copy before a plain one. A copy last checked more than 8 weeks before wall_millis does not count.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn ai_agents_enabled(&self) -> Result<bool, NodeError>

Whether the person allowed AI agents on this replica, with nib mcp enable.

§Errors

Returns an error if the file of AI agents cannot be read.

Source

pub fn enable_ai_agents( &mut self, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Allows AI agents on this replica, as the person’s consent: AI clients on this computer may then work on it, each with a key of its own, in the personal space. Keys of clients that were revoked since are forgotten, so that a client named as one of them gets a new key.

§Errors

Returns NodeError::AiAgentMayNot if the library acts as an AI agent, and an error if the file cannot be written.

Source

pub fn disable_ai_agents( &mut self, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Vec<String>, NodeError>

Withdraws the person’s consent to AI agents on this replica, and revokes every key that it made for them. Returns the names of the clients whose keys it revoked.

§Errors

Returns NodeError::AiAgentMayNot if the library acts as an AI agent, and an error if a key cannot be revoked or the file written.

Source

pub fn act_as_ai_agent( &mut self, name: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Acts as the AI client named name from now on, for as long as the library is open: its key signs every change, the library refuses what an AI agent may not do, and it keeps only the personal space, so that nothing reads another. The client’s key is made the first time, and listed by this replica.

§Errors

Returns NodeError::AiAgentsNotAllowedHere if the person did not allow AI agents here, NodeError::AiAgentRevoked if the client’s key was revoked, and an error if the key cannot be made or listed.

Source

pub fn acting_as(&self) -> Option<&str>

The name of the AI client that the library acts as, if it does.

Source

pub fn ai_agent_record(&self, name: &str) -> Result<Option<EntityId>, NodeError>

The record of the key of the AI client named name, if this replica made one.

§Errors

Returns an error if the file of AI agents cannot be read.

Source§

impl Library

Source

pub fn backups(&self) -> Result<Vec<Backup>, NodeError>

The person’s backups, as their personal space records them, by name.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn find_backup(&self, reference: &str) -> Result<Backup, NodeError>

The backup that reference names, by its ID or its name.

§Errors

Returns NodeError::WhichBackup if it names none, or several.

Source

pub fn add_backup( &mut self, folder: &Path, new: &NewBackup, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<AddedBackup, NodeError>

Makes a backup in folder, which must be new or empty, and records it in the personal space (technical design: backups).

§Errors

Returns NodeError::EmptyName for an empty name, NodeError::NoSpace for a space that this replica does not hold, NodeError::NoEntity for a policy of none of them, NodeError::BackupFolder for a folder that is not empty, lies in a library or in a cloud drive’s folder, and an error if the folder or the change cannot be written.

Source

pub fn add_backup_in( &mut self, folder: &dyn BackupFolder, new: &NewBackup, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<AddedBackup, NodeError>

Makes a backup as Library::add_backup does, in a folder reached through the interface of files, as the folder that Android’s picker gives: it checks only that the folder is empty, and records it by the path that its drive gives.

§Errors

Returns the errors of Library::add_backup but those of where the folder is.

Source

pub fn edit_backup( &mut self, backup: EntityId, edit: &BackupEdit, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Changes one of the person’s backups.

§Errors

Returns NodeError::WhichBackup if backup is none of the person’s backups, the errors of Library::add_backup for what is given, and an error if the change cannot be saved.

Source

pub fn remove_backup( &mut self, backup: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Forgets one of the person’s backups: its record is deleted, and its folder stays for the person to delete.

§Errors

Returns NodeError::WhichBackup if backup is none of the person’s backups, and an error if the change cannot be saved.

Source

pub fn find_backups( &self, remembered: &BTreeMap<EntityId, PathBuf>, ) -> Result<Vec<(Backup, PathBuf)>, NodeError>

The person’s backups that hold a space of this replica’s and are reachable from this computer, each with its folder: at its path under each folder that a drive or share is mounted at, and where remembered says this computer found it last.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn backup_state( &self, backup: &Backup, folder: &Path, wall_millis: u64, ) -> Result<BackupState, NodeError>

What a backup’s folder says of it, as of wall_millis, without updating it.

§Errors

Returns NodeError::NotTheBackup if the folder is not the backup, and an error if it cannot be read.

Source

pub fn backup_state_in( &self, backup: &Backup, folder: &dyn BackupFolder, wall_millis: u64, ) -> Result<BackupState, NodeError>

What a backup’s folder, reached through the interface of files, says of it, as Library::backup_state does.

§Errors

Returns NodeError::NotTheBackup if the folder is not the backup, and an error if it cannot be read.

Source

pub fn update_backup( &mut self, backup: &Backup, folder: &Path, now: &dyn Fn() -> u64, stop: &dyn Fn() -> bool, ) -> Result<Option<BackupUpdate>, NodeError>

Updates a backup in folder (technical design: backups): takes in what the replica lacks, applies its purges, writes what the backup lacks, and checks the backup’s copies, until stop says to stop. None while another program updates it.

§Errors

Returns NodeError::NotTheBackup if the folder is not the backup, and an error if the library or the backup cannot be read or written.

Source

pub fn update_backup_in( &mut self, backup: &Backup, folder: &dyn BackupFolder, now: &dyn Fn() -> u64, stop: &dyn Fn() -> bool, ) -> Result<Option<BackupUpdate>, NodeError>

Updates a backup as Library::update_backup does, in a folder reached through the interface of files, as the folder that Android’s picker gives.

§Errors

Returns the errors of Library::update_backup.

Source§

impl Library

Source

pub fn settle_moves( &mut self, synced: &Synced, started: u64, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Vec<PathBuf>, NodeError>

Purges what moves that this replica made left behind, where a sync that started at started, after the move, just synced the new entity’s space with another device, which then holds it: what this replica’s member may purge in the old space, its own changes as an editor, everything but the marks as an admin or in the personal space. Leftovers that hold content, which the old space’s replicas would lose, wait for the planner, which purges them once that content’s copies in the new space are proven (Library::remove_proven). Called after each sync; returns the copies of this device’s checkouts that it deleted.

§Errors

Returns an error if a space cannot be read, or a purge cannot be saved.

Source

pub fn purge_requests( &self, space: SpaceId, ) -> Result<Vec<PurgeRequest>, NodeError>

The entities of a space that moves left behind and whose movers asked that the rest be purged, which this replica’s member, an admin there, may purge: those whose new entity counts in a space this replica holds, with the same values, and that still hold more than their marks. Empty for a member who is no admin, and for the personal space, where the mover purges all.

§Errors

Returns an error if the space cannot be read.

Source

pub fn behind( &self, space: SpaceId, entity: EntityId, ) -> Result<Option<usize>, NodeError>

How many values Library::purge_behind would purge of an entity that a move left behind: what this replica’s member may purge there. None if no move asked for a purge of it.

§Errors

Returns an error if the space cannot be read.

Source

pub fn purge_behind( &mut self, space: SpaceId, entity: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Purges what a move left behind of an entity, as asked: what this replica’s member may purge there, as Library::settle_moves says, once the new entity counts in a space this replica holds with the values that the old one shows; returns how many values it purged.

§Errors

Returns NodeError::NoPurgeAsked if no move asked for a purge of the entity, NodeError::MovedDiffers if what moved is not here or differs, and an error if the space cannot be read or the purge saved.

Source§

impl Library

Source

pub fn check_copies( &mut self, records: &Records, wall: &dyn Fn() -> u64, pace: Pace, stop: &dyn Fn() -> bool, ) -> Result<CheckRun, NodeError>

Runs the regular check of the replica’s copies, as the holder of the sync role does every few minutes: reads what the round under way says is due, sealed blobs in the order of their sealed hashes against their sealed hashes, and this device’s unchanged plain copies in the order of their files’ IDs against their content, each from where the last run stopped, resting after each file as pace says, for pace.run_for at most, or until stop says to stop. A sealed blob found damaged is moved aside, so that the replica no longer holds it, and recorded at once; the run then asks the holder to sync with every replica it finds, which brings it again. A plain copy found damaged is recorded, and left as it is. As a round begins, the copies kept aside are read again, and one found intact after all goes back in place. Where the round stands, and what the run found, are saved as it ends, after a failure too (technical design: checking and repair).

§Errors

Returns an error if the records or a space cannot be read, or what the run found cannot be saved. A copy that cannot be read is no error: it is read again in the next round.

Source

pub fn check_status( &self, records: &Records, wall_millis: u64, ) -> Result<CheckStatus, NodeError>

Where this replica’s checks stand at wall_millis: the round under way, as records keep it, and what checks found damaged in each space, the personal space first: what is damaged still, and what came again in the 4 weeks before.

§Errors

Returns an error if the records or a space cannot be read.

Source§

impl Library

Source

pub fn checkout( &mut self, space: SpaceId, file: EntityId, place: &Path, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<CheckedOut, NodeError>

Checks out a file of a space: writes a plain copy of its current content at place, and records it, as a checkout on this device. place is a folder, where the copy takes the file’s name, or the path of a new file. The content comes from the store, or else from an original on this device whose hash still matches. A checkout there already, unchanged, is left as it is; one whose copy is gone is written again.

The copy is written beside its place, under a hidden name, checked against the content’s hash and synced; then the checkout is recorded, and only then is the copy put in place, without replacing anything.

§Errors

Returns NodeError::NoContent if the file has no content, NodeError::NotAFileName if place is a folder and the file’s name is no name a file can have, NodeError::PlaceTaken if something is at the copy’s place, and NodeError::NoCopyHere if this device holds no copy of the content, which it then keeps whatever its size for a while, so that a sync with a device that holds it fetches it (Library::record_opened); and another error if the copy cannot be written, or the change saved.

Source

pub fn view_copy( &mut self, space: SpaceId, file: EntityId, folder: &Path, wall_millis: u64, ) -> Result<PathBuf, NodeError>

Writes a plain copy of a file’s current content for a viewer to show, in a folder of the program’s own, and returns where: read-only, in a folder named after the content, under the file’s name, so that the viewer knows its kind. It is no checkout: nothing records it, no edit of it is taken, and the program removes it later (remove_view_copies). A copy written before is given again. The file is recorded as opened (Library::record_opened).

§Errors

Returns NodeError::NoContent if the file has no content, NodeError::SecretFile for a secret file, and NodeError::NoCopyHere if this device holds no copy of the content, which it then keeps whatever its size for a while, so that a sync with a device that holds it fetches it; and another error if the copy cannot be written.

Source

pub fn checkouts(&self, space: SpaceId) -> Result<Vec<Checkout>, NodeError>

The checkouts on this device of a space, that are not deleted, ordered by path, with whether each copy is unchanged.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn checkout_at( &self, space: SpaceId, path: &Path, ) -> Result<Option<Checkout>, NodeError>

The checkout on this device of a space whose copy is at path, as the file system resolves its folder, if there is one.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn checkouts_of( &self, space: SpaceId, file: EntityId, ) -> Result<Vec<Checkout>, NodeError>

The checkouts on this device of a file of a space, ordered by path.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn record_edits( &mut self, space: SpaceId, checkout: EntityId, force: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EditsRecorded, NodeError>

Records the edits of a checkout’s copy as a new version of its file: the copy is sealed into the store, whatever the file’s policy says, and becomes the file’s content, with its size and media type, and the checkout’s, in one change; history keeps the version before. Returns whether the copy was edited, as its hash tells, and the new version’s content hash; a copy that is unchanged or gone records nothing. Unless force, edits of a version that is no longer the file’s are refused.

§Errors

Returns NodeError::NotCheckedOut if the checkout is not one on this device that is not deleted, NodeError::Stale if the file got a new version since the copy was written and force is false, and another error if the copy cannot be read, or changed while it was, or the change cannot be saved.

Source

pub fn end_checkout( &mut self, space: SpaceId, checkout: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Ended, NodeError>

Ends a checkout: deletes its copy, which must be unchanged, and its record. A copy whose content no other copy on this device holds, neither the store nor an original whose hash still matches, is sealed into the store first. A copy that is gone only ends its record.

§Errors

Returns NodeError::NotCheckedOut if the checkout is not one on this device that is not deleted, NodeError::Unrecorded if its copy was edited, as Library::record_edits records, and another error if the copy cannot be read or deleted, or the change cannot be saved.

Source

pub fn settle_checkouts( &mut self, known: &BTreeMap<EntityId, Hash>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Vec<PathBuf>, NodeError>

Deletes, in every space, the copies of this device’s checkouts whose content a purge took away, where they are unchanged, and ends their checkouts, and those whose copies are gone. known holds the contents of this device’s checkouts before the purges arrived, as Library::checkout_contents gave them, by which their hashes tell whether they are unchanged; without it, the size and modification time recorded tell. An edited copy holds the person’s work, and stays; its record loses its modification time, so that no later settling takes it for unchanged. A copy whose folder cannot be reached, as on a drive that is not plugged in, waits for a later settling. Returns the copies deleted. If the change cannot be saved, as on a replica that can no longer write, a later settling makes it again.

§Errors

Returns an error if a space cannot be read.

Source

pub fn checkout_contents(&self) -> Result<BTreeMap<EntityId, Hash>, NodeError>

The contents of this device’s checkouts, in every space, by checkout, for Library::settle_checkouts to tell later whether their copies are unchanged.

§Errors

Returns an error if a space cannot be read.

Source

pub fn file_content( &self, space: SpaceId, content: &Hash, limit: u64, ) -> Result<Option<Vec<u8>>, NodeError>

The content of a file of a space, if it is no larger than limit bytes: from the copy that this replica holds, or else from a place on this device where it was found, checked against its hash, as a checkout writes it, for an app to show, such as a picture. None if neither has it as it was added, or it is larger. Content that only the secrets open is never read here.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn claims(&self, space: SpaceId) -> Result<Vec<ClaimInSpace>, NodeError>

The claims to the admin role in a shared space, with their claimants’ names.

§Errors

Returns NodeError::NeverShared for the personal space, and an error if the space cannot be read.

Source

pub fn claim_admin( &mut self, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Claims the admin role of a shared space, as a direct member who is an editor there, when its admins are gone: every member sees the claim, which takes effect 30 days after another member’s device first sees it, unless an admin rejects it, and for 30 days after that this user can only undo.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::Revoked if this replica is revoked there, NodeError::AiAgentMayNot for an AI agent’s replica, NodeError::ClaimNeedsDirect if this replica’s user is no direct member there, NodeError::ClaimNeedsEditor if they are no editor, and an error if the change cannot be saved.

Source

pub fn check_claim(&self, space: SpaceId) -> Result<EntityId, NodeError>

Checks that this replica’s user may claim the admin role of a shared space now, as before saying what claiming would do, and returns their member.

§Errors

The errors of Library::claim_admin but those of saving.

Source

pub fn reject_claim( &mut self, space: SpaceId, member: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Rejects, as an admin of a shared space, the claims to the admin role that a member made there: if another member’s device sees the rejection within 30 days after a claim took effect, the claim counts for nothing, nor what the member did as an admin.

§Errors

Returns NodeError::AdminsOnly if this replica’s member is no admin there, for good, NodeError::NoClaim if the member made no claim there that stands and is not settled, which no rejection undoes, and an error if the change cannot be saved.

Source§

impl Library

Source

pub fn copies_in(directory: &Path) -> Vec<ReplicaCopy>

The copies that a library’s directory holds: the folders of replicas that are not here, also those that a program may still be bringing in, but the one that a recovery in place replaces, until it is set aside.

Source

pub fn copies(&self) -> Vec<ReplicaCopy>

The copies beside this replica in its library’s directory.

Source

pub fn add_from_copy( directory: &Path, (copy, unlocker): (&Path, &Unlocker<'_>), joining: Joining<'_>, protection: &NewProtection<'_>, secrets: Option<(&Unlocker<'_>, &NewProtection<'_>)>, now: &dyn Fn() -> u64, rng: &mut impl CryptoRng, ) -> Result<Self, NodeError>

Adds this computer as a device of its own, in a new replica beside the copy in copy in the library’s directory directory, with the copy’s own keys, which unlocker opens: for when no other device of the person’s can add it, as after a library restored from the backup of the only one. The copy is opened in a private copy of its own, with its keys in a key file of that copy’s, and nothing of the copy or its keystore entries is written to. It adds the new replica as pairing does, in this process; the new replica takes in what the copy holds, and with secrets, which open the copy’s secrets and protect them here, the secrets too, as Library::take_secrets_from_copy does; then it revokes the replicas of the copy’s device, whose keys a thief of that device may hold. A device of the person’s that turns up later does not know the new one, and is added anew.

§Errors

Returns NodeError::Exists if a replica is here already, an error of the keys if unlocker does not open the copy’s, NodeError::AiAgentMayNot if the copy is an AI agent’s, NodeError::NewerFormats if a later version of NibKeep changed the copy, and an error if the copy does not read, or the new replica cannot be made.

Source

pub fn take_in_from( &mut self, copy: &Path, now: &dyn Fn() -> u64, ) -> Result<TakenIn, NodeError>

Takes in what the copy in copy holds and this replica lacks, as Library::take_in_copies does.

§Errors

As Library::take_in_copies.

Source

pub fn pair_in_process( &mut self, directory: &Path, joining: Joining<'_>, protection: &NewProtection<'_>, now: &dyn Fn() -> u64, rng: &mut impl CryptoRng, ) -> Result<Self, NodeError>

Adds a new replica of this library in directory, which joining asks for, as pairing does, but in this process and without a network: pairing, then the new replica’s first sync, which brings it the personal space. now is the new replica’s wall clock; this one makes its changes at the time pairing starts. Benchmarks time a first sync with it.

§Errors

Returns an error if this replica cannot sponsor one, directory holds a library already, or the first sync fails, in which case the new replica is removed.

Source

pub fn take_in_copies( &mut self, now: &dyn Fn() -> u64, ) -> Result<TakenIn, NodeError>

Takes in what the copies beside this replica hold and it lacks, in the spaces that it holds: changes, the keys of statements and blobs, and sealed blobs, as a sync takes in what another replica sends, checking each. The copies’ keys are not needed, and nothing of them is written to. now is the wall clock, read as each change comes in.

§Errors

Returns an error if what is taken in cannot be saved. A copy whose log does not read, or that a later version of NibKeep changed, is passed over.

Source§

impl Library

Source

pub fn told_of_syncing(&self) -> Result<bool, NodeError>

Whether a program that syncs folders syncs this library’s folder, as the marks it leaves in the folder or above it show, or as the copies beside this replica do, when their files changed since this replica last looked: only the first time that it is found, so that the person is told once. NibKeep syncs on its own, and such a program puts every replica’s key file on every computer and with its provider.

§Errors

Returns an error if what this replica saw cannot be saved.

Source§

impl Library

Source

pub fn delete_type( &mut self, space: SpaceId, kind: &TypeName, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Deletes a type that a space defines: each of its definitions that is not deleted, in one change. The space’s types then leave it out, and the fields that only it lists; Library::restore_type brings it back with them. Only a type of the space’s own is deleted, not one of the standard vocabulary, which comes back as it is installed, nor one of NibKeep’s, which is defined in code; and only once no entity that is not deleted has it, so that no entity is left with a type that no definition makes.

§Errors

Returns NodeError::NotOwnType for a standard type or one defined in code; NodeError::NoTypeDefined if the space has no definition of it that is not deleted; NodeError::TypeInUse if entities still have it; NodeError::AiAgentMayNot if this replica is an AI agent’s; and another error if the library has no such space, or the change cannot be saved.

Source

pub fn deleted_types(&self, space: SpaceId) -> Result<Vec<TypeName>, NodeError>

The types of a space’s own that it deleted: those whose definitions are all deleted, which Library::restore_type brings back, ordered by name.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn restore_type( &mut self, space: SpaceId, kind: &TypeName, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Restores a type that a space deleted: each of its deleted definitions, in one change, so that it comes back with the fields it had.

§Errors

Returns NodeError::NotOwnType for a standard type or one defined in code; NodeError::NoTypeDefined if the space has no deleted definition of it; NodeError::AiAgentMayNot if this replica is an AI agent’s; and another error if the library has no such space, or the change cannot be saved.

Source§

impl Library

Source

pub fn find_group_member( &self, space: SpaceId, reference: &str, ) -> Result<(SpaceId, EntityId), NodeError>

The member through a group, at any level, of a shared space that reference names: by name, whatever the case, or by the start of their record’s ID in the group, at least four characters long. Returns the group and their record there.

§Errors

Returns NodeError::NoMember if none matches, NodeError::Ambiguous if several do, and an error if a space cannot be read.

Source

pub fn make_direct( &mut self, space: SpaceId, (group, member): (SpaceId, EntityId), role: MemberRole, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Makes a member through a group a direct member of a shared space, as an admin of it, such as to make them an admin: a member’s record with role, their user ID and name, and one of their keys, on which their replicas list themselves once they confirm (Library::confirm_direct). Returns the record.

§Errors

Returns NodeError::AdminsOnly if this replica’s member is no admin of the space, NodeError::NoMember if no group in the space, at any level, holds such a member, with a replica, and an error if a change cannot be saved.

Source

pub fn confirm_direct( &mut self, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Confirms, as a member through a group, the record that an admin of a shared space made for this replica’s user there: lists this replica on it, which makes the user a direct member, with its role; the user’s other replicas list themselves as they learn of it. Returns the record.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::AiAgentMayNot for an AI agent’s replica, NodeError::NoDirectRecord if no admin made a record there for the user, and an error if a change cannot be saved.

Source

pub fn keep_out( &mut self, space: SpaceId, (group, member): (SpaceId, EntityId), wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Keeps a member through a group out of a shared space, as an admin of it, naming them by their keys: they stay in the group, but no group gives them the space, which gets a new key, sealed to the replicas that remain.

§Errors

Returns NodeError::AdminsOnly if this replica’s member is no admin of the space, NodeError::NoMember if the group holds no such member with a replica, and an error if a change cannot be saved.

Source

pub fn let_in( &mut self, space: SpaceId, (group, member): (SpaceId, EntityId), wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Lets a member through a group whom a shared space keeps out back in, as an admin of it.

§Errors

As Library::keep_out.

Source§

impl Library

Source

pub fn drop_space( &mut self, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Dropping, NodeError>

Drops a space on this device, as the person asks here: refuses as DropRefusal says; otherwise marks it, and moves the drop on as far as it can now, as Library::drop_progress then tells. The holder of the sync role goes on with it, a pass of removals at a time, and the syncs after, until the space is deleted. A drop asked for again tells how far it has come.

§Errors

Returns NodeError::PersonalSpaceHeld for the personal space, NodeError::NoSpace for a space that this device does not hold, NodeError::DropRefused with the reasons, and an error if this replica is an AI agent’s or revoked, or the library cannot be read or changed.

Source

pub fn drop_progress( &self, space: SpaceId, ) -> Result<Option<Dropping>, NodeError>

How far a drop of a space on this device has come, and what it waits for; None if this device does not drop it, as when it never did, took it back, or deleted it.

§Errors

Returns an error if the library cannot be read.

Source§

impl Library

Source

pub fn create_entity( &mut self, space: SpaceId, types: &[TypeName], values: Vec<(FieldName, Value)>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Adds an entity of these types, with these values, to a space. Returns the entity.

§Errors

Returns an error if the library has no such space; if a type is one of those that define types, which Library::define_type defines; if a field is one of NibKeep’s own, which its own operations set; if a field with one value gets several; or if the change cannot be saved, such as a secret value without the space’s secrets key.

Source

pub fn create_entity_with_language( &mut self, space: SpaceId, types: &[TypeName], values: Vec<(FieldName, Value)>, language: &Tag, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Adds an entity as Library::create_entity does, with its text, names and files in language.

§Errors

As Library::create_entity.

Source

pub fn create_entity_with( &mut self, space: SpaceId, types: &[TypeName], values: Vec<NewValue>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Adds an entity as Library::create_entity does, with values that can be in a language and have other forms, as an import of data in several languages writes them. Forms of one value count as one.

§Errors

As Library::create_entity.

Source

pub fn edit_entity( &mut self, space: SpaceId, entity: EntityId, edits: Vec<Edit>, dating: &Dating, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Changes an entity of a space, with every edit in one change, as of dating, except that edits of what governs the space, such as a replica’s key, make a change of their own, committed first. Each edit sees what the edits before it did. Edits that change nothing, such as deleting a deleted entity or setting a field to the values it shows, commit nothing.

§Errors

Returns an error if the library has no such space or the space no such entity; if the entity defines a type or field, which only Library::define_type changes; if a field is one of NibKeep’s own; if a field with one value is set to several; if a value to remove is not shown; if a type to give or take away is one of NibKeep’s own, or one to take away is not the entity’s, or its only one; or if the change cannot be saved.

Source

pub fn search( &self, space: SpaceId, query: &str, ) -> Result<Vec<Listed>, NodeError>

Finds the entities of a space that are not deleted and whose values shown hold every word of query, in the order of the search index: those with more matching values first. Secret values are never searched, nor the text of NibKeep’s fields for structure, keys and positions. A search that matches where a file was found, the path of one of its origins, or where it is checked out, finds the file, unless it is deleted, rather than the origin or the checkout. Entities that define types are never found.

Through links, it finds more, each with the entity it was found through, after those found by their words (docs/spec/model.md, section 10): for each of them, the entities that stand for it, such as a pen name for a person who uses it, and those that link to it through a field that searches go through, such as a book through its author, ordered by name; and then, through each entity that stands for it, those that link to that entity so. No entity is found twice.

Everything found is listed, which costs most for common words: where a page is enough, Library::search_first costs less.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn search_first( &self, space: SpaceId, query: &str, first: usize, keep: impl FnMut(EntityId, &BTreeSet<TypeName>) -> Result<bool, NodeError>, ) -> Result<Searched, NodeError>

Lists what Library::search finds, in its order, but only the entities that keep keeps, given each one’s ID and types, and only the first first of those; and counts the others it keeps. Naming entities is most of what a search costs, and those past the page are not named, but for those found through links in the group that the page ends in, which are ordered by name. Entities found through links come after every entity found by its words, so links are followed only when no more than first of those are kept; otherwise the count leaves out what links would find, and is More::AtLeast.

§Errors

Returns an error if the library has no such space, the space cannot be read, or keep fails.

Source

pub fn entity( &self, space: SpaceId, entity: EntityId, day: Day, ) -> Result<Option<EntityView>, NodeError>

An entity of a space, as a person sees it on day, or None if the space says nothing about it. Of entities merged together, the one they were merged into is shown.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn name( &self, space: SpaceId, entity: EntityId, ) -> Result<Option<String>, NodeError>

The name to show for an entity of a space, if it has one.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn entities( &self, space: SpaceId, of_type: Option<&TypeName>, ) -> Result<Vec<Listed>, NodeError>

The entities of a space that are not deleted, without those that define types, or the entities of a type, ordered by name without regard to case, unnamed ones last.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn deleted(&self, space: SpaceId) -> Result<Vec<Listed>, NodeError>

The deleted entities of a space, without those that define types, ordered by name without regard to case, unnamed ones last: those that can be restored.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn census(&self, space: SpaceId) -> Result<Census, NodeError>

Counts what a space holds, as Library::entities and Library::deleted list it, in one pass over the space that names nothing, which costs much less than listing: for an overview of a large space.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn dated_values( &self, space: SpaceId, entity: EntityId, field: &FieldName, ) -> Result<Vec<DatedValue>, NodeError>

The current values of a field of an entity that have a valid time, with it, ordered by statement ID: what the field held over time, such as each of a dog’s weights, for a chart of how it changed. Of entities merged together, those of all of them; a value in several forms counts once, by its first, and statements that repeat one with a smaller ID count as that one.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn all_dated_values( &self, space: SpaceId, entity: EntityId, wanted: impl Fn(&FieldName) -> bool, ) -> Result<Vec<(FieldName, Vec<DatedValue>)>, NodeError>

Each field of an entity that wanted accepts and that has current values with a valid time, with those values, as Library::dated_values gives them, ordered by field: what an entity held over time in all its fields, read at once, for a time line of many entities. Fields that wanted refuses, such as secret ones, are not read.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn find_entity( &self, space: SpaceId, reference: &str, ) -> Result<EntityId, NodeError>

Finds an entity of a space by its ID, or else by a prefix of its ID of at least six characters or by its name, without regard to case. A name and a prefix that match different entities are ambiguous. Names find only entities that are not deleted, so that references never point to a deleted entity by accident.

§Errors

Returns an error if the library has no such space, the space cannot be read, or no entity or several match.

Source

pub fn find_entity_or_deleted( &self, space: SpaceId, reference: &str, ) -> Result<EntityId, NodeError>

Finds an entity as Library::find_entity does, except that a name that finds no entity that is not deleted finds deleted ones, for showing or restoring them.

§Errors

Returns an error if the library has no such space, the space cannot be read, or no entity or several match.

Source§

impl Library

Source

pub fn export( &self, space: SpaceId, directory: &Path, kind: ExportKind, ) -> Result<Exported, NodeError>

Exports a space into a directory, which must be empty or not exist yet: its entities as JSON, the files its values refer to as they were added, a manifest, a note for people, and the SHA-256 sums of them all, as docs/spec/export.md says. Secret values are left out. A space that has not changed since gives the same files.

§Errors

Returns an error if the library has no such space, the directory holds anything, or the space cannot be read, or the files written.

Source§

impl Library

Source

pub fn verify_export(&self, directory: &Path) -> Result<ExportCheck, NodeError>

Checks an export against the library it came from: every file against SHA256SUMS, and its entities and files against those that an export of the space as of the export’s moment holds, so that changes made since do not count. The types the space has now decide what is secret and how entities are named, and values purged since are gone from the library, so either makes an export differ.

§Errors

Returns an error if a space cannot be read, or a file of the export.

Source§

impl Library

Source

pub fn add_file( &mut self, space: SpaceId, path: &Path, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<AddedFile, NodeError>

Adds the file at path to a space, found on this device. Its content is stored once: a file whose content the space holds already, as a file, is that file, found again, and a new origin records where, unless the space knows the file was found there, unchanged since. A file that this device found at the same path, with the same size and modification time, is taken to be unchanged and is not read again, as rsync takes it. A new file is named as it was found, with its content’s media type and size, and is a photo or a video too if it says it is one, with when and where it was taken, by which camera, and how large it is. The types it needs are added to the space if it lacks them. Paths are kept as the file system resolves them, links and .. followed, so that one place has one path. A file in the system’s temporary folder, while the library is not there, goes into the store, and no origin records where it was, as the folder is soon emptied.

Its storage policy, chosen before the file is read in full, says whether the device keeps it in the store, or where it is, of which the space records its hash alone (technical design: storage policies). The space gets the default policies if it never had them. A file that the rule choosing for it would ask about, as Library::question_for tells, goes into the store until Library::answer answers for its folder.

§Errors

Returns NodeError::Unreadable if path is not a file that can be read, NodeError::CheckedOut if it is the copy of a checkout on this device, and another error if the library has no such space, the types cannot be added, or the content or the changes cannot be saved.

Source

pub fn add_file_from( &mut self, space: SpaceId, path: &Path, from: &FileFrom, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<AddedFile, NodeError>

Adds the file at path to a space, as Library::add_file does, from where from says (technical design: importers): its origin names the source it was imported from, with its path and name there; a file read from a copy that is no original, as one unpacked from an archive, is found where from says, and goes into the store; the values from gives replace what the file says of itself, but on a file the library holds already, a value that someone changed since; and the file goes into the folders it names. The same file found again from another source gets an origin of its own.

§Errors

As Library::add_file.

Source

pub fn question_for( &self, space: SpaceId, path: &Path, ) -> Result<Option<Question>, NodeError>

The question to ask before the file at path is added to a space, if the rule that would choose its policy, as for a new file found there, asks about files as large: whether it can be got again, if it is lost.

§Errors

Returns NodeError::Unreadable if path is not a file that can be read, and another error if the library has no such space, or the space cannot be read.

Source

pub fn answer( &mut self, space: SpaceId, question: &Question, again: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Answers the question about a large file for its folder on this device: a rule that chooses Replaceable for the files there if they can be got again, again, and Standard if not, just before the rule that asked, so that it asks no more about them. If the space no longer has that default policy, nothing is added, and such files go into the store.

§Errors

Returns NodeError::Unreadable if the folder is not one, and another error if the library has no such space, or the change cannot be saved.

Source

pub fn found_before( &self, space: SpaceId, found: &FoundElsewhere, ) -> Result<Option<EntityId>, NodeError>

The file that this device found where found says, as last changed at the same moment, as an earlier import did: then adding it again records nothing, and an importer need not unpack it to tell.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source

pub fn install_standard( &mut self, space: SpaceId, names: &[TypeName], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Adds to a space what the standard types named lack, such as logins in a space made before them, in a change of its own: each as carefully as the space defines its fields already, after checking that it can be added so. Nothing is added if the space lacks nothing.

§Errors

Returns an error if the library has no such space, if a type cannot be added, such as one whose field the space defines with another kind, or if the change cannot be saved.

Source§

impl Library

Source

pub fn is_group(&self, space: SpaceId) -> Result<bool, NodeError>

Whether a space this library holds is a group.

§Errors

Returns NodeError::NoSpace if the library holds no such space, and an error if it cannot be read.

Source

pub fn add_group( &mut self, space: SpaceId, group: SpaceId, role: MemberRole, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Adds a group to a space, as an admin of the space who is a member of the group, with role, an editor’s or a viewer’s: a record of the group in the space, and a request in the group that it join, with the space’s name sealed to the group’s admins. As an admin of the group too, this replica agrees at once, and anchors the agreement in the space, which gives the space the group’s first key. Returns the group’s record in the space.

§Errors

Returns NodeError::AdminsOnly if this replica’s member is no admin of the space, NodeError::GroupAsAdmin for the role of admin, NodeError::NotAGroup if the library holds no such group, NodeError::NotInGroup if this replica is no member of it, NodeError::GroupCycle if the space is the group or a group inside it, at any level, and an error if a change cannot be saved.

Source

pub fn remove_group( &mut self, space: SpaceId, group: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Takes a group out of a space, as an admin of the space, with the role none on its record there: its members leave the space, unless they are members there some other way, and it joins again only by a new addition.

§Errors

Returns NodeError::AdminsOnly if this replica’s member is no admin of the space, NodeError::NotAGroup if the space adds no such group, and an error if the change cannot be saved.

Source

pub fn join_requests( &self, group: SpaceId, ) -> Result<Vec<GroupJoinRequest>, NodeError>

The requests in a group that it join spaces, with the spaces’ names where they are sealed to this replica, and whether an admin agreed or withdrew.

§Errors

Returns NodeError::NotAGroup if the space is no group, and an error if it cannot be read.

Source

pub fn agree_to_join( &mut self, group: SpaceId, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Agrees, as an admin of a group, to the requests that it join a space, and anchors the agreement there if this replica holds the space.

§Errors

Returns NodeError::AdminsOnly if this replica’s member is no admin of the group, NodeError::NoGroupRequest if no request names the space, and an error if a change cannot be saved.

Source

pub fn withdraw_group( &mut self, group: SpaceId, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Withdraws, as an admin of a group, its agreement to join a space, for good: the group leaves the space as a removal does, and joins it again only by a new addition and a new agreement.

§Errors

As Library::agree_to_join.

Source

pub fn space_groups( &self, space: SpaceId, ) -> Result<Vec<GroupInSpace>, NodeError>

The groups that a space’s governing changes add, with their roles, whether they agreed, and, where this replica holds a group’s log, its name and members.

§Errors

Returns NodeError::NeverShared for the personal space, and an error if a space cannot be read.

Source§

impl Library

Source

pub fn history( &self, space: SpaceId, entity: EntityId, field: Option<&FieldName>, ) -> Result<Option<History>, NodeError>

Every value an entity of a space has had, or one field’s, with when each was recorded, by whom, and when it was replaced: the history of the record, in system time. Of entities merged together, the values of all of them. None if the space says nothing about the entity. Values that were purged are gone; secret values that this replica has not opened are left out.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn name_as_of( &self, space: SpaceId, entity: EntityId, millis: u64, ) -> Result<Option<String>, NodeError>

The name an entity of a space had as the library had recorded it at the end of the millisecond millis, if it had one: what Library::name gave then.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn entity_as_of( &self, space: SpaceId, entity: EntityId, day: Day, millis: u64, ) -> Result<Option<EntityView>, NodeError>

An entity of a space as the library had recorded it at the end of the millisecond millis, shown as on day: what Library::entity showed then. Changes recorded later are left out, and values replaced later are shown. The space’s types are those it has now. None if the library knew nothing of the entity then.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

The entities that linked to an entity on day, as the library had recorded them at the end of the millisecond millis, as Library::links_to gives them.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn out_of_reach( &self, replicas: &[EntityId], ) -> Result<Vec<HeldElsewhere>, NodeError>

The spaces of the user’s that a revocation of replicas, by their records in the personal space, cannot reach from this device: those that one of them holds, as its choices say, and this device does not. Each comes with the other devices of the user’s that hold it, but replicas, which revoke them there after a sync that brings them the revocation; where none does, a replica revoked there stays in the user’s place, as no device of theirs can revoke it there. By name, then by ID; the same after the revocation as before.

§Errors

Returns an error if the personal space cannot be read.

Source§

impl Library

Source

pub fn import( &mut self, space: SpaceId, directory: &Path, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Imported, NodeError>

Imports an export into a space, as docs/spec/export.md says: its files, and each of its statements that the space lacks, with their IDs, replaced as the export shows them; never NibKeep’s own records of users, devices, replicas and spaces, nor the fields that govern a space. Importing an export again adds nothing. Changes are saved in batches.

§Errors

Returns an error if the library has no such space; if the folder holds no export that this version reads, one whose sums or counts do not match, or one of this space made before one of its purges, of which nothing is imported; or if a file cannot be read or the changes saved, and then how far the import got.

Source§

impl Library

Source

pub const fn languages(&self) -> &Languages

The languages that the library shows values in, ranked, as LanguageSettings::in_use says.

Source

pub fn language_settings(&self) -> Result<LanguageSettings, NodeError>

The ranked languages of the user, this device and this replica. A list that cannot be read, such as one that a newer version wrote, and an empty one, count as not set.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn set_languages( &mut self, whose: LanguagesFor, languages: Option<&Languages>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Sets the ranked languages of the user, this device or this replica, or, with None, clears them, so that the next list counts.

§Errors

Returns an error if the change cannot be saved.

Source§

impl Library

Links an edit of a file, such as a photo that Google Photos keeps cropped beside its original, to the original, by std.edit-of, unless it is or was an edit already, or has the same content, or either is no file of the space, as one gone or moved away. Returns whether it linked it.

§Errors

Returns an error if the library has no such space, or the space cannot be read or saved.

Source§

impl Library

The entities of a space that link to an entity on day, grouped by the field that links them and ordered by its name: those whose field shows a reference to it, or to an entity merged into it, on that day. Deleted entities, and those that define types, are left out. Of each field, limit entities are given, and how many there are.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

The entities of a space that link to an entity on any day, as Library::links_to gives those that link on one: those whose field shows a reference to it on some day, as a publisher that had someone as its head for some years, and has another now. A relationship’s participants are those on day.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn same_relationship( &self, space: SpaceId, kinds: &[TypeName], values: &[(FieldName, Value)], ) -> Result<Vec<EntityId>, NodeError>

The entities of a space, not deleted, that are relationships of all these types with the participants that these values give in roles: those that hold, of each such role, every entity given, on whichever days. None if the values give no participant in a role. A relationship is an entity, so two devices that record one make two, which this finds, as recorded rather than as shown on some day.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn list_members( &self, space: SpaceId, list: EntityId, ) -> Result<Vec<Member>, NodeError>

The items of an ordered list of a space, in their order: the memberships that put them in it, not deleted, by position key (technical design: ordered lists).

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn list( &self, space: SpaceId, listing: &Listing, today: Day, ) -> Result<Vec<Listed>, NodeError>

The things of a space, deleted ones and those that define types aside, that the listing asks for, as they are on its day, or else today, ordered by name without regard to case, unnamed ones last, unless the listing orders them by a field.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn types_with( &self, space: SpaceId, of_type: &TypeName, ) -> Result<BTreeSet<TypeName>, NodeError>

The types that the entities of a type have, that type too, deleted entities aside: what else they are, such as editions that are audiobooks.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn members(&self, space: SpaceId) -> Result<Vec<SpaceMember>, NodeError>

The members of a shared space, as its counting governing changes say, with their roles now and their replicas, sorted by name and record.

§Errors

Returns NodeError::NeverShared for the personal space, and an error if the space cannot be read.

Source

pub fn find_member( &self, space: SpaceId, reference: &str, ) -> Result<EntityId, NodeError>

The member of a shared space that reference names: by name, whatever the case, or by the start of the record’s ID, at least four characters long; of several, the one with a role, if one alone has one.

§Errors

Returns NodeError::NoMember if none matches, NodeError::Ambiguous if several do, and the errors of Library::members.

Source

pub fn find_members( &self, space: SpaceId, reference: &str, ) -> Result<Vec<EntityId>, NodeError>

Every member of a shared space that reference names, as Library::find_member finds them, those who left or were removed included: one who came back has a record of the past too.

§Errors

Returns NodeError::NoMember if none matches, and the errors of Library::members.

Source

pub fn give_role( &mut self, space: SpaceId, member: EntityId, role: MemberRole, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Gives a member of a shared space a role, as an admin of it: viewer, editor or admin; the role none removes them, as Library::remove_member does.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::AdminsOnly if this replica’s member is no admin, NodeError::NoMember if the space has no such member, NodeError::LastAdmin if the space would have no admin left, and an error if the change cannot be saved.

Source

pub fn remove_member( &mut self, space: SpaceId, member: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Removes a member of a shared space, as an admin of it, or, for this replica’s own member, leaves, as Library::leave does: gives them the role none, which ends every replica of theirs there, and gives the space a new key, sealed to the replicas that remain, so that they read nothing added after. What they did without knowing of it is set aside on every device, for an admin to review.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::AdminsOnly if this replica’s member is no admin, NodeError::NoMember if the space has no such member, or they left already, NodeError::LastAdmin if the space would have no admin left, and an error if the changes cannot be saved.

Source

pub fn leave( &mut self, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<bool, NodeError>

Leaves a shared space: gives this replica’s own member the role none, which ends every replica of the user there, and keeps the user out of it through groups, where they are in it through one, staying in the group. They keep what they hold, read only, and get nothing added after; the members who remain give the space a new key as they learn of it. Returns whether it closed the space, as the last member there.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::Removed if the member left or was removed already, NodeError::NotListed if this replica is no member’s there, NodeError::AiAgentMayNot for an AI agent’s replica, NodeError::LastAdmin if the member is the only admin while others remain, who makes another an admin first, and an error if the change cannot be saved.

Source

pub fn check_leave(&self, space: SpaceId) -> Result<bool, NodeError>

Checks that this replica’s member may leave a shared space now, as before saying what leaving would do, and returns whether leaving would close it, as its last member.

§Errors

Returns the errors of Library::leave but those of saving.

Source

pub fn check_remove( &self, space: SpaceId, member: EntityId, ) -> Result<bool, NodeError>

Checks that this replica’s member may remove member from a shared space now, as before saying what removing would do; returns whether member is this replica’s own, whose removal is leaving, as Library::check_leave checks.

§Errors

Returns the errors of Library::remove_member but those of saving.

Source

pub fn suggests_second_admin(&self, space: SpaceId) -> Result<bool, NodeError>

Whether inviting someone to a space should suggest making them a second admin: a shared space with a single admin does, and the personal space never.

§Errors

Returns an error if the space cannot be read.

Source

pub fn ai_agents_allowed(&self, space: SpaceId) -> Result<bool, NodeError>

Whether a space allows AI agents now: the personal space does, and a shared space where its admins said so last (technical design).

§Errors

Returns an error if the space cannot be read.

Source

pub fn allow_ai_agents( &mut self, space: SpaceId, allow: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Says, as an admin of a shared space, whether it allows AI agents: an AI agent’s replica is listed there only while it does, and what it writes counts only then. Stopping them ends the AI agents’ replicas listed there, as a removal does, and gives the space a new key that they do not get; allowing them again brings those back.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::AdminsOnly if this replica’s member is no admin there, and an error if the change cannot be saved.

Source

pub fn find_person( &self, space: SpaceId, reference: &str, ) -> Result<EntityId, NodeError>

The person in a shared space that reference names, as Library::find_entity finds entities, but of the type std.person alone: so that neither a member’s record, which has the user’s name, nor another entity is taken for a person.

§Errors

Returns NodeError::NoEntity if no person matches, NodeError::Ambiguous if several do, and an error if the space cannot be read.

Source

pub fn check_admin( &self, space: SpaceId, what: &'static str, ) -> Result<EntityId, NodeError>

Checks that this replica’s member is an admin of a shared space now, as before showing a code that could not be used, and returns the member.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::Revoked if this replica is revoked there, NodeError::AiAgentMayNot for an AI agent’s replica, NodeError::AdminsOnly if its member is no admin, and an error if the space cannot be read.

Links a member of a shared space to a person in it, or, without one, unlinks them: as the member, for themselves, or as an admin, for another member. The link holds once an admin’s statement and the member’s own agree; an admin’s own statement counts for both while they are an admin.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::NotListed if this replica is no member’s there, NodeError::AdminsOnly for another member if this replica’s member is no admin, NodeError::NoMember if the space has no such member, NodeError::NoEntity if it holds no such person, and an error if the change cannot be saved.

Source§

impl Library

Source

pub fn merge_entities( &mut self, space: SpaceId, from: EntityId, into: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Merges an entity of a space into another that it turns out to be the same as: from then on, the entity it is merged into shows what both say, and references to either lead to it. The entities merged into from go with it. A merge of from into another entity is replaced. A merge is undone by Library::undo_merge.

§Errors

Returns an error if the library has no such space, the space no such entities; if they are one entity already, merged or not; if either is deleted, defines a type or a field, or is one of NibKeep’s own records of a user, device, replica or space; or if the change cannot be saved.

Source

pub fn undo_merge( &mut self, space: SpaceId, entity: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Undoes the merge of an entity of a space into another: it shows what it says again, apart from the entity it was merged into, with the entities merged into it.

§Errors

Returns an error if the library has no such space, if the entity was not merged into another, or if the change cannot be saved.

Source

pub fn merged( &self, space: SpaceId, entity: EntityId, ) -> Result<Vec<Listed>, NodeError>

The other entities merged with an entity of a space, by their own names, ordered by name without regard to case, unnamed ones last: those that a merge undone would set apart.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn merged_as_of( &self, space: SpaceId, entity: EntityId, millis: u64, ) -> Result<Vec<Listed>, NodeError>

The other entities merged with an entity of a space, as the library had recorded them at the end of the millisecond millis, as Library::merged gives them.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn own_types( &self, space: SpaceId, entity: EntityId, ) -> Result<Vec<TypeName>, NodeError>

The types that an entity’s own statements give it, apart from those of the entities merged with it: what it is, set apart from a merge.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn find_merged( &self, space: SpaceId, entity: EntityId, reference: &str, ) -> Result<EntityId, NodeError>

One of the other entities merged with an entity of a space, found by its ID, a prefix of its ID of at least six characters, or one of its own names, in any form, without regard to case: what a merge undone would set apart, or merged again move.

§Errors

Returns an error if the library has no such space, the space cannot be read, or no entity merged with it, or several, match.

Source§

impl Library

Source

pub fn move_entity( &mut self, from: SpaceId, entity: EntityId, to: SpaceId, history: MoveHistory, behind: Behind, secrets: MoveSecrets, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Moves an entity of from to the space to, with the folders, lists, memberships and members that it holds, through every level, each once, as Library::move_preview lists them: marks each in from as moved into a new one, and writes the new ones in to, with their values, references among them leading to the new ones; with MoveHistory::Bring, their past values too, replaced, each value with the mover’s note of where it came from, when that space recorded it and by whom, and when it was replaced there; with MoveSecrets::Bring, their secret values, sealed with the secrets key of to, which this replica sets up there first if it may, and the fields secret in from made secret for good in to where its types leave them plain; the definitions of their types that to lacks; and their files’ content, whose keys are wrapped for to. A folder that stays no longer holds what moved, which it finds through its mark. Returns the entity the given one is now. The old entities keep their history in from, and links to them lead to the new ones for those who hold to. The marks come first: a mark whose entity never came is passed over, so a move cut short leaves the entities where they were.

§Errors

Returns an error if the spaces are one, this library lacks either, this replica is an AI agent’s or revoked there, the entity is not in from, was moved already, or what would move holds one of the library’s own records, a definition or a tree, or is in a tree; with MoveSecrets::Bring, NodeError::MoveNeedsSecrets if any of it may hold secret values while the secrets of from are locked, or those of to, the personal space, are; NodeError::NotSecretThere if a field of its secret values is secret in from and would be plain in to, whose admins alone make it secret; the errors of setting up the secrets of to, if this replica holds none there, such as NodeError::AdminsOnly or NodeError::SpaceSecretsElsewhere; NodeError::NotHere if a file’s content is not on this device; or an error if a change cannot be saved. Nothing moves then.

Source

pub fn move_preview( &self, from: SpaceId, entity: EntityId, to: SpaceId, ) -> Result<MovePreview, NodeError>

What moving an entity of from to to would take: the entity, and the folders, lists, memberships and members that it holds, through every level, each once, but those deleted or moved already; and the folders and lists of from that stay and hold some of them, which no longer hold them in to (technical design: spaces and moves). An app shows this before a move takes more than the entity, or takes it out of a folder or a list.

§Errors

As Library::move_entity, for what a move refuses.

Source

pub fn moved_into( &self, space: SpaceId, entity: EntityId, ) -> Result<Option<(SpaceId, EntityId)>, NodeError>

The entity that an entity of a space was moved into, and its space, following moves onward, if this replica holds the space of where it is now: of several, as two moves at the same time make, the one with the smallest ID. A mark whose entity this replica holds nowhere is passed over.

§Errors

Returns an error if the library has no such space, or a space cannot be read.

Source

pub fn moved_from( &self, space: SpaceId, entity: EntityId, ) -> Result<Vec<(SpaceId, EntityId)>, NodeError>

The entities of the replica’s other spaces that moved into an entity of space, or into one merged into it there, each with its space, following moves back, as far as Library::moved_into leads them to it.

§Errors

Returns an error if the library has no such space, or a space cannot be read.

The entities that link to an entity of a space on day, as Library::links_to gives them, together with those of the replica’s other spaces that link to the entities that moved into it, as a replica that holds both spaces shows them (technical design: spaces and moves): but those whose new entities link to it here, as what moved along does. Each field’s count counts them all, and its entities are the first limit by name.

§Errors

Returns an error if the library has no such space, or a space cannot be read.

Source

pub fn name_anywhere( &self, entity: EntityId, ) -> Result<Option<String>, NodeError>

An entity’s name, in the space it was moved into, if it was, or else in whichever space holds it.

§Errors

Returns an error if a space cannot be read.

Source

pub fn may_hold_secrets( &self, space: SpaceId, entity: EntityId, ) -> Result<bool, NodeError>

Whether an entity of a space holds secret values, as far as this replica can tell: a value it opened, or a value written before its field was secret; or, while the space’s secrets are locked, which hides which entity a sealed value is of, a field secret there that its types list.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source§

impl Library

Source

pub fn keeps_up_to(&self) -> Result<u64, NodeError>

How many bytes of files this device keeps as an everyday device: as the person set it, else a tenth of the size of the disk its replica is on, on a computer, and none on a phone, which keeps thumbnails alone (technical design: the planner).

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn pinned_files( &self, device: EntityId, ) -> Result<BTreeSet<EntityId>, NodeError>

The files pinned to one of the person’s devices, in any space, by their IDs.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn pin_file( &mut self, (space, file): (SpaceId, EntityId), device: EntityId, pinned: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Pins a file of a space to one of the person’s devices that holds the space, which then keeps it whatever its size, or unpins it: in the personal space, where other members never see it. The device keeps it from its next sync.

§Errors

Returns NodeError::NotAFile if file is no file of the space, NodeError::WhichDevice if device is no device of the person’s, NodeError::DeviceLacksSpace if it does not hold the space, as its choices say, and another error if the change cannot be saved.

Source

pub fn record_opened( &mut self, space: SpaceId, file: EntityId, wall_millis: u64, ) -> Result<(), NodeError>

Records that a file of a space was opened on this device at wall_millis, outside the history: an everyday device then keeps it whatever its size for a while, which makes a sync fetch it, and ranks it by when it was last opened. It is never synced.

§Errors

Returns an error if the library has no such space, or the record cannot be saved.

Source

pub fn holders_of( &self, space: SpaceId, file: EntityId, ) -> Result<Vec<Replica>, NodeError>

The other replicas whose latest accounts list a sealed copy of a file’s current content, which a sync with one of them would bring: those to look for when the file is opened on this device and it lacks the content.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source§

impl Library

Source

pub fn install_policies( &mut self, space: SpaceId, downloads: Option<&Path>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Gives a space the default policies and rules, if it never had them, and this device a rule for its downloads folder, downloads, if it never had one (technical design: storage policies): Critical, Standard and Replaceable, and rules that choose Standard for a file from a camera, Replaceable for one from the downloads folder, and Standard for any other, asking above 1 GiB.

§Errors

Returns an error if the library has no such space, or the change cannot be saved.

Source

pub fn policies(&self, space: SpaceId) -> Result<Vec<Policy>, NodeError>

The policies of a space that are not deleted, ordered by name without regard to case.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn rules(&self, space: SpaceId) -> Result<Vec<Rule>, NodeError>

The rules of a space that are not deleted, in the order in which they choose.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn find_policy( &self, space: SpaceId, reference: &str, ) -> Result<EntityId, NodeError>

The policy of a space that reference names: its name, without regard to case, its ID, or a prefix of its ID of at least six characters.

§Errors

Returns NodeError::NoEntity if no policy is named so, NodeError::Ambiguous if several are, and an error if the space cannot be read.

Source

pub fn add_policy( &mut self, space: SpaceId, name: &str, needs: Needs, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Adds a policy to a space.

§Errors

Returns NodeError::EmptyName if the name is empty, and an error if the library has no such space, or the change cannot be saved.

Source

pub fn edit_policy( &mut self, space: SpaceId, policy: EntityId, edit: &PolicyEdit, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Changes a policy of a space: each value given replaces the values the policy has of it.

§Errors

Returns NodeError::NoEntity if policy is no policy of the space, NodeError::EmptyName if the name is empty, and an error if the change cannot be saved.

Source

pub fn add_rule( &mut self, space: SpaceId, rule: &NewRule, place: Place, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

Adds a rule to a space, at place among its rules. A folder is on this device.

§Errors

Returns NodeError::NoEntity if the rule’s policy is no policy of the space, NodeError::Unreadable if its folder is not one, and an error if the change cannot be saved.

Source

pub fn remove_rule( &mut self, space: SpaceId, rule: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Removes a rule of a space: deletes it, so that it chooses nothing until it is restored.

§Errors

Returns NodeError::NoEntity if rule is no rule of the space, and an error if the change cannot be saved.

Source

pub fn remove_policy( &mut self, space: SpaceId, policy: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Removes a policy of a space: deletes it, so that rules that choose it choose nothing, and files that chose it have their policy chosen by the rules, until it is restored.

§Errors

Returns NodeError::NoEntity if policy is no policy of the space, and an error if the change cannot be saved.

Source

pub fn move_rule( &mut self, space: SpaceId, rule: EntityId, place: Place, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Moves a rule of a space to place among the others.

§Errors

Returns NodeError::NoEntity if rule is no rule of the space, and an error if the change cannot be saved.

Source

pub fn set_policy( &mut self, space: SpaceId, entity: EntityId, policy: Option<EntityId>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Sets an entity’s own choice of policy, which wins over the rules, or clears it with None, so that the rules choose again.

§Errors

Returns NodeError::NoEntity if policy is no policy of the space, and an error if the change cannot be saved.

Source

pub fn policy_of( &self, space: SpaceId, entity: EntityId, ) -> Result<Choice, NodeError>

The policy chosen for an entity of a space, as its own choice or the rules choose.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn check_policies( &self, space: SpaceId, wall_millis: u64, ) -> Result<PolicyCheck, NodeError>

How the policies of a space are met for its files, as of wall_millis: for each policy, how many files it is chosen for, and which of them lack copies; the disks that hold copies; and how the space’s changes are held. Copies count disks: this device’s are on its disk, as it holds them now, in the store, where they were found, unchanged, and as unchanged copies of checkouts of their current content; the other devices’ are on theirs, as their accounts last said (technical design: where the copies are). A copy counts only if it was checked in the 8 weeks before wall_millis (technical design: checking and repair).

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn protect( &mut self, protection: &NewProtection<'_>, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Protects the library’s keys another way: with a new passphrase, or with a new key in the platform’s keystore. The keystore key of the old protection, if it had one, is deleted once the key file is written. The library stays open, and closes and opens again with the new protection.

§Errors

Returns NodeError::LibraryPassphrase if the passphrase unlocks the library’s secrets; an error if the passphrase cannot be used or the keystore fails, or if the key file cannot be read or written, in which case nothing changed.

Source

pub fn protect_secrets( &mut self, protection: &NewProtection<'_>, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Protects the library’s secrets another way: with a new passphrase, or with a new key in the platform’s keystore, while they are unlocked, which they stay. They are sealed before the key file is locked, as deriving a key from a passphrase, or a keystore’s prompt, takes a while; secrets keys that another program gave meanwhile are kept. The keystore key of the old protection, if it had one, is deleted once the key file is written.

§Errors

Returns NodeError::SecretsLocked if the secrets are locked; an error of the keys, KeysError::NoSecrets, if there are none; NodeError::LibraryPassphrase if the passphrase is the library’s; an error if this replica is an AI agent’s; an error if the passphrase cannot be used or the keystore fails, or if the key file cannot be read or written, in which case nothing changed.

Source

pub fn forget_lost_secrets(&mut self) -> Result<(), NodeError>

Forgets the secrets compartment, whose key the keystore lost, as Android destroys keys that need the person’s confirmation once the screen lock is removed: it opens never again. The library can then ask another replica for the secrets, as a new one does; where none holds them, they are lost, and new ones can be set up.

§Errors

Returns NodeError::SecretsKeyKept if the secrets can still be unlocked: the keystore has their key, or a passphrase protects them; an error of the keys, KeysError::NoSecrets, if there are none; an error if the keystore fails, or the key file cannot be read or written, in which case nothing changed.

Source§

impl Library

Source

pub fn purgeable( &self, space: SpaceId, entity: EntityId, field: &FieldName, value: Option<&Value>, ) -> Result<Purge, NodeError>

What purging an entity’s values of a field would take away: every value it has held, current or past, or only those equal to value, also those of the entities merged into it. Content that a value refers to, such as a file’s, goes with every value that holds it in a field of the same kind, secret or ordinary, of any entity, current or past, and with its sealed copies of that kind; finding those values reads the whole space, as content is rarely purged, and a value left behind would refer to content that nothing can read. Ordinary content takes its thumbnails with it, whole, with their own content. The same content in a field of the other kind is sealed apart, and stays: purging a file leaves a secret file of the same content, whether the secrets are unlocked or not, and the other way round.

§Errors

Returns an error if the library has no such space; if the entity has no such value; if the field is secret and the space’s secrets are locked while it holds secret values, as only unlocked secrets show which values they are; if a value cannot be purged, such as a replica’s key; or if the space’s state cannot be read.

Source

pub fn purge( &mut self, space: SpaceId, entity: EntityId, field: &FieldName, value: Option<&Value>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Purge, NodeError>

Purges an entity’s values of a field for good, as Library::purgeable finds them: destroys, on every replica, the keys and payloads of the changes that asserted them, or the record keys of secret ones, and states again what else those changes held. What a purged value replaced stays replaced. The same change destroys the keys of the sealed copies of the content they refer to, and the copies of this device’s checkouts of it are deleted where they are unchanged, as Library::settle_checkouts deletes them after a sync on other devices. Whoever may purge is decided with roles; the person confirms before the call.

§Errors

Returns the errors of Library::purgeable, or an error if a value cannot be purged, such as a replica’s key, or the purge cannot be saved.

Source§

impl Library

Source

pub fn check_recovery_source( source: &Path, code: &RecoveryCode, ) -> Result<(), NodeError>

Checks, before anything is asked or made, that code opens what the source in source holds for it, a backup or a library that no longer unlocks: the personal space’s first key, from its recovery file.

§Errors

Returns NodeError::NoRecoverySource if source is neither a backup nor a library with a recovery file, NodeError::CodeOpensNothing if the code opens nothing there, NodeError::RecoveryFileChanged if the file’s entry for the code is not what the code signed, NodeError::NewerFormats if a later version of NibKeep changed the library, and an error if the file cannot be read.

Source

pub fn recovery_replaces(directory: &Path, source: &Path) -> bool

Whether recovering in directory from the library in source would replace the library here, which no longer unlocks: its replica is the one here, which a recovery sets aside once it is done.

Source

pub fn recover( directory: &Path, (source, code): (&Path, &RecoveryCode), joining: Joining<'_>, (protection, secrets): (&NewProtection<'_>, Option<&NewProtection<'_>>), now: &dyn Fn() -> u64, rng: &mut impl CryptoRng, ) -> Result<(Self, Recovered), NodeError>

Recovers the library of the person whose recovery code is code on this computer, in directory, from the source in source, as a new replica that joining makes, protected as protection says, and the secrets as secrets says, if the code holds them: Library::start_recovery, then Recovering::finish.

§Errors

Returns the errors of Library::start_recovery and Recovering::finish.

Source

pub fn start_recovery<'a>( directory: &Path, (source, code): (&'a Path, &'a RecoveryCode), joining: Joining<'_>, protection: &NewProtection<'_>, now: &dyn Fn() -> u64, rng: &mut impl CryptoRng, ) -> Result<Recovering<'a>, NodeError>

Starts recovering the library of the person whose recovery code is code on this computer, in directory, from the source in source, as a new replica that joining makes, protected as protection says: it opens the personal space’s first key from the source’s recovery file, takes in what the source holds of the personal space, and opens the keys sealed to the code; Recovering::finish does the rest. The code’s keys are held in memory alone. Until it is done, nobody knows the new replica, and a recovery that fails removes it; one cut short, as by a crash, leaves it marked, and a recovery run again removes it and starts over.

The source is a backup, or a library on this computer that no longer unlocks: its directory, in which the replica that is here is read, or else its one copy with a recovery file, or the folder of one of its replicas. It is read as a copy is, and never written to. If it is the library in directory, the new replica goes beside its replica, which Recovering::finish sets aside.

§Errors

Returns NodeError::Exists if another library is here, NodeError::NoRecoverySource if source is neither a backup nor a library with a recovery file, NodeError::CodeOpensNothing if the code opens nothing there, NodeError::RecoveryFileChanged if the file’s entry for the code is not what the code signed, all before anything is written, NodeError::RecoveryCodeRevoked if the source holds the code’s revocation, NodeError::BackupBusy if another program updates the backup, and an error if the source cannot be read or the new replica made.

Source§

impl Library

Source

pub fn recovery_codes(&self) -> Result<Vec<RecoveryCodeInfo>, NodeError>

The person’s recovery codes, as their personal space names them, the oldest first, revoked ones too: every code that the space names, whichever member its statement names, as every replica there is the user’s, and each is given the space’s keys.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn revoke_replaced_recovery_codes( &mut self, at_once: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Vec<RecoveryCodeInfo>, NodeError>

Revokes the person’s codes that a newer one replaces, as their records say: once every backup carries the newest code that stands, or at once with at_once, as the person says. Done after each sync and each update of a backup, and as a new code stands. Returns those it revoked; none on an AI agent’s replica, which revokes no code.

§Errors

Returns an error if the personal space cannot be read, or a revocation saved.

Source

pub fn recovery_codes_made_by( &self, replicas: &[EntityId], ) -> Result<Vec<RecoveryCodeInfo>, NodeError>

The person’s codes that stand and that one of replicas made, as the key that signed each one’s statement says: those that revoking a device names.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn find_recovery_code( &self, reference: &str, ) -> Result<RecoveryCodeInfo, NodeError>

The recovery code that reference names, by its short name, in either case, or by its record’s ID, of those that stand.

§Errors

Returns NodeError::WhichRecoveryCode if it names none that stands, or several.

Source

pub fn add_recovery_code( &mut self, code: &RecoveryCode, secrets: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<RecoveryCodeInfo, NodeError>

Names a recovery code in the personal space, once the person wrote it down and typed it back, and gives it the keys of the space that were given out, as a replica that lacks them is given them. With secrets, as the person chose, it also gives the code the secrets, which must be unlocked: the code then opens them too. Naming a code that is named already changes nothing, but gives it the secrets if asked, on the device that made it alone.

§Errors

Returns NodeError::AiAgentMayNot on an AI agent’s replica, NodeError::WhichRecoveryCode if the code was revoked, as a revocation is final, NodeError::SecretsLocked if secrets is asked while they are locked, before anything is named, NodeError::RecoveryCodeMadeElsewhere if they are asked for a code that another device made, and an error if the changes cannot be saved.

Source

pub fn check_recovery_code( &self, code: &RecoveryCode, ) -> Result<RecoveryCheck, NodeError>

Checks a recovery code on this device, which works: whether the personal space names it, whether it stands, and, in each space that names it, which of the keys that this replica holds it opens.

§Errors

Returns an error if a space cannot be read.

Source

pub fn revoke_recovery_code( &mut self, reference: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<RecoveryCodeInfo, NodeError>

Revokes the recovery code that reference names, as Library::find_recovery_code finds it, and gives the personal space a new key in the same change, which the code is not given: so it opens nothing added later, and brings no device back.

§Errors

Returns NodeError::AiAgentMayNot on an AI agent’s replica, NodeError::WhichRecoveryCode if reference names no code that stands, or several, and an error if the change cannot be saved.

Source§

impl Library

Source

pub fn plan_removals( &self, records: &Records, found: &BTreeSet<[u8; 32]>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Removals, NodeError>

Plans a pass of removals, as of wall_millis: the sealed blobs that this replica holds and no longer keeps, as the planner says, at most REMOVALS_AT_ONCE of them, and for each, other disks whose copies together meet the strictest policy of the files that hold or held its content without this replica’s, each with a replica on it found on the network, whose found endpoints say, whose latest account lists a copy checked in the last 8 weeks, or a backup plugged into this computer, which this replica reads itself and proves at once; the challenges to put to those replicas, with the answers that this replica’s copies give. A copy whose policy needs a copy away from home waits for relays, as no replica away is on the home network, unless a backup kept away is plugged in; so does one that another space of the replica keeps a key for, which that space may keep. So does one that this replica holds for another, as records say, which is about to remove its own: asking that one to prove its copy would hold it there in turn, and the two would keep each other from removing for as long as both try.

§Errors

Returns an error if the library or the records cannot be read.

Source

pub fn remove_proven( &mut self, removals: &Removals, records: &Records, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Removed, NodeError>

Removes the copies of a pass whose proofs came while they stand, as of wall_millis, those that this replica still does not keep and whose policy the proven copies still meet: marked first in records as being removed, so that this replica proves none of them to another meanwhile, and none that it holds for another, which it proved. Its account then says that it no longer holds them. Then it purges what this replica’s moves left behind, of those whose content’s copies in the new space were proven while they stand, and this replica holds still; and moves on the drops of spaces that this replica makes (Library::drop_space).

§Errors

Returns an error if the library cannot be read, the records cannot be written, or a file cannot be removed; those removed before stay removed.

Source§

impl Library

Source

pub fn replicas_named(&self, target: &str) -> Result<Vec<Replica>, NodeError>

The user’s replicas that target names: the replica with that ID, or the replicas of the device with that ID or name, or the AI agent’s replica of that name, revoked ones included. A device’s name names no AI agent’s replica. An ID may be given by its first eight characters or more, as lists show them.

§Errors

Returns NodeError::WhichDevice if target names no device or replica of the user’s, or several, and an error if the personal space cannot be read.

Source

pub fn to_revoke(&self, target: &str) -> Result<Vec<Replica>, NodeError>

The replicas that revoking target revokes, as Library::replicas_named finds them, those whose every key is revoked already left out.

§Errors

Returns the errors of Library::replicas_named, and NodeError::WhichDevice if target names this replica or its device.

Source

pub fn space_key_numbers( &self, space: SpaceId, ) -> Result<(Vec<u64>, u64), NodeError>

The numbers of the keys of a space that this replica holds, in order, and the number of the one it writes with.

§Errors

Returns an error if the library has no such space.

Source

pub fn is_revoked(&self) -> Result<bool, NodeError>

Whether this replica knows that it was revoked. A revoked replica seldom does: every replica that knows of the revocation refuses to sync with it.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn revoke( &mut self, replicas: &[EntityId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Vec<SpaceId>, NodeError>

Revokes replicas of the user, for good: no replica syncs with them any more, those of their changes that this replica does not have are set aside, and the personal space gets a new key, sealed to every replica that remains, so that they cannot read what is added later. Each revocation names the key it revokes: every key that the replica’s record has, but this replica’s own. The person confirms before the call. In every other space and group where they are listed, it revokes them too, and the devices that they added there and that the personal space does not list, which nothing tells from one that a thief paired on them: returns the spaces and groups where it revoked such a device.

§Errors

Returns NodeError::WhichDevice if a replica is this one or not the user’s, NodeError::Revoked if this replica was revoked itself, and an error if the keys or the change cannot be saved.

Source

pub fn set_aside(&self) -> Result<Vec<SetAside>, NodeError>

The changes set aside in the personal space, waiting for review, ordered by ID.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn set_aside_in(&self, space: SpaceId) -> Result<Vec<SetAside>, NodeError>

The changes set aside in a space, waiting for review, ordered by ID.

§Errors

Returns an error if the space cannot be read.

Source

pub fn accept_set_aside( &mut self, changes: &[ChangeId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Accepts changes that were set aside in the personal space, as Library::accept_set_aside_in does there.

§Errors

Returns the errors of Library::accept_set_aside_in.

Source

pub fn accept_set_aside_in( &mut self, space: SpaceId, changes: &[ChangeId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Accepts changes that were set aside in a space, so that they count after all, with their own authors and times, in a change that governs the space: in a space with members, as an admin of it. Only those that accepting makes count are accepted, as SetAside::acceptable says: never one that governs the space, nor one of a key that no replica of the space has. Returns how many were accepted. The person confirms before the call, having seen what they do.

§Errors

Returns NodeError::AiAgentMayNot for an AI agent’s replica, NodeError::Revoked if this replica was revoked, NodeError::AdminsOnly in a space with members if its member is no admin there, and an error if the space cannot be read or the change saved.

Source

pub fn settle_keys( &mut self, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Settles the keys of the spaces after a sync: takes the keys sealed to this replica, gives the keys it holds to the replicas that lack them, and makes a new key where its newest is not safe, as after two revocations at the same time; and states that the fields the types make secret are secret for good. A replica that is revoked, or that no counting change lists, does nothing, and an AI agent’s only takes its keys: the rest governs the space, which it may not.

§Errors

Returns an error if a space cannot be read, or the keys or the changes saved.

Source§

impl Library

Source

pub fn add_secret_file( &mut self, space: SpaceId, name: &str, content: impl Read, attached_to: &[EntityId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<AddedSecretFile, NodeError>

Adds a secret file to a space, with its secrets unlocked: seals content for the secrets, so that only the replicas that hold them read it, and records it as a secret file named name, with its media type as its first bytes tell it and its size, attached to the entities attached_to. Nothing records where it was found: the person decides what becomes of the original. The type of secret files is added to the space if it lacks it.

§Errors

Returns NodeError::SecretsLocked if the space’s secrets are locked or were never set up, NodeError::NoEntity if an entity to attach it to is not in the space, NodeError::Unreadable, naming the file by name, if reading content fails, and another error if the library has no such space, or the content or the change cannot be saved.

Source

pub fn open_secret_file( &self, space: SpaceId, file: EntityId, ) -> Result<impl Read + use<>, NodeError>

Opens the content of a secret file of a space for reading, with the secrets unlocked. The reader checks the content’s hash when it reads all of it in order.

§Errors

Returns NodeError::SecretsLocked if the space’s secrets are locked, NodeError::NotSecretFile if the entity is no secret file, NodeError::Deleted if it is deleted, NodeError::NoCopyHere if this device holds no copy of its content yet, and another error if the library has no such space, or the content cannot be read.

Source

pub fn save_secret_file( &self, space: SpaceId, file: EntityId, place: &Path, ) -> Result<PathBuf, NodeError>

Saves a plain copy of a secret file of a space, with the secrets unlocked, at place: into a folder, under the file’s name, or as a new file. Nothing records it: NibKeep neither protects the copy, nor knows of it, nor deletes it when the file is purged. It replaces nothing. The copy is written beside its place first, checked against the content’s hash and synced; on Unix, only its owner may read it. Returns where the copy is.

§Errors

Returns the errors of Library::open_secret_file, NodeError::PlaceTaken if something is where the copy would go, NodeError::NotAFileName if a copy into a folder would have no name, and NodeError::File if writing fails.

Source§

impl Library

Source

pub fn secrets_protection(&self) -> Result<Option<Protection>, NodeError>

How the library’s secrets keys are protected, or None if it has none yet, as the key file on the disk says: another program may have given them since the library was opened.

§Errors

Returns an error if the key file cannot be read.

Source

pub fn secrets_elsewhere(&self) -> Result<bool, NodeError>

Whether another replica keeps the library’s secrets, which this one cannot read or write until one that holds them gives them: it has not asked for them, or waits.

§Errors

Returns an error if the key file or a space cannot be read.

Source

pub fn secrets_state(&self) -> Result<SecretsState, NodeError>

Where the library’s secrets are: here, asked for, held by another replica, or not set up anywhere yet, as the key file on the disk and the personal space’s records say. A replica with a secrets compartment holds them, unless it asked another replica that gave it nothing yet; one whose secrets compartment is gone, whatever its records say, can ask for them again.

§Errors

Returns an error if the key file or a space cannot be read.

Source

pub fn secrets_unlocked(&self, space: SpaceId) -> bool

Whether a space’s secrets are unlocked: whether its secret values can be read and written.

Source

pub fn set_up_secrets( &mut self, protection: &NewProtection<'_>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Gives the library its secrets keys, the first time a secret is stored: a new secrets key for the personal space, in the key file’s secrets compartment, protected as protection says, apart from the library’s other keys, and never by the library’s own passphrase. The records then say that this replica holds them, at the time wall_millis. The secrets are unlocked afterwards.

§Errors

Returns an error if the passphrase is the library’s; NodeError::SecretsElsewhere if another replica holds the secrets, which this one asks for instead; if the library has secrets keys already, also when another program gave them since the library was opened; if the passphrase cannot be used or the keystore fails; or if the key file cannot be read or written, in which case nothing changed. If only the records cannot be written, the secrets are set up all the same, and locked: the next time they are unlocked, the records say so.

Source

pub fn take_secrets_from_copy( &mut self, copy: &Path, unlocker: &Unlocker<'_>, protection: &NewProtection<'_>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Takes the secrets from a copy of a replica made elsewhere, whose secrets unlocker opens, by their passphrase or their keystore entry (technical design: copies of a replica): only the keys that the records gave the copy’s replica, by number and hash, so that no key of another’s making is taken, as a replica takes keys given to it. This replica then holds them, in its secrets compartment, protected as protection says, and the records say so, as when a replica sets up the secrets. The copy is only read. Returns how many keys it took. The secrets are unlocked afterwards.

§Errors

Returns an error if the passphrase is the library’s; NodeError::SecretsSetUp if this replica holds the secrets or asked for them already; an error of the keys if unlocker does not open the copy’s secrets; NodeError::NoSecretsInCopy if they hold none of the keys that the records gave the copy’s replica; NodeError::NewerFormats if a later version of NibKeep changed the copy; and the errors of Library::set_up_secrets.

Source

pub fn check_may_ask(&self, from: EntityId) -> Result<(), NodeError>

Whether this replica may ask for the secrets from from: it holds none, while from does, is not this one, and is not revoked. A replica that asked already may name another, with Library::ask_secrets_from.

§Errors

Returns NodeError::SecretsNowhere if no replica holds the secrets yet, NodeError::SecretsSetUp if this one does, NodeError::SecretsAsked if it asked already, NodeError::WhichDevice if from holds none, as the records say, or is revoked; NodeError::ForeignKey if this replica’s record lists a key that it did not make; and an error if this replica is an AI agent’s, or the library cannot be read.

Source

pub fn ask_for_secrets( &mut self, from: EntityId, protection: &NewProtection<'_>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Asks for the secrets that another replica holds, from from, which the person chose: states, at the time wall_millis, a new key that opens what is sealed to it, and that it takes the secrets from from alone; then makes this replica’s secrets compartment, protected as protection says, and never by the library’s passphrase, with that key and no secrets keys yet. When the person chooses to, from gives them, and this replica takes them while its secrets are unlocked. They are unlocked afterwards.

§Errors

Returns the errors of Library::check_may_ask; an error if the passphrase is the library’s, cannot be used, or the keystore fails; or if the key file cannot be read or written. If the compartment cannot be written after the records were, the replica can ask again.

Source

pub fn ask_secrets_from( &mut self, from: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Asks for the secrets from another replica than the one this one asked first, which may have been lost: it takes them from from alone from now on.

§Errors

Returns NodeError::NotAsked if this replica did not ask for the secrets, NodeError::WhichDevice if from holds none or is revoked, and an error if the change cannot be saved.

Source

pub fn give_secrets( &mut self, replica: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Gives the secrets keys this replica holds to replica, which asked for them from this one, sealed to the key it asked with, at the time wall_millis: in each space that both are replicas of, those keys that it was not given yet. The secrets must be unlocked: the person confirmed. It checks all of it before it gives any. Returns how many keys it gave.

§Errors

Returns NodeError::SecretsLocked if the secrets are locked, and NodeError::SecretsElsewhere or NodeError::SecretsNowhere if this replica holds none; NodeError::NotAsked if replica did not ask for them; NodeError::WhichDevice if it asked another, or is this one, an AI agent’s, revoked, or no replica of the user’s; NodeError::ForeignKey if this replica’s record lists a key that it did not make, so that what it gives would not count; and an error if a change cannot be saved, in which case the spaces before it were given theirs.

Source

pub fn ask_for_space_secrets( &mut self, space: SpaceId, from: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Asks for the secrets of a shared space from from, the record there of a replica of another member that holds them, which the person chose: states, at the time wall_millis, this replica’s secrets encryption key in the space and that it takes the space’s secrets from from. When the person of from chooses to, it gives them, with Library::give_space_secrets, and this replica takes them while its secrets are unlocked. This user’s own replicas pass a space’s secrets on to each other by themselves, and need not ask.

§Errors

Returns NodeError::NeverShared for a space with no members, NodeError::SetUpSecretsFirst if this replica has no secrets compartment, NodeError::SecretsLocked if it is locked, NodeError::SecretsSetUp if this replica holds the space’s secrets, NodeError::WhichDevice if from holds none, as the records say, or is this replica or ended there, NodeError::Removed if this replica’s member left or was removed, NodeError::ForeignKey if its record lists a key it did not make, and an error if this replica is an AI agent’s or the change cannot be saved.

Source

pub fn give_space_secrets( &mut self, space: SpaceId, replica: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Gives the secrets of a shared space that this replica holds to replica, the record there of another member’s replica that asked this one for them, sealed to the key it asked with, at the time wall_millis: those keys it was not given yet. The secrets must be unlocked: the person confirmed. From then on this replica gives it the space’s new keys by itself, as it does to every replica known to hold them. Returns how many keys it gave.

§Errors

Returns NodeError::NeverShared for a space with no members, NodeError::SecretsLocked if the secrets are locked, NodeError::SpaceSecretsElsewhere if this replica holds none of the space’s; NodeError::NotAsked if replica did not ask for them; NodeError::WhichDevice if it asked another, or is this one, an AI agent’s, or ended or no replica of the space; NodeError::ForeignKey if this replica’s record lists a key it did not make; and an error if the change cannot be saved.

Source

pub fn settle_secrets( &mut self, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

While the secrets compartment is open: takes the secrets keys given to this replica, by the replica it takes the secrets from, sealed to the key it asked with, if their hashes are those stated; saves them, and opens the secret values. Then states, at the time wall_millis, what the records do not say yet: that key, the replica it takes the secrets from, and for one that set them up, the keys it holds; if that cannot be saved, the next time tries again. A compartment that holds no secrets keys, for a key that the records do not say it asks with, is removed, so that the replica can ask anew: one that joined and stopped before it said so, or whose record lists a key that it did not make. Does nothing while the compartment is closed, and on a replica that is an AI agent’s, revoked or not listed; if another program protected the secrets anew, they are locked.

§Errors

Returns an error if the key file or a space cannot be read, or the keys taken saved.

Source

pub fn unlock_secrets( &mut self, unlocker: &Unlocker<'_>, ) -> Result<(), NodeError>

Unlocks the secrets: the secrets keys, after the person has confirmed, which open the secret values of the spaces and seal new ones. Lock them again soon, with Library::lock_secrets. Secrets keys that another replica gave this one since are taken by Library::settle_secrets, which apps call next.

§Errors

Returns an error if the library has no secrets compartment, unlocker does not unlock it, or the key file cannot be read. A replica that asked for the secrets, and was not given them yet, unlocks a compartment without keys.

Source

pub fn secrets_key( directory: &Path, unlocker: &Unlocker<'_>, ) -> Result<CompartmentKey, NodeError>

The key of the secrets of the library in directory, after the person has confirmed, without opening the library: a keystore’s prompt may take a while, during which other programs may use the library. Library::unlock_secrets_with unlocks them with it.

§Errors

Returns an error if the library has no secrets compartment, unlocker does not unlock it, or the key file cannot be read.

Source

pub fn unlock_secrets_with( &mut self, key: &CompartmentKey, ) -> Result<(), NodeError>

Unlocks the secrets with their key, as Library::unlock_secrets does.

§Errors

Returns an error if the library has no secrets compartment, key does not open it, as when another program protected it anew since, or the key file cannot be read.

Source

pub fn unlock_kept_secrets(&mut self) -> Result<bool, NodeError>

Unlocks the secrets with the key that a library opened again from Closed kept, if it kept one: whether they are unlocked now. If another program protected them anew since, the key opens them no longer, and is forgotten.

§Errors

Returns an error if the key file cannot be read, or the secret values cannot be opened.

Source

pub fn lock_secrets(&mut self)

Locks the secrets: forgets the secrets keys and the secret values they opened.

Source§

impl Library

Source

pub fn secrets_key_numbers( &self, space: SpaceId, ) -> Result<(Vec<u64>, Option<u64>), NodeError>

The numbers of the secrets keys of a space that this replica holds while its secrets are unlocked, in order, and the number of the one it seals new secret values with.

§Errors

Returns an error if the library has no such space.

Source§

impl Library

Source

pub fn sources(&self, space: SpaceId) -> Result<Vec<Source>, NodeError>

The sources of a space’s files, ordered by name, each with how many files were found there.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source

pub fn folder_named( &mut self, space: SpaceId, (name, parent): (&str, Option<EntityId>), description: Option<&str>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(EntityId, bool), NodeError>

The folder of a space named name in the folder parent, or in none, made if the space has none, with description if it is made or has none, and whether it was made. An importer puts albums in folders so.

§Errors

Returns NodeError::EmptyName for an empty name, and an error if the space cannot be read or written.

Source

pub fn scratch_folder(&self) -> Result<PathBuf, NodeError>

A folder on the library’s disk for files that an importer unpacks before it adds them, as from an archive, emptied of what an import cut short left: on the same disk, so that a large file does not fill a smaller one, such as a temporary file system in memory.

§Errors

Returns an error if the folder cannot be made.

Source

pub fn source_named( &mut self, space: SpaceId, name: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<EntityId, NodeError>

The source of a space named name, made if the space has none of that name, whatever its case.

§Errors

Returns NodeError::EmptyName for an empty name, and an error if the space cannot be read or written.

Source§

impl Library

Source

pub fn spaces(&self) -> Vec<SpaceId>

The spaces this replica holds: the personal space first, then the others by ID.

Source

pub fn choose_space(&mut self, space: Option<SpaceId>) -> Result<(), NodeError>

Chooses the space that new entities go to for as long as the library is open, and the only one that Library::locate looks in; with none, new entities go to the personal space, and every space is looked in.

§Errors

Returns NodeError::NoSpace if this library holds no such space.

Source

pub const fn chosen_space(&self) -> Option<SpaceId>

The space chosen for this session, if one is.

Source

pub fn space_of(&self, entity: EntityId) -> Result<Option<SpaceId>, NodeError>

The space that holds an entity, of those this replica holds: the first, the personal space first, where the entity has a statement, or was merged into another.

§Errors

Returns an error if a space cannot be read.

Source

pub fn default_space(&self) -> SpaceId

The space that new entities go to: the one chosen, or else the personal space.

Source

pub fn space_name(&self, space: SpaceId) -> Result<Option<String>, NodeError>

A space’s name, as this library’s languages show it, if it has one: the name kept for it in the personal space where its own has not come yet, as on a device that took the space and has not synced it since.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source

pub fn find_space(&self, reference: &str) -> Result<SpaceId, NodeError>

Finds a space by its name, in any case, by its ID, or by the start of its ID.

§Errors

Returns NodeError::NoSpaceNamed if no space matches, and NodeError::Ambiguous-like NodeError::SpacesNamed if several do.

Source

pub fn create_space( &mut self, name: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<SpaceId, NodeError>

Makes a space besides the personal one, named name: this replica founds it, with the user as its member and first admin, states that it holds it, and lists it in the personal space with its first key sealed to each of the user’s devices that take new spaces, as computers do, so that they hold it too, and returns its ID (technical design).

§Errors

Returns an error if the name is empty, this replica is an AI agent’s or revoked, or the keys or the changes cannot be saved.

Source

pub fn create_space_on( &mut self, name: &str, also: &[EntityId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<SpaceId, NodeError>

Makes a space as Library::create_space does, and gives it too to the devices of the user’s that the person chose, also, by their records in the personal space, besides those that take new spaces (technical design).

§Errors

The errors of Library::create_space.

Source

pub fn create_group( &mut self, name: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<SpaceId, NodeError>

Makes a group, named name: a space with members and no data of its own, which can be a member of spaces, as an editor or a viewer, so that whoever joins the group joins each of them (technical design). This replica founds it, with the user as its first admin, as Library::create_space founds a space, and returns its ID.

§Errors

The errors of Library::create_space.

Source

pub fn create_group_on( &mut self, name: &str, also: &[EntityId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<SpaceId, NodeError>

Makes a group as Library::create_group does, and gives it too to the devices of the user’s that the person chose, as Library::create_space_on does.

§Errors

The errors of Library::create_space.

Source

pub fn rename_space( &mut self, space: SpaceId, name: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Renames a space besides the personal one, whose name stays.

§Errors

Returns an error if the space is the personal one or this library has none such, the name is empty, or the change cannot be saved.

Source

pub fn search_everywhere( &self, query: &str, ) -> Result<Vec<(SpaceId, Listed)>, NodeError>

Searches every space for what holds the words, as Library::search does in one: what each finds, with the space, the personal space first.

§Errors

Returns an error if a space cannot be read.

Source

pub fn locate(&self, reference: &str) -> Result<(SpaceId, EntityId), NodeError>

Finds an entity in whichever space holds it, or in the space chosen, if one is, by its ID, the start of its ID, or its name, as Library::find_entity does in one space.

§Errors

Returns NodeError::NoEntity if no space has it, and NodeError::Ambiguous if several entities match, in one space or in several.

Source

pub fn locate_or_deleted( &self, reference: &str, ) -> Result<(SpaceId, EntityId), NodeError>

Finds an entity as Library::locate does, except that a name that finds no entity that is not deleted finds deleted ones, as Library::find_entity_or_deleted does.

§Errors

As Library::locate.

Source

pub fn state_space_choice( &mut self, space: SpaceId, holds: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Choice, NodeError>

States this replica’s choice of a space: whether it holds it, signed by its key, with a number one above the highest of its choices of that space that the personal space and the space state; on its own record in the personal space, where its user’s other devices read it, and, where this replica holds the space, by its choices too, and is listed there, on its record there, where a choice not to hold it ends this replica, as a removal does (technical design).

§Errors

Returns NodeError::PersonalSpaceHeld for the personal space, and an error if this replica is an AI agent’s, or a change cannot be saved.

Source

pub fn list_again( &mut self, space: SpaceId, replica: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Lists again, in space, the replica of this replica’s user whose record in the personal space is replica, after it dropped the space, once it asked for the space again: carries there its newest choice of the space that the personal space states, where that is one to hold it that outranks the one that stands there, which brings it back, and gives it the space’s keys. Step 2 calls it once the person approves on this device.

§Errors

Returns NodeError::NoNewerChoice if that replica’s newest choice of the space is none, a drop, or one that does not outrank the one that stands there; NodeError::Removed if this replica may not change the space; and an error if a change cannot be saved.

Source§

impl Library

Source

pub fn endpoint(&self) -> [u8; 32]

This replica’s endpoint ID.

Source

pub fn replicas(&self) -> Result<Vec<Replica>, NodeError>

The replicas that the personal space’s counting governing changes list, with what their records say of them, revoked and deleted ones too, as all of them but the revoked sync: this one first, then the others by ID.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn peers(&self) -> Result<Vec<Replica>, NodeError>

The replicas to sync with: the user’s other replicas, then those of other members of the shared spaces that this replica is listed in, each with an endpoint and not revoked.

§Errors

Returns an error if a space cannot be read.

Source

pub fn record_own_endpoint( &mut self, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Makes sure that this replica’s record has its current encryption key and endpoint ID, which an AI agent may have taken away. An AI agent’s replica, which may not write them, leaves them to the replica that paired it.

§Errors

Returns an error if the personal space cannot be read or the change saved.

Source§

impl Library

Source

pub fn takes_new_spaces(&self) -> Result<bool, NodeError>

Whether this device takes the spaces given to it later, or asks first, as it said itself: a device that said nothing takes them.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn new_space_marks(&self) -> Result<BTreeMap<EntityId, bool>, NodeError>

What each replica of the user’s said, itself, of the spaces given to it later: by its record in the personal space, whether it takes them; one that said nothing takes them. A statement counts only where one of the record’s own keys made it, the last of those by the order of the changes; so that no other device can have it take what it was given.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn set_takes_new_spaces( &mut self, takes: bool, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Says, on this device, whether it takes the spaces given to it later, or asks first, as its own statement in the personal space, which no other device can make for it.

§Errors

Returns an error if this replica is an AI agent’s or revoked, or the change cannot be saved.

Source

pub fn give_space( &mut self, space: SpaceId, replicas: &[EntityId], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Gives a space that this device holds to the devices of the user’s that the person chose, by their records in the personal space: its first key sealed to each, with the user’s member there, in one change of the personal space. Each takes it as its own choice says: a computer at once, a phone once the person says so there. A device that has it already, or declined or dropped it, an AI agent’s, and one revoked are passed over.

§Errors

Returns NodeError::NeverShared for the personal space, NodeError::Removed if this device may not give the space, and an error if the change cannot be saved.

Source

pub fn check_new_device(&self, device: &NewDevice) -> Result<(), NodeError>

Checks, before the code is shown, that this device can give a new device each space chosen for it: one it holds, besides the personal one, and is listed in.

§Errors

Returns NodeError::NoSpace for a space that this device does not hold, and NodeError::NotListed for one it is not listed in, or whose member left.

Source

pub fn take_space( &mut self, space: SpaceId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Taking, NodeError>

Takes a space on this device, as the person says here: one given to it, through the personal space or a group, at once, stating that it holds it; one it drops, before its choice is stated, at once too, as it holds it still; one it was not given, or dropped, by asking for it with a choice of its own to hold it, which the person approves on a device that holds it.

§Errors

Returns NodeError::PersonalSpaceHeld for the personal space, NodeError::HoldsSpace if this device holds the space already, and an error if this replica is an AI agent’s or revoked, or a change cannot be saved.

Source

pub fn space_requests(&self) -> Result<Vec<SpaceRequest>, NodeError>

The requests of the user’s other devices for the spaces that this device holds and may give: a device’s newest choice of the space, in the personal space, holds it, and it was never given the space, nor is listed there; or the choice that stands there is a drop that its newer choice outranks. Shown only on a device that holds the space.

§Errors

Returns an error if a space cannot be read.

Source

pub fn allow_space( &mut self, space: SpaceId, replica: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<(), NodeError>

Approves, on this device, the request of the device of the user’s whose record in the personal space is replica for space, as Library::space_requests shows it: gives it the space, or, where it dropped the space, lists it there again, with every key made meanwhile, and gives it the space too where it was never given it, as the device that made it.

§Errors

Returns NodeError::NoRequest if that device asks for no such space here, and an error if a change cannot be saved.

Source

pub fn known_spaces(&self) -> Result<Vec<KnownSpace>, NodeError>

Every space of the user’s but the personal one, whether this device holds it or not, as the personal space knows them: those it holds, those given to any device of the user’s, those whose names it keeps, and those that a device chose; each with its name, what this device did with it, and the devices that hold it. A space that the user left is left out. By name, then by ID.

§Errors

Returns an error if a space cannot be read.

Source

pub fn find_known_space(&self, reference: &str) -> Result<SpaceId, NodeError>

Finds a space of the user’s, held here or not, by its name, in any case, by its ID, or by the start of its ID, as Library::known_spaces knows them, and as Library::find_space finds those held here.

§Errors

Returns NodeError::NoSpaceNamed if no space matches, and NodeError::SpacesNamed if several do.

Source§

impl Library

Source

pub fn make_thumbnails_with(&mut self, thumbnailer: Arc<dyn Thumbnailer>)

Brings what reads pictures, so that Library::make_thumbnails makes thumbnails. Without one, as in a program that adds no files, none are made.

Source

pub fn make_thumbnails( &mut self, space: SpaceId, contents: &[Hash], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<ThumbnailsMade, NodeError>

Makes the thumbnails of these contents of files of a space, those that lack one, as the device that adds a file does: each that is the current content of a file that is not a tree’s, of a media type that the thumbnailer reads, that this device holds, in the store or where it was found, unchanged, and no larger than MOST_PICTURE_BYTES. Pictures are read here and made into thumbnails on the computer’s other cores, and each thumbnail is recorded as it comes: sealed as a blob, in a change of its own. A picture that cannot be read gets none, and is counted, as are those still in hand when the thumbnailer has made nothing for a minute, which it is left to finish alone. Nothing is made without a thumbnailer, by an AI agent’s replica, which seals nothing, or where files’ content is secret.

§Errors

Returns an error if the library has no such space, or it cannot be read, or a thumbnail cannot be saved; those recorded before stay.

Source

pub fn record_thumbnails_made( &mut self, space: SpaceId, thumbnails: &[(Hash, Thumbnail)], made_with: &str, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<ThumbnailsMade, NodeError>

Records thumbnails that the program made itself, each of a content of a space, as a phone’s app does, which reads the files it adds with the phone’s own decoders: each of a content that lacks one and is the current content of a picture or a video that is not a tree’s, recorded as made with made_with, such as android 1. The others are left out. Nothing is recorded by an AI agent’s replica, or where files’ content is secret.

§Errors

Returns an error if the library has no such space, or it cannot be read, or a thumbnail cannot be saved; those recorded before stay.

Source

pub fn make_missing_thumbnails( &mut self, space: SpaceId, round: usize, wall_millis: u64, rng: &mut impl CryptoRng, progress: &mut dyn FnMut(ThumbnailsMade, usize), ) -> Result<ThumbnailsMade, NodeError>

Makes the thumbnails that the files of a space lack, whichever device added them, as nib file thumbnails does: for files added before thumbnails were made, or of a format that a newer thumbnailer reads. The newest go first, by when a photo was taken, else when its content was recorded, in rounds of round, after each of which progress hears what was made so far, of how many.

§Errors

As Library::make_thumbnails.

Source

pub fn missing_thumbnails(&self, space: SpaceId) -> Result<Vec<Hash>, NodeError>

The contents of the files of a space that lack a thumbnail, and of a media type that the thumbnailer reads, newest first, as Library::make_missing_thumbnails makes them; none without a thumbnailer.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source

pub fn thumbnail( &self, space: SpaceId, file: EntityId, ) -> Result<Option<ThumbnailOf>, NodeError>

The thumbnail that a file of a space shows, of its current content: of those made of it, the one made the newest way, the first recorded among those, as every device chooses alike; None if none was made, or the file has no content.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source

pub fn purge_thumbnails_made_twice( &mut self, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<usize, NodeError>

Purges, in each space where this replica may, the thumbnails that it made of contents that have another thumbnail shown, as two devices that add one photo before they sync both make one (technical design: thumbnails): each whole, but its marks, and its own content unless something else holds that; once the one shown is held here, so that this device shows a picture all along. The device that made a thumbnail purges it, as a member may purge what they wrote; one that never syncs again leaves its own. Returns how many it purged.

§Errors

Returns an error if a space cannot be read, or a purge cannot be saved.

Source

pub fn thumbnail_jpeg( &self, space: SpaceId, thumbnail: &ThumbnailOf, ) -> Result<Option<Vec<u8>>, NodeError>

The JPEG of a thumbnail, from the copy this replica holds, or None if it holds none.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source

pub fn save_thumbnail( &self, space: SpaceId, thumbnail: &ThumbnailOf, path: &Path, ) -> Result<(), NodeError>

Writes the JPEG of a thumbnail into a new file at path, for scripts and tests. It replaces nothing: the JPEG is written beside path first, synced, and then put in place, so that a write that fails leaves nothing at path.

§Errors

Returns NodeError::PlaceTaken if something is at path, NodeError::NotHere if this replica does not hold the JPEG, and NodeError::File if writing fails.

Source

pub fn thumbnail_counts( &self, space: SpaceId, ) -> Result<ThumbnailCounts, NodeError>

How many of a space’s files are pictures or videos, and how many of those have a thumbnail.

§Errors

Returns an error if the library has no such space, or it cannot be read.

Source§

impl Library

Source

pub fn tree_diff( &self, space: SpaceId, tree: EntityId, between: Option<(TreePoint, TreePoint)>, ) -> Result<Vec<FileDiff>, NodeError>

How a tree differs: with between given, from its first point to its second, as each is read (TreePoint); without, the copy on this device from the tree as the library has it now, what a commit would record. Files are paired by what they are, so that a move shows as one.

§Errors

Returns NodeError::NoRevision if a revision is not the tree’s, NodeError::NoTreeHere if the copy is asked for and the tree has none here, and an error if the space or the copy cannot be read.

Source

pub fn tree_diff_with( &self, space: SpaceId, tree: EntityId, between: Option<(TreePoint, TreePoint)>, secrets: bool, ) -> Result<Vec<FileDiff>, NodeError>

How a tree differs, as Library::tree_diff tells it, with the lines of secret files too if secrets says so, which this device reads with the secrets unlocked; without, a secret file shows only that it changed.

§Errors

As Library::tree_diff.

Source

pub fn revision_diff( &self, space: SpaceId, revision: EntityId, secrets: bool, ) -> Result<Option<Vec<FileDiff>>, NodeError>

What a revision changed, as git show shows a commit: from the tree as its author had it without its commit’s parts to the tree with them, so that changes made meanwhile on other devices do not slip in. None if revision is no revision of a tree.

§Errors

Returns an error if the space cannot be read.

Source§

impl Library

Source

pub fn tree_log( &self, space: SpaceId, tree: EntityId, path: Option<&str>, ) -> Result<Vec<TreeLogEntry>, NodeError>

The log of a tree, newest first: each change that touched its files and links, with who made it, its revision and the revision’s message, and what it did, by path. With path, only the changes to the file or link there, also when it was elsewhere then.

§Errors

Returns NodeError::NotInTree if the tree holds nothing at path, and an error if the space cannot be read.

Source

pub fn tree_blame( &self, space: SpaceId, tree: EntityId, path: &str, ) -> Result<Vec<BlameLine>, NodeError>

Blame for the file at path of a tree: for each line of its current version, the revision and the author that last changed it, through every version it had, whatever its path then.

§Errors

Returns NodeError::NotInTree if the tree holds no file at path, NodeError::NotText if a version is no text, NodeError::NoCopyHere if this device holds no copy of one, and an error if the space cannot be read.

Source

pub fn tree_blame_with( &self, space: SpaceId, tree: EntityId, path: &str, secrets: bool, ) -> Result<Vec<BlameLine>, NodeError>

Blame for the file at path of a tree, as Library::tree_blame gives it, and of a secret file too if secrets says so, with the secrets unlocked.

§Errors

The errors of Library::tree_blame; NodeError::SecretLines if the file is a secret one and secrets does not ask for it, and NodeError::SecretsLocked if it does while the secrets are locked.

Source§

impl Library

Source

pub fn tree_repositories( &self, space: SpaceId, tree: EntityId, ) -> Result<Vec<RecordedRepository>, NodeError>

The repositories that a tree records, in the order of their paths, each with whether this device’s copy holds it.

§Errors

Returns an error if the space or the index cannot be read.

Source

pub fn tree_repository_folders( &self, space: SpaceId, tree: EntityId, ) -> Result<Vec<String>, NodeError>

The folders of the copy of a tree on this device that hold Git repositories, by their paths in the tree: what nib asks Git about before a commit. The folder is walked, and nothing is read.

§Errors

Returns NodeError::NoTreeHere if the tree has no folder on this device, and an error if the space or the index cannot be read.

Source

pub fn repository_changes( &self, space: SpaceId, tree: EntityId, (found, described): (&[String], &[GitRepository]), ) -> Result<Vec<TreeChange>, NodeError>

What a commit would record of a tree’s repositories, for a status: of those found in the copy, what Git says of them, in described, as Library::commit_tree records it with Commit::with_repositories.

§Errors

Returns NodeError::NoTreeHere if the tree has no folder on this device, and an error if the space or the index cannot be read.

Source

pub fn pin_repository( &mut self, space: SpaceId, tree: EntityId, path: &str, commit: Option<&str>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Committed, NodeError>

Pins the repository at path of a tree at commit, a full commit as Git names it, or with None takes its pin away, as a revision of its own: a pinned repository is cloned at that commit, and commits keep it as Git says it is.

§Errors

Returns NodeError::NoRepository if the tree records no repository at path, NodeError::NotACommit if commit is no full commit, and an error if saving fails.

Source

pub fn repositories_to_clone( &self, space: SpaceId, tree: EntityId, ) -> Result<Vec<ToClone>, NodeError>

The repositories that a tree records and this device’s copy does not hold, whose folders are not there: what writing or updating the copy would clone, each with the remote it comes from and the device that recorded it, or why it may not be cloned. One deleted here, which the index says the copy held, is not listed.

§Errors

Returns NodeError::NoTreeHere if the tree has no folder on this device, and an error if the space or the index cannot be read.

Source

pub fn prepare_clone( &self, space: SpaceId, tree: EntityId, to: &ToClone, ) -> Result<CloneFolder, NodeError>

Makes the folder that a clone goes into, empty, once its place is checked as a file’s is, parents and all: never through a link, outside the tree’s folder, into .nib, a .git or the library’s own folder, nor inside another Git repository. What the tree records must still be what to says, as the person agreed to it.

§Errors

Returns NodeError::RepositoryChanged if the record is no longer what to says, or a clone may not take it now, NodeError::UnsafePath if its place is no safe one, NodeError::PlaceTaken if something is there, and an error if a folder cannot be made.

Source

pub fn repository_cloned( &self, space: SpaceId, tree: EntityId, (to, described): (&ToClone, &GitRepository), ) -> Result<(), NodeError>

Notes that this device’s copy of a tree holds the repository that to names, as a clone made it at its path, with what Git says of the clone, described: no longer one to clone, and one whose folder gone later is deleted.

§Errors

Returns NodeError::RepositoryChanged if the tree no longer records it at that path, as when another device moved or deleted it meanwhile, and an error if the index cannot be written.

Source§

impl Library

Source

pub fn update_tree( &self, space: SpaceId, tree: EntityId, partial: bool, ) -> Result<Updated, NodeError>

Brings the copy of a tree on this device to the tree as the library has it, as other devices left it: writes new versions, moves, additions and deletions, merges edits made here with newer versions, and writes out competing values. What was deleted or moved here and not committed stays so. A commit of another device in several parts is left out until all its parts have arrived, unless partial, after which this copy keeps what it took. Nothing is recorded: committing what it wrote settles what competed.

§Errors

Returns NodeError::NoTreeHere if the tree has no folder on this device, NodeError::TreeEmptied if the copy holds none of its files, as a drive that is not there leaves it, and an error if the space or the index cannot be read.

Source

pub fn update_tree_agreeing( &self, space: SpaceId, tree: EntityId, partial: bool, ) -> Result<Updated, NodeError>

Brings the copy of a tree on this device to the tree, as Library::update_tree does, with what waits for the person’s agreement too: moves of secret files, and .nibsecret files that lose lines, which Updated::held lists.

§Errors

As Library::update_tree.

Source

pub fn update_tree_cut_after( &self, space: SpaceId, tree: EntityId, written: usize, ) -> Result<Updated, NodeError>

Updates the copy of a tree as Library::update_tree_agreeing does, but stops once it has written written copies, after its moves and deletions, before it records anything, as a crash would: for trying what an update cut short leaves.

§Errors

As Library::update_tree.

Source§

impl Library

Source

pub fn write_tree( &mut self, space: SpaceId, tree: EntityId, folder: &Path, at: TreePoint, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Written, NodeError>

Writes a tree into folder, empty or new, at a point of its history: as it is, which becomes this device’s copy of it, with its root recorded; or at a revision, or as of a moment, which is a picture of the past and no copy, never over one.

§Errors

Returns NodeError::NotATree if tree is none, NodeError::FolderNotEmpty if the folder holds anything, NodeError::TreeHereAlready if the tree as it is is asked for and this device has a copy of it already, NodeError::TreeInTree or NodeError::NotATreeFolder if the folder is in a tree’s, the library’s or Git’s, and an error if writing or saving fails.

Source

pub fn restore_in_tree( &self, space: SpaceId, tree: EntityId, path: &str, at: TreePoint, ) -> Result<Written, NodeError>

Writes into the copy of a tree on this device the file or link at path, or what is in the folder at path, as it was at a point of the tree’s history; as it is, a file deleted from the tree comes back too. It records nothing: committing it does, after the person checked it. A copy with edits that are not committed, its executable bit too, is moved beside its path first, and marked, so that no commit takes it in (Written::aside).

§Errors

Returns NodeError::NotInTree if the tree held nothing there then, NodeError::EditedCopy if a copy to write over cannot be read, and an error if the index cannot be read or written.

Source

pub fn remove_in_tree( &self, space: SpaceId, tree: EntityId, paths: &[String], force: bool, ) -> Result<CopiesRemoved, NodeError>

Deletes from the copy of a tree on this device the file or link at each of paths, or the tree’s files and links in the folder there, the whole copy for an empty path, and the folders they leave empty, as Git’s rm does: what the next commit records as deleted. It records nothing. A copy with edits that are not committed stays, unless force, and so does whatever the tree does not hold; every copy is looked at before any is deleted.

§Errors

Returns NodeError::UnsafePath if a path leaves the tree, NodeError::NotInTree if the tree holds nothing at one, NodeError::EditedCopy if a copy has edits not committed, or cannot be read, and an error if the index cannot be read.

Source

pub fn revert_in_tree( &self, space: SpaceId, tree: EntityId, revision: EntityId, ) -> Result<Reverted, NodeError>

Writes into the copy of a tree on this device what undoes a revision, and only that, as git revert --no-commit does: each file it changed goes back to its version before it, merged three ways with what later revisions changed; files it moved go back, files it deleted come back, and files it added go. It records nothing. What it cannot undo, it lists with why.

§Errors

Returns NodeError::NoRevision if the revision is not the tree’s, NodeError::EditedCopy if a copy it would change has edits not committed, NodeError::TreeStale if a copy it would change is behind the tree, which an update brings first, and an error if the space cannot be read or writing fails.

Source§

impl Library

Source

pub fn would_start_tree( &self, space: SpaceId, folder: &Path, ) -> Result<StartPreview, NodeError>

Whether a tree could start in folder, and how much it would take in: for asking the person first, as Library::start_tree makes the folder’s files the tree’s copies.

§Errors

As Library::start_tree, before it writes anything.

Source

pub fn start_tree( &mut self, space: SpaceId, folder: &Path, message: Option<&str>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<TreeStarted, NodeError>

Starts a tree in folder: a tree named after the folder, its root on this device, and a first commit of every file in it, with message, in parts, as every commit is. The folder’s files become the tree’s copies, which a purge of their content deletes where they were not edited, so apps ask the person first.

§Errors

Returns NodeError::TreeInTree if the folder is in a tree’s folder on this device, or holds one; NodeError::GitRepositoryHere if it holds a Git repository, which trees record as references; and another error if it is no folder, or reading it or saving the changes fails.

Source

pub fn start_tree_with( &mut self, space: SpaceId, folder: &Path, commit: &Commit<'_>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<TreeStarted, NodeError>

Starts a tree in folder, as Library::start_tree does, with the first commit’s message and the Git repositories in the folder, as Git describes them, from commit.

§Errors

As Library::start_tree.

Source

pub fn trees(&self, space: SpaceId) -> Result<Vec<Tree>, NodeError>

The trees of a space that are not deleted, with their folders on this device, ordered by name.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn tree_at( &self, space: SpaceId, folder: &Path, ) -> Result<Option<Tree>, NodeError>

The tree whose folder on this device holds folder, or is it, if there is one.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn tree_entries( &self, space: SpaceId, tree: EntityId, ) -> Result<Vec<TreeEntry>, NodeError>

The files and links of a tree, as the library has them now, ordered by path. Of competing values, the one in the statement with the smallest ID.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn tree_status( &self, space: SpaceId, tree: EntityId, ) -> Result<TreeStatus, NodeError>

What the copy of a tree on this device holds that the tree does not, and what the tree holds that the copy does not. It reads only the files whose size or modification time changed since they were written or committed, and records what it found unchanged, so that it is not read again. It waits for a commit to the tree that runs, and deletes the copies of content that a purge took away, as Library::settle_checkouts does after a sync.

§Errors

Returns NodeError::NoTreeHere if the tree has no folder on this device, NodeError::TreeFolderGone if its folder is gone, and an error if the space or the index cannot be read.

Source

pub fn commit_tree( &mut self, space: SpaceId, tree: EntityId, commit: &Commit<'_>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Committed, NodeError>

Commits what changed in the copy of a tree on this device, or at the paths given: new files and links, new versions, moves, deletions and executable bits, in parts made one after another (technical design: one entity per change): a first that makes the commit’s revision, with the message and how many parts there are, then a part for each entity it records, which names the revision. Every version is sealed into the store, whatever storage policies say. Returns nothing if nothing changed.

§Errors

Returns NodeError::TreeStale if a path changed here and in the tree since the copy was written, as by another device, NodeError::UnknownVersion if a copy was edited from a version this replica does not know, and NodeError::TreeEmptied if every file of the tree is gone from its copy, unless the commit is forced; NodeError::NoTreeHere if the tree has no folder on this device, and NodeError::TreeFolderGone if its folder is gone; and an error if a file cannot be read or the changes saved.

Source

pub fn tree_secrets( &self, space: SpaceId, tree: EntityId, ) -> Result<TreeSecrets, NodeError>

The secret files of a tree, and its ordinary files that a built-in name, or a .nibsecret file of this device’s copy, matches: files committed before one did, which stay ordinary until a commit makes them secret.

§Errors

Returns NodeError::NotATree if tree is none, and an error if the space, the index or the copy cannot be read.

Source

pub fn secret_file_in_tree( &self, space: SpaceId, file: EntityId, ) -> Result<Option<InTree>, NodeError>

The tree that a secret file belongs to, and its path there, if it is a tree’s: the tree whose commit made it, whatever changes said later of its tree, as any replica of the space may say them, an AI agent’s too. A secret file that no commit of a tree made, as a password record’s, is no tree’s, whatever its tree and path say. A file deleted from its tree is still the tree’s. It needs neither the secrets nor a copy of the tree on this device.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source

pub fn would_purge_made_secret( &self, space: SpaceId, file: EntityId, ) -> Result<MadeSecret, NodeError>

What purging the versions of an ordinary file that a commit made secret would take: the contents its versions held, current or past, that no other value holds as an ordinary file’s, which Library::purge_made_secret purges; and those that another holds, which were never secret, and stay. A file that is not deleted, as one still in its tree, takes nothing.

§Errors

The errors of Library::purgeable.

Source

pub fn purge_made_secret( &mut self, space: SpaceId, file: EntityId, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<MadeSecret, NodeError>

Purges, for good and everywhere, the contents of the versions of an ordinary file that a commit made secret, as Library::would_purge_made_secret finds them, once the person agreed: the secret file at its path keeps its own sealed copy.

§Errors

The errors of Library::purge.

Source

pub fn move_in_tree( &mut self, space: SpaceId, tree: EntityId, (from, to): (&str, &str), wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Committed, NodeError>

Moves a file or a link of a tree, or a folder with everything in it, on the disk and in the tree at once, as one commit: from the path from of the tree to to, which must be free. Edits not committed move with the copy, and stay to commit.

§Errors

Returns NodeError::NotInTree if the tree holds nothing at or under from, NodeError::UnsafePath if to is no path a tree may hold, would go through a link or names what cannot be written here, NodeError::PlaceTaken if something is at to, and an error if moving or saving fails.

Source§

impl Library

Source

pub fn verify(&mut self, wall_millis: u64) -> Result<Report, NodeError>

Checks the library: SQLite’s check of every log file, the signature of every change, and every blob that the replica can read, read in full against its content hash. The rest of every change was checked again, and bad stored keys removed, when the library was opened; the report names the keys removed. Blobs found intact are recorded as checked at wall_millis; a damaged copy is moved aside, so that a sync brings it again, as the regular check does (technical design: checking and repair). Files that this device keeps where they were found are read there and checked against their hashes too, and those whose size and modification time are unchanged recorded as checked. What one check cannot finish is a problem in the report, and the other checks go on.

§Errors

Returns an error if a batch of changes is open, whose changes are not saved yet, or if the library has a space it did not open, which it never should.

Source§

impl Library

Source

pub fn own_wait_days(&self) -> Result<u64, NodeError>

How many days this device waits before purging, as marked now.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn waiting_purges(&self) -> Result<Vec<WaitingPurge>, NodeError>

The purges whose destruction this replica keeps apart, by space and then by when it took them in, with when each wait ends.

§Errors

Returns an error if a space cannot be read.

Source

pub fn waiting_purges_on( &self, found: &[(Backup, PathBuf)], ) -> Result<Vec<WaitingPurge>, NodeError>

The purges that wait on the backups found here before what they destroyed leaves them, as each backup’s record says, by backup and then by when each came.

§Errors

Returns an error if a space cannot be read.

Source

pub fn find_waiting_purges( &self, name: &str, (found, on): (&[(Backup, PathBuf)], Option<&str>), ) -> Result<Vec<WaitingPurge>, NodeError>

The places where the purge that name names waits, on this device and on the backups found here: name is the start of its ID, as nib purges shows it; on, if given, names one backup, by its name or ID, or here this device.

§Errors

Returns NodeError::WhichPurge if it names no purge that waits there, or several.

Source

pub fn stop_purge( &mut self, waiting: &[WaitingPurge], wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Vec<Backup>, NodeError>

Stops a purge where it waits, as waiting lists the places of one purge: makes one change that restores what it destroyed and they keep, which every replica takes, and gives back what this replica kept, and from each backup, through an update of it, what the backup kept, so that what was purged counts again as it was. Returns the backups updated: one that another program holds is not, and gives back at its next update.

§Errors

Returns NodeError::CannotRestore if this member’s role does not allow it: an admin may stop any purge, an editor one of the changes their member’s replicas signed, and nothing is made; and another error if a space or a backup cannot be read or written.

Source

pub fn end_wait( &mut self, waiting: &[WaitingPurge], wall_millis: u64, ) -> Result<(usize, Vec<Backup>), NodeError>

Ends the wait of a purge where it waits, as waiting lists the places of one purge: destroys what this replica kept of what it destroyed, and has each backup let it go at once, through an update of it. Returns how many parts went, and the backups updated.

§Errors

Returns NodeError::WhichPurge if another program updates a backup now, and another error if a space or a backup cannot be written.

Source

pub fn destroy_due(&mut self, now: u64) -> Result<usize, NodeError>

Destroys what this replica keeps apart of the purges whose wait has ended at now, as the holder of the sync role does in its passes, after bringing the wait up to date with the marks. Returns how many parts went.

§Errors

Returns an error if a space cannot be read or written.

Source

pub fn settle_waiting(&mut self, now: u64) -> Result<usize, NodeError>

After a sync: brings this device’s wait up to date with marks that may have come, and gives back what a restore that came brought back, as Library::take_back_restored does.

§Errors

Returns an error if a space cannot be read or written.

Source

pub fn take_back_restored( &mut self, now: u64, opening: bool, ) -> Result<usize, NodeError>

Gives back what this replica keeps apart where a change that restores it came to count, as after a sync brought one, or at now once the library opened. Returns how many parts came back.

§Errors

Returns an error if a space cannot be read or written.

Source

pub fn waiting_copies( &self, space: SpaceId, ) -> Result<Vec<WaitingCopy>, NodeError>

The copies that wait before destroying what a purge of space destroys: the person’s archive nodes listed in that space, this device first, as their marks say; their backups of it; and other members’ archive nodes and backups, as their accounts say.

§Errors

Returns an error if a space cannot be read.

Source§

impl Library

Source

pub fn create( directory: &Path, new: &NewLibrary<'_>, protection: &NewProtection<'_>, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Self, NodeError>

Starts a library in a directory that holds none: a new replica, named after the app that keeps it, with new keys protected as protection says, and the user’s personal space, founded with the user, a person linked to the user, this device, the replica and the space itself, as new says. If starting fails, what was written is removed, keystore keys included.

§Errors

Returns an error if a name is empty, if the directory holds a library already, or if the keys or the space cannot be saved.

Source

pub fn exists(directory: &Path) -> bool

Whether the directory holds a library: a replica that is here, what is left of starting one, or copies of replicas made elsewhere.

Source

pub fn discard(directory: &Path) -> Result<(), NodeError>

Deletes a library’s directory from this device, with the keys of its replicas that the platform’s keystore keeps: for one that the person replaces, as a phone’s app, which keeps one library, does as it joins another. No program may have it open. What other devices hold of it stays there.

§Errors

Returns an error if the directory cannot be removed. A key that the keystore does not delete stays there.

Source

pub fn replica_folder(directory: &Path) -> Result<PathBuf, NodeError>

The folder, in a library’s directory, of its replica that is here, whole or not.

§Errors

Returns an error if the directory holds no library, only copies, or several replicas that are here.

Source

pub fn check_place(directory: &Path) -> Result<(), NodeError>

Whether a new replica of a library can be made in directory, as making, joining or adding it from a copy would find, so that a program can tell before it asks the person for anything: not on a network drive, nor in a folder that a program takes to the cloud, nor on a drive without a journal unless the person allowed it.

§Errors

Returns NodeError::RemoteDrive, NodeError::CloudFolder or NodeError::NoJournal.

Source

pub fn allow_fat(directory: &Path) -> Result<(), NodeError>

Allows the replicas of the library in directory on a drive without a journal, as FAT and exFAT, where a removal without unmounting can damage them later, as the person asked: they are then guarded, and a drive removed while one was open is checked before it is used again (technical design: drives without a journal).

§Errors

Returns NodeError::RemoteDrive or NodeError::CloudFolder for a folder that holds no library, before anything is written there, or an error if the file that says so cannot be written.

Source

pub fn drive_checked(directory: &Path) -> Result<(), NodeError>

Says that the drive of the library in directory was checked, as by fsck or Windows’ “Scan and fix”, after it was removed, or lost its power, while the library was open: the library opens again. The caller then verifies it, as Library::verify does, before it is used (technical design: drives without a journal).

§Errors

Returns an error if the directory holds no replica here, or the guard’s files cannot be written.

Source

pub fn protection(directory: &Path) -> Result<Protection, NodeError>

How the library’s keys are protected, so that an app knows whether to ask for a passphrase before it opens the library.

§Errors

Returns an error if the directory holds no library, one whose start was cut short, or only copies, or its key file is damaged, and NodeError::UncleanRemoval if its drive must be checked before it opens, so that nothing is asked for in vain.

Source

pub fn open( directory: &Path, unlocker: &Unlocker<'_>, ) -> Result<Self, NodeError>

Opens a library: unlocks the replica’s keys, and opens every space.

§Errors

Returns an error if the directory holds no library, or one whose start was cut short, unlocker does not unlock it, or a space cannot be opened.

Source

pub fn open_timed( directory: &Path, unlocker: &Unlocker<'_>, ) -> Result<(Self, Opening), NodeError>

Opens a library as Library::open does, and tells how long its two parts took.

§Errors

As Library::open.

Source

pub fn library_directory(&self) -> Option<&Path>

The library’s directory, as Library::open takes it: the folder that holds its replicas.

Source

pub fn close(self) -> Closed

Closes the library, and keeps its replica’s keys unlocked, and its secrets if they are, so that it opens again without a passphrase: for a program that waits for other replicas, or an app that opens the library for each operation, which should hold no lock on the spaces in between.

Source

pub fn set_ticks(&mut self, ticks: &Ticks)

Reads the times that tell bursts of changes apart from ticks, in every space it has open, instead of the system’s monotonic clock, as StoredLog::set_ticks does: tests give a clock of their own, so that the same changes form the same bursts on every machine.

Source

pub const fn personal_space(&self) -> SpaceId

The user’s personal space.

Source

pub fn secret_fields(&self, space: SpaceId) -> Option<&BTreeSet<FieldName>>

The fields whose values are secret in a space: those that the types of NibKeep, of apps or of the space mark as secret, those that statements governing the space make secret for good, and those that the standard vocabulary makes secret, in every space (Data model). Whether a field is secret is decided here, not by a type’s own definition of it.

Source

pub fn secret_fields_of( &self, space: SpaceId, types: &[TypeName], ) -> Result<Vec<FieldName>, NodeError>

The fields that these types of a space list and that are secret there, as Library::secret_fields says, ordered by name: those whose values an entity of the types may hold sealed. A type of the standard vocabulary that the space does not define lists its fields as the vocabulary does.

§Errors

Returns an error if the library has no such space.

Source

pub fn types(&self, space: SpaceId) -> Result<Types, NodeError>

The types of a space: those that NibKeep defines, combined with those of the space.

§Errors

Returns an error if the library has no such space.

Source

pub fn define_type( &mut self, space: SpaceId, definition: &TypeDef, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Types, NodeError>

Defines a type in a space, or adds to it what the space’s types lack, as Types::define_in says, after Types::check found nothing wrong with it. Returns the space’s types afterwards.

§Errors

Returns an error if the library has no such space, the definition cannot be added as it is, or the change cannot be saved.

Source

pub fn status(&self) -> Result<Status, NodeError>

What the library holds.

§Errors

Returns an error if a space cannot be read.

Source

pub fn user_and_device(&self) -> Result<(Described, Described), NodeError>

The user the library belongs to and this device, named as Library::status names them, without counting what the spaces hold, which costs much more in a large library.

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn state_mark(&self, space: SpaceId) -> Result<StateMark, NodeError>

Where a space’s state stands, and the personal space’s, whose lists of languages name entities: how far into its log file each state file goes. It moves whenever either space takes in anything, here or in another program, so a program may keep what it worked out from the space while the mark stays the same, as an app keeps a long list while a person pages through it.

§Errors

Returns an error if the library has no such space, or a state file cannot be read.

Source

pub fn author_of( &self, space: SpaceId, statement: StatementId, ) -> Result<Option<Author>, NodeError>

Who made the change that asserted a statement of a space: the replica whose key signed it, and the user it belongs to, as the space says. None if the space holds no such statement, or no replica of the space that is not deleted has the key that signed it now, or that replica has no owner.

§Errors

Returns an error if the library has no such space, or the space cannot be read.

Source§

impl Library

Source

pub fn import_blob( &mut self, space: SpaceId, content: impl Read, wall_millis: u64, rng: &mut impl CryptoRng, ) -> Result<Hash, NodeError>

Seals content as a blob of a space, unless the device holds it already, and returns its content hash. Content that another space of the replica holds is not sealed again: the space takes up that copy, once it has read it whole, unless it purged it (technical design).

§Errors

Returns an error if the library has no such space, or reading the content or saving the blob fails.

Source

pub fn batch<T>( &mut self, space: SpaceId, run: impl FnOnce(&mut Self) -> Result<T, NodeError>, ) -> Result<T, NodeError>

Runs run as a batch of changes to a space, saved together when it returns, which makes many changes quicker to save (technical design: saving in batches). Until then, the changes it makes are read as any others, but a crash loses all of them. Whether run succeeds or fails, the changes it made to the space that were not refused are saved, and what it returned is returned; if saving fails, none of them is, and that error is returned. If run panics, none of them is saved. Changes to other spaces are saved one at a time, unless they are in a batch of their own; a space has one batch open at a time. What writes outside a change, such as importing a blob or a purge, is refused, and so is verifying the library. Each batch holds up the space’s other writers until it ends, so it is kept short, such as a thousand changes.

§Errors

Returns an error if the library has no such space, a batch of the space is open already, or the files fail, and otherwise the error of run.

Source

pub fn is_ai_agent(&self) -> Result<bool, NodeError>

Whether this replica is an AI agent’s: whether the change that listed its key in the personal space marks it so (technical design).

§Errors

Returns an error if the personal space cannot be read.

Source

pub fn check_not_ai_agent(&self, what: &'static str) -> Result<(), NodeError>

Refuses, with NodeError::AiAgentMayNot and what, if this replica is an AI agent’s, before an app asks for more, such as pairing a device.

§Errors

Returns NodeError::AiAgentMayNot if this replica is an AI agent’s, and an error if the personal space cannot be read.

Source

pub fn has_left(&self, space: SpaceId) -> Result<bool, NodeError>

Whether this replica’s member left a shared space or was removed from it, or, for an AI agent’s replica, the space allows AI agents no more: it then keeps what it holds there, read only, and gets nothing added after. Never for the personal space.

§Errors

Returns an error if the space cannot be read.

Source

pub fn own_role(&self, space: SpaceId) -> Result<MemberRole, NodeError>

The role that this replica’s user has in a space now, which says what they may do there, as an app shows it: admin in the personal space; in a shared space, the role that its counting governing changes give this replica, through its member directly or through groups, or admin by a claim of theirs that took effect by the latest wall clock time the library was given; none while this replica is not listed there or holds nothing of the space yet, and once it is revoked, or its member left or was removed.

§Errors

Returns NodeError::NoSpace if the library holds no such space, and an error if it cannot be read.

Source

pub fn directory(&self) -> &Path

The folder of the library’s replica.

Source

pub fn changes_kept(&self) -> Result<usize, NodeError>

How many changes the replica keeps, in all its spaces: what grows when changes come into it, made here or received.

§Errors

Returns an error if a log cannot be read.

Source

pub fn catch_up(&mut self) -> Result<bool, NodeError>

Catches up with what other programs, or other libraries of the replica open in this one, wrote to it since this one last read it (technical design: several programs on one replica): reads again what it keeps of each space in memory, such as its types, from each space that another wrote to. A change catches up by itself before it is made; a program that keeps the library open catches up before it reads what it keeps. Returns whether another wrote.

§Errors

Returns NodeError::in_use errors if a space’s state file must be made anew while another program has it open: the library is to be closed, and opened again later.

Source§

impl Library

Source

pub fn network(&self, options: Options) -> Result<Network, NodeError>

Starts this replica’s endpoint, as options say.

§Errors

Returns an error if networking cannot start.

Source§

impl Library

Source

pub fn take_role(&self) -> Result<Option<Role>, NodeError>

Takes the sync role of the library’s replica, as Role::take does: for a program that has it open.

§Errors

Returns an error if the lock’s file cannot be opened or locked.

Source

pub fn sync_records( &self, rng: impl CryptoRng + Send + 'static, ) -> Result<Records, NodeError>

The records of the replica’s sync role, which programs read and write through an encrypted database beside its lock; rng makes the database’s own key and nonces.

§Errors

Returns an error if the database cannot be opened or made.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more