pub trait Reading: P2P{
type Message: Send;
type Codec: Decoder<Item = Self::Message, Error = Error> + Send;
const INITIAL_BUFFER_SIZE: usize = 1_048_576usize;
// Required methods
fn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec;
fn process_message<'life0, 'async_trait>(
&'life0 self,
source: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn message_queue_depth(&self) -> usize { ... }
fn enable_reading<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
Can be used to specify and enable reading, i.e. receiving inbound messages. If the Handshake
protocol is enabled too, it goes into force only after the handshake has been concluded.
Each inbound message is isolated by the user-supplied Reading::Codec
, creating a Reading::Message
,
which is immediately queued (with a [Reading::MESSAGE_QUEUE_DEPTH
] limit) to be processed by
Reading::process_message
. The configured fatal IO errors result in an immediate disconnect
(in order to e.g. avoid accidentally reading “borked” messages).
Provided Associated Constants§
Sourceconst INITIAL_BUFFER_SIZE: usize = 1_048_576usize
const INITIAL_BUFFER_SIZE: usize = 1_048_576usize
The initial size of a per-connection buffer for reading inbound messages. Can be set to the maximum expected size of the inbound message in order to only allocate it once.
The default value is 1024KiB.
Required Associated Types§
Required Methods§
Sourcefn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec
fn codec(&self, addr: SocketAddr, side: ConnectionSide) -> Self::Codec
Creates a Decoder
used to interpret messages from the network.
The side
param indicates the connection side from the node’s perspective.
Sourcefn process_message<'life0, 'async_trait>(
&'life0 self,
source: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_message<'life0, 'async_trait>(
&'life0 self,
source: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Processes an inbound message. Can be used to update state, send replies etc.
Provided Methods§
Sourcefn message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
The depth of per-connection queues used to process inbound messages; the greater it is, the more inbound messages the node can enqueue, but setting it to a large value can make the node more susceptible to DoS attacks.
The default value is 1024.
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.