Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Quic.Client

Feature notes: Asynchronous QUIC server and HTTP/3 component

Classes, interfaces and records

classtQuicClient

A QUIC client connection over a UDP socket and a TsmStreamSecII host that you own and drive; tHttp3QuicClient runs HTTP/3 over it. The host and every socket passed to Create or Migrate are borrowed: free this object first. It has no lock: call it from one thread at a time. TLS callbacks run inside Poll and ReceiveDatagram, and most calls made from them raise eQuicError.

Setup: bind a socket (NewDatagramSocket, Bind), Create with fresh random connection IDs, set TLSConnection.TLS.DNSNameToCheck and ApplicationProtocols, optionally call ConfigureVersions, ConfigurePathMtu, ConfigureEcn, ConfigureResumption and ConfigureEarlyData, then Start. Drive: whenever the socket is readable or the NextWakeup deadline has come, call Poll, or ReceiveDatagram for each datagram you read yourself and then Flush. Nothing here waits. Pass every aNowMicros from the same monotone microsecond clock; a smaller value than before raises eQuicError. Streams: OpenStream, QueueSend, TakeReceived, and QueueControl to give the server more credit. Teardown: Close, Flush, then free this object.

If the server answers the first packet with Version Negotiation, the client starts over in another version with a new TLS session, and TLSConnection, Dispatcher, Timers and both connection-ID registries become new objects; Dispatcher.Streams is also new after a 0-RTT rejection. Read them through the properties each time.

constructor Create(aHost: TsmStreamSecII; aSocket: tAbstractDatagramSocket; const aPeer: tSocketAddress; aVersion: Cardinal; const aInitialDestinationID, aLocalSourceID: TBytes; const aLocalParameters: tQuicTransportParameters; const aStreamBudgets: tQuicStreamBudgets; aMaxDatagramSize: Integer = 1200; aMaxSendBytes: Integer = 0);
Raises eQuicError for invalid arguments. aSocket must be bound, in aPeer's address family; aVersion is cQuicVersion1 or cQuicVersion2. Full description »
destructor Destroy; override; procedure DetachDestroyedHost;
Free this client before its TsmStreamSecII host. If the host is destroyed first, it has already freed this client's TLS session: then, from the host's destruction notification and with no other thread using the client, call DetachDestroyedHost and next free the client, making no other call in between.
procedure ConfigureVersions(const aPreferredVersions: tQuicVersionList);
The QUIC versions the client may switch to when the server answers with Version Negotiation, most preferred first: one or two distinct values out of cQuicVersion1 and cQuicVersion2, including the version given to Create (that version alone means never switch). The default is that version, then the other one. Call before Start.
function CaptureResumptionTicket(aTicket: TTls13ClientTicket; const aApplicationContext: TBytes): tQuicSessionTicket;
Turns a TLS 1.3 session ticket from this connection into a tQuicSessionTicket for ConfigureResumption on a later client; you own the result. Full description »
function ConfigureResumption(aTicket: tQuicSessionTicket; const aApplicationContext: TBytes; aNow: TDateTime): Boolean;
Offers aTicket so that the server can resume its session (PSK). Call after setting TLSConnection.TLS.DNSNameToCheck and ApplicationProtocols, and before ConfigureEarlyData and Start (later raises eQuicError). Full description »
procedure ConfigurePathMtu(aCeiling: Integer);
Lets the client probe for larger datagrams, up to aCeiling bytes (1200..aMaxDatagramSize of Create). By default (1200) datagrams stay at 1200 bytes or less and no probes are sent. Call before Start.
procedure ConfigureEcn(aEnabled: Boolean);
ECN (Explicit Congestion Notification) is used by default; False turns it off. If the socket cannot report or set ECN bits, the client just sends unmarked (Not-ECT) datagrams. Call before Start.
function RequestKeyUpdate(aNowMicros: UInt64): Boolean;
Starts a QUIC key update: later 1-RTT packets use new keys, and a packet is queued to carry the first of them (Flush sends it). Full description »
function Ping(aNowMicros: UInt64): Boolean;
Sends a PING on the next Flush, without changing the traffic keys, so the peer acknowledges and neither end's idle timer expires. Several calls before a Flush send one PING. Returns False when the connection is not active (still handshaking, closing or closed).
procedure ConfigureEarlyData(const aContext: TBytes);
Also sends 0-RTT data on the resumed connection. Call after a ConfigureResumption that returned True and before Start, with the same nonempty application context (at most 32768 bytes); otherwise it raises eQuicError. If the ticket does not allow 0-RTT, nothing is offered (EarlyDataOffered stays False). Send as 0-RTT only data that is safe for the server to receive twice.
function ResumptionContext: tQuicResumptionContext;
A copy of the context of the ticket that ConfigureResumption accepted; empty when there is none.
property EarlyDataOffered: Boolean read GetEarlyDataOffered;
0-RTT progress after Start. While EarlyDataWindowOpen, streams opened and data queued go out as 0-RTT: queue them right after Start and Flush before reading the server's reply, since the window ends during the handshake (HTTP.txt section 23.4 gives this order for HTTP/3). Full description »
property EarlyDataAccepted: Boolean read GetEarlyDataAccepted; property EarlyDataRejected: Boolean read GetEarlyDataRejected; property EarlyDataWindowOpen: Boolean read GetEarlyDataWindowOpen; procedure Start;
Starts the handshake; the next Flush or Poll sends it. Call once, after the setup calls. Raises eQuicError when the socket cannot forbid IP fragmentation (SetDontFragment), which QUIC requires.
procedure Migrate(aSocket: tAbstractDatagramSocket; const aPeer: tSocketAddress; aNowMicros: UInt64);
Moves the connection to aSocket, another bound socket of aPeer's family, with aPeer either the current server address or the preferred_address in the server's authenticated transport parameters. Full description »
procedure Close(aErrorCode: UInt64; const aReason: TBytes; aNowMicros: UInt64; aApplication: Boolean = False);
Closes the connection with aErrorCode and aReason (UTF-8, at most 1024 bytes); aApplication: True for an application protocol code, False for a QUIC transport code. Queued data is dropped and the next Flush sends CONNECTION_CLOSE. To also answer the server during the closing period, keep driving until NextWakeup returns False. A call after the connection has started closing does nothing.
function NextWakeup(out aDeadline: UInt64): Boolean;
When the client next needs Flush or Poll without new input. True: aDeadline is that time in your microsecond clock (never before your last aNowMicros; at or before the current time means now). False: nothing is scheduled and aDeadline is 0, as always before Start and after the connection has ended. Socket input is not included: wait for readability as well.
function ReceiveDatagram(const aData: TBytes; const aFrom: tSocketAddress; aNowMicros: UInt64; aEcn: tDatagramEcn = deUnknown): Boolean;
Feeds the client one datagram that you read from its socket, with the sender and, when known, the ECN marking; call Flush afterwards. True: it was used. False: it was ignored or kept for later (another path, not decryptable yet, connection ended); nothing to do. aData is copied. A protocol error raises eQuicError; the connection is then closing and the next Flush tells the server.
function ReceiveDatagramOn(aSocket: tAbstractDatagramSocket; const aData: TBytes; const aFrom: tSocketAddress; aNowMicros: UInt64; aEcn: tDatagramEcn = deUnknown): Boolean;
As ReceiveDatagram, for a datagram read from aSocket. Use it when you read more than one socket yourself, as around a Migrate; ReceiveDatagram assumes the current active socket.
function Flush(aNowMicros: UInt64; aMaxPackets: Integer = 32): Integer;
Sends what is ready (stream data, ACKs, retransmissions, the CONNECTION_CLOSE after Close) in at most aMaxPackets datagrams (0..65536) and returns how many were sent. Full description »
function Poll(aNowMicros: UInt64; aMaxReceive: Integer = 64; aMaxSend: Integer = 32): Integer;
Reads up to aMaxReceive datagrams (0..65536) from the client's own sockets (the active one and, around a Migrate, the old and new ones), processes them, then sends as Flush does with aMaxSend; it never waits. Returns how many datagrams were read, ignored ones included. Use it unless you read the sockets yourself. A receive error shows in LastSocketError when sending had none.
function OpenStream(aUnidirectional: Boolean): UInt64;
Opens a local stream, bidirectional unless aUnidirectional, and returns its ID. Possible once the handshake is complete, or earlier while EarlyDataWindowOpen. Raises eQuicError when the server's stream limit or aStreamBudgets.MaxStreams of Create is used up; Dispatcher.Streams.CanOpenStream checks the former beforehand.
procedure QueueSend(aStreamID: UInt64; const aData: TBytes; aFin: Boolean); overload;
QueueSend of the whole of aData; see the overload below. » member page
procedure QueueSend(aStreamID: UInt64; const aData: TBytes; aDataOffset, aCount: Integer; aFin: Boolean); overload;
Queues aCount bytes of aData from aDataOffset on aStreamID, and ends the send direction when aFin is True (aCount 0 with aFin True only ends it); Flush sends them. Full description »
procedure ResetSend(aStreamID, aError: UInt64);
Abandons the send direction of aStreamID: unsent data is dropped and RESET_STREAM with application error code aError is queued. Does nothing once all data is acknowledged or after an earlier reset.
procedure StopReceive(aStreamID, aError: UInt64);
Asks the server to stop sending on aStreamID (STOP_SENDING with application error code aError), for example when the rest of a response is no longer wanted; it is resent until acknowledged. Does nothing once the stream's data or reset has fully arrived. Raises eQuicError for a stream without a receive direction.
function TakeReceived(aStreamID: UInt64; out aData: TBytes; out aFin: Boolean): Boolean; overload;
Takes the next in-order chunk received on aStreamID; call until False. True: aData holds it (empty when only the end arrived), and aFin is True with the last of the stream. False: nothing in order yet, the handshake is not complete, or the stream was reset (Dispatcher.Streams.ConsumeReset reports that). Taking data gives the server no new credit; see QueueControl.
function TakeReceived(aStreamID: UInt64; out aData: TBytes; out aFin, aEarly: Boolean): Boolean; overload; procedure QueueControl(const aFrame: tQuicFrame);
Gives the server more receive credit, which TakeReceived never does by itself (tHttp3QuicClient does it for you). Full description »
property TLSConnection: tQuicTLSConnection read fTLS;
TLSConnection.TLS is the TLS session (nil once the connection has ended): set DNSNameToCheck, ApplicationProtocols and other TLS options on it before Start. TLSConnection.State shows progress, for example HandshakeComplete and Phase. Dispatcher.Streams is the stream manager (SendCapacity, CanOpenStream, the receive-limit methods); it raises eQuicError while streams are not yet usable.
property Dispatcher: tQuicFrameDispatcher read fDispatch; property LastSocketError: Integer read fLastSocketError; property Negotiation: tQuicClientNegotiation read fNegotiation; property Paths: tQuicPathManager read fPaths;
Path validation, path MTU and idle/close timer state, owned by the client, for diagnostics only: read them, but never call their methods that change state.
property Mtu: tQuicPathMtu read fMtu; property Timers: tQuicLifetime read fTimers; property PeerConnectionIDs: tQuicPeerConnectionIDs read fPeerConnectionIDs;
The connection IDs the server issued to the client and those the client issued, owned by the client, for diagnostics only: never change them.
property LocalConnectionIDs: tQuicLocalConnectionIDs read fLocalConnectionIDs;