pub trait Handshake: Pea2Pea{
const TIMEOUT_MS: u64 = 3_000u64;
// Required method
fn perform_handshake(
&self,
conn: Connection
) -> impl Future<Output = Result<Connection>> + Send;
// Provided methods
fn enable_handshake(&self) -> impl Future<Output = ()> + Send { ... }
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§
sourceconst TIMEOUT_MS: u64 = 3_000u64
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§
sourcefn perform_handshake(
&self,
conn: Connection
) -> impl Future<Output = Result<Connection>> + Send
fn perform_handshake( &self, conn: Connection ) -> impl Future<Output = Result<Connection>> + Send
Performs the handshake; temporarily assumes control of the Connection
and returns it if the handshake is
successful.
Provided Methods§
sourcefn enable_handshake(&self) -> impl Future<Output = ()> + Send
fn enable_handshake(&self) -> impl Future<Output = ()> + Send
Prepares the node to perform specified network handshakes.
sourcefn borrow_stream<'a>(&self, conn: &'a mut Connection) -> &'a mut TcpStream
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
.
sourcefn take_stream(&self, conn: &mut Connection) -> TcpStream
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
.
sourcefn return_stream<T: AsyncRead + AsyncWrite + Send + Sync + 'static>(
&self,
conn: &mut Connection,
stream: T
)
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.