Class LocalCidState

java.lang.Object
io.github.mahmoudimus.quic.connection.LocalCidState

public final class LocalCidState extends Object
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.

  • Field Details

    • LOC_CID_COUNT

      public static final long LOC_CID_COUNT
      The 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 which handshakeCids were used: the first with sequence number 0, then for example a server's preferred address with 1.
      Parameters:
      generator - generates new IDs
      resetKey - the static key reset tokens are derived from (see StatelessResetToken.derive(byte[], io.github.mahmoudimus.quic.ConnectionId)), at least 32 random bytes
      now - the current time
      handshakeCids - 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's active_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's active_connection_id_limit
      Returns:
      min(limit, 8)
    • issue

      public List<IssuedCid> issue(long now, long count)
      Issues new IDs, to send in NEW_CONNECTION_ID frames with retirePriorTo().
      Parameters:
      now - the current time
      count - how many
      Returns:
      the IDs, with sequence numbers and reset tokens
    • resetToken

      public StatelessResetToken resetToken(ConnectionId cid)
      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 number
      packetDestinationId - the Destination Connection ID of the packet that carried the frame
      peerActiveConnectionIdLimit - the peer's active_connection_id_limit
      Returns:
      the retired ID and whether to issue a replacement
      Throws:
      QuicException - PROTOCOL_VIOLATION when 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 of Timer.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

      public Map<Long,ConnectionId> 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