pub struct Connection(/* private fields */);
quic
only.Expand description
A QUIC connection.
Implementations§
Source§impl Connection
impl 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, or when the platform does not
expose this information.
Sourcepub fn remote_address(&self) -> SocketAddr
pub fn remote_address(&self) -> SocketAddr
The peer’s UDP address.
Will panic if called after poll
has returned Ready
.
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
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 peer_identity(&self) -> Option<Box<Vec<CertificateDer<'static>>>>
pub fn peer_identity(&self) -> Option<Box<Vec<CertificateDer<'static>>>>
Cryptographic identity of the peer.
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.
This function fails if called with an empty output
or called prior to
the handshake completing.
See RFC5705 for more information.
Sourcepub fn handshake_data(&mut self) -> Result<Box<HandshakeData>, ConnectionError>
Available on rustls
only.
pub fn handshake_data(&mut self) -> Result<Box<HandshakeData>, ConnectionError>
rustls
only.Parameters negotiated during the handshake.
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 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.
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.
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
. 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, and Endpoint::shutdown()
can
be used 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.
Sourcepub async fn closed(&self) -> ConnectionError
pub async fn closed(&self) -> ConnectionError
Wait for the connection to be closed for any reason.
Sourcepub 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.
Sourcepub async fn recv_datagram(&self) -> Result<Bytes, ConnectionError>
pub async fn recv_datagram(&self) -> Result<Bytes, ConnectionError>
Receive an application datagram.
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 async fn send_datagram_wait(
&self,
data: Bytes,
) -> Result<(), SendDatagramError>
pub async fn send_datagram_wait( &self, data: Bytes, ) -> Result<(), SendDatagramError>
Transmit 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.
Sourcepub fn open_uni(&self) -> Result<SendStream, OpenStreamError>
pub fn open_uni(&self) -> Result<SendStream, OpenStreamError>
Initiate a new outgoing unidirectional stream.
Streams are cheap and instantaneous to open. As a consequence, the peer won’t be notified that a stream has been opened until the stream is actually used.
Sourcepub async fn open_uni_wait(&self) -> Result<SendStream, ConnectionError>
pub async fn open_uni_wait(&self) -> Result<SendStream, ConnectionError>
Initiate a new outgoing unidirectional stream.
Unlike open_uni()
, this method will wait for the connection to allow
a new stream to be opened.
See open_uni()
for details.
Sourcepub fn open_bi(&self) -> Result<(SendStream, RecvStream), OpenStreamError>
pub fn open_bi(&self) -> Result<(SendStream, RecvStream), OpenStreamError>
Initiate a new outgoing bidirectional stream.
Streams are cheap and instantaneous to open. As a consequence, the peer won’t be notified that a stream has been opened until the stream is actually used.
Sourcepub async fn open_bi_wait(
&self,
) -> Result<(SendStream, RecvStream), ConnectionError>
pub async fn open_bi_wait( &self, ) -> Result<(SendStream, RecvStream), ConnectionError>
Sourcepub async fn accept_uni(&self) -> Result<RecvStream, ConnectionError>
pub async fn accept_uni(&self) -> Result<RecvStream, ConnectionError>
Accept the next incoming uni-directional stream
Sourcepub async fn accept_bi(
&self,
) -> Result<(SendStream, RecvStream), ConnectionError>
pub async fn accept_bi( &self, ) -> Result<(SendStream, RecvStream), ConnectionError>
Accept the next incoming bidirectional stream
Important Note: The Connection
that calls open_bi()
must write
to its SendStream
before the other Connection
is able to
accept_bi()
. Calling open_bi()
then waiting on the RecvStream
without writing anything to SendStream
will never succeed.
Sourcepub async fn accepted_0rtt(&self) -> Result<bool, ConnectionError>
pub async fn accepted_0rtt(&self) -> Result<bool, ConnectionError>
Wait for the connection to be fully established.
For clients, the resulting value indicates if 0-RTT was accepted. For servers, the resulting value is meaningless.
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<B> Connection<B> for Connectionwhere
B: Buf,
impl<B> Connection<B> for Connectionwhere
B: Buf,
Source§type AcceptError = ConnectionError
type AcceptError = ConnectionError
Source§type OpenStreams = OpenStreams
type OpenStreams = OpenStreams
Source§type RecvStream = RecvStream
type RecvStream = RecvStream
poll_accept_recv()
Source§fn poll_accept_recv(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<<Connection as Connection<B>>::RecvStream>, <Connection as Connection<B>>::AcceptError>>
fn poll_accept_recv( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<<Connection as Connection<B>>::RecvStream>, <Connection as Connection<B>>::AcceptError>>
Source§fn poll_accept_bidi(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<<Connection as OpenStreams<B>>::BidiStream>, <Connection as Connection<B>>::AcceptError>>
fn poll_accept_bidi( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<<Connection as OpenStreams<B>>::BidiStream>, <Connection as Connection<B>>::AcceptError>>
Source§fn opener(&self) -> <Connection as Connection<B>>::OpenStreams
fn opener(&self) -> <Connection as Connection<B>>::OpenStreams
Source§impl Debug for Connection
impl Debug for Connection
Source§impl Drop for Connection
impl Drop for Connection
Source§impl<B> OpenStreams<B> for Connectionwhere
B: Buf,
impl<B> OpenStreams<B> for Connectionwhere
B: Buf,
Source§type BidiStream = BidiStream<B>
type BidiStream = BidiStream<B>
poll_open_bidi()
Source§type OpenError = ConnectionError
type OpenError = ConnectionError
Source§type SendStream = SendStream<B>
type SendStream = SendStream<B>
poll_open_send()
Source§fn poll_open_bidi(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<<Connection as OpenStreams<B>>::BidiStream, <Connection as OpenStreams<B>>::OpenError>>
fn poll_open_bidi( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<<Connection as OpenStreams<B>>::BidiStream, <Connection as OpenStreams<B>>::OpenError>>
Source§fn poll_open_send(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<<Connection as OpenStreams<B>>::SendStream, <Connection as OpenStreams<B>>::OpenError>>
fn poll_open_send( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<<Connection as OpenStreams<B>>::SendStream, <Connection as OpenStreams<B>>::OpenError>>
Source§impl PartialEq for Connection
impl PartialEq for Connection
Source§impl RecvDatagramExt for Connection
impl RecvDatagramExt for Connection
Source§type Error = ConnectionError
type Error = ConnectionError
Source§fn poll_accept_datagram(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<<Connection as RecvDatagramExt>::Buf>, <Connection as RecvDatagramExt>::Error>>
fn poll_accept_datagram( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<<Connection as RecvDatagramExt>::Buf>, <Connection as RecvDatagramExt>::Error>>
Source§impl<B> SendDatagramExt<B> for Connectionwhere
B: Buf,
impl<B> SendDatagramExt<B> for Connectionwhere
B: Buf,
Source§fn send_datagram(
&mut self,
data: Datagram<B>,
) -> Result<(), <Connection as SendDatagramExt<B>>::Error>
fn send_datagram( &mut self, data: Datagram<B>, ) -> Result<(), <Connection as SendDatagramExt<B>>::Error>
impl Eq for Connection
Auto Trait Implementations§
impl Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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