Service

Struct Service 

Source
pub struct Service<D, S, G> { /* private fields */ }
Expand description

The node service.

Implementations§

Source§

impl<D, S, G> Service<D, S, G>

Source

pub fn node_id(&self) -> NodeId

Get the local node id.

Source

pub fn local_time(&self) -> LocalTime

Get the local service time.

Source

pub fn emitter(&self) -> Emitter<Event>

Source§

impl<D, S, G> Service<D, S, G>
where D: Store, S: ReadStorage + 'static, G: Signer<Signature>,

Source

pub fn new( config: Config, db: Stores<D>, storage: S, policies: Config<Write>, signer: Device<G>, rng: Rng, node: NodeAnnouncement, emitter: Emitter<Event>, ) -> Self

Source

pub fn started(&self) -> Option<LocalTime>

Whether the service was started (initialized) and if so, at what time.

Source

pub fn next(&mut self) -> Option<Io>

Return the next i/o action to execute.

Source

pub fn seed(&mut self, id: &RepoId, scope: Scope) -> Result<bool, Error>

Seed a repository. Returns whether or not the repo policy was updated.

Source

pub fn unseed(&mut self, id: &RepoId) -> Result<bool, Error>

Unseed a repository. Returns whether or not the repo policy was updated. Note that when unseeding, we don’t announce anything to the network. This is because by simply not announcing it anymore, it will eventually be pruned by nodes.

Source

pub fn closest_peers(&self, n: usize) -> Vec<NodeId>

Find the closest n peers by proximity in seeding graphs. Returns a sorted list from the closest peer to the furthest. Peers with more seedings in common score score higher.

Source

pub fn database(&self) -> &Stores<D>

Get the database.

Source

pub fn database_mut(&mut self) -> &mut Stores<D>

Get the mutable database.

Source

pub fn storage(&self) -> &S

Get the storage instance.

Source

pub fn storage_mut(&mut self) -> &mut S

Get the mutable storage instance.

Source

pub fn policies(&self) -> &Config<Write>

Get the node policies.

Source

pub fn signer(&self) -> &Device<G>

Get the local signer.

Source

pub fn events(&mut self) -> Events

Subscriber to inner Emitter events.

Source

pub fn outbox(&mut self) -> &mut Outbox

Get I/O outbox.

Source

pub fn config(&self) -> &Config

Get configuration.

Source

pub fn lookup(&self, rid: RepoId) -> Result<Lookup, LookupError>

Lookup a repository, both locally and in the routing table.

Source

pub fn initialize(&mut self, time: LocalTime) -> Result<(), Error>

Initialize service with current time. Call this once.

Source

pub fn tick(&mut self, now: LocalTime, metrics: &Metrics)

Source

pub fn wake(&mut self)

Source

pub fn command(&mut self, cmd: Command)

Source

pub fn fetched( &mut self, rid: RepoId, remote: NodeId, result: Result<FetchResult, FetchError>, )

Source

pub fn dequeue_fetches(&mut self)

Attempt to dequeue fetches from all peers. At most one fetch is dequeued per peer. If the fetch cannot be processed, it is put back on the queue for that peer.

Fetches are queued for two reasons:

  1. The RID was already being fetched.
  2. The session was already at fetch capacity.
Source

pub fn accepted(&mut self, ip: IpAddr) -> bool

Inbound connection attempt.

Source

pub fn attempted(&mut self, nid: NodeId, addr: Address)

Source

pub fn listening(&mut self, local_addr: SocketAddr)

Source

pub fn connected(&mut self, remote: NodeId, addr: Address, link: Link)

Source

pub fn disconnected( &mut self, remote: NodeId, link: Link, reason: &DisconnectReason, )

Source

pub fn received_message(&mut self, remote: NodeId, message: Message)

Source

pub fn handle_announcement( &mut self, relayer: &NodeId, relayer_addr: &Address, announcement: &Announcement, ) -> Result<Option<AnnouncementId>, Error>

Handle an announcement message.

Returns true if this announcement should be stored and relayed to connected peers, and false if it should not.

Source

pub fn handle_info(&mut self, remote: NodeId, info: &Info) -> Result<(), Error>

Source

pub fn handle_message( &mut self, remote: &NodeId, message: Message, ) -> Result<(), Error>

Trait Implementations§

Source§

impl<D: Debug, S: Debug, G: Debug> Debug for Service<D, S, G>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<D, S, G> ServiceState for Service<D, S, G>
where D: Store, G: Signer<Signature>, S: ReadStorage,

Source§

fn nid(&self) -> &NodeId

Get the Node ID.
Source§

fn sessions(&self) -> &Sessions

Get the existing sessions.
Source§

fn fetching(&self) -> &HashMap<RepoId, FetchState>

Get fetch state.
Source§

fn outbox(&self) -> &Outbox

Get outbox.
Source§

fn limiter(&self) -> &RateLimiter

Get rate limiter.
Source§

fn emitter(&self) -> &Emitter<Event>

Get event emitter.
Source§

fn get(&self, rid: RepoId) -> Result<Option<Doc>, RepositoryError>

Get a repository from storage.
Source§

fn clock(&self) -> &LocalTime

Get the clock.
Source§

fn clock_mut(&mut self) -> &mut LocalTime

Get the clock mutably.
Source§

fn config(&self) -> &Config

Get service configuration.
Source§

fn metrics(&self) -> &Metrics

Get service metrics.

Auto Trait Implementations§

§

impl<D, S, G> !Freeze for Service<D, S, G>

§

impl<D, S, G> !RefUnwindSafe for Service<D, S, G>

§

impl<D, S, G> Send for Service<D, S, G>
where S: Send, G: Send, D: Send,

§

impl<D, S, G> !Sync for Service<D, S, G>

§

impl<D, S, G> Unpin for Service<D, S, G>
where S: Unpin, G: Unpin, D: Unpin,

§

impl<D, S, G> !UnwindSafe for Service<D, S, G>

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> 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<T> ErasedDestructor for T
where T: 'static,