pub trait Writing: Pea2Pea
where Self: Clone + Send + Sync + 'static,
{ type Message: Send; type Codec: Encoder<Self::Message, Error = Error> + Send; const MESSAGE_QUEUE_DEPTH: usize = 64usize; const INITIAL_BUFFER_SIZE: usize = 65_536usize; // Required method fn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec; // Provided methods fn enable_writing(&self) -> impl Future<Output = ()> { ... } fn unicast( &self, addr: SocketAddr, message: Self::Message ) -> Result<Receiver<Result<()>>> { ... } fn broadcast(&self, message: Self::Message) -> Result<()> where Self::Message: Clone { ... } }
Expand description

Can be used to specify and enable writing, i.e. sending outbound messages. If the Handshake protocol is enabled too, it goes into force only after the handshake has been concluded.

Required Associated Types§

source

type Message: Send

The type of the outbound messages; unless their serialization is expensive and the message is broadcasted (in which case it would get serialized multiple times), serialization should be done in the implementation of Self::Codec.

source

type Codec: Encoder<Self::Message, Error = Error> + Send

The user-supplied Encoder used to write outbound messages to the target stream.

Provided Associated Constants§

source

const MESSAGE_QUEUE_DEPTH: usize = 64usize

The depth of per-connection queues used to send outbound messages; the greater it is, the more outbound messages the node can enqueue. Setting it to a large value is not recommended, as doing it might obscure potential issues with your implementation (like slow serialization) or network.

The default value is 64.

source

const INITIAL_BUFFER_SIZE: usize = 65_536usize

The initial size of a per-connection buffer for writing outbound messages. Can be set to the maximum expected size of the outbound message in order to only allocate it once.

The default value is 64KiB.

Required Methods§

source

fn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec

Creates an Encoder used to write the outbound messages to the target stream. The side param indicates the connection side from the node’s perspective.

Provided Methods§

source

fn enable_writing(&self) -> impl Future<Output = ()>

Prepares the node to send messages.

source

fn unicast( &self, addr: SocketAddr, message: Self::Message ) -> Result<Receiver<Result<()>>>

Sends the provided message to the specified SocketAddr. Returns as soon as the message is queued to be sent, without waiting for the actual delivery; instead, the caller is provided with a oneshot::Receiver which can be used to determine when and whether the message has been delivered.

Errors

The following errors can be returned:

source

fn broadcast(&self, message: Self::Message) -> Result<()>
where Self::Message: Clone,

Broadcasts the provided message to all connected peers. Returns as soon as the message is queued to be sent to all the peers, without waiting for the actual delivery. This method doesn’t provide the means to check when and if the messages actually get delivered; you can achieve that by calling Writing::unicast for each address returned by Node::connected_addrs.

Errors

Returns io::ErrorKind::Unsupported if Writing::enable_writing hadn’t been called yet.

Object Safety§

This trait is not object safe.

Implementors§