Skip to main content

Policy

Trait Policy 

pub trait Policy<P>:
    Debug
    + Send
    + Sync
    + 'static
where P: PeerId,
{ // Required method fn decide( &self, request: &PeerRequest<P>, ) -> impl Future<Output = Result<Authorization, Rejection>> + Send; // Provided method fn filter<F>(self, admit: F) -> Filter<Self, F> where Self: Sized, F: Fn(&PeerRequest<P>) -> bool + Send + Sync + 'static { ... } }
Expand description

A rule that decides whether a peer may hold a session, and with which rights.

Implement it with async fn decide.

Required Methods§

fn decide( &self, request: &PeerRequest<P>, ) -> impl Future<Output = Result<Authorization, Rejection>> + Send

Decides whether the peer may hold a session, and with which rights.

A node drops the future on its decide timeout and when it shuts down, so an implementation must tolerate cancellation at any await.

Provided Methods§

fn filter<F>(self, admit: F) -> Filter<Self, F>
where Self: Sized, F: Fn(&PeerRequest<P>) -> bool + Send + Sync + 'static,

Returns a policy that rejects the peers admit refuses, and asks this one otherwise.

The predicate is not watched: when the state it reads changes, tell the node to decide again.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl<P> Policy<P> for Arc<dyn DynPolicy<P>>
where P: PeerId,

§

async fn decide( &self, request: &PeerRequest<P>, ) -> Result<Authorization, Rejection>

Implementors§

§

impl<P, F> Policy<P> for FromFn<F>
where P: PeerId, F: Fn(&PeerRequest<P>) -> Result<Authorization, Rejection> + Send + Sync + 'static,

§

impl<P, T, F> Policy<P> for Filter<T, F>
where P: PeerId, T: Policy<P>, F: Fn(&PeerRequest<P>) -> bool + Send + Sync + 'static,

§

impl<P, V, F> Policy<P> for Verify<V, F>
where P: PeerId, V: TokenVerifier<P>, F: Policy<P>,

§

impl<P> Policy<P> for Closed
where P: PeerId,

§

impl<P> Policy<P> for Open
where P: PeerId,

§

impl<P> Policy<P> for Queue<P>
where P: PeerId,