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

public abstract sealed Class QuicEndpoint

extends Object
implements AutoCloseable
permits QuicSelectableEndpoint, QuicVirtualThreadedEndpoint
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Known Direct Subclasses
jdk.internal.net.http.quic.QuicEndpoint.QuicSelectableEndpoint, jdk.internal.net.http.quic.QuicEndpoint.QuicVirtualThreadedEndpoint
Imports
java.io.IOException, java.net.InetSocketAddress, .SocketAddress, .SocketOption, .SocketException, java.nio.ByteBuffer, java.nio.channels.CancelledKeyException, .ClosedChannelException, .DatagramChannel, .SelectionKey, .Selector, java.security.InvalidKeyException, .Key, .NoSuchAlgorithmException, java.util.Arrays, .HashSet, .HexFormat, .List, .Objects, .Optional, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentLinkedQueue, .ConcurrentMap, .Executor, .Future, .RejectedExecutionException, java.util.concurrent.atomic.AtomicInteger, java.util.function.Consumer, java.util.stream.Stream, jdk.internal.net.http.common.Deadline, .Log, .Logger, .SequentialScheduler, .TimeLine, .TimeSource, .Utils, .Utils.UseVTForSelector, jdk.internal.net.http.quic.QuicSelector.QuicNioSelector, .QuicSelector.QuicVirtualThreadPoller, jdk.internal.net.http.quic.packets.QuicPacket.HeadersType, .QuicPacketDecoder, jdk.internal.util.OperatingSystem, javax.crypto.BadPaddingException, .Cipher, .IllegalBlockSizeException, .KeyGenerator, .NoSuchPaddingException

A QUIC Endpoint. A QUIC endpoint encapsulate a DatagramChannel and is registered with a Selector. It subscribes for read and write events from the selector, and implements a readLoop and a writeLoop.

The read event or write event are triggered by the selector thread. When the read event is triggered, all available datagrams are read from the channel and pushed into a read queue. Then the readLoop is triggered. When the write event is triggered, the key interestOps are modified to pause write events, and the writeLoop is triggered.

The readLoop and writeLoop should never execute on the selector thread, but rather, in the client's executor.

When the writeLoop is triggered, it polls the writeQueue and writes as many datagram as it can to the channel. At the end, if there still remains some datagrams in the writeQueue, the write event is resumed. Otherwise, the writeLoop is next triggered when new datagrams are added to the writeQueue.

When the readLoop is triggered, it polls the read queue and attempts to match each received packet with a QuicConnection. If no connection matches, it attempts to match the packet with stateless reset tokens. If no stateless reset token match, the packet is discarded.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
QuicEndpoint.ChannelType

An enum identifying the type of channels used and supported by QuicEndpoint and QuicSelector

pack-priv abstract class
QuicEndpoint.ClosedConnection

Represent a closing or draining quic connection: if we receive any packet for this connection we ignore them (if in draining state) or replay the closed packets in decreasing frequency: we reply to the first packet, then to the third, then to the seventh, etc...

pack-priv class
QuicEndpoint.ClosingConnection

Represent a closing quic connection: if we receive any packet for this connection we simply replay the packet(s) that contained the ConnectionCloseFrame frame.

public static interface
QuicEndpoint.Datagram

This interface represent a UDP Datagram.

pack-priv class
QuicEndpoint.DrainingConnection

Represent a draining quic connection: if we receive any packet for this connection we simply ignore them.

public static record
QuicEndpoint.QuicDatagram

An outgoing datagram, or an incoming datagram for which a connection was identified.

public static class
pack-priv static class
QuicEndpoint.QuicSelectableEndpoint

A QuicEndpoint implementation based on non blocking Datagram Channels and using a NIO Selector.

pack-priv static class
QuicEndpoint.QuicVirtualThreadedEndpoint

A QuicEndpoint implementation based on blocking Datagram Channels and using a Virtual Threads to poll the channel.

public static record
QuicEndpoint.SendStatelessReset

A stateless reset that should be sent in response to an incoming datagram targeted at a deleted connection.

public static record
QuicEndpoint.StatelessReset

An incoming datagram containing a stateless reset

private static record
public static record
QuicEndpoint.UnmatchedDatagram

An incoming UDP Datagram for which no connection was found.

Field Summary

Modifier and TypeField and Description
private final AtomicInteger
private final DatagramChannel
private volatile boolean
public static final QuicEndpoint.ChannelType
CONFIGURED_CHANNEL_TYPE

The configured channel type

private final ConcurrentMap<QuicConnectionId, QuicPacketReceiver>
pack-priv final Logger
pack-priv static final boolean
pack-priv final Executor
pack-priv volatile boolean
private final QuicConnectionIdFactory
private static final int
pack-priv static final int
pack-priv static final int
private final String
private final ConcurrentMap<QuicEndpoint.StatelessResetToken, QuicPacketReceiver>
private final QuicInstance
pack-priv volatile boolean
pack-priv final SequentialScheduler
pack-priv final ConcurrentLinkedQueue<QuicEndpoint.Datagram>
private final ByteBuffer
pack-priv final QuicTimerQueue
private final Key
private static final boolean
pack-priv static final Utils.UseVTForSelector
pack-priv final SequentialScheduler
pack-priv final ConcurrentLinkedQueue<QuicEndpoint.QuicDatagram>

Constructor Summary

AccessConstructor and Description
private
QuicEndpoint(QuicInstance quicInstance, DatagramChannel channel, String name, QuicTimerQueue timerQueue)

Method Summary

Modifier and TypeMethod and Description
public void
pack-priv void
public boolean

Returns:

true if connection ID was added, false otherwise
addConnectionId
(QuicConnectionId
the connection ID to be added
cid
,
QuicPacketReceiver
the connection that should be mapped to the cid
connection
)

Add the cid to connection mapping to the endpoint.

private static Stream<QuicConnectionId>
private static ByteBuffer
pack-priv void
associateStatelessResetToken(final byte[]
the peer issued (16 byte) stateless reset token
statelessResetToken
,
final QuicPacketReceiver
the connection to link the token against
connection
)

A peer issues a stateless reset token which it can then send to close the connection.

public int
buffer(int bytes)

public int
pack-priv boolean
public DatagramChannel
pack-priv void
protected abstract QuicEndpoint.ChannelType
protected QuicPacketReceiver

Returns:

connection associated with the stateless token, or null
checkStatelessReset
(SocketAddress
the sender's address
source
,
final ByteBuffer
datagram contents
buffer
)

checks if the received datagram contains a stateless reset token; returns the associated connection if true, null otherwise

public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

pack-priv void
protected void
closing(QuicConnectionImpl connection, ByteBuffer datagram)

public final int
private ByteBuffer
private static <
the concrete endpoint type, one of QuicSelectableEndpoint or QuicVirtualThreadedEndpoint
T extends QuicEndpoint
>
T

Returns:

a new QuicEndpoint of the given endpointType
create
(Class<T> endpointType, QuicInstance
the quic instance
quicInstance
,
String
the endpoint name
name
,
SocketAddress
the address to bind to
bindAddress
,
QuicTimerQueue
the timer queue
timerQueue
)

Returns a new QuicEndpoint of the given endpointType.

public abstract void
detach()

Detach the channel from the selector implementation

private void
public void
draining(final QuicConnectionImpl connection)

private void
pack-priv QuicPacketReceiver
findQuicConnectionFor(SocketAddress peerAddress, ByteBuffer idbytes, boolean longHeaders)

pack-priv boolean
pack-priv void
forgetStatelessResetToken(final byte[]
The stateless reset token
statelessResetToken
)

Discard the stateless reset token that this endpoint might have previously associated any connection with

public SocketAddress
public String
pack-priv int
public QuicConnectionIdFactory
public boolean
private boolean
pack-priv boolean
private boolean
private QuicEndpoint.StatelessResetToken
makeToken(byte[] tokenBytes)

private QuicEndpoint.Datagram

Returns:

a Datagram to be processed by the read loop if a match is found, or null if the datagram can be dropped immediately
matchDatagram
(SocketAddress
the source address
source
,
ByteBuffer
the incoming datagram payload
buffer
)

This method tries to figure out whether the received packet matches a connection, or a stateless reset.

public String
name()

private void
pack-priv void
pack-priv abstract void
private ByteBuffer
public void
pushClosedDatagram(QuicConnectionImpl
the connection being closed
connection
,
InetSocketAddress
the peer address
destination
,
ByteBuffer
the datagram
datagram
)

Called to schedule sending of a datagram that contains a single ConnectionCloseFrame sent in response to a ConnectionClose frame.

public void
pushClosingDatagram(QuicConnectionImpl
the connection being closed
connection
,
InetSocketAddress
the peer address
destination
,
ByteBuffer
the datagram
datagram
)

Called to schedule sending of a datagram that contains a ConnectionCloseFrame.

public void
pushDatagram(QuicPacketReceiver
the source connection
source
,
SocketAddress
the destination address
destination
,
ByteBuffer
the encrypted datagram
payload
)

Schedule a datagram for writing to the underlying channel.

private void
pack-priv boolean
pack-priv void
public void
public static void
registerWithSelector(QuicEndpoint
the endpoint
endpoint
,
QuicSelector<?>
the selector
selector
,
Logger
a logger for debugging
debug
)

Registers the given endpoint with the given selector.

private QuicEndpoint.ClosedConnection
private QuicEndpoint.DrainingConnection
private void
pack-priv void
removeConnection(final QuicPacketReceiver
the connection to be removed
connection
)

This will completely remove the connection from the endpoint.

public boolean

Returns:

true if connection ID was removed, false otherwise
removeConnectionId
(QuicConnectionId
the connection ID to be removed
cid
,
QuicPacketReceiver
the connection that is mapped to the cid
connection
)

Remove the cid to connection mapping from the endpoint.

pack-priv abstract void
private int
send(ByteBuffer datagram, SocketAddress destination)

private void
pack-priv boolean
private void
public QuicTimerQueue

Returns:

the timer queue associated with this endpoint
timer
()

Returns the timer queue associated with this endpoint.

protected TimeLine

Returns:

the time source associated with this endpoint
timeSource
()

Returns the time source associated with this endpoint.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public int
unbuffer(int bytes)

protected void
unmatchedQuicPacket(QuicEndpoint.Datagram
The datagram containing the packet
datagram
,
QuicPacket.HeadersType
The quic packet type
headersType
,
ByteBuffer
A buffer positioned at the start of the unmatched quic packet. The buffer may contain more coalesced quic packets.
buffer
)

Called when parsing a quic packet that couldn't be matched to any registered connection.

pack-priv void
private void
pack-priv Executor
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait