pub struct ContentStore { /* private fields */ }Expand description
An app’s handle to binary content: cheap to clone, passed to whatever needs it.
Everything here takes a reference (ContentRef) where it names content: a plain address, or a
sealed reference, which reads through its key. What a store hands back for what it stored is the
reference to keep: sealed when the store seals (Self::sealing).
Implementations§
Source§impl ContentStore
impl ContentStore
pub fn new(backend: impl ContentBackend + 'static) -> Self
pub fn from_backend(backend: Arc<dyn ContentBackend>) -> Self
Sourcepub fn sealing(self) -> Self
pub fn sealing(self) -> Self
This store, sealing what it stores: each item under a key of its own, kept under the
address of its ciphertext, and named by a reference that carries the key. The key derives
from the members’ content secret and the bytes when the backend holds one
(ContentBackend::content_secret), and is fresh otherwise. The store a record’s content
travels through seals, so the record’s readers alone open it.
Sourcepub fn unsealed(self) -> Self
pub fn unsealed(self) -> Self
This store, keeping what it stores under its own address, unsealed: for code that must name content alike wherever it runs (an action applying on every replica). Sealed references still read.
pub fn memory() -> Self
pub fn in_dir(root: impl Into<PathBuf>) -> Self
Sourcepub fn local_for_app() -> Self
pub fn local_for_app() -> Self
The store an app keeps on this machine when the launcher handed it no device content
store (tilo_content_device::for_app prefers that one): the session’s shared directory
when the host names one (SHARED_STORE_ENV), otherwise, where files have no native path
(a browser page), the profile’s app files (FilesBackend), otherwise tilo/content in
the user’s data directory. Content an earlier version kept in the cache directory
(tilo/blobs) still reads. With no usable directory at all, content is kept in memory.
Sourcepub fn page_files() -> Self
pub fn page_files() -> Self
Where files have no native path (a browser page): content in the profile’s app files,
which outlive the page, so an upload a page stored is still here after a reload. Every
app of the profile shares the one store, as native apps share tilo/content. The page
holds those files in memory, so the store is bounded: an item or store past the bound is
refused, never dropped, and nothing collects what the page stored on its own. A page whose
host loaded no app files keeps content in memory, under the same bounds, as a tab alone can.
This is the store a page host lends each window it opens, as the framework’s native
process host lends tilo_content_device::for_app’s: a window keeps content in the store
its host lent it (cx.content()), never in one it opens itself.
Sourcepub const fn seals(&self) -> bool
pub const fn seals(&self) -> bool
Whether this store seals what it keeps, so its writes go one at a time.
Sourcepub fn put(&self, bytes: &[u8]) -> Result<String, ContentError>
pub fn put(&self, bytes: &[u8]) -> Result<String, ContentError>
Store bytes, returning the reference to keep: sealed when this store seals. The media
type is sniffed from the content.
§Errors
See ContentBackend::put.
Sourcepub fn put_public(&self, bytes: &[u8]) -> Result<String, ContentError>
pub fn put_public(&self, bytes: &[u8]) -> Result<String, ContentError>
Store bytes as they are, under their own address, even in a store that seals: content
that is public by nature (an app’s surface, which whoever decides its changes reads).
§Errors
See ContentBackend::put.
Sourcepub fn put_public_many(
&self,
items: &[&[u8]],
) -> Vec<Result<String, ContentError>>
pub fn put_public_many( &self, items: &[&[u8]], ) -> Vec<Result<String, ContentError>>
Keep many items, answering each one’s address in order: Self::put_public
for each, one store write where the backend can make it.
§Errors
Each item its own, as Self::put_public refuses it.
Sourcepub fn put_as(&self, reference: &str, bytes: &[u8]) -> Result<(), ContentError>
pub fn put_as(&self, reference: &str, bytes: &[u8]) -> Result<(), ContentError>
Keep bytes as the content reference names: sealed under its key when it carries one, so
a device that holds the bytes keeps exactly what the writer stored. Refused when bytes
are not that content.
§Errors
ContentError::HashMismatch for other bytes, else see ContentBackend::put.
Sourcepub fn put_reader(
&self,
reader: &mut dyn Read,
mime: &str,
) -> Result<Stored, ContentError>
pub fn put_reader( &self, reader: &mut dyn Read, mime: &str, ) -> Result<Stored, ContentError>
Store everything reader yields without holding it in memory: the device store sends it
to the daemon one runtime_fs::blobs::MAX_PUT_CHUNK at a time. Stored::hash is the
reference to keep, sealed when this store seals.
A sealing store with the members’ secret hashes the plaintext in a first pass and seals it
in a second, and refuses it once it is past ContentBackend::max_item_bytes: a large
item waits in a file beside the store’s own content
(ContentBackend::scratch_dir) rather than whole in memory, and an oversized one is
refused without being held at all.
§Errors
See ContentBackend::put, and ContentError::ItemTooLarge for an item past the
store’s limit.
Sourcepub fn put_inputs(
&self,
inputs: &ContentInputs,
) -> Result<BTreeMap<String, String>, ContentError>
pub fn put_inputs( &self, inputs: &ContentInputs, ) -> Result<BTreeMap<String, String>, ContentError>
Store every input inputs collected (an import’s images, say), answering the reference to
keep for each input’s address: the address itself, or a sealed reference when this store
seals, which the document naming the input names instead.
§Errors
The first refusal; inputs stored before it stay stored.
Sourcepub fn reseal(&self, reference: &str) -> Option<String>
pub fn reseal(&self, reference: &str) -> Option<String>
Store again, sealed, the plain content reference names, when this store seals and it is
here: the sealed reference a record keeps in its place. None for a reference already
sealed, a store that does not seal, or content not here yet. The plain copy stays until
nothing references it (Self::collect_unreferenced), so a reader still holding the old
reference reads it meanwhile.
Sourcepub fn read(&self, reference: &str) -> Option<Vec<u8>>
pub fn read(&self, reference: &str) -> Option<Vec<u8>>
The verified content reference names, opened when sealed, or None when it is not here
(or not intact).
Sourcepub fn open(&self, reference: &str) -> Option<ContentReader>
pub fn open(&self, reference: &str) -> Option<ContentReader>
A streaming, verifying read of the content reference names, opened as it streams when
sealed; see ContentReader. Content kept in parts (Self::put_parts) reads as the
content its parts make, and is None until every part is here: each part not here is
asked for at once.
Sourcepub fn put_parts(&self, reader: &mut dyn Read) -> Result<Stored, ContentError>
pub fn put_parts(&self, reader: &mut dyn Read) -> Result<Stored, ContentError>
Store everything reader yields a part at a time (list::PART_BYTES), never holding
more than one part: content of any size, kept as items no larger than a part. Content
that fits in one part is that one item; larger content is its parts and a list naming
them, whose reference reads as the whole (Self::open). Each is sealed when this store
seals.
§Errors
What storing a part or the list refused, or reading reader failed with.
Sourcepub fn size(&self, reference: &str) -> Option<u64>
pub fn size(&self, reference: &str) -> Option<u64>
The length of the content reference names, when the store knows it
without reading it: for sealed content, the plaintext its sealed
bytes hold; for content kept in parts, what its parts make.
Sourcepub fn read_range(
&self,
reference: &str,
offset: u64,
length: u64,
) -> Result<(u64, Vec<u8>), ContentError>
pub fn read_range( &self, reference: &str, offset: u64, length: u64, ) -> Result<(u64, Vec<u8>), ContentError>
length bytes of the content reference names, from offset: the
bytes read, and the content’s length. Reads only what it answers, so
serving one piece of a large file does not read the file: sealed
content opens from the chunk the piece begins in, and content kept in
parts reads only the parts the piece is in.
§Errors
The content is not here, or cannot be read.
pub fn has(&self, reference: &str) -> bool
pub fn state(&self, reference: &str) -> ContentState
Whether content stored here reaches the app’s other devices and members; see
ContentBackend::shared.
Sourcepub fn workspace_scoped(&self) -> bool
pub fn workspace_scoped(&self) -> bool
Whether this store answers only for content readable in one workspace;
see ContentBackend::workspace_scoped.
Sourcepub fn scratch_dir(&self) -> Option<PathBuf>
pub 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; see ContentBackend::scratch_dir.
Sourcepub fn for_one_workspace(self) -> Self
pub fn for_one_workspace(self) -> Self
This store, declared as one workspace’s (Self::workspace_scoped): for a host that
keeps a store for one workspace alone, so everything in it is that workspace’s (a
test’s profile, one workspace’s headless drive).
Sourcepub fn memory_in_workspace() -> Self
pub fn memory_in_workspace() -> Self
Content in memory, as one workspace’s store
(Self::for_one_workspace): for tests of what a
caller may name by reference.
Sourcepub fn collect_unreferenced(
&self,
live: &BTreeSet<String>,
) -> Result<Collected, ContentError>
pub fn collect_unreferenced( &self, live: &BTreeSet<String>, ) -> Result<Collected, ContentError>
Remove every item not named in live, references or addresses; see
ContentBackend::collect_unreferenced.