forked from quic-go/quic-go
fix dropping of the Initial packet number space for clients
This commit is contained in:
@@ -116,6 +116,16 @@ func newSentPacketHandler(
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) DropPackets(encLevel protocol.EncryptionLevel) {
|
||||
if h.perspective == protocol.PerspectiveClient && encLevel == protocol.EncryptionInitial {
|
||||
// This function is called when the crypto setup seals a Handshake packet.
|
||||
// If this Handshake packet is coalesced behind an Initial packet, we would drop the Initial packet number space
|
||||
// before SentPacket() was called for that Initial packet.
|
||||
return
|
||||
}
|
||||
h.dropPackets(encLevel)
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) dropPackets(encLevel protocol.EncryptionLevel) {
|
||||
// remove outstanding packets from bytes_in_flight
|
||||
if encLevel == protocol.EncryptionInitial || encLevel == protocol.EncryptionHandshake {
|
||||
pnSpace := h.getPacketNumberSpace(encLevel)
|
||||
@@ -153,6 +163,10 @@ func (h *sentPacketHandler) DropPackets(encLevel protocol.EncryptionLevel) {
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) SentPacket(packet *Packet) {
|
||||
// For the client, drop the Initial packet number space when the first Handshake packet is sent.
|
||||
if h.perspective == protocol.PerspectiveClient && packet.EncryptionLevel == protocol.EncryptionHandshake && h.initialPackets != nil {
|
||||
h.dropPackets(protocol.EncryptionInitial)
|
||||
}
|
||||
isAckEliciting := h.sentPacketImpl(packet)
|
||||
if isAckEliciting {
|
||||
h.getPacketNumberSpace(packet.EncryptionLevel).history.SentPacket(packet)
|
||||
|
||||
@@ -767,9 +767,8 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
protocol.EncryptionInitial,
|
||||
time.Now(),
|
||||
)).To(Succeed())
|
||||
handler.DropPackets(protocol.EncryptionInitial) // Initial keys are dropped when a Handshake packet is received.
|
||||
|
||||
handler.SentPacket(handshakePacketNonAckEliciting(&Packet{PacketNumber: 1}))
|
||||
handler.SentPacket(handshakePacketNonAckEliciting(&Packet{PacketNumber: 1})) // also drops Initial packets
|
||||
Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero())
|
||||
Expect(handler.OnLossDetectionTimeout()).To(Succeed())
|
||||
Expect(handler.SendMode()).To(Equal(SendPTOHandshake))
|
||||
@@ -853,7 +852,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
Expect(handler.ReceivedAck(ack, protocol.EncryptionHandshake, time.Now())).To(MatchError("PROTOCOL_VIOLATION: Received ACK for an unsent packet"))
|
||||
})
|
||||
|
||||
It("deletes Initial packets", func() {
|
||||
It("deletes Initial packets, as a server", func() {
|
||||
for i := protocol.PacketNumber(0); i < 6; i++ {
|
||||
handler.SentPacket(ackElicitingPacket(&Packet{
|
||||
PacketNumber: i,
|
||||
@@ -874,6 +873,37 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
Expect(handler.handshakePackets.history.Len()).ToNot(BeZero())
|
||||
})
|
||||
|
||||
Context("deleting Initials", func() {
|
||||
BeforeEach(func() { perspective = protocol.PerspectiveClient })
|
||||
|
||||
It("deletes Initials, as a client", func() {
|
||||
for i := protocol.PacketNumber(0); i < 6; i++ {
|
||||
handler.SentPacket(ackElicitingPacket(&Packet{
|
||||
PacketNumber: i,
|
||||
EncryptionLevel: protocol.EncryptionInitial,
|
||||
}))
|
||||
}
|
||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(6)))
|
||||
handler.DropPackets(protocol.EncryptionInitial)
|
||||
// DropPackets should be ignored for clients and the Initial packet number space.
|
||||
// It has to be possible to send another Initial packets after this function was called.
|
||||
handler.SentPacket(ackElicitingPacket(&Packet{
|
||||
PacketNumber: 10,
|
||||
EncryptionLevel: protocol.EncryptionInitial,
|
||||
}))
|
||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(7)))
|
||||
// Sending a Handshake packet triggers dropping of Initials.
|
||||
handler.SentPacket(ackElicitingPacket(&Packet{
|
||||
PacketNumber: 1,
|
||||
EncryptionLevel: protocol.EncryptionHandshake,
|
||||
}))
|
||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(1)))
|
||||
Expect(lostPackets).To(BeEmpty()) // frames must not be queued for retransmission
|
||||
Expect(handler.initialPackets).To(BeNil())
|
||||
Expect(handler.handshakePackets.history.Len()).ToNot(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
It("deletes Handshake packets", func() {
|
||||
for i := protocol.PacketNumber(0); i < 6; i++ {
|
||||
handler.SentPacket(ackElicitingPacket(&Packet{
|
||||
|
||||
Reference in New Issue
Block a user