Skip to main content

ContentBackend

Trait ContentBackend 

Source
pub trait ContentBackend: Send + Sync {
Show 15 methods // Required methods fn put( &self, reader: &mut dyn Read, mime: &str, ) -> Result<Stored, ContentError>; fn open(&self, hash: &str) -> Result<Option<ContentReader>, ContentError>; fn has(&self, hash: &str) -> bool; // Provided methods fn put_many( &self, items: &[(&[u8], &str)], ) -> Vec<Result<Stored, ContentError>> { ... } fn open_at( &self, hash: &str, offset: u64, ) -> Result<Option<ContentReader>, ContentError> { ... } fn size(&self, hash: &str) -> Option<u64> { ... } fn state(&self, hash: &str) -> ContentState { ... } fn collect_unreferenced( &self, live: &BTreeSet<String>, ) -> Result<Collected, ContentError> { ... } fn release(&self, hash: &str) -> Result<Collected, ContentError> { ... } fn shared(&self) -> bool { ... } fn workspace_scoped(&self) -> bool { ... } fn content_secret(&self) -> Option<SymmetricKey> { ... } fn put_sealed( &self, reader: &mut dyn Read, mime: &str, ) -> Option<Result<Stored, ContentError>> { ... } fn max_item_bytes(&self) -> usize { ... } fn scratch_dir(&self) -> Option<PathBuf> { ... }
}
Expand description

What a ContentStore runs on. Implementations treat the address as authoritative and verify content against it; a store that trusts the key would let one peer poison every replica that later reads that address.

Required Methods§

Source

fn put(&self, reader: &mut dyn Read, mime: &str) -> Result<Stored, ContentError>

Store everything reader yields, returning its address. Storing content already present is a no-op that succeeds. mime is advisory (a backend may index or serve by it).

§Errors

Quota, integrity or I/O failures. Nothing is stored on error.

Source

fn open(&self, hash: &str) -> Result<Option<ContentReader>, ContentError>

Source

fn has(&self, hash: &str) -> bool

Provided Methods§

Source

fn put_many(&self, items: &[(&[u8], &str)]) -> Vec<Result<Stored, ContentError>>

Store many items, answering each address in order: what Self::put does for each, done together where a backend can (one index update, one flush), so a folder of small files costs its bytes rather than its calls. A failing item leaves the others’ answers in place.

Source

fn open_at( &self, hash: &str, offset: u64, ) -> Result<Option<ContentReader>, ContentError>

The content at hash read from offset on: a backend that keeps it in a file seeks there, so serving one piece of a large item reads only that piece. Bytes read so are not checked against the address (that takes the whole item); sealed content is still checked chunk by chunk as it opens.

§Errors

What Self::open answers.

Source

fn size(&self, hash: &str) -> Option<u64>

The length of the content at hash, when the store knows it without reading the bytes: what a reader serving one piece of a large file asks before it seeks there.

Source

fn state(&self, hash: &str) -> ContentState

Where the content at hash has got to. A backend that can fetch from elsewhere reports ContentState::Pending while it does, and may start fetching when asked.

Source

fn collect_unreferenced( &self, live: &BTreeSet<String>, ) -> Result<Collected, ContentError>

Remove every item whose address is not in live, which must be complete: the caller asserts nothing outside it is referenced by anything it is responsible for.

§Errors

ContentError::CollectionUnsupported for backends whose retention is governed elsewhere (a shared device store), or an I/O failure part-way (retry with the same live set).

Source

fn release(&self, hash: &str) -> Result<Collected, ContentError>

Remove the item hash, when the one who keeps it here knows nothing it is responsible for references it any longer (a quota letting the oldest item go). Content kept for another reason under the same address goes with it, so a caller sharing a store removes only what it alone keeps.

§Errors

ContentError::CollectionUnsupported for backends whose retention is governed elsewhere, or an I/O failure.

Source

fn shared(&self) -> bool

Whether content stored here reaches beyond this device’s own copy: the device content store serves it to the app’s other devices and members. A document may then refer to content by address alone; with a store that is not shared, a member would be left holding an address nothing can resolve.

Source

fn workspace_scoped(&self) -> bool

Whether this store answers only for content readable in one workspace: the device content store reads through the scope the launcher handed the window, and serves an address only when that workspace references it. A caller’s content reference is resolved only in such a store, so naming a hash never reaches content from elsewhere on this machine.

Source

fn content_secret(&self) -> Option<SymmetricKey>

The secret the members who read what this store keeps hold, when it is at hand: a sealing store (ContentStore::sealing) then seals each item under a key derived from it and the item’s bytes, rather than a fresh one, so the same bytes stored twice are the same ciphertext under the same reference, kept and carried once.

Whoever holds the secret learns which items are the same bytes, and can tell whether a given item is among them; the members can tell that anyway, by opening both. Whoever does not hold it (the hosts that keep and carry the ciphertext, a device removed before the secret was derived) learns nothing: without the secret no key, and no address, follows from any bytes. The key never leaves the reference, which travels inside the sealed record, so a reader who joins later opens the item as before, and a reference sealed under a fresh key opens as it always did.

Source

fn put_sealed( &self, reader: &mut dyn Read, mime: &str, ) -> Option<Result<Stored, ContentError>>

Seal and keep what reader yields, when the store behind this backend seals what it is handed itself, under the members’ secret it holds and this backend does not (a session’s store, whose device’s daemon holds the workspace’s keys): the sealed reference it answers is what a sealing store hands back. None, reading nothing, when the backend keeps only what is sealed before it reaches it.

Source

fn max_item_bytes(&self) -> usize

The largest item this store accepts: a write that hashes before it seals refuses a larger one as it reads it, rather than holding it whole first (ContentStore::put_reader).

Source

fn scratch_dir(&self) -> Option<PathBuf>

A directory beside the content this store keeps, where a sealing write may keep the plaintext it hashes in a file rather than in memory. None for a store with no directory of its own: one that keeps content on a host, or holds it in memory.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§