Skip to main content

Policy

Trait Policy 

Source
pub trait Policy<P: PeerId>:
    Debug
    + Send
    + Sync
    + 'static {
    // Required method
    fn decide(
        &self,
        request: &PeerRequest<P>,
    ) -> impl Future<Output = Decision> + 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§

Source

fn decide( &self, request: &PeerRequest<P>, ) -> impl Future<Output = Decision> + 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§

Source

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§

Source§

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

Source§

async fn decide(&self, request: &PeerRequest<P>) -> Decision

Implementors§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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