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

public Class QuicConnectionIdFactory

extends Object
Class Inheritance
Imports
javax.crypto.KeyGenerator, .Mac, java.nio.ByteBuffer, java.security.InvalidKeyException, .Key, .NoSuchAlgorithmException, .SecureRandom, java.util.Arrays, .Random, java.util.concurrent.atomic.AtomicLong

A class to generate connection ids bytes. This algorithm is specific to our implementation - it's not defined in any RFC (connection id bytes are free form). For the purpose of validation we encode the length of the connection id into the connection id bytes. For the purpose of uniqueness we encode a unique id. The rest of the connection id are random bytes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private final int
private static final int
private static final Random
private final byte[]
private static final String
private final String
private final Key
private final AtomicLong
private volatile boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the connection ID length used by this instance
connectionIdLength
()

The connection ID length used by this Quic instance.

private int
private int
public static QuicConnectionIdFactory
public int
getConnectionIdLength(byte[] bytes)

public long
getConnectionIdToken(byte[] bytes)

public static QuicConnectionIdFactory
private boolean
isValidToken(long token)

public QuicConnectionId

Returns:

a new connection ID
newConnectionId
()

Creates a new connection ID for a connection.

public byte[]
newConnectionId(int length, long token)

public long
private long
public ByteBuffer

Returns:

stateless reset datagram payload, or null
statelessReset
(ByteBuffer
the destination connection id that was received on the packet
connId
,
int
maximum length of the stateless reset packet
length
)

Checks if connId looks like a connection ID we could possibly generate.

public byte[]

Returns:

stateless reset token for the given connection ID
statelessTokenFor
(QuicConnectionId
connection ID
connectionId
)

Returns a stateless reset token for the given connection ID

public QuicConnectionId

Returns:

a new QuicConnectionId if the buffer can contain a connection id generated by this instance, null otherwise.
unsafeConnectionIdFor
(ByteBuffer
A buffer that delimits a connection id.
buffer
)

Quick validation to see if the buffer can contain a connection id generated by this instance.

private static int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENT_DESCback to summary
private static final String CLIENT_DESC
connectionIdLengthback to summary
private final int connectionIdLength
MIN_CONNECTION_ID_LENGTHback to summary
private static final int MIN_CONNECTION_ID_LENGTH
RANDOMback to summary
private static final Random RANDOM
scramblerback to summary
private final byte[] scrambler
SERVER_DESCback to summary
private static final String SERVER_DESC
simpleDescback to summary
private final String simpleDesc
statelessTokenKeyback to summary
private final Key statelessTokenKey
tokensback to summary
private final AtomicLong tokens
wrappedback to summary
private volatile boolean wrapped

Constructor Detail

QuicConnectionIdFactoryback to summary
private QuicConnectionIdFactory(String simpleDesc)

Method Detail

connectionIdLengthback to summary
public int connectionIdLength()

The connection ID length used by this Quic instance. This is the source connection id length for outgoing packets, and the destination connection id length for incoming packets.

Returns:int

the connection ID length used by this instance

extractConnectionIdLengthback to summary
private int extractConnectionIdLength(byte b)
extractTokenLengthback to summary
private int extractTokenLength(byte b)
getClientback to summary
public static QuicConnectionIdFactory getClient()
getConnectionIdLengthback to summary
public int getConnectionIdLength(byte[] bytes)
getConnectionIdTokenback to summary
public long getConnectionIdToken(byte[] bytes)
getServerback to summary
public static QuicConnectionIdFactory getServer()
isValidTokenback to summary
private boolean isValidToken(long token)
newConnectionIdback to summary
public QuicConnectionId newConnectionId()

Creates a new connection ID for a connection.

Returns:QuicConnectionId

a new connection ID

newConnectionIdback to summary
public byte[] newConnectionId(int length, long token)
newTokenback to summary
public long newToken()
peekConnectionIdTokenback to summary
private long peekConnectionIdToken(ByteBuffer bytes)
statelessResetback to summary
public ByteBuffer statelessReset(ByteBuffer connId, int length)

Checks if connId looks like a connection ID we could possibly generate. If it does, returns a stateless reset datagram.

Parameters
connId:ByteBuffer

the destination connection id that was received on the packet

length:int

maximum length of the stateless reset packet

Returns:ByteBuffer

stateless reset datagram payload, or null

statelessTokenForback to summary
public byte[] statelessTokenFor(QuicConnectionId connectionId)

Returns a stateless reset token for the given connection ID

Parameters
connectionId:QuicConnectionId

connection ID

Returns:byte[]

stateless reset token for the given connection ID

Exceptions
IllegalArgumentException:
if the connection ID was not generated by this factory
unsafeConnectionIdForback to summary
public QuicConnectionId unsafeConnectionIdFor(ByteBuffer buffer)

Quick validation to see if the buffer can contain a connection id generated by this instance. The byte buffer is expected to have its position set at the start of the connection id, and its limit at the end. In other words, Buffer.remaining() should indicate the connection id length.

This method does not advance the buffer position, and returns a connection id that wraps the given buffer. The returned connection id is only safe to use as long as the buffer is not modified.

It is usually only used temporarily as a lookup key to locate an existing QuicConnection.

Parameters
buffer:ByteBuffer

A buffer that delimits a connection id.

Returns:QuicConnectionId

a new QuicConnectionId if the buffer can contain a connection id generated by this instance, null otherwise.

variableLengthLengthback to summary
private static int variableLengthLength(long token)
jdk.internal.net.http.quic back to summary

private final Class QuicConnectionIdFactory.QuicLocalConnectionId

extends QuicConnectionId
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final long
Inherited from jdk.internal.net.http.quic.QuicConnectionId:
bufhashCodeMAX_CONNECTION_ID_LENGTH

Constructor Summary

AccessConstructor and Description
private
QuicLocalConnectionId(long token, String simpleDesc, byte[] bytes)

private
QuicLocalConnectionId(ByteBuffer buffer, long token, String simpleDesc)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from jdk.internal.net.http.quic.QuicConnectionId:
asReadOnlyBuffercompareBytescompareToequalsgetByteshashCodelengthmatchestoHexString

Field Detail

simpleDescback to summary
private final String simpleDesc
tokenback to summary
private final long token

Constructor Detail

QuicLocalConnectionIdback to summary
private QuicLocalConnectionId(long token, String simpleDesc, byte[] bytes)
QuicLocalConnectionIdback to summary
private QuicLocalConnectionId(ByteBuffer buffer, long token, String simpleDesc)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override