pub struct Queue<P: PeerId> { /* private fields */ }Expand description
A policy that hands each decision to the application, through a bounded queue.
The application takes the requests with next and answers
each Pending with admit or
reject. Clones share one queue, so the node can hold
the policy while the application holds a clone to answer from.
A request that finds the queue full is rejected at once with
moq_net::Error::TooManyRequests, so a slow application does not pile up
sessions whose peers wait. A node also gives up on a decision after its
decide timeout, such as NodeConfig::decide_timeout in iroh-live-node,
which is 10 seconds there by default. Raise it when a person answers.
§Examples
Admit the peers that present a known token:
use moq_ext_access::{
Grant,
policy::{Queue, Rejection},
};
let queue = Queue::<String>::new(16);
// Give `queue.clone()` to the node as its policy, then answer:
while let Some(pending) = queue.next().await {
if pending.request().token() == Some("secret") {
pending.admit(Grant::subscribe_only());
} else {
pending.reject(Rejection::new("unknown token"));
}
}Implementations§
Source§impl<P: PeerId> Queue<P>
impl<P: PeerId> Queue<P>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a queue that holds up to capacity requests.
A request that finds the queue full is rejected with
moq_net::Error::TooManyRequests. A node treats that as no answer
when it asks again about a live peer: the peer keeps its
authorization, and the node asks again later.
§Panics
Panics if capacity is zero.
Trait Implementations§
Auto Trait Implementations§
impl<P> !Unpin for Queue<P>
impl<P> !UnsafeUnpin for Queue<P>
impl<P> Freeze for Queue<P>
impl<P> RefUnwindSafe for Queue<P>
impl<P> Send for Queue<P>
impl<P> Sync for Queue<P>
impl<P> UnwindSafe for Queue<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<P, T> DynPolicy<P> for T
impl<P, T> DynPolicy<P> for T
Source§fn decide<'a>(
&'a self,
request: &'a PeerRequest<P>,
) -> Pin<Box<dyn Future<Output = Result<Authorization, Rejection>> + Send + 'a>>
fn decide<'a>( &'a self, request: &'a PeerRequest<P>, ) -> Pin<Box<dyn Future<Output = Result<Authorization, Rejection>> + Send + 'a>>
Policy::decide does, with a boxed future.