pub trait Writing: Pea2Pea{
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§
sourcetype Message: Send
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
.
Provided Associated Constants§
sourceconst MESSAGE_QUEUE_DEPTH: usize = 64usize
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.
sourceconst INITIAL_BUFFER_SIZE: usize = 65_536usize
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§
sourcefn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec
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§
sourcefn enable_writing(&self) -> impl Future<Output = ()>
fn enable_writing(&self) -> impl Future<Output = ()>
Prepares the node to send messages.
sourcefn unicast(
&self,
addr: SocketAddr,
message: Self::Message
) -> Result<Receiver<Result<()>>>
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:
io::ErrorKind::NotConnected
if the node is not connected to the provided addressio::ErrorKind::Other
if the outbound message queue for this address is fullio::ErrorKind::Unsupported
ifWriting::enable_writing
hadn’t been called yet
sourcefn broadcast(&self, message: Self::Message) -> Result<()>
fn broadcast(&self, message: Self::Message) -> Result<()>
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.