Struct quinn::Connection
source · [−]pub struct Connection(_);
Expand description
A QUIC connection.
If all references to a connection (including every clone of the Connection
handle, streams of
incoming streams, and the various stream types) have been dropped, then the connection will be
automatically closed with an error_code
of 0 and an empty reason
. You can also close the
connection explicitly by calling Connection::close()
.
May be cloned to obtain another handle to the same connection.
Implementations
sourceimpl Connection
impl Connection
sourcepub fn open_uni(&self) -> OpenUniⓘNotable traits for OpenUniimpl Future for OpenUni type Output = Result<SendStream, ConnectionError>;
pub fn open_uni(&self) -> OpenUniⓘNotable traits for OpenUniimpl Future for OpenUni type Output = Result<SendStream, ConnectionError>;
Initiate 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.
sourcepub fn open_bi(&self) -> OpenBiⓘNotable traits for OpenBiimpl Future for OpenBi type Output = Result<(SendStream, RecvStream), ConnectionError>;
pub fn open_bi(&self) -> OpenBiⓘNotable traits for OpenBiimpl Future for OpenBi type Output = Result<(SendStream, RecvStream), ConnectionError>;
Initiate 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.
sourcepub fn close(&self, error_code: VarInt, reason: &[u8])
pub fn close(&self, error_code: VarInt, reason: &[u8])
Close the connection immediately.
Pending operations will fail immediately with ConnectionError::LocallyClosed
. Delivery
of data on unfinished streams is not guaranteed, so the application must call this only
when all important communications have been completed, e.g. by calling finish
on
outstanding SendStream
s and waiting for the resulting futures to complete.
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.
sourcepub fn send_datagram(&self, data: Bytes) -> Result<(), SendDatagramError>
pub fn send_datagram(&self, data: Bytes) -> Result<(), SendDatagramError>
Transmit 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.
sourcepub fn max_datagram_size(&self) -> Option<usize>
pub fn max_datagram_size(&self) -> Option<usize>
Compute 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.
sourcepub fn remote_address(&self) -> SocketAddr
pub fn remote_address(&self) -> SocketAddr
The peer’s UDP address
If ServerConfig::migration
is true
, clients may change addresses at will, e.g. when
switching to a cellular internet connection.
sourcepub fn local_ip(&self) -> Option<IpAddr>
pub fn local_ip(&self) -> Option<IpAddr>
The local IP address which was used when the peer established the connection
This can be different from the address the endpoint is bound to, in case
the endpoint is bound to a wildcard address like 0.0.0.0
or ::
.
This will return None
for clients.
Retrieving the local IP address is currently supported on the following platforms:
- Linux
On all non-supported platforms the local IP address will not be available,
and the method will return None
.
sourcepub fn rtt(&self) -> Duration
pub fn rtt(&self) -> Duration
Current best estimate of this connection’s latency (round-trip-time)
sourcepub fn stats(&self) -> ConnectionStats
pub fn stats(&self) -> ConnectionStats
Returns connection statistics
sourcepub fn congestion_state(&self) -> Box<dyn Controller>
pub fn congestion_state(&self) -> Box<dyn Controller>
Current state of the congestion control algorithm, for debugging purposes
sourcepub 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.
sourcepub fn peer_identity(&self) -> Option<Box<dyn Any>>
pub fn peer_identity(&self) -> Option<Box<dyn Any>>
Cryptographic identity of the peer
The dynamic type returned is determined by the configured
Session
. For the default rustls
session, the return value can
be downcast
to a Vec<rustls::Certificate>
sourcepub 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.
sourcepub 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>
Derive 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.
sourcepub fn set_max_concurrent_uni_streams(&self, count: VarInt)
pub fn set_max_concurrent_uni_streams(&self, count: VarInt)
Modify the number of remotely initiated unidirectional streams that may be concurrently open
No streams may be opened by the peer unless fewer than count
are already open. Large
count
s increase both minimum and worst-case memory consumption.
sourcepub fn set_receive_window(&self, receive_window: VarInt)
pub fn set_receive_window(&self, receive_window: VarInt)
sourcepub fn set_max_concurrent_bi_streams(&self, count: VarInt)
pub fn set_max_concurrent_bi_streams(&self, count: VarInt)
Modify the number of remotely initiated bidirectional streams that may be concurrently open
No streams may be opened by the peer unless fewer than count
are already open. Large
count
s increase both minimum and worst-case memory consumption.
Trait Implementations
sourceimpl Clone for Connection
impl Clone for Connection
Auto Trait Implementations
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more