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

public Class QuicPacketEncoder

extends Object
Class Inheritance
Imports
java.nio.BufferOverflowException, .ByteBuffer, .ByteOrder, java.util.ArrayList, .Arrays, .List, .Random, java.util.function.IntFunction, jdk.internal.net.http.common.Logger, .Utils, jdk.internal.net.quic.QuicKeyUnavailableException, .QuicTransportErrors, .QuicTransportException, .QuicVersion, .QuicTLSEngine, .QuicTLSEngine.KeySpace, jdk.internal.net.http.quic.frames.PaddingFrame, .QuicFrame, jdk.internal.net.http.quic.CodingContext, .QuicConnectionId, .VariableLengthEncoder, jdk.internal.net.http.quic.packets.QuicPacket.PacketNumberSpace, .QuicPacket.PacketType, javax.crypto.ShortBufferException

A QuicPacketEncoder encapsulates the logic to encode a quic packet. A QuicPacketEncoder is typically tied to a particular version of the QUIC protocol.
External Specification
https://www.rfc-editor.org/info/rfc9000, https://www.rfc-editor.org/info/rfc9001, https://www.rfc-editor.org/info/rfc9369

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private abstract static class
private static class
public abstract static class
private static class
private abstract static class
private static class
private static class
pack-priv static class
QuicPacketEncoder.PacketWriter

A PacketWriter to write a Quic packet.

Field Summary

Modifier and TypeField and Description
private static final Logger
private final QuicVersion

Constructor Summary

AccessConstructor and Description
private
QuicPacketEncoder(final QuicVersion quicVersion)

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the maximum size of the payload that can be fit into this initial packet
computeMaxHandshakePayloadSize
(CodingContext
the coding context, used to compute the encoded packet number
codingContext
,
long
the full packet number
packetNumber
,
int
the length of the source connection id
scidLength
,
int
the length of the destination connection id
dstidLength
,
int
the desired total maximum size of the packet after encryption
maxDatagramSize
)

Compute the max size of the usable payload of a handshake packet, given the max size of the datagram.

public static int

Returns:

the maximum size of the payload that can be fit into this initial packet
computeMaxInitialPayloadSize
(CodingContext
the coding context, used to compute the encoded packet number
codingContext
,
int
packet number length
pnsize
,
int
the length of the token (or 0)
tokenLength
,
int
the length of the source connection id
scidLength
,
int
the length of the destination connection id
dstidLength
,
int
the desired total maximum size of the packet after encryption
maxDatagramSize
)

Compute the max size of the usable payload of an initial packet, given the max size of the datagram.

public static int

Returns:

the maximum payload that can be carried on in a OneRttPacket given the max datagram size before encryption
computeMaxOneRTTPayloadSize
(final CodingContext
the coding context
codingContext
,
final long
the packet number
packetNumber
,
final int
the peer connection id length
dstidLength
,
final int
the maximum size of the datagram
maxDatagramSizeBeforeEncryption
,
final long largestPeerAckedPN)

Computes the maximum usable payload that can be carried on in a OneRttPacket given the max datagram size before encryption.

public void
encode(QuicPacket
the packet to encode
packet
,
ByteBuffer
the byte buffer to write the packet into
buffer
,
CodingContext
context for encoding
context
)

Encodes the given QuicPacket.

private void
encodePacket(QuicPacketEncoder.OutgoingOneRttPacket packet, ByteBuffer
A buffer to encode the packet into
buffer
,
CodingContext context)

Encode the OneRttPacket into the provided buffer.

private void
encodePacket(QuicPacketEncoder.OutgoingZeroRttPacket packet, ByteBuffer
A buffer to encode the packet into.
buffer
,
CodingContext context)

Encode the ZeroRttPacket into the provided buffer.

private static void
encodePacket(QuicPacketEncoder.OutgoingVersionNegotiationPacket packet, ByteBuffer
A buffer to encode the packet into.
buffer
)

Encode the VersionNegotiationPacket into the provided buffer.

private void
encodePacket(QuicPacketEncoder.OutgoingHandshakePacket packet, ByteBuffer
A buffer to encode the packet into.
buffer
,
CodingContext context)

Encode the HandshakePacket into the provided buffer.

private void
encodePacket(QuicPacketEncoder.OutgoingInitialPacket packet, ByteBuffer
A buffer to encode the packet into.
buffer
,
CodingContext
coding context
context
)

Encode the InitialPacket into the provided buffer.

private void
encodePacket(QuicPacketEncoder.OutgoingRetryPacket packet, ByteBuffer
A buffer to encode the packet into.
buffer
,
CodingContext context)

Encode the RetryPacket into the provided buffer.

private static byte

Returns:

the packet's header byte
headers
(byte
quic-dependent packet type encoding
packetTypeTag
,
int
the number of bytes needed to encode the packet number
pnsize
)

Computes the packet's header byte, which also encodes the packetNumber length.

public QuicPacketEncoder.OutgoingQuicPacket

Returns:

the new handshake packet
newHandshakePacket
(QuicConnectionId
The source connection ID
source
,
QuicConnectionId
The destination connection ID
destination
,
long
The packet number
packetNumber
,
long largestAckedPN, List<QuicFrame>
The handshake packet payload
frames
,
CodingContext codingContext)

Create a new unencrypted HandshakePacket to be transmitted over the wire after encryption.

public QuicPacketEncoder.OutgoingQuicPacket

Returns:

the new initial packet
newInitialPacket
(QuicConnectionId
The source connection ID
source
,
QuicConnectionId
The destination connection ID
destination
,
byte[]
The token field (may be null if no token)
token
,
long
The packet number
packetNumber
,
long
The largest acknowledged packet number
ackedPacketNumber
,
List<QuicFrame>
The initial packet payload
frames
,
CodingContext codingContext)

Create a new unencrypted InitialPacket to be transmitted over the wire after encryption.

public OneRttPacket

Returns:

the new one RTT packet
newOneRttPacket
(QuicConnectionId
The destination connection ID
destination
,
long
The packet number
packetNumber
,
long
The largest acknowledged packet number
ackedPacketNumber
,
List<? extends QuicFrame>
The one RTT packet payload
frames
,
CodingContext codingContext)

Create a new unencrypted OneRttPacket to be transmitted over the wire after encryption.

public QuicPacketEncoder.OutgoingQuicPacket

Returns:

a packet in the given key space
newOutgoingPacket
(QuicTLSEngine.KeySpace
the sending key space
keySpace
,
PacketSpace
the packet space
packetSpace
,
QuicConnectionId
the source connection id
sourceId
,
QuicConnectionId
the destination connection id
destinationId
,
byte[]
the initial token for INITIAL packets
initialToken
,
List<QuicFrame>
the list of frames
frames
,
CodingContext
the coding context
codingContext
)

Creates a packet in the given keyspace for the purpose of sending a CONNECTION_CLOSE, or a generic list of frames.

public QuicPacketEncoder.OutgoingQuicPacket

Returns:

the new retry packet
newRetryPacket
(QuicConnectionId
The source connection ID
source
,
QuicConnectionId
The destination connection ID
destination
,
byte[]
The retry token
retryToken
)

Create a new unencrypted RetryPacket to be transmitted over the wire after encryption.

public static QuicPacketEncoder.OutgoingQuicPacket

Returns:

the new initial packet
newVersionNegotiationPacket
(QuicConnectionId
The source connection ID
source
,
QuicConnectionId
The destination connection ID
destination
,
int[]
The supported quic versions
versions
)

Create a new unencrypted VersionNegotiationPacket to be transmitted over the wire after encryption.

public QuicPacketEncoder.OutgoingQuicPacket

Returns:

the new zero RTT packet
newZeroRttPacket
(QuicConnectionId
The source connection ID
source
,
QuicConnectionId
The destination connection ID
destination
,
long
The packet number
packetNumber
,
long
The largest acknowledged packet number
ackedPacketNumber
,
List<? extends QuicFrame>
The zero RTT packet payload
frames
,
CodingContext codingContext)

Create a new unencrypted ZeroRttPacket to be transmitted over the wire after encryption.

public static QuicPacketEncoder

Returns:

an encoder for the given Quic version or null
of
(final QuicVersion
the Quic protocol version number
quicVersion
)

Returns an encoder for the given Quic version.

private byte

Returns:

the headers tag for the given packet type.
packetHeadersTag
(QuicPacket.PacketType
the packet type
packetType
)

Returns the headers tag for the given packet type.

private static List<? extends QuicFrame>

Returns:

list of frames that meets the minimum length requirement
padFrames
(List<? extends QuicFrame>
requested list of frames
frames
,
int
requested minimum length
minLength
)

Adds required padding frames if necessary.

private static ByteBuffer
putInt32(ByteBuffer buffer, int value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait