Struct LiveLayout
pub struct LiveLayout { /* private fields */ }Expand description
The <root>/<peer>/<name> layout, with the root live by default.
Two peers with different roots do not see each other’s broadcasts: the
node reports NotGranted.
§Examples
use iroh_live_node::layout::LiveLayout;
let layout = LiveLayout::default();
let peer = iroh::SecretKey::generate().public();
let path = layout.path(peer, "studio")?;
assert_eq!(path.as_str(), format!("live/{peer}/studio"));
assert_eq!(layout.parse(&path), Some((peer, "studio")));Implementations§
§impl LiveLayout
impl LiveLayout
pub fn new(root: impl Into<String>) -> LiveLayout
pub fn new(root: impl Into<String>) -> LiveLayout
Creates a layout under root.
§Panics
Panics unless root is one valid path segment: not empty, no /, and
not a wildcard.
pub fn path(&self, peer: PublicKey, name: &str) -> Result<Path, Error>
pub fn path(&self, peer: PublicKey, name: &str) -> Result<Path, Error>
Returns the path of peer’s broadcast name: <root>/<peer>/<name>.
§Errors
Fails with [Error::InvalidPath] if name is empty, has an empty
segment, or makes no valid path.
pub fn parse<'a>(&self, path: &'a Path) -> Option<(PublicKey, &'a str)>
pub fn parse<'a>(&self, path: &'a Path) -> Option<(PublicKey, &'a str)>
Splits a path of this layout into the peer and the name.
The inverse of path. Returns None for a path
elsewhere, one whose second segment is not an endpoint id in its
canonical hex spelling, or one without a name.
pub fn policy(&self) -> impl Policy<PublicKey> + Clone + use<>
pub fn policy(&self) -> impl Policy<PublicKey> + Clone + use<>
Returns a policy that admits every peer with its grant under this layout.
Narrow it with [Policy::filter], and call Node::reauthorize when
the filter’s state changes. To let peers publish room broadcasts too,
pass the pair of this layout and the rooms layout to policy().
§Examples
Admit only contacts:
use std::collections::BTreeSet;
use iroh_live_node::{NodeConfig, layout::LiveLayout, policy::Policy};
use n0_watcher::{Watchable, Watcher};
let contacts = Watchable::new(BTreeSet::<iroh::EndpointId>::new());
let known = contacts.clone();
let policy = LiveLayout::default()
.policy()
.filter(move |request| known.get().contains(request.peer()));
let config = NodeConfig::default().with_policy(policy);pub fn config(&self) -> NodeConfig
pub fn config(&self) -> NodeConfig
Returns the NodeConfig of a node on this layout, with its policy.
The config’s layout is this layout, so ticket
claims follow its owner rule.
pub fn publish<B>(&self, node: &Node, name: &str) -> Result<B, Error>
pub fn publish<B>(&self, node: &Node, name: &str) -> Result<B, Error>
Publishes a broadcast at <root>/<this node's id>/<name> to granted sessions, and returns it.
B is built from the route table’s broadcast::Producer: a
LocalBroadcast, or the producer itself. The audience is
Audience::Granted, which includes attached media relays.
The publication lasts until the broadcast closes. A LocalBroadcast
closes when it is closed or its last clone drops. A producer closes only
when it is closed, since the node holds the broadcast open while it is
published. To keep the Publication, or
to publish to another audience, use Node::publish_with with
path.
§Errors
Fails if something is already published under name, the name makes
no valid path, or B cannot be built from the broadcast.
§Examples
use iroh_live_node::{Node, layout::LiveLayout};
use moq_net::broadcast;
let layout = LiveLayout::default();
let producer: broadcast::Producer = layout.publish(&node, "studio")?;Trait Implementations§
§impl Clone for LiveLayout
impl Clone for LiveLayout
§fn clone(&self) -> LiveLayout
fn clone(&self) -> LiveLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for LiveLayout
impl Debug for LiveLayout
§impl Default for LiveLayout
impl Default for LiveLayout
§fn default() -> LiveLayout
fn default() -> LiveLayout
impl Eq for LiveLayout
§impl Hash for LiveLayout
impl Hash for LiveLayout
§impl Layout<PublicKey> for LiveLayout
impl Layout<PublicKey> for LiveLayout
§impl PartialEq for LiveLayout
impl PartialEq for LiveLayout
impl StructuralPartialEq for LiveLayout
Auto Trait Implementations§
impl Freeze for LiveLayout
impl RefUnwindSafe for LiveLayout
impl Send for LiveLayout
impl Sync for LiveLayout
impl Unpin for LiveLayout
impl UnsafeUnpin for LiveLayout
impl UnwindSafe for LiveLayout
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.