Class LocalCidState
java.lang.Object
io.github.mahmoudimus.quic.connection.LocalCidState
The connection IDs this endpoint issued to its peer (RFC 9000 section 5.1.1): sequence numbers,
stateless reset tokens derived from a static key, retirement by the peer, and periodic rotation
through
retire_prior_to when IDs have a lifetime.
No more than min(peer's active_connection_id_limit, 8) IDs are active at once.
Threads. Not thread-safe; owned by one connection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe outcome of a RETIRE_CONNECTION_ID. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe most connection IDs issued to a peer at once, as in quinn. -
Constructor Summary
ConstructorsConstructorDescriptionLocalCidState(ConnectionIdGenerator generator, byte[] resetKey, long now, ConnectionId... handshakeCids) The state after the handshake, during whichhandshakeCidswere used: the first with sequence number 0, then for example a server's preferred address with 1. -
Method Summary
Modifier and TypeMethodDescriptionThe IDs issued and not retired, by sequence number.intThe length of the IDs, to parse short headers.longinitialIssueCount(long peerActiveConnectionIdLimit) How many IDs to issue after the handshake: the peer's limit (at most 8L) less those already in use.issue(long now, long count) Issues new IDs, to send in NEW_CONNECTION_ID frames withretirePriorTo().longThe number of IDs issued so far.static longissueLimit(long peerActiveConnectionIdLimit) The most IDs to keep active for a peer.longWhen the next batch of IDs reaches the end of its lifetime.booleanHandles the expiry ofTimer.PUSH_NEW_CID: advances Retire Prior To past the expired batch, unless the peer has not yet retired the IDs the previous value asked for (RFC 9000 section 5.1.2).onRetireConnectionId(long sequence, ConnectionId packetDestinationId, long peerActiveConnectionIdLimit) Processes a RETIRE_CONNECTION_ID frame.resetToken(ConnectionId cid) The reset token of one of our IDs.longThe Retire Prior To value for NEW_CONNECTION_ID frames.
-
Field Details
-
LOC_CID_COUNT
public static final long LOC_CID_COUNTThe most connection IDs issued to a peer at once, as in quinn.- See Also:
-
-
Constructor Details
-
LocalCidState
public LocalCidState(ConnectionIdGenerator generator, byte[] resetKey, long now, ConnectionId... handshakeCids) The state after the handshake, during whichhandshakeCidswere used: the first with sequence number 0, then for example a server's preferred address with 1.- Parameters:
generator- generates new IDsresetKey- the static key reset tokens are derived from (seeStatelessResetToken.derive(byte[], io.github.mahmoudimus.quic.ConnectionId)), at least 32 random bytesnow- the current timehandshakeCids- the IDs already in use, in sequence order
-
-
Method Details
-
initialIssueCount
public long initialIssueCount(long peerActiveConnectionIdLimit) How many IDs to issue after the handshake: the peer's limit (at most 8L) less those already in use.- Parameters:
peerActiveConnectionIdLimit- the peer'sactive_connection_id_limit- Returns:
- the count, zero for zero-length IDs
-
issueLimit
public static long issueLimit(long peerActiveConnectionIdLimit) The most IDs to keep active for a peer.- Parameters:
peerActiveConnectionIdLimit- the peer'sactive_connection_id_limit- Returns:
min(limit, 8)
-
issue
Issues new IDs, to send in NEW_CONNECTION_ID frames withretirePriorTo().- Parameters:
now- the current timecount- how many- Returns:
- the IDs, with sequence numbers and reset tokens
-
resetToken
The reset token of one of our IDs.- Parameters:
cid- the ID- Returns:
- the token, HMAC-derived from the static key
-
onRetireConnectionId
public LocalCidState.Retirement onRetireConnectionId(long sequence, ConnectionId packetDestinationId, long peerActiveConnectionIdLimit) throws QuicException Processes a RETIRE_CONNECTION_ID frame.- Parameters:
sequence- the retired sequence numberpacketDestinationId- the Destination Connection ID of the packet that carried the framepeerActiveConnectionIdLimit- the peer'sactive_connection_id_limit- Returns:
- the retired ID and whether to issue a replacement
- Throws:
QuicException-PROTOCOL_VIOLATIONwhen IDs are zero-length, for a sequence number never issued, or for the ID the packet itself was sent to (RFC 9000 section 19.16)
-
nextTimeout
public long nextTimeout()When the next batch of IDs reaches the end of its lifetime.- Returns:
- the time, or
NanoClock.NONE
-
onCidTimeout
public boolean onCidTimeout()Handles the expiry ofTimer.PUSH_NEW_CID: advances Retire Prior To past the expired batch, unless the peer has not yet retired the IDs the previous value asked for (RFC 9000 section 5.1.2).- Returns:
- true if an ID must be issued now to carry the new Retire Prior To
-
retirePriorTo
public long retirePriorTo()The Retire Prior To value for NEW_CONNECTION_ID frames.- Returns:
- the sequence number below which the peer must retire IDs
-
cidLength
public int cidLength()The length of the IDs, to parse short headers.- Returns:
- bytes
-
activeCids
The IDs issued and not retired, by sequence number.- Returns:
- an unmodifiable view
-
issuedCount
public long issuedCount()The number of IDs issued so far.- Returns:
- the count
-