drop Initial and Handshake keys when receiving the first 1-RTT ACK

This commit is contained in:
Marten Seemann
2019-05-30 02:23:07 +08:00
parent 4834962cbd
commit a4989c3d9c
8 changed files with 111 additions and 35 deletions

View File

@@ -105,17 +105,12 @@ func NewSentPacketHandler(
func (h *sentPacketHandler) DropPackets(encLevel protocol.EncryptionLevel) {
// remove outstanding packets from bytes_in_flight
pnSpace := h.getPacketNumberSpace(encLevel)
var packets []*Packet
pnSpace.history.Iterate(func(p *Packet) (bool, error) {
packets = append(packets, p)
if p.includedInBytesInFlight {
h.bytesInFlight -= p.Length
}
return true, nil
})
for _, p := range packets {
pnSpace.history.Remove(p.PacketNumber)
}
// remove packets from the retransmission queue
var queue []*Packet
for _, packet := range h.retransmissionQueue {
@@ -124,6 +119,15 @@ func (h *sentPacketHandler) DropPackets(encLevel protocol.EncryptionLevel) {
}
}
h.retransmissionQueue = queue
// drop the packet history
switch encLevel {
case protocol.EncryptionInitial:
h.initialPackets = nil
case protocol.EncryptionHandshake:
h.handshakePackets = nil
default:
panic(fmt.Sprintf("Cannot drop keys for encryption level %s", encLevel))
}
}
func (h *sentPacketHandler) SetMaxAckDelay(mad time.Duration) {
@@ -312,7 +316,14 @@ func (h *sentPacketHandler) determineNewlyAckedPackets(
}
func (h *sentPacketHandler) hasOutstandingCryptoPackets() bool {
return h.initialPackets.history.HasOutstandingPackets() || h.handshakePackets.history.HasOutstandingPackets()
var hasInitial, hasHandshake bool
if h.initialPackets != nil {
hasInitial = h.initialPackets.history.HasOutstandingPackets()
}
if h.handshakePackets != nil {
hasHandshake = h.handshakePackets.history.HasOutstandingPackets()
}
return hasInitial || hasHandshake
}
func (h *sentPacketHandler) hasOutstandingPackets() bool {
@@ -536,8 +547,13 @@ func (h *sentPacketHandler) PopPacketNumber(encLevel protocol.EncryptionLevel) p
}
func (h *sentPacketHandler) SendMode() SendMode {
numTrackedPackets := len(h.retransmissionQueue) + h.initialPackets.history.Len() +
h.handshakePackets.history.Len() + h.oneRTTPackets.history.Len()
numTrackedPackets := len(h.retransmissionQueue) + h.oneRTTPackets.history.Len()
if h.initialPackets != nil {
numTrackedPackets += h.initialPackets.history.Len()
}
if h.handshakePackets != nil {
numTrackedPackets += h.handshakePackets.history.Len()
}
// Don't send any packets if we're keeping track of the maximum number of packets.
// Note that since MaxOutstandingSentPackets is smaller than MaxTrackedSentPackets,

View File

@@ -861,7 +861,7 @@ var _ = Describe("SentPacketHandler", func() {
handler.queuePacketForRetransmission(lostPacket, handler.getPacketNumberSpace(protocol.EncryptionHandshake))
handler.DropPackets(protocol.EncryptionInitial)
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(10)))
Expect(handler.initialPackets.history.Len()).To(BeZero())
Expect(handler.initialPackets).To(BeNil())
Expect(handler.handshakePackets.history.Len()).ToNot(BeZero())
packet := handler.DequeuePacketForRetransmission()
Expect(packet).To(Equal(lostPacket))
@@ -882,7 +882,7 @@ var _ = Describe("SentPacketHandler", func() {
handler.queuePacketForRetransmission(lostPacket, handler.getPacketNumberSpace(protocol.EncryptionHandshake))
handler.DropPackets(protocol.EncryptionHandshake)
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(10)))
Expect(handler.handshakePackets.history.Len()).To(BeZero())
Expect(handler.handshakePackets).To(BeNil())
packet := handler.DequeuePacketForRetransmission()
Expect(packet).To(Equal(lostPacket))
})