pub struct Repository {
commit: SignedCommit,
tree: Tree,
records: BTreeMap<Cid, Held>,
leaves: BTreeMap<String, Cid>,
}Expand description
A signed repository, ready to be handed to somebody who does not trust us.
Fields§
§commit: SignedCommit§tree: TreeThe tree, kept rather than flattened into blocks, because a proof is a walk through it and a walk needs the nodes.
records: BTreeMap<Cid, Held>The record blocks, keyed by CID. Tree nodes are the tree’s.
leaves: BTreeMap<String, Cid>Every record’s tree key and the CID it names.
Implementations§
Source§impl Repository
impl Repository
Sourcepub fn commit(&self) -> &SignedCommit
pub fn commit(&self) -> &SignedCommit
The signed commit at the top of it.
Sourcepub fn record_cid(&self, collection: &str, rkey: &str) -> Option<&Cid>
pub fn record_cid(&self, collection: &str, rkey: &str) -> Option<&Cid>
The CID a record is filed under, if the repository holds it.
Sourcepub fn block(&self, cid: &Cid) -> Option<Vec<u8>>
pub fn block(&self, cid: &Cid) -> Option<Vec<u8>>
One block by CID: the commit, a tree node, or a record.
The three are searched in that order, which is arbitrary — a CID names exactly one of them or none.
Sourcefn stored(&self, cid: &Cid) -> Option<&Vec<u8>>
fn stored(&self, cid: &Cid) -> Option<&Vec<u8>>
A tree node or a record block by CID, without the commit.
Sourcepub fn proof(&self, collection: &str, rkey: &str) -> Proof
pub fn proof(&self, collection: &str, rkey: &str) -> Proof
The blocks that prove what this repository says about one record.
Answers for a key the repository does not hold too: see Proof,
where the difference between the two answers is one field.
Sourcepub fn covering_proof(&self, keys: &BTreeSet<String>) -> BTreeMap<Cid, Vec<u8>>
pub fn covering_proof(&self, keys: &BTreeSet<String>) -> BTreeMap<Cid, Vec<u8>>
The Merkle search tree blocks that cover every key in keys, over the
tree as this repository now stands.
The union of [Tree::covering_proof] over each key — not just its
own path, but the paths to its neighbours either side, because a
split or merge moves nodes on both. A caller that touched several
keys in one commit (com.atproto.repo.applyWrites) unions their
proofs here rather than calling the tree once per key and merging
itself.
This is what a com.atproto.sync.subscribeRepos#commit frame’s
blocks are built from: a relay holds no previous state to walk a
created-only diff against, so it needs enough of the tree to invert
the operations back to prevData starting from nothing. See
docs/conformance.md.
Each key’s neighbours are found in the repository’s own index of keys, so this walks three paths per key and nothing else.
Sourcepub fn nodes(&self) -> usize
pub fn nodes(&self) -> usize
How many Merkle search tree nodes it took to key them.
An operator-facing number, and the cheapest signal that the tree is doing something: a repository whose node count tracks its record count one for one has a broken height function.
Sourcepub fn block_cids(&self) -> BTreeSet<Cid>
pub fn block_cids(&self) -> BTreeSet<Cid>
Every block in the repository, named.
The commit, every tree node and every record, which is exactly what
Self::to_car writes. It exists for a caller keeping a history: the
difference between two repositories’ block sets is the set a commit
created, and a caller that has one repository and the CIDs another one
held can work out what to send without either party holding both.
Sourcepub fn to_car(&self) -> Vec<u8> ⓘ
pub fn to_car(&self) -> Vec<u8> ⓘ
The whole repository as a CARv1 file.
Commit first, then the tree nodes and the records in CID order. The order carries no meaning to a reader — it walks from the root by following links — but it is fixed, so two exports of the same state are byte-identical.
Sourcepub fn to_car_without(&self, held: &BTreeSet<Cid>) -> Vec<u8> ⓘ
pub fn to_car_without(&self, held: &BTreeSet<Cid>) -> Vec<u8> ⓘ
The repository as a CARv1 file carrying only the blocks a reader lacks.
held is what the reader is known to have already. The root is the
current commit either way, so a reader walks from the same place; what
changes is how much of the walk it can do out of the file alone.
The commit block is always written, even when held names it. A CAR
whose root is not in it is legal and every reader here can follow one,
but a file that declares a root and then omits it is the kind of
answer that makes a caller wonder whether the transfer failed, and one
block is not worth the doubt.
Ordering matches Self::to_car’s, so a diff and a full export agree
about the blocks they have in common.
Sourcepub fn to_car_with(&self, wanted: &BTreeSet<Cid>) -> Vec<u8> ⓘ
pub fn to_car_with(&self, wanted: &BTreeSet<Cid>) -> Vec<u8> ⓘ
The repository as a CARv1 file carrying the commit and the blocks in
wanted that it holds.
The same file Self::to_car_without writes when held is every
other block. This looks each wanted block up rather than walking every
block the repository holds, which is what makes it the one a firehose
frame is written with.
Trait Implementations§
Source§impl Clone for Repository
impl Clone for Repository
Source§fn clone(&self) -> Repository
fn clone(&self) -> Repository
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more