Class RandomConnectionIdGenerator
java.lang.Object
io.github.mahmoudimus.quic.connection.RandomConnectionIdGenerator
- All Implemented Interfaces:
ConnectionIdGenerator
Generates random connection IDs of a fixed length, 8 bytes by default.
Threads. Safe to share if the Random is (a SecureRandom is).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionA generator of 8-byte IDs from a newSecureRandom, which never expire.RandomConnectionIdGenerator(int length, long lifetime, Random random) A generator. -
Method Summary
Modifier and TypeMethodDescriptionintThe length of the IDs, which the endpoint needs to parse short headers.longHow long an ID lives before it is retired and replaced.A new connection ID.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.mahmoudimus.quic.connection.ConnectionIdGenerator
validate
-
Field Details
-
DEFAULT_LENGTH
public static final int DEFAULT_LENGTHThe default ID length, 8 bytes.- See Also:
-
-
Constructor Details
-
RandomConnectionIdGenerator
public RandomConnectionIdGenerator()A generator of 8-byte IDs from a newSecureRandom, which never expire. -
RandomConnectionIdGenerator
A generator.- Parameters:
length- the ID length, 0 to 20lifetime- how long IDs live in nanoseconds, or -1 for foreverrandom- the source of randomness; aSecureRandomoutside tests- Throws:
IllegalArgumentException- if the length is out of range
-
-
Method Details
-
generateCid
Description copied from interface:ConnectionIdGeneratorA new connection ID.- Specified by:
generateCidin interfaceConnectionIdGenerator- Returns:
- an ID of
ConnectionIdGenerator.cidLength()bytes
-
cidLength
public int cidLength()Description copied from interface:ConnectionIdGeneratorThe length of the IDs, which the endpoint needs to parse short headers.- Specified by:
cidLengthin interfaceConnectionIdGenerator- Returns:
- 0 to 20 bytes
-
cidLifetime
public long cidLifetime()Description copied from interface:ConnectionIdGeneratorHow long an ID lives before it is retired and replaced.- Specified by:
cidLifetimein interfaceConnectionIdGenerator- Returns:
- nanoseconds, or -1 for forever
-