pub struct Connection { /* private fields */ }
Expand description

Protocol state and logic for a single QUIC connection

Objects of this type receive ConnectionEvents and emit EndpointEvents and application Events to make progress. To handle timeouts, a Connection returns timer updates and expects timeouts through various methods. A number of simple getter methods are exposed to allow callers to inspect some of the connection state.

Connection has roughly 4 types of methods:

  • A. Simple getters, taking &self
  • B. Handlers for incoming events from the network or system, named handle_*.
  • C. State machine mutators, for incoming commands from the application. For convenience we refer to this as “performing I/O” below, however as per the design of this library none of the functions actually perform system-level I/O. For example, read and write, but also things like reset.
  • D. Polling functions for outgoing events or actions for the caller to take, named poll_*.

The simplest way to use this API correctly is to call (B) and (C) whenever appropriate, then after each of those calls, as soon as feasible call all polling methods (D) and deal with their outputs appropriately, e.g. by passing it to the application or by making a system-level I/O call. You should call the polling functions in this order:

  1. poll_transmit
  2. poll_timeout
  3. poll_endpoint_events
  4. poll

Currently the only actual dependency is from (2) to (1), however additional dependencies may be added in future, so the above order is recommended.

(A) may be called whenever desired.

Care should be made to ensure that the input events represent monotonically increasing time. Specifically, calling handle_timeout with events of the same Instant may be interleaved in any order with a call to handle_event at that same instant; however events or timeouts with different instants must not be interleaved.

Implementations

Returns the next time at which handle_timeout should be called

The value returned may change after:

  • the application performed some I/O on the connection
  • a call was made to handle_event
  • a call to poll_transmit returned Some
  • a call was made to handle_timeout

Returns application-facing events

Connections should be polled for events after:

  • a call was made to handle_event
  • a call was made to handle_timeout

Return endpoint-facing events

Provide control over streams

Provide control over streams

Provide control over streams

Returns packets to transmit

Connections should be polled for transmit after:

  • the application performed some I/O on the connection
  • a call was made to handle_event
  • a call was made to handle_timeout

max_datagrams specifies how many datagrams can be returned inside a single Transmit using GSO. This must be at least 1.

Process ConnectionEvents generated by the associated Endpoint

Will execute protocol logic upon receipt of a connection event, in turn preparing signals (including application Events, EndpointEvents and outgoing datagrams) that should be extracted through the relevant methods.

Process timer expirations

Executes protocol logic, potentially preparing signals (including application Events, EndpointEvents and outgoing datagrams) that should be extracted through the relevant methods.

It is most efficient to call this immediately after the system clock reaches the latest Instant that was output by poll_timeout; however spurious extra calls will simply no-op and therefore are safe.

Close a connection immediately

This does not ensure delivery of outstanding data. It is the application’s responsibility to call this only when all important communications have been completed, e.g. by calling SendStream::finish on outstanding streams and waiting for the corresponding StreamEvent::Finished event.

If Streams::send_streams returns 0, all outstanding stream data has been delivered. There may still be data from the peer that has not been received.

Control datagrams

Returns connection statistics

Ping the remote endpoint

Causes an ACK-eliciting packet to be transmitted.

Get a session reference

Whether the connection is in the process of being established

If this returns false, the connection may be either established or closed, signaled by the emission of a Connected or ConnectionLost message respectively.

Whether the connection is closed

Closed connections cannot transport any further data. A connection becomes closed when either peer application intentionally closes it, or when either transport layer detects an error such as a time-out or certificate validation failure.

A ConnectionLost event is emitted with details when the connection becomes closed.

Whether there is no longer any need to keep the connection around

Closed connections become drained after a brief timeout to absorb any remaining in-flight packets from the peer. All drained connections have been closed.

For clients, if the peer accepted the 0-RTT data packets

The value is meaningless until after the handshake completes.

Whether 0-RTT is/was possible during the handshake

Whether there are any pending retransmits

Look up whether we’re the client or server of this Connection

The latest socket address for this connection’s peer

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.

Current best estimate of this connection’s latency (round-trip-time)

Current state of this connection’s congestion controller, for debugging purposes

Modify the number of remotely initiated streams that may be concurrently open

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.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more