pub trait EndpointHooks:
Debug
+ Send
+ Sync {
// Provided methods
fn before_connect<'a>(
&'a self,
_remote_addr: &'a EndpointAddr,
_alpn: &'a [u8],
) -> impl Future<Output = BeforeConnectOutcome> + Send + 'a { ... }
fn after_handshake<'a>(
&'a self,
_conn: &'a ConnectionInfo,
) -> impl Future<Output = AfterHandshakeOutcome> + Send + 'a { ... }
}Expand description
EndpointHooks intercept the connection establishment process of an Endpoint.
Use Builder::hooks to install hooks onto an endpoint.
For each hook, all installed hooks are invoked in the order they were installed on
the endpoint builder. If a hook returns Accept, processing continues with the next
hook. If a hook returns Reject, processing is aborted and further hooks
are not invoked for this hook.
§Notes to implementers
As hooks are stored on the endpoint, you must make sure to never store an Endpoint
on the hook struct itself, as this would create reference counting loop and cause the
endpoint to never be dropped, leaking memory.
Provided Methods§
Sourcefn before_connect<'a>(
&'a self,
_remote_addr: &'a EndpointAddr,
_alpn: &'a [u8],
) -> impl Future<Output = BeforeConnectOutcome> + Send + 'a
fn before_connect<'a>( &'a self, _remote_addr: &'a EndpointAddr, _alpn: &'a [u8], ) -> impl Future<Output = BeforeConnectOutcome> + Send + 'a
Intercept outgoing connections before they are started.
This is called whenever a new outgoing connection is initiated via Endpoint::connect
or Endpoint::connect_with_opts.
If any hook returns BeforeConnectOutcome::Reject, the connection attempt is aborted
before any packets are sent to the remote.
Sourcefn after_handshake<'a>(
&'a self,
_conn: &'a ConnectionInfo,
) -> impl Future<Output = AfterHandshakeOutcome> + Send + 'a
fn after_handshake<'a>( &'a self, _conn: &'a ConnectionInfo, ) -> impl Future<Output = AfterHandshakeOutcome> + Send + 'a
Intercept both incoming and outgoing connections once the TLS handshake has completed.
At this point in time, we know the remote’s endpoint id and ALPN. If any hook returns
AfterHandshakeOutcome::Reject, the connection is closed with the provided error code
and reason.
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.