Skip to main content

Peer

Struct Peer 

Source
pub struct Peer {
    conf: Arc<Config>,
    budget: Budget,
    conn: Connection,
    msgs: Queue<(RetryPolicy, Bytes)>,
    retry: DelayQueue,
    next_slot: Receiver<Slot>,
    lower_bound: Slot,
    tx: UnboundedSender<(PublicKey, Bytes, Option<OwnedSemaphorePermit>)>,
    countdown: Countdown,
    cancel: CancellationToken,
    max_message_size: usize,
    metrics: Arc<dyn Metrics>,
}
Expand description

A peer sends and receives messages over a connection with a remote.

Peers are initialised with a Connection, which can be replaced later, should it be necessary.

Messages sent are expected to be acknowledged, i.e. the remote needs to send back an ACK frame. Otherwise the message is resent after some time.

Fields§

§conf: Arc<Config>

Network configuration.

§budget: Budget

A budget limits how many message a peer can deliver to the application.

§conn: Connection

The current TCP+Noise connection.

§msgs: Queue<(RetryPolicy, Bytes)>

Messages the application wants to be sent to the remote.

§retry: DelayQueue

Messages waiting to be retried if no ACK has been received.

§next_slot: Receiver<Slot>

Receive notifications about changes to the GC threshold

§lower_bound: Slot

Our current GC threshold.

§tx: UnboundedSender<(PublicKey, Bytes, Option<OwnedSemaphorePermit>)>

The channel over which to deliver inbound messages to the application.

§countdown: Countdown

A healthcheck countdown.

When dropped to 0 the connection should be replaced.

§cancel: CancellationToken

Token to interrupt processing.

§max_message_size: usize

The true max. message size.

It accounts for the additional Trailer bytes.

§metrics: Arc<dyn Metrics>

Implementations§

Source§

impl Peer

Source

pub fn set_connection(&mut self, c: Connection)

Replace the existing connection.

Source

pub fn cancel_token(&self) -> CancellationToken

Get a token to interrupt processing.

Source

pub fn public_key(&self) -> &PublicKey

Get the peer’s public key.

Source

pub fn socket_addr(&self) -> &SocketAddr

Get the peer’s socket address.

Source

pub async fn start(&mut self) -> Result<Empty, NetworkError>

Start I/O with a connected peer.

This method continues until an error occurs, after which callers may want to reconnect and resume peer operation with a new Connection.

Source

fn update_metrics(&self)

Source

pub fn builder() -> PeerBuilder

Auto Trait Implementations§

§

impl !Freeze for Peer

§

impl !RefUnwindSafe for Peer

§

impl Send for Peer

§

impl Sync for Peer

§

impl Unpin for Peer

§

impl UnsafeUnpin for Peer

§

impl !UnwindSafe for Peer

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.

§

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.

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

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