Class PacketNumberFilter

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

public final class PacketNumberFilter extends Object
Mitigates optimistic ACK attacks (RFC 9000 section 21.4) by occasionally skipping a packet number in the application data space: an ACK of a skipped number proves the peer acknowledges packets it never received. Skips get exponentially rarer, since a peer that behaved for long is less likely to start misbehaving.

Threads. Not thread-safe; owned by one connection.

  • Constructor Details

    • PacketNumberFilter

      public PacketNumberFilter(RandomGenerator random)
      A filter whose first skip is somewhere in packet numbers 0 to 63.
      Parameters:
      random - the source of randomness
  • Method Details

    • disabled

      public static PacketNumberFilter disabled()
      A filter that never skips, for tests.
      Returns:
      the filter
    • peek

      public long peek(PacketSpace space)
      Parameters:
      space - the application data space
      Returns:
      the packet number
    • allocate

      public long allocate(RandomGenerator random, PacketSpace space)
      Allocates the next packet number, skipping it if it is the chosen one.
      Parameters:
      random - the source of randomness
      space - the application data space
      Returns:
      the packet number to send
    • checkAck

      public void checkAck(SpaceId space, long smallest, long largest) throws QuicException
      Rejects an ACK of the skipped packet number.
      Parameters:
      space - the space the ACK arrived in
      smallest - the smallest packet number of an acknowledged range
      largest - the largest packet number of the range
      Throws:
      QuicException - PROTOCOL_VIOLATION if the range covers a skipped packet number