AccessControl

Trait AccessControl 

Source
pub trait AccessControl:
    Debug
    + Send
    + Sync
    + 'static {
    // Required method
    fn on_connect(
        &self,
        request: &ClientRequest,
    ) -> impl Future<Output = Access> + Send;

    // Provided method
    fn on_disconnect(
        &self,
        endpoint_id: EndpointId,
        connection_id: ConnectionId,
    ) { ... }
}
Available on crate feature server only.
Expand description

Controls which endpoints may use the relay and observes their lifecycle.

Implement this trait to gate access to a relay server.

Both callbacks carry the connection’s ConnectionId, so an implementation can index connections precisely even when one endpoint holds several.

Required Methods§

Source

fn on_connect( &self, request: &ClientRequest, ) -> impl Future<Output = Access> + Send

Decides whether a connecting client is admitted.

Called once per incoming connection, before the connection is registered. Returns Access::Allow to admit it or Access::Deny to reject it.

Can be implemented as async fn on_connect(&self, request: &ClientRequest) -> Access.

Provided Methods§

Source

fn on_disconnect(&self, endpoint_id: EndpointId, connection_id: ConnectionId)

Notifies that a connection has ended.

Called once for every connection that Self::on_connect admitted, identified by the same ConnectionId.

Note that this is a sync method being called in an async context. Make sure that your implementation does not block the runtime.

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§