pub trait Writing: P2P{
type Message: Send;
type Codec: Encoder<Self::Message, Error = Error> + Send;
// Required method
fn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec;
// Provided methods
fn message_queue_depth(&self) -> usize { ... }
fn enable_writing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
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
.
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 message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
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 1024.
Sourcefn enable_writing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn enable_writing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
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 Tcp::connected_addrs
.
§Errors
Returns io::ErrorKind::Unsupported
if Writing::enable_writing
hadn’t been called yet.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.