don't send an ACK delay time for Initial and Handshake ACKs

This commit is contained in:
Marten Seemann 2019-05-08 14:18:59 +09:00
parent f981339bc0
commit 0e33f3c0da
2 changed files with 19 additions and 9 deletions

View file

@ -83,14 +83,21 @@ func (h *receivedPacketHandler) GetAlarmTimeout() time.Time {
}
func (h *receivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel) *wire.AckFrame {
var ack *wire.AckFrame
switch encLevel {
case protocol.EncryptionInitial:
return h.initialPackets.GetAckFrame()
ack = h.initialPackets.GetAckFrame()
case protocol.EncryptionHandshake:
return h.handshakePackets.GetAckFrame()
ack = h.handshakePackets.GetAckFrame()
case protocol.Encryption1RTT:
return h.oneRTTPackets.GetAckFrame()
default:
return nil
}
// For Initial and Handshake ACKs, the delay time is ignored by the receiver.
// Set it to 0 in order to save bytes.
if ack != nil {
ack.DelayTime = 0
}
return ack
}

View file

@ -24,24 +24,27 @@ var _ = Describe("Received Packet Handler", func() {
})
It("generates ACKs for different packet number spaces", func() {
now := time.Now()
Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, now, true)).To(Succeed())
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, now, true)).To(Succeed())
Expect(handler.ReceivedPacket(5, protocol.Encryption1RTT, now, true)).To(Succeed())
Expect(handler.ReceivedPacket(3, protocol.EncryptionInitial, now, true)).To(Succeed())
Expect(handler.ReceivedPacket(2, protocol.EncryptionHandshake, now, true)).To(Succeed())
Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, now, true)).To(Succeed())
sendTime := time.Now().Add(-time.Second)
Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(5, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(3, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(2, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
initialAck := handler.GetAckFrame(protocol.EncryptionInitial)
Expect(initialAck).ToNot(BeNil())
Expect(initialAck.AckRanges).To(HaveLen(1))
Expect(initialAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 2, Largest: 3}))
Expect(initialAck.DelayTime).To(BeZero())
handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake)
Expect(handshakeAck).ToNot(BeNil())
Expect(handshakeAck.AckRanges).To(HaveLen(1))
Expect(handshakeAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 1, Largest: 2}))
Expect(handshakeAck.DelayTime).To(BeZero())
oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT)
Expect(oneRTTAck).ToNot(BeNil())
Expect(oneRTTAck.AckRanges).To(HaveLen(1))
Expect(oneRTTAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 4, Largest: 5}))
Expect(oneRTTAck.DelayTime).To(BeNumerically("~", time.Second, 50*time.Millisecond))
})
})