Skip to main content

LiveLayout

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

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 root(&self) -> &str

Returns the first segment of every path in this layout.

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)>

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<>

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

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>
where B: TryFrom<Producer>, <B as TryFrom<Producer>>::Error: Error + Send + Sync + 'static,

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")?;

pub fn ticket( &self, peer: PublicKey, name: &str, ) -> Result<BroadcastTicket, Error>

Returns the ticket of peer’s broadcast name.

Does not check that anything is published there.

§Errors

Fails like path.

Trait Implementations§

§

impl Clone for LiveLayout

§

fn clone(&self) -> LiveLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for LiveLayout

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for LiveLayout

§

fn default() -> LiveLayout

Returns the “default value” for a type. Read more
§

impl Eq for LiveLayout

§

impl Hash for LiveLayout

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl Layout<PublicKey> for LiveLayout

§

fn scope(&self, peer: &PublicKey) -> Prefixes

Returns <root>/<peer>, which covers every path beneath it.

§

fn owner(&self, path: &str) -> Option<PublicKey>

Returns the peer a path names, if path spells it that way.

§

impl PartialEq for LiveLayout

§

fn eq(&self, other: &LiveLayout) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for LiveLayout

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more