Struct vapcore_light::net::LightProtocol[][src]

pub struct LightProtocol { /* fields omitted */ }

This is an implementation of the light vapory network protocol, abstracted over a Provider of data and a p2p network.

This is simply designed for request-response purposes. Higher level uses of the protocol, such as synchronization, will function as wrappers around this system.

Implementations

impl LightProtocol[src]

pub fn new(provider: Arc<dyn Provider>, params: Params) -> Self[src]

Create a new instance of the protocol manager.

pub fn peer_status(&self, peer: PeerId) -> Option<Status>[src]

Attempt to get peer status.

pub fn peer_count(&self) -> (usize, usize)[src]

Get number of (connected, active) peers.

pub fn leecher_count(&self) -> usize[src]

Get the number of active light peers downloading from the node

pub fn request_from(
    &self,
    io: &dyn IoContext,
    peer_id: PeerId,
    requests: Requests
) -> Result<ReqId, Error>
[src]

Make a request to a peer.

Fails on: nonexistent peer, network error, peer not server, insufficient credits. Does not check capabilities before sending. On success, returns a request id which can later be coordinated with an event.

pub fn make_announcement(&self, io: &dyn IoContext, announcement: Announcement)[src]

Make an announcement of new chain head and capabilities to all peers. The announcement is expected to be valid.

pub fn add_handler(&mut self, handler: Arc<dyn Handler>)[src]

Add an event handler.

These are intended to be added when the protocol structure is initialized as a means of customizing its behavior, and dispatching requests immediately upon events.

pub fn abort(&self)[src]

Signal to handlers that network activity is being aborted and clear peer data.

pub fn handle_packet(
    &self,
    io: &dyn IoContext,
    peer: PeerId,
    packet_id: u8,
    data: &[u8]
)
[src]

Handle a packet using the given io context. Packet data is untrusted, which means that invalid data won’t lead to issues.

pub fn on_connect(&self, peer: PeerId, io: &dyn IoContext)[src]

called when a peer connects.

pub fn on_disconnect(&self, peer: PeerId, io: &dyn IoContext)[src]

called when a peer disconnects.

pub fn with_context<F, T>(&self, io: &dyn IoContext, f: F) -> T where
    F: FnOnce(&dyn BasicContext) -> T, 
[src]

Execute the given closure with a basic context derived from the I/O context.

Trait Implementations

impl NetworkProtocolHandler for LightProtocol[src]

Auto Trait Implementations

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

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

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

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

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>,