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
impl Session
Sourcepub fn peer(&self) -> EndpointId
pub fn peer(&self) -> EndpointId
Returns the peer’s endpoint id.
Sourcepub fn grant(&self) -> Grant
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.
Sourcepub fn request(&self) -> &SessionRequest
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.
Sourcepub async fn subscribe(
&self,
path: impl TryInto<Path, Error: Into<Error>>,
) -> Result<Subscription, Error>
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.
Sourcepub fn connection(&self) -> &Connection
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()
);
}Sourcepub fn network_paths(&self) -> Vec<NetworkPath>
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
);
}Sourcepub fn sample(&self) -> NetworkSample
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.
Sourcepub fn moq(&self) -> &Session
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.
Sourcepub fn close(&self, code: Error)
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).
Sourcepub async fn closed(&self) -> Error
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Session
impl !UnwindSafe for Session
impl Freeze for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
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,
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.