Expand description
Policies that decide who may hold a session with a node, and with which rights.
The types are [moq_ext_access::policy]’s, with the peer fixed to an
iroh EndpointId. Set a node’s policy with
NodeConfig::with_policy. The node asks
it when it accepts a session, after the peer’s MoQ SETUP, and before it
dials a peer. It decides each session on its own.
To decide in the application, as a person who answers a call does, use a
Queue and answer each Pending it yields. Raise
NodeConfig::decide_timeout then,
since the node rejects a session whose decision takes longer.
To admit the peers that present a token, wrap a TokenVerifier in a
Verify. The jwt feature adds JwtVerifier, for moq-relay’s JWTs,
and the rcan feature adds RcanVerifier, for capability chains bound to
the peer’s key. A dial carries no token, so it gets the verifier’s
fallback: with the default Closed, every dial of the node fails with
Error::Rejected. Give a node that dials a
fallback, or check request.direction() in it.
§Examples
Admit only known peers, and let each publish under its own id:
use std::collections::BTreeSet;
use iroh::EndpointId;
use iroh_live_node::{
Grant, NodeConfig,
moq_net::Prefix,
policy::{self, PeerRequest, Rejection},
};
let known: BTreeSet<EndpointId> = BTreeSet::new();
let config =
NodeConfig::default().with_policy(policy::from_fn(move |request: &PeerRequest| {
let peer = request.peer();
if !known.contains(peer) {
return Err(Rejection::new("unknown peer"));
}
let own: Prefix = format!("live/{peer}").parse().expect("a prefix");
Ok(Grant::publish_under(own).into())
}));Structs§
- Authorization
- What an admitted session may do, and until when.
- Closed
- A policy that rejects everyone.
- Filter
- A policy that rejects the peers a predicate refuses, built by
Policy::filter. - FromFn
- A policy that decides with a closure, built by
from_fn. - JwtVerifier
- A
TokenVerifierof JWTs, which checks them with a moq-auth [KeySet] as moq-relay does. - MoqCapability
- What a holder may do at a moq node: publish and subscribe under a root.
- Open
- A policy that admits everyone with one grant.
- Rcan
Verifier - A
TokenVerifierof rcan capability chains that a principal issued. - Rejection
- Why a policy rejected a session.
- Verify
- A policy that decides with a
TokenVerifierwhen the peer presents a token.
Enums§
- Event
- Why a node asks its policy.
Constants§
- MAX_
LINKS - The most links a capability chain may have.
- MAX_
LINK_ BYTES - The most bytes one encoded link of a capability chain may take.
Traits§
- DynPolicy
- A
Policywith its type erased, as a node stores it. - Policy
- A rule that decides whether a peer may hold a session, and with which rights.
- Token
Verifier - A check of the token a peer presents, which returns what the token authorizes.
Functions§
- encode_
chain - Encodes a capability chain as a token, first link first.
- from_fn
- Returns a policy that decides with the synchronous closure
decide.
Type Aliases§
- Decision
- A policy’s answer: the session’s rights, or a rejection that closes it.
- Peer
Request - A peer’s request for a session with this node, as a policy sees it.
- Pending
- A request about a peer, waiting in a
Queuefor the application’s answer. - Queue
- A policy that hands each decision about a peer to the application.