impl: QUIC Header mimicry

This commit is contained in:
Gaukas Wang 2023-07-29 13:17:27 -06:00
parent 1429e6718b
commit 251b3afe6e
No known key found for this signature in database
GPG key ID: 9E2F8986D76F8B5D
11 changed files with 262 additions and 30 deletions

View file

@ -96,6 +96,8 @@ type sentPacketHandler struct {
tracer logging.ConnectionTracer
logger utils.Logger
initialPacketNumberLength protocol.PacketNumberLen // [UQUIC]
}
var (
@ -136,6 +138,12 @@ func newSentPacketHandler(
}
}
func SetInitialPacketNumberLength(h SentPacketHandler, pnLen protocol.PacketNumberLen) {
if sph, ok := h.(*sentPacketHandler); ok {
sph.initialPacketNumberLength = pnLen
}
}
func (h *sentPacketHandler) removeFromBytesInFlight(p *packet) {
if p.includedInBytesInFlight {
if p.Length > h.bytesInFlight {
@ -716,6 +724,12 @@ func (h *sentPacketHandler) PeekPacketNumber(encLevel protocol.EncryptionLevel)
pnSpace := h.getPacketNumberSpace(encLevel)
pn := pnSpace.pns.Peek()
// See section 17.1 of RFC 9000.
// [UQUIC] This kinda breaks PN length mimicry.
if encLevel == protocol.EncryptionInitial && h.initialPacketNumberLength != 0 {
return pn, h.initialPacketNumberLength
}
return pn, protocol.GetPacketNumberLengthForHeader(pn, pnSpace.largestAcked)
}