Struct ConnectionRef
pub struct ConnectionRef { /* private fields */ }Expand description
A reference to a connection that is owned by a connection pool.
Methods from Deref<Target = Connection>§
pub fn open_uni(&self) -> OpenUni<'_>
pub fn open_uni(&self) -> OpenUni<'_>
Initiates a new outgoing unidirectional stream.
Streams are cheap and instantaneous to open unless blocked by flow control. As a consequence, the peer won’t be notified that a stream has been opened until the stream is actually used.
pub fn open_bi(&self) -> OpenBi<'_>
pub fn open_bi(&self) -> OpenBi<'_>
Initiates a new outgoing bidirectional stream.
Streams are cheap and instantaneous to open unless blocked by flow control. As a
consequence, the peer won’t be notified that a stream has been opened until the
stream is actually used. Calling open_bi then waiting on the RecvStream
without writing anything to SendStream will never succeed.
pub fn accept_uni(&self) -> AcceptUni<'_>
pub fn accept_uni(&self) -> AcceptUni<'_>
Accepts the next incoming uni-directional stream.
pub fn accept_bi(&self) -> AcceptBi<'_>
pub fn accept_bi(&self) -> AcceptBi<'_>
Accept the next incoming bidirectional stream.
Important Note: The peer that calls open_bi must write to its SendStream
before the peer Connection is able to accept the stream using
accept_bi(). Calling open_bi then waiting on the RecvStream without
writing anything to the connected SendStream will never succeed.
pub fn read_datagram(&self) -> ReadDatagram<'_>
pub fn read_datagram(&self) -> ReadDatagram<'_>
Receives an application datagram.
pub async fn closed(&self) -> ConnectionError
pub async fn closed(&self) -> ConnectionError
Wait for the connection to be closed for any reason.
Despite the return type’s name, closed connections are often not an error condition
at the application layer. Cases that might be routine include
[ConnectionError::LocallyClosed] and [ConnectionError::ApplicationClosed].
pub fn close_reason(&self) -> Option<ConnectionError>
pub fn close_reason(&self) -> Option<ConnectionError>
If the connection is closed, the reason why.
Returns None if the connection is still open.
pub fn close(&self, error_code: VarInt, reason: &[u8])
pub fn close(&self, error_code: VarInt, reason: &[u8])
Closes the connection immediately.
Pending operations will fail immediately with [ConnectionError::LocallyClosed]. No
more data is sent to the peer and the peer may drop buffered data upon receiving the
CONNECTION_CLOSE frame.
error_code and reason are not interpreted, and are provided directly to the
peer.
reason will be truncated to fit in a single packet with overhead; to improve odds
that it is preserved in full, it should be kept under 1KiB.
§Gracefully closing a connection
Only the peer last receiving application data can be certain that all data is
delivered. The only reliable action it can then take is to close the connection,
potentially with a custom error code. The delivery of the final CONNECTION_CLOSE
frame is very likely if both endpoints stay online long enough, calling
[Endpoint::close] will wait to provide sufficient time. Otherwise, the remote peer
will time out the connection, provided that the idle timeout is not disabled.
The sending side can not guarantee all stream data is delivered to the remote
application. It only knows the data is delivered to the QUIC stack of the remote
endpoint. Once the local side sends a CONNECTION_CLOSE frame in response to calling
close the remote endpoint may drop any data it received but is as yet
undelivered to the application, including data that was acknowledged as received to
the local endpoint.
pub fn send_datagram(&self, data: Bytes) -> Result<(), SendDatagramError>
pub fn send_datagram(&self, data: Bytes) -> Result<(), SendDatagramError>
Transmits data as an unreliable, unordered application datagram.
Application datagrams are a low-level primitive. They may be lost or delivered out
of order, and data must both fit inside a single QUIC packet and be smaller than
the maximum dictated by the peer.
pub fn send_datagram_wait(&self, data: Bytes) -> SendDatagram<'_>
pub fn send_datagram_wait(&self, data: Bytes) -> SendDatagram<'_>
Transmits data as an unreliable, unordered application datagram
Unlike send_datagram(), this method will wait for buffer space during congestion
conditions, which effectively prioritizes old datagrams over new datagrams.
See send_datagram() for details.
pub fn max_datagram_size(&self) -> Option<usize>
pub fn max_datagram_size(&self) -> Option<usize>
Computes the maximum size of datagrams that may be passed to send_datagram.
Returns None if datagrams are unsupported by the peer or disabled locally.
This may change over the lifetime of a connection according to variation in the path MTU estimate. The peer can also enforce an arbitrarily small fixed limit, but if the peer’s limit is large this is guaranteed to be a little over a kilobyte at minimum.
Not necessarily the maximum size of received datagrams.
pub fn datagram_send_buffer_space(&self) -> usize
pub fn datagram_send_buffer_space(&self) -> usize
Bytes available in the outgoing datagram buffer.
When greater than zero, calling send_datagram with a
datagram of at most this size is guaranteed not to cause older datagrams to be
dropped.
pub fn rtt(&self, path_id: PathId) -> Option<Duration>
pub fn rtt(&self, path_id: PathId) -> Option<Duration>
Current best estimate of this connection’s latency (round-trip-time).
pub fn stats(&self) -> ConnectionStats
pub fn stats(&self) -> ConnectionStats
Returns connection statistics.
pub fn congestion_state(&self, path_id: PathId) -> Option<Box<dyn Controller>>
pub fn congestion_state(&self, path_id: PathId) -> Option<Box<dyn Controller>>
Current state of the congestion control algorithm, for debugging purposes.
pub fn handshake_data(&self) -> Option<Box<dyn Any>>
pub fn handshake_data(&self) -> Option<Box<dyn Any>>
Parameters negotiated during the handshake.
Guaranteed to return Some on fully established connections or after
[Connecting::handshake_data()] succeeds. See that method’s documentations for
details on the returned value.
pub fn peer_identity(&self) -> Option<Box<dyn Any>>
pub fn peer_identity(&self) -> Option<Box<dyn Any>>
pub fn stable_id(&self) -> usize
pub fn stable_id(&self) -> usize
A stable identifier for this connection.
Peer addresses and connection IDs can change, but this value will remain fixed for the lifetime of the connection.
pub fn export_keying_material(
&self,
output: &mut [u8],
label: &[u8],
context: &[u8],
) -> Result<(), ExportKeyingMaterialError>
pub fn export_keying_material( &self, output: &mut [u8], label: &[u8], context: &[u8], ) -> Result<(), ExportKeyingMaterialError>
Derives keying material from this connection’s TLS session secrets.
When both peers call this method with the same label and context
arguments and output buffers of equal length, they will get the
same sequence of bytes in output. These bytes are cryptographically
strong and pseudorandom, and are suitable for use as keying material.
See RFC5705 for more information.
pub fn set_max_concurrent_uni_streams(&self, count: VarInt)
pub fn set_max_concurrent_uni_streams(&self, count: VarInt)
Modifies the number of unidirectional streams that may be concurrently opened.
No streams may be opened by the peer unless fewer than count are already
open. Large counts increase both minimum and worst-case memory consumption.
pub fn set_receive_window(&self, receive_window: VarInt)
pub fn set_receive_window(&self, receive_window: VarInt)
See [noq_proto::TransportConfig::receive_window].
pub fn set_max_concurrent_bi_streams(&self, count: VarInt)
pub fn set_max_concurrent_bi_streams(&self, count: VarInt)
Modifies the number of bidirectional streams that may be concurrently opened.
No streams may be opened by the peer unless fewer than count are already
open. Large counts increase both minimum and worst-case memory consumption.
pub fn remote_id(&self) -> PublicKey
pub fn remote_id(&self) -> PublicKey
Returns the [EndpointId] from the peer’s TLS certificate.
The PublicKey of an endpoint is also known as an [EndpointId]. This PublicKey is
included in the TLS certificate presented during the handshake when connecting.
This function allows you to get the [EndpointId] of the remote endpoint of this
connection.
pub fn paths(&self) -> PathList<'_>
pub fn paths(&self) -> PathList<'_>
Returns the currently open network paths for this connection.
A connection typically has one path via the relay server and,
once holepunching succeeds, a direct path. The returned
[PathList] is a snapshot taken at call time: it does not
reflect later changes, and it does not include paths that have
already closed.
To observe changes over time, see [Connection::paths_stream]
for a stream of [PathList] snapshots and
[Connection::path_events] for individual PathEvents.
pub fn paths_stream(&self) -> PathListStream<'_>
pub fn paths_stream(&self) -> PathListStream<'_>
Returns a stream of [PathList] snapshots for this connection.
Yields the current snapshot on the first poll, and a fresh snapshot whenever the open paths or the selected path change. Ends when the connection closes.
The stream borrows this [Connection]. To consume it from a
spawned task, move a [Connection] clone into the task and
call this method inside.
pub fn path_events(&self) -> PathEventStream
pub fn path_events(&self) -> PathEventStream
Returns a stream of PathEvents for this connection.
Each event reports one of: a path opened, a path closed (with
final per-path statistics), the selected transmission path
changed, or the consumer fell behind. The stream ends when the
connection closes. It does not borrow this [Connection] and
may be moved into a spawned task.
If the consumer does not poll fast enough, the stream yields a
single PathEvent::Lagged; the current state of the open
paths and the selected path remains recoverable via
[Connection::paths].
pub fn side(&self) -> Side
pub fn side(&self) -> Side
Returns the side of the connection (client or server).
pub fn weak_handle(&self) -> WeakConnectionHandle
pub fn weak_handle(&self) -> WeakConnectionHandle
Returns a [WeakConnectionHandle] for this connection.
A [WeakConnectionHandle] does not keep the connection alive. It can be used to
wait for the connection to be closed via [WeakConnectionHandle::closed] and to
attempt to upgrade back to a strong [Connection] via
[WeakConnectionHandle::upgrade].
pub async fn handshake_completed(&self) -> Result<Connection, ConnectingError>
pub async fn handshake_completed(&self) -> Result<Connection, ConnectingError>
Waits until the full handshake occurs and then returns a [Connection].
This may fail with [ConnectingError::ConnectionError], if there was
some general failure with the connection, such as a network timeout since
we accepted the connection.
This may fail with [ConnectingError::HandshakeFailure], if the other side
doesn’t use the right TLS authentication, which usually every iroh endpoint
uses and requires.
Thus, those errors should only occur if someone connects to you with a modified iroh endpoint or with a plain QUIC client.
pub fn remote_id(&self) -> Result<PublicKey, RemoteEndpointIdError>
pub fn remote_id(&self) -> Result<PublicKey, RemoteEndpointIdError>
Returns the [EndpointId] from the peer’s TLS certificate.
The PublicKey of an endpoint is also known as an [EndpointId]. This PublicKey is
included in the TLS certificate presented during the handshake when connecting.
This function allows you to get the [EndpointId] of the remote endpoint of this
connection.
pub async fn handshake_completed(
&self,
) -> Result<ZeroRttStatus, ConnectingError>
pub async fn handshake_completed( &self, ) -> Result<ZeroRttStatus, ConnectingError>
Waits until the full handshake occurs and returns a [ZeroRttStatus].
If ZeroRttStatus::Accepted is returned, than any streams created before
the handshake has completed can still be used.
If ZeroRttStatus::Rejected is returned, than any streams created before
the handshake will error and any data sent should be re-sent on a
new stream.
This may fail with [ConnectingError::ConnectionError], if there was
some general failure with the connection, such as a network timeout since
we initiated the connection.
This may fail with [ConnectingError::HandshakeFailure], if the other side
doesn’t use the right TLS authentication, which usually every iroh endpoint
uses and requires.
Thus, those errors should only occur if someone connects to you with a modified iroh endpoint or with a plain QUIC client.
pub fn remote_id(&self) -> Result<PublicKey, RemoteEndpointIdError>
pub fn remote_id(&self) -> Result<PublicKey, RemoteEndpointIdError>
Returns the [EndpointId] from the peer’s TLS certificate.
The PublicKey of an endpoint is also known as an [EndpointId]. This PublicKey is
included in the TLS certificate presented during the handshake when connecting.
This function allows you to get the [EndpointId] of the remote endpoint of this
connection.
Trait Implementations§
§impl Debug for ConnectionRef
impl Debug for ConnectionRef
§impl Deref for ConnectionRef
impl Deref for ConnectionRef
Auto Trait Implementations§
impl Freeze for ConnectionRef
impl RefUnwindSafe for ConnectionRef
impl Send for ConnectionRef
impl Sync for ConnectionRef
impl Unpin for ConnectionRef
impl UnsafeUnpin for ConnectionRef
impl UnwindSafe for ConnectionRef
Blanket Implementations§
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more