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: BudgetA budget limits how many message a peer can deliver to the application.
conn: ConnectionThe current TCP+Noise connection.
msgs: Queue<(RetryPolicy, Bytes)>Messages the application wants to be sent to the remote.
retry: DelayQueueMessages waiting to be retried if no ACK has been received.
next_slot: Receiver<Slot>Receive notifications about changes to the GC threshold
lower_bound: SlotOur current GC threshold.
tx: UnboundedSender<(PublicKey, Bytes, Option<OwnedSemaphorePermit>)>The channel over which to deliver inbound messages to the application.
countdown: CountdownA healthcheck countdown.
When dropped to 0 the connection should be replaced.
cancel: CancellationTokenToken to interrupt processing.
max_message_size: usizeThe true max. message size.
It accounts for the additional Trailer bytes.
metrics: Arc<dyn Metrics>Implementations§
Source§impl Peer
impl Peer
Sourcepub fn set_connection(&mut self, c: Connection)
pub fn set_connection(&mut self, c: Connection)
Replace the existing connection.
Sourcepub fn cancel_token(&self) -> CancellationToken
pub fn cancel_token(&self) -> CancellationToken
Get a token to interrupt processing.
Sourcepub fn public_key(&self) -> &PublicKey
pub fn public_key(&self) -> &PublicKey
Get the peer’s public key.
Sourcepub fn socket_addr(&self) -> &SocketAddr
pub fn socket_addr(&self) -> &SocketAddr
Get the peer’s socket address.
Sourcepub async fn start(&mut self) -> Result<Empty, NetworkError>
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.