Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

A direct session with a peer.

Cheap to clone. Dropping the handles does not close it: it ends when either side closes it, the connection fails, or the node shuts down.

§Examples

let session = node.connect(peer).await?;
// Resolves through this session only, never through a media relay.
let subscription = session.subscribe("live/camera").await?;
session.close(moq_net::Error::Cancel);
let reason = session.closed().await;

Implementations§

Source§

impl Session

Source

pub fn peer(&self) -> EndpointId

Returns the peer’s endpoint id.

Source

pub fn direction(&self) -> Direction

Returns which side opened the session.

Source

pub fn grant(&self) -> Grant

Returns what the peer may do on this session.

That is the grant the policy decided for this session, widened by the paths that live ticket subscriptions claimed for the peer (see Node::claim_path). It is Grant::nothing after a rejection, once the authorization expired, and once the session has ended.

Source

pub fn request(&self) -> &SessionRequest

Returns what the peer asked for when it opened the session.

For a dialed session, the path this node requested, without a token.

Source

pub async fn subscribe( &self, path: impl TryInto<Path, Error: Into<Error>>, ) -> Result<Subscription, Error>

Resolves path through this session’s peer, and not through a media relay.

Waits for the peer to announce the path, then pins the subscription to the stream the peer announced: moq may move it to another route of that stream, but never to another stream at the path.

The session is told from other links by the hop its routes carry: the one derived from the peer’s id, or, for a peer that declares a hop of its own (as moq-relay does), one no other link carries. This node cannot read the declaration on a session it dialed, so the guarantee is only as strong as the grants: a peer whose grant lets it publish the path could declare this peer’s hop and be resolved here.

§Errors

Fails with Error::NotGranted if the session’s grant does not let the peer publish the path, Error::NotAnnounced if the session ends before the peer announces it, Error::Unresolved if the route table refuses the path, and Error::ShutDown once the node is gone.

Source

pub fn connection(&self) -> &Connection

Returns the iroh connection under the session.

Its paths are iroh’s: Connection::paths lists the open ones, with each one’s remote address, whether it is selected, and its RTT, and Connection::paths_stream yields the list again whenever it changes. Connection::stats holds the counters of the whole connection. network_paths summarizes each path.

§Examples
for path in session.connection().paths().iter() {
    println!(
        "{:?} selected={} rtt={:?}",
        path.remote_addr(),
        path.is_selected(),
        path.rtt()
    );
}
Source

pub fn network_paths(&self) -> Vec<NetworkPath>

Returns the open network paths of the session’s connection, the selected one first.

The counters are per path and cumulative, unlike the windowed, connection-wide rates of sample. They count QUIC packets and leave out path MTU probes.

§Examples
for path in session.network_paths() {
    println!(
        "{} {} selected={} rtt={:?}",
        path.kind(),
        path.addr(),
        path.selected,
        path.rtt
    );
}
Source

pub fn sample(&self) -> NetworkSample

Returns the latest reading of the session’s link.

The connection monitor refreshes it every 200 ms. A publisher reads its uplink here as NetworkSample::send_rate. A subscriber reaches the same reading through Subscription::serving_link, and the session itself through Subscription::session.

Source

pub fn moq(&self) -> &Session

Returns the moq-net session, for its statistics, bandwidth estimates and announcements.

Closing it closes this session, as close does.

Source

pub fn close(&self, code: Error)

Closes the session, and every subscription over it, in both directions.

The peer receives code as the session’s close code, and its closed reports it as a moq_net::Error::Session source, for example Session(SessionError::App(7)) for App(7).

Source

pub async fn closed(&self) -> Error

Waits until the session ends, and returns why.

A close either side asked for is Error::SessionClosed with moq_net::Error::Cancel as its source. Cancellation safe.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

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

impl Debug for Session

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Session

Source§

impl PartialEq for Session

Source§

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

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

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

Inequality operator !=. Read more

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