Struct Fetcher

Source
pub struct Fetcher { /* private fields */ }
Expand description

A Fetcher describes a machine for driving a fetching process.

The Fetcher can be constructed using Fetcher::new, providing a FetcherConfig.

It builds a Target that it attempts to reach:

  • Number of replicas that it should successfully fetch from, where a replica is any seed node that the repository is potentially seeded by.
  • A set of preferred seeds that it should successfully fetch from.

If either of these targets are reached, then the fetch process can be considered complete – with preference given to the preferred seeds target.

To drive the Fetcher, it must be provided with nodes to fetch from. These are added via the FetcherConfig. Note that the nodes provided are retrieved in the order they are provided.

Before candidate nodes can be fetched from, the caller needs to mark them as connected to. To get the next available node we call Fetcher::next_node. Once the caller attempts to connect to this node and retrieves its Address, then it can mark it as ready to fetch by calling Fetcher::ready_to_fetch.

To then retrieve the next available node for fetching, the caller uses Fetcher::next_fetch.

To mark that fetch as complete, we call Fetcher::fetch_complete, with the result. At this point, the Fetcher returns a ControlFlow to let the caller know if they should continue processing nodes, to reach the desired target, or they can exit the loop knowing they have successfully reached the target.

The caller may also call Fetcher::fetch_failed to mark a fetch for a given node as failed – this is useful for reasons when the caller cannot connect to the node for fetching.

Finally, if the caller wishes to exit from the fetching process and get the final set of results, they may call Fetcher::finish.

Implementations§

Source§

impl Fetcher

Source

pub fn new(config: FetcherConfig) -> Result<Fetcher, FetcherError>

Construct a new Fetcher from the FetcherConfig.

Source

pub fn next_node(&mut self) -> Option<PublicKey>

Get the next candidate NodeId to attempt connection and/or retrieving their connection session.

Source

pub fn next_fetch(&mut self) -> Option<(PublicKey, Address)>

Get the next NodeId and Address for performing a fetch from.

Note that this NodeId must have been added to the Fetcher using the Fetcher::ready_to_fetch method.

Source

pub fn fetch_failed(&mut self, node: PublicKey, reason: impl ToString)

Mark a fetch as failed for the NodeId, using the provided reason.

Source

pub fn fetch_complete( &mut self, node: PublicKey, result: FetchResult, ) -> ControlFlow<Success, Progress>

Mark a fetch as complete for the NodeId, with the provided FetchResult.

If the target for the Fetcher has been reached, then a Success is returned via ControlFlow::Break. Otherwise, Progress is returned via ControlFlow::Continue.

The caller decides whether they wish to continue the fetching process.

Source

pub fn finish(self) -> FetcherResult

Complete the Fetcher process returning a FetcherResult.

Which variant of the result is returned is determined by whether the Fetcher’s target was reached.

Source

pub fn ready_to_fetch(&mut self, node: PublicKey, addr: Address)

Mark the node as ready to fetch, by providing its Address.

This will prime the node for fetching.

Source

pub fn progress(&self) -> Progress

Get the latest Progress of the Fetcher.

Source

pub fn target(&self) -> &Target

Get the Target that the Fetcher is aiming to reach.

Trait Implementations§

Source§

impl Debug for Fetcher

Source§

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

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoInit<ZeroInit> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,