APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http.quic

public Class QuicConnectionImpl

extends QuicConnection
implements QuicPacketReceiver
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.quic.QuicPacketReceiver
Imports
java.io.IOException, .UncheckedIOException, java.lang.invoke.MethodHandles, .MethodHandles.Lookup, .VarHandle, java.net.ConnectException, .Inet6Address, .InetSocketAddress, .SocketAddress, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, .NetworkChannel, .UnresolvedAddressException, java.security.SecureRandom, java.time.Duration, java.util.ArrayList, .Arrays, .LinkedList, .List, .Objects, .Optional, .Queue, .Random, .Set, java.util.concurrent.CompletableFuture, .CompletionException, .ConcurrentLinkedQueue, .Executor, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, java.util.concurrent.locks.ReentrantLock, java.util.function.Function, .Predicate, .Supplier, java.util.stream.Collectors, .Stream, javax.net.ssl.SSLHandshakeException, .SSLParameters, jdk.internal.net.http.common.Deadline, .Log, .Logger, .MinimalFuture, .SequentialScheduler, .TimeSource, .Utils, jdk.internal.net.http.quic.OrderedFlow.CryptoDataFlow, .QuicEndpoint.QuicDatagram, .QuicTransportParameters.VersionInformation, .QuicTransportParameters.ParameterId, jdk.internal.net.http.quic.frames.AckFrame, .ConnectionCloseFrame, .CryptoFrame, .DataBlockedFrame, .HandshakeDoneFrame, .MaxDataFrame, .MaxStreamDataFrame, .MaxStreamsFrame, .NewConnectionIDFrame, .NewTokenFrame, .PaddingFrame, .PathChallengeFrame, .PathResponseFrame, .PingFrame, .QuicFrame, .ResetStreamFrame, .RetireConnectionIDFrame, .StopSendingFrame, .StreamDataBlockedFrame, .StreamFrame, .StreamsBlockedFrame, jdk.internal.net.http.quic.packets.HandshakePacket, .InitialPacket, .LongHeader, .OneRttPacket, .PacketSpace, .QuicPacketDecoder, .QuicPacketEncoder, .QuicPacketEncoder.OutgoingQuicPacket, .RetryPacket, .VersionNegotiationPacket, .QuicPacket, .QuicPacket.PacketNumberSpace, .QuicPacket.PacketType, jdk.internal.net.http.quic.streams.CryptoWriterQueue, .QuicBidiStream, .QuicBidiStreamImpl, .QuicConnectionStreams, .QuicReceiverStream, .QuicSenderStream, .QuicStream, .QuicStream.StreamState, .QuicStreams, jdk.internal.net.quic.QuicKeyUnavailableException, .QuicOneRttContext, .QuicTLSEngine, .QuicTLSEngine.HandshakeState, .QuicTLSEngine.KeySpace, .QuicTransportErrors, .QuicTransportException, .QuicVersion

This class implements a QUIC connection. A QUIC connection is established between a client and a server over a QuicEndpoint endpoint. A QUIC connection can then multiplex multiple QUIC streams to the same server.
External Specification
https://www.rfc-editor.org/info/rfc9000, https://www.rfc-editor.org/info/rfc9001, https://www.rfc-editor.org/info/rfc9002

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
QuicConnectionImpl.HandshakeFlow

Keeps track of: - handshakeCF the handshake completable future - localInitial the local initial crypto writer queue - peerInitial the peer initial crypto flow - localHandshake the local handshake crypto queue - peerHandshake the peer handshake crypto flow

private static record
pack-priv class
QuicConnectionImpl.MaxInitialTimer

A {link QuicTimedEvent} used to interrupt the handshake if no response to the first initial packet is received within a reasonable delay (default is ~ 30s).

pack-priv class
QuicConnectionImpl.OneRttFlowControlledReceivingQueue

A class used to check that 1-RTT received data doesn't exceed the MAX_DATA of the connection

pack-priv class
QuicConnectionImpl.OneRttFlowControlledSendingQueue

An event loop triggered when stream data is available for sending.

public static record
public static record
QuicConnectionImpl.ProtectionRecord

A protection record contains a packet to encrypt, and a datagram that may already contain encrypted packets.

protected class
public abstract static class
QuicConnectionImpl.QuicConnectionState

An abstraction to represent the connection state as a bit mask.

protected class
QuicConnectionImpl.StateHandle

A state handle is a mutable implementation of QuicConnectionState that allows to view the volatile connection int variable state as a QuicConnectionState, and provides methods to mutate it in a thread safe atomic way.

Field Summary

Modifier and TypeField and Description
private final AtomicInteger
private final AtomicInteger
private final AtomicInteger
private final ConcurrentLinkedQueue<ByteBuffer>
pack-priv final AtomicInteger
private final String
private final CodingContext
pack-priv final QuicCongestionController
private final QuicConnectionId
private final String
protected final Logger
private volatile QuicPacketDecoder
public static final int
public static final long
public static final long
public static final int
public static final int
public static final int
private volatile QuicPacketEncoder
protected final QuicEndpoint
private final QuicConnectionImpl.HandshakeFlow
private final ReentrantLock
private final SequentialScheduler
protected final IdleTimeoutManager
private final ConcurrentLinkedQueue<QuicConnectionImpl.IncomingDatagram>
private volatile QuicConnectionId
private final SequentialScheduler
private volatile byte[]
private final long
private final LocalConnIdManager
private final CryptoWriterQueue
private volatile QuicTransportParameters
private final String
private static final int
private static final int
private static final int
private static final int
private static final VarHandle
private static final VarHandle
public static final long
private final int
private volatile QuicConnectionImpl.MaxInitialTimer
private int
private final QuicConnectionImpl.OneRttFlowControlledReceivingQueue
private final QuicConnectionImpl.OneRttFlowControlledSendingQueue
private final QuicVersion
protected final Queue<QuicFrame>
private final QuicConnectionImpl.PacketSpaces
private final Queue<PathChallengeFrame>
private int
private volatile long
private final InetSocketAddress
private final PeerConnIdManager
private final OrderedFlow.CryptoDataFlow
private volatile QuicTransportParameters
private volatile boolean
private final QuicInstance
private final QuicTLSEngine
private volatile QuicVersion
private static final Random
public static final int
pack-priv final QuicRttEstimator
public static final int
private final AtomicBoolean
private static final VarHandle
private volatile int
private final QuicConnectionImpl.StateHandle
stateHandle

The state of the quic connection.

protected final QuicConnectionStreams
pack-priv final ConnectionTerminatorImpl
protected final QuicTransportParameters
public static final boolean
private static final VarHandle
private volatile boolean
private volatile boolean

Constructor Summary

AccessConstructor and Description
protected
QuicConnectionImpl(final QuicVersion firstFlightVersion, final QuicInstance quicInstance, final InetSocketAddress peerAddress, final String peerName, final int peerPort, final SSLParameters sslParameters, final String logTagFormat, final long labelId)

Method Summary

Modifier and TypeMethod and Description
public boolean
accepts(SocketAddress source)

Overrides default jdk.internal.net.http.quic.QuicPacketReceiver.accepts.

Returns whether this receiver accepts packets from the given source.

private List<QuicFrame>
ackOrPing(AckFrame ack, boolean sendPing)

public List<byte[]>
activeResetTokens()

Implements jdk.internal.net.http.quic.QuicPacketReceiver.activeResetTokens.

{@return a list of active peer stateless reset tokens for this connection)

public void
addRemoteStreamListener(Predicate<? super QuicReceiverStream> streamConsumer)

Implements abstract jdk.internal.net.http.quic.QuicConnection.addRemoteStreamListener.

Adds a listener that will be invoked when a remote stream is created.

protected ByteBuffer

Returns:

a new ByteBuffer with sufficient space to encrypt the given packet.
allocateDatagramForEncryption
(QuicPacket
the packet to encrypt
packet
)

Allocate a ByteBuffer that can be used to encrypt the given packet.

protected ByteBuffer
public NetworkChannel

Returns:

the underlying NetworkChannel used by this connection, which may be null if the endpoint has not been configured yet
channel
()

Returns the underlying NetworkChannel used by this connection, which may be null if the endpoint has not been configured yet.

private void
public void
protected CodingContext
protected void
protected final void
pack-priv final Optional<QuicEndpoint.Datagram>

Returns:

the datagram containing the QUIC packet with a CONNECTION_CLOSE frame or an empty Optional if the datagram couldn't be constructed.
connectionCloseDatagram
()

Returns a jdk.internal.net.http.quic.QuicEndpoint.Datagram which contains an encrypted QUIC packet containing a CONNECTION_CLOSE frame.

public int
public List<QuicConnectionId>
connectionIds()

Implements jdk.internal.net.http.quic.QuicPacketReceiver.connectionIds.

{@return a list of local connectionIds for this connection)

public ConnectionTerminator
protected void
private static boolean

Returns:

true if the packet contains a CONNECTION_CLOSE frame, false otherwise
containsConnectionClose
(final QuicPacket
the QUIC packet
packet
)

Returns true if the packet contains a CONNECTION_CLOSE frame, false otherwise.

protected void
continueHandshake()

Retrieves cryptographic messages from TLS engine, enqueues them for sending and starts the transmitter.

protected void
private void
private static QuicCongestionController
public void
datagramDiscarded(QuicEndpoint.QuicDatagram datagram)

Overrides default jdk.internal.net.http.quic.QuicPacketReceiver.datagramDiscarded.

Called after a datagram has been discarded as a result of some error being raised, for instance, when an attempt to write it to the socket has failed, or if the encryption of a packet in the datagram has failed.

public void
datagramDropped(QuicEndpoint.QuicDatagram datagram)

Overrides default jdk.internal.net.http.quic.QuicPacketReceiver.datagramDropped.

Called after a datagram has been dropped.

protected void
datagramReleased(QuicEndpoint.QuicDatagram
the released datagram
datagram
)

Called when a datagram is being released, either from datagramSent(QuicDatagram), datagramDiscarded(QuicDatagram), or datagramDropped(QuicDatagram).

public void
datagramSent(QuicEndpoint.QuicDatagram datagram)

Overrides default jdk.internal.net.http.quic.QuicPacketReceiver.datagramSent.

Called after a datagram has been written to the socket.

pack-priv static String
dbgTag(QuicInstance quicInstance, String logTag)

public String
dbgTag()

Implements abstract jdk.internal.net.http.quic.QuicConnection.dbgTag.

Returns a debug tag to be used with lower level logging.

protected QuicPacketDecoder
private void
decrypt(ByteBuffer
a byte buffer containing the incoming packet
buffer
)

Schedule an incoming quic packet for decryption.

private long

Returns:

the emitted packet number, or -1L if not applicable or not emitted
emitAckPacket
(final PacketSpace
the packet space manager on behalf of which the acknowledgement should be sent.
packetSpaceManager
,
final AckFrame
the ACK frame to be sent.
ackFrame
,
final boolean
whether a PING frame should be sent.
sendPing
)

Emit a possibly non ACK-eliciting packet containing the given ACK frame.

protected PacketEmitter
protected QuicPacketEncoder
public QuicEndpoint
protected void
enqueue1RTTFrame(final QuicFrame
frame to send
frame
)

Schedule a frame for sending in a 1-RTT packet.

protected QuicStream

Returns:

the stream identified by the given streamId, or null.
findStream
(long
the stream ID
streamId
)

If a stream with this streamId was already created, returns it.

private void
public final CompletableFuture<TerminationCause>
public QuicConnectionId
protected long

Returns:

the number of (active) connection ids that this endpoint is willing to accept from the peer for a given connection
getLocalActiveConnIDLimit
()

Returns the number of (active) connection ids that this endpoint is willing to accept from the peer for a given connection.

public int

Returns:

the maximum datagram size that can be used on the connection path
getMaxDatagramSize
()

Returns the maximum datagram size that can be used on the connection path.

protected ByteBuffer

Returns:

a new ByteBuffer to encode and encrypt packets in a datagram
getOutgoingByteBuffer
(int
the maximum size of the datagram
size
)

Returns a new ByteBuffer to encode and encrypt packets in a datagram.

protected long

Returns:

the number of (active) connection ids that the peer is willing to accept for a given connection
getPeerActiveConnIDLimit
()

Returns the number of (active) connection ids that the peer is willing to accept for a given connection.

private QuicReceiverStream

Returns:

receiver stream, or null if stream is already gone
getReceivingStream
(long
stream ID
streamId
,
long
received frame type. Used in QuicTransportException
frameType
)

Gets a receiving stream instance for the given ID, used for processing incoming STREAM, RESET_STREAM and STREAM_DATA_BLOCKED frames.

private QuicSenderStream

Returns:

sender stream, or null if stream is already gone
getSendingStream
(long
stream ID
streamId
,
long
received frame type. Used in QuicTransportException
frameType
)

Gets a sending stream instance for the given ID, used for processing incoming MAX_STREAM_DATA and STOP_SENDING frames.

public QuicTLSEngine
protected void
handleIncomingPeerTransportParams(final QuicTransportParameters
the peer's new quic transport parameter
params
)

Called when new quic transport parameters are available from the peer.

protected QuicConnectionImpl.HandshakeFlow
public CompletableFuture<Void>
handshakeReachedPeer()

Implements abstract jdk.internal.net.http.quic.QuicConnection.handshakeReachedPeer.

{@return a CompletableFuture that gets completed when the peer has acknowledged, or replied to the first INITIAL packet

private boolean

Returns:

true if queued frames are available for sending
hasQueuedFrames
()

Returns true if queued frames are available for sending.

private void
protected void
incoming1RTTFrame(final AckFrame ackFrame)

protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
incoming1RTTFrame(final OneRttPacket oneRttPacket, final RetireConnectionIDFrame frame)

protected void
protected void
protected void
protected void
protected int
protected void
protected void
protected void
protected void
protected int
protected void
protected void
protected void
public void
increaseProcessedData(long
amount of data processed
diff
)

Called when frame data is removed from the connection and the amount of data can be added to MAX_DATA window.

public void
increaseReceivedData(long diff, long
type of frame received
frameType
)

Called when frame data can be safely added to the amount of data received by the connection for MAX_DATA flow control purpose.

private QuicConnectionId
private byte[]
public void
public boolean

Returns:

true if this connection is a client connection
isClientConnection
()

Returns true if this connection is a client connection.

protected boolean

Returns:

a boolean value telling whether the datagram in the protection record is complete
isDatagramComplete
(QuicConnectionImpl.ProtectionRecord
the protection record
protectionRecord
)

Returns a boolean value telling whether the datagram in the protection record is complete.

protected boolean
isExistingStreamId(long
the stream id
streamId
)

Returns: true if this stream ID identifies a stream that was already opened

protected final boolean

Returns:

true if this is a stream initiated locally, and false if this is a stream initiated by the peer
isLocalStream
(long
a stream ID.
streamId
)

Returns true if this is a stream initiated locally, and false if this is a stream initiated by the peer.

public boolean
isOpen()

Implements abstract jdk.internal.net.http.quic.QuicConnection.isOpen.

Returns true if this connection is open.

public long
public long
public SocketAddress

Returns:

the local address of the quic endpoint
localAddress
()

Implements abstract jdk.internal.net.http.quic.QuicConnection.localAddress.

Returns the local address of the quic endpoint.

public QuicConnectionId

Returns:

the local connection id
localConnectionId
()

Overrides jdk.internal.net.http.quic.QuicConnection.localConnectionId.

Returns the local connection id.

pack-priv LocalConnIdManager
public QuicTransportParameters
public String
public final String
logTag()

Implements abstract jdk.internal.net.http.quic.QuicConnection.logTag.

Returns a debug tag.

private List<QuicFrame>

Returns:

A list of QuicFrame.
makeList
(CryptoFrame
the crypto frame
crypto
,
AckFrame
the ack frame
ack
)

Compose a list of Quic frames containing a crypto frame and an ack frame, omitting null frames.

protected void
markVersionNegotiated(int
the packet version
packetVersion
)

Mark the version as negotiated.

protected void
pack-priv final QuicPacket
newQuicPacket(final QuicTLSEngine.KeySpace keySpace, final List<QuicFrame> frames)

public long

Returns:

the next (higher) max streams limit that should be advertised to the remote peer. Returns 0 if the limit should not be increased
nextMaxStreamsLimit
(final boolean
true if bidirectional stream, false otherwise
bidi
)

Returns the next (higher) max streams limit that should be advertised to the remote peer.

public void
notifyTerminalState(long
the id of the stream
streamId
,
QuicStream.StreamState
the terminal state
state
)

Called when the receiving part or the sending part of a stream reaches a terminal state.

protected QuicEndpoint
onHandshakeCompletion(final QuicTLSEngine.HandshakeState
the result of the handshake
result
)

This method is called when the handshake is successfully completed.

public void
onProcessingError(QuicPacket packet, Throwable
the error that occurred
t
)

Called when a packet couldn't be processed

public void
onWriteError(Throwable
the error that occurred
t
)

Implements jdk.internal.net.http.quic.QuicPacketReceiver.onWriteError.

Called when a datagram scheduled for writing by this connection could not be written to the network.

public CompletableFuture<QuicBidiStream>
openNewLocalBidiStream(final Duration limitIncreaseDuration)

Implements abstract jdk.internal.net.http.quic.QuicConnection.openNewLocalBidiStream.

Creates a new locally initiated bidirectional stream.

public CompletableFuture<QuicSenderStream>
openNewLocalUniStream(final Duration limitIncreaseDuration)

Implements abstract jdk.internal.net.http.quic.QuicConnection.openNewLocalUniStream.

Creates a new locally initiated unidirectional stream.

protected QuicStream

Returns:

the remote initiated stream identified by the given stream ID, or null
openOrGetRemoteStream
(long
the id of the remote stream
streamId
,
long
type of the frame received, used in exceptions
frameType
)

Get or open a peer initiated stream with the given stream ID

protected QuicConnectionId

Returns:

the original connection id
originalServerConnId
()

Returns the original connection id. This is the original destination connection id that the client generated when connecting to the server for the first time.

private void
protected QuicConnectionImpl.PacketSpaces
protected PacketSpace
public InetSocketAddress

Returns:

the peer address that should be used when sending datagram to the peer
peerAddress
()

Implements abstract jdk.internal.net.http.quic.QuicConnection.peerAddress.

Returns the peer address that should be used when sending datagram to the peer.

public QuicConnectionId

Returns:

the peer connection id
peerConnectionId
()

Returns the peer connection id.

pack-priv PeerConnIdManager
public long

Returns:

the computed PTO for the current packet number space, adjusted by our max ack delay
peerPtoMs
()

Returns the computed PTO for the current packet number space, adjusted by our max ack delay.

public QuicTransportParameters
public void
processDecrypted(QuicPacket
the decrypted quic packet
quicPacket
)

Called when an incoming packet has been decrypted.

protected void
processHandshakePacket(final QuicPacket
the handshake quic packet
quicPacket
)

Called to process an HandshakePacket after it has been decrypted.

protected int

Returns:

the total number of bytes consumed
processHandshakePacketPayload
(final HandshakePacket
the incoming packet
packet
)

Process the payload of an incoming handshake packet

public void
processIncoming(SocketAddress source, ByteBuffer destConnId, QuicPacket.HeadersType headersType, ByteBuffer buffer)

Implements jdk.internal.net.http.quic.QuicPacketReceiver.processIncoming.

Called when an incoming datagram is received.

protected void
processInitialPacket(final QuicPacket
the Quic packet
quicPacket
)

Called to process an InitialPacket after it has been decrypted.

protected int

Returns:

the total number of bytes consumed
processInitialPacketPayload
(final InitialPacket
the incoming packet
packet
)

Process the payload of an incoming initial packet

protected void
processOneRTTPacket(final QuicPacket
the Quic packet
quicPacket
)

Called to process a OneRttPacket after it has been successfully decrypted

protected void
processRetryPacket(final QuicPacket
the retry quic packet
quicPacket
)

Called to process a RetryPacket after it has been decrypted.

public void
processStatelessReset()

Implements jdk.internal.net.http.quic.QuicPacketReceiver.processStatelessReset.

Called when a stateless reset token is received.

protected void
pack-priv final void
pushDatagram(final QuicConnectionImpl.ProtectionRecord
a record containing a quic packet to encrypt, a destination byte buffer, and various offset information.
protectionRecord
)

Encrypt an outgoing quic packet.

protected void
pushDatagram(final SocketAddress
The destination of this datagram
destination
,
final ByteBuffer
The datagram
datagram
)

Calls the QuicEndpoint#pushDatagram(QuicPacketReceiver, SocketAddress, ByteBuffer)

private void
pushEncryptedDatagram(final QuicConnectionImpl.ProtectionRecord
the ProtectionRecord containing the datagram
protectionRecord
)

Pushes the datagram contained in the protectionRecord, through the endpoint.

public QuicInstance
public Stream<? extends QuicStream>
quicStreams()

Implements abstract jdk.internal.net.http.quic.QuicConnection.quicStreams.

Returns a stream of all currently opened QuicStream in the connection.

public QuicVersion
private LinkedList<QuicFrame>
public boolean
public void
requestResetStream(long
the id of the stream that should be reset
streamId
,
long
the application error code
errorCode
)

Called to request sending of a RESET_STREAM frame.

public void
requestSendMaxStreamData(long
the stream id to be cancelled
streamId
,
long
the new max data we are prepared to receive on this stream
maxStreamData
)

Called to request sending of a MAX_STREAM_DATA frame.

public CompletableFuture<Long>
requestSendPing()

Implements abstract jdk.internal.net.http.quic.QuicConnection.requestSendPing.

Requests to send a PING frame to the peer.

private void
retransmit(PacketSpace
the packet space manager on behalf of which the packet is being retransmitted
packetSpaceManager
,
QuicPacket
the unacknowledged packet which should be retransmitted
packet
,
int attempts)

Retransmit the given packet on behalf of the given packet space manager.

public void
private void
public void
scheduleStopSendingFrame(long
the stream id to be cancelled
streamId
,
long
the application error code
errorCode
)

Called to request sending of a STOP_SENDING frame.

protected void
send1RTTPacket(final OneRttPacket
The ONERTT packet to send.
packet
)

Invoked to send a ONERTT packet containing stream data or control frames.

private boolean
private QuicConnectionImpl.HandshakeFlow
private boolean
protected static void
public void
shutdown()

Implements jdk.internal.net.http.quic.QuicPacketReceiver.shutdown.

Called to shut a closed connection down.

public final CompletableFuture<QuicEndpoint>

Returns:

A completable future which will be completed when the handshake is completed.
startHandshake
()

Implements abstract jdk.internal.net.http.quic.QuicConnection.startHandshake.

Starts the Quic Handshake.

protected void
protected final QuicConnectionImpl.StateHandle
public void
streamDataAvailableForSending(final Set<Long>
the stream ids
streamIds
)

Signal the connection that some stream data is available for sending on one or more streams.

public String
streamDbgTag(long streamId, String direction)

protected boolean

Returns:

true if switching to the new version was successful
switchVersion
(QuicVersion
the new version that was negotiated
negotiated
)

Switch to a new version after receiving a version negotiation packet.

public TerminationCause
terminationCause()

Implements abstract jdk.internal.net.http.quic.QuicConnection.terminationCause.

Returns the TerminationCause if the connection has closed or is being closed, otherwise returns null.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public final long
uniqueId()

Overrides jdk.internal.net.http.quic.QuicConnection.uniqueId.

Returns a long identifier that can be used to uniquely identify a quic connection in the context of the QuicInstance that created it.

protected void
protected boolean
verifyToken(QuicConnectionId destinationID, byte[] token)