Class MtuDiscovery
java.lang.Object
io.github.mahmoudimus.quic.connection.MtuDiscovery
Datagram packetization layer path MTU discovery (DPLPMTUD, RFC 8899): probes larger packets in
the application data space by binary search, and detects MTU black holes from the pattern of
lost packets. Times are nanoseconds.
Probes are padded PING packets of the size pollTransmit(long, long) returns; an acknowledged
probe raises the MTU, and a probe lost three times lowers the next size tried. Lost probes do not
count as congestion.
Threads. Not thread-safe; owned by one connection.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanblackHoleDetected(long now) Ends the current loss burst and checks for a black hole.copy()A copy with the same MTU, search and black hole state, for a new path that is presumably the same network (a NAT rebinding), as quinn clones it.intThe current MTU.static MtuDiscoverydisabled(int mtu, int minMtu) Disabled discovery: the MTU stays fixed, except that a black hole still lowers it to the minimum.static MtuDiscoveryenabled(int initialMtu, int minMtu, int peerMaxUdpPayloadSize, MtuDiscoveryConfig config) Enabled discovery.longThe packet number of the probe in flight.booleanRecords an acknowledged packet.voidonNonProbeLost(long pn, int length) Records a lost packet that was not a probe.voidonPeerMaxUdpPayloadSizeReceived(int peerMaxUdpPayloadSize) Applies the peer'smax_udp_payload_size, which caps the MTU and the search.voidRecords that the in-flight probe was lost.intpollTransmit(long now, long nextPacketNumber) The size of the next probe to send, if one is due.
-
Method Details
-
enabled
public static MtuDiscovery enabled(int initialMtu, int minMtu, int peerMaxUdpPayloadSize, MtuDiscoveryConfig config) Enabled discovery.- Parameters:
initialMtu- the MTU to start from, at leastminMtuminMtu- the MTU the path is assumed to support, 1200 for QUICpeerMaxUdpPayloadSize- the peer'smax_udp_payload_sizeif already known (after a migration), or -1config- the configuration- Returns:
- the discovery state
-
disabled
Disabled discovery: the MTU stays fixed, except that a black hole still lowers it to the minimum.- Parameters:
mtu- the fixed MTUminMtu- the minimum MTU- Returns:
- the discovery state
-
copy
A copy with the same MTU, search and black hole state, for a new path that is presumably the same network (a NAT rebinding), as quinn clones it.- Returns:
- the copy
-
currentMtu
public int currentMtu()The current MTU.- Returns:
- the largest UDP payload to send
-
pollTransmit
public int pollTransmit(long now, long nextPacketNumber) The size of the next probe to send, if one is due.- Parameters:
now- the current timenextPacketNumber- the number the probe packet will have- Returns:
- the probe's UDP payload size, or -1 if no probe should be sent now
-
onPeerMaxUdpPayloadSizeReceived
public void onPeerMaxUdpPayloadSizeReceived(int peerMaxUdpPayloadSize) Applies the peer'smax_udp_payload_size, which caps the MTU and the search. It must arrive before probing starts.- Parameters:
peerMaxUdpPayloadSize- the transport parameter
-
onAcked
Records an acknowledged packet.- Parameters:
space- the packet's space; probes are only sent in the application data spacepn- the packet numberlength- the packet's size- Returns:
- true if it was the in-flight probe, which raised the MTU
-
inFlightMtuProbe
public long inFlightMtuProbe()The packet number of the probe in flight.- Returns:
- the packet number, or -1 if none
-
onProbeLost
public void onProbeLost()Records that the in-flight probe was lost. -
onNonProbeLost
public void onNonProbeLost(long pn, int length) Records a lost packet that was not a probe. CallblackHoleDetected(long)once the losses of a batch are recorded.- Parameters:
pn- the packet numberlength- the packet's size
-
blackHoleDetected
public boolean blackHoleDetected(long now) Ends the current loss burst and checks for a black hole. On a black hole the MTU drops to the minimum and discovery pauses for the cooldown.- Parameters:
now- the current time- Returns:
- true if a black hole was detected
-