[][src]Struct hypercore::Feed

pub struct Feed<T> where
    T: RandomAccess<Error = Box<dyn Error + Send + Sync>> + Debug
{ /* fields omitted */ }

Feed is an append-only log structure.

To read an entry from a Feed you only need to know its PublicKey, to write to a Feed you must also have its SecretKey. The SecretKey should not be shared unless you know what you're doing as only one client should be able to write to a single Feed. If 2 seperate clients write conflicting information to the same Feed it will become corupted. The feed needs an implementation of RandomAccess as a storage backing for the entrys added to it.

There are several ways to construct a Feed

If you have a Feed's PublicKey, but have not opened a given Feed before Use builder to initalize a new local Feed instance. You will not be able to write to this feed.

If you want to create a new Feed Use with_storage and Feed will create a new SecretKey/PublicKey keypair and store it in the Storage

If you want to reopen a Feed you have previously opened Use with_storage, giving it a Storage that contains the previously opened Feed

these references can be changed to the +nightly version, as docs.rs uses +nightly

Implementations

impl<T> Feed<T> where
    T: RandomAccess<Error = Box<dyn Error + Send + Sync>> + Debug + Send
[src]

pub async fn with_storage(__arg0: Storage<T>) -> Result<Self>[src]

Create a new instance with a custom storage backend.

pub fn builder(public_key: PublicKey, storage: Storage<T>) -> FeedBuilder<T>[src]

Starts a FeedBuilder with the provided PublicKey and Storage.

pub fn len(&self) -> u64[src]

Get the number of entries in the feed.

pub fn is_empty(&self) -> bool[src]

Check if the length is 0.

pub fn byte_len(&self) -> u64[src]

Get the total amount of bytes stored in the feed.

pub async fn append<'_, '_>(&'_ mut self, data: &'_ [u8]) -> Result<()>[src]

Append data into the log. /// append will return an Err if this feed was not initalized with a SecretKey.

It inserts the inputed data, it's signature, and a new Merkle node into Storage.

pub async fn head<'_>(&'_ mut self) -> Result<Option<Vec<u8>>>[src]

Get the block of data at the tip of the feed. This will be the most recently appended block.

pub fn has(&mut self, index: u64) -> bool[src]

Return true if a data block is available locally.

pub fn has_all(&mut self, range: Range<u64>) -> bool[src]

Return true if all data blocks within a range are available locally.

pub fn downloaded(&mut self, range: Range<u64>) -> u8[src]

Get the total amount of chunks downloaded.

pub async fn get<'_>(&'_ mut self, index: u64) -> Result<Option<Vec<u8>>>[src]

Retrieve data from the log.

pub async fn proof<'_>(
    &'_ mut self,
    index: u64,
    include_hash: bool
) -> Result<Proof>
[src]

Return the Nodes which prove the correctness for the Node at index.

pub async fn proof_with_digest<'_>(
    &'_ mut self,
    index: u64,
    digest: u64,
    include_hash: bool
) -> Result<Proof>
[src]

Return the Nodes which prove the correctness for the Node at index with a digest.

pub fn digest(&mut self, index: u64) -> u64[src]

Compute the digest for the index.

pub async fn put<'_, '_>(
    &'_ mut self,
    index: u64,
    data: Option<&'_ [u8]>,
    __arg3: Proof
) -> Result<()>
[src]

Insert data into the tree at index. Verifies the proof when inserting to make sure data is correct. Useful when replicating data from a remote host.

pub async fn signature<'_>(&'_ mut self, index: u64) -> Result<Signature>[src]

Get a signature from the store.

pub async fn verify<'_, '_>(
    &'_ mut self,
    index: u64,
    signature: &'_ Signature
) -> Result<()>
[src]

Verify the entire feed. Checks a signature against the signature of all root nodes combined.

pub fn announce(&mut self, message: &Message, from: &Peer)[src]

Announce we have a piece of data to all other peers.

pub fn unannounce(&mut self, message: &Message)[src]

Announce we no longer have a piece of data to all other peers.

pub async fn root_hashes<'_>(&'_ mut self, index: u64) -> Result<Vec<Node>>[src]

Get all root hashes from the feed.

pub fn public_key(&self) -> &PublicKey[src]

Access the public key.

pub fn secret_key(&self) -> &Option<SecretKey>[src]

Access the secret key.

pub async fn audit<'_>(&'_ mut self) -> Result<Audit>[src]

Audit all data in the feed. Checks that all current data matches the hashes in the merkle tree, and clears the bitfield if not. The tuple returns is (valid_blocks, invalid_blocks)

pub fn bitfield(&self) -> &Bitfield[src]

Expose the bitfield attribute to use on during download

pub fn download(&mut self, _range: Range<u64>) -> Result<()>[src]

(unimplemented) Provide a range of data to download.

pub fn undownload(&mut self, _range: Range<u64>) -> Result<()>[src]

(unimplemented) Provide a range of data to remove from the local storage.

pub fn finalize(&mut self) -> Result<()>[src]

(unimplemented) End the feed.

pub fn update_peers(&mut self)[src]

Update all peers.

impl Feed<RandomAccessDisk>[src]

pub async fn open<P: AsRef<Path>>(path: P) -> Result<Self>[src]

Create a new instance that persists to disk at the location of dir. If dir was not there, it will be created.

Trait Implementations

impl<T: Debug> Debug for Feed<T> where
    T: RandomAccess<Error = Box<dyn Error + Send + Sync>> + Debug
[src]

impl Default for Feed<RandomAccessMemory>[src]

Create a new instance with an in-memory storage backend.

Panics

Can panic if constructing the in-memory store fails, which is highly unlikely.

impl<T: RandomAccess<Error = Box<dyn Error + Send + Sync>> + Debug + Send> Display for Feed<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Feed<T> where
    T: RefUnwindSafe

impl<T> Send for Feed<T> where
    T: Send

impl<T> Sync for Feed<T> where
    T: Sync

impl<T> Unpin for Feed<T> where
    T: Unpin

impl<T> UnwindSafe for Feed<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Clear for T where
    T: InitializableFromZeroed + ?Sized

impl<T> From<T> for T[src]

impl<T> InitializableFromZeroed for T where
    T: Default

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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