Handshake

Trait Handshake 

Source
pub trait Handshake: P2P
where Self: Clone + Send + Sync + 'static,
{ const TIMEOUT_MS: u64 = 3_000u64; // Required method fn perform_handshake<'life0, 'async_trait>( &'life0 self, conn: Connection, ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn enable_handshake<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait { ... } fn borrow_stream<'a>(&self, conn: &'a mut Connection) -> &'a mut TcpStream { ... } fn take_stream(&self, conn: &mut Connection) -> TcpStream { ... } fn return_stream<T: AsyncRead + AsyncWrite + Send + Sync + 'static>( &self, conn: &mut Connection, stream: T, ) { ... } }
Expand description

Can be used to specify and enable network handshakes. Upon establishing a connection, both sides will need to adhere to the specified handshake rules in order to finalize the connection and be able to send or receive any messages.

Provided Associated Constants§

Source

const TIMEOUT_MS: u64 = 3_000u64

The maximum time allowed for a connection to perform a handshake before it is rejected.

The default value is 3000ms.

Required Methods§

Source

fn perform_handshake<'life0, 'async_trait>( &'life0 self, conn: Connection, ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Performs the handshake; temporarily assumes control of the Connection and returns it if the handshake is successful.

Provided Methods§

Source

fn enable_handshake<'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 perform specified network handshakes.

Source

fn borrow_stream<'a>(&self, conn: &'a mut Connection) -> &'a mut TcpStream

Borrows the full connection stream to be used in the implementation of Handshake::perform_handshake.

Source

fn take_stream(&self, conn: &mut Connection) -> TcpStream

Assumes full control of a connection’s stream in the implementation of Handshake::perform_handshake, by the end of which it must be followed by Handshake::return_stream.

Source

fn return_stream<T: AsyncRead + AsyncWrite + Send + Sync + 'static>( &self, conn: &mut Connection, stream: T, )

This method only needs to be called if Handshake::take_stream had been called before; it is used to return a (potentially modified) stream back to the applicable connection.

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.

Implementors§