Skip to main content

Repository

Struct Repository 

Source
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: Tree

The 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

Source

pub fn commit(&self) -> &SignedCommit

The signed commit at the top of it.

Source

pub fn root(&self) -> Cid

The CID of the commit, which is a CAR export’s root.

Source

pub fn rev(&self) -> &str

The revision this repository committed at.

Source

pub fn records(&self) -> usize

How many records it holds.

Source

pub fn record_cid(&self, collection: &str, rkey: &str) -> Option<&Cid>

The CID a record is filed under, if the repository holds it.

Source

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.

Source

fn stored(&self, cid: &Cid) -> Option<&Vec<u8>>

A tree node or a record block by CID, without the commit.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn draft(self) -> Draft

Opens this repository to be changed one record at a time.

See Draft. The repository is moved into the draft, so a caller sharing it clones it first.

Source

fn car(&self, wanted: impl Fn(&Cid) -> bool) -> Vec<u8> ⓘ

Writes a CAR of the blocks wanted accepts, plus the commit.

Trait Implementations§

Source§

impl Clone for Repository

Source§

fn clone(&self) -> Repository

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Repository

Source§

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

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,