forked from quic-go/quic-go
Merge pull request #1690 from lucas-clemente/rename-handshake-packets
rename handshake packets to crypto packets
This commit is contained in:
@@ -34,7 +34,7 @@ type sentPacketHandler struct {
|
||||
packetNumberGenerator *packetNumberGenerator
|
||||
|
||||
lastSentRetransmittablePacketTime time.Time
|
||||
lastSentHandshakePacketTime time.Time
|
||||
lastSentCryptoPacketTime time.Time
|
||||
|
||||
nextPacketSendTime time.Time
|
||||
|
||||
@@ -56,8 +56,8 @@ type sentPacketHandler struct {
|
||||
rttStats *congestion.RTTStats
|
||||
|
||||
handshakeComplete bool
|
||||
// The number of times the handshake packets have been retransmitted without receiving an ack.
|
||||
handshakeCount uint32
|
||||
// The number of times the crypto packets have been retransmitted without receiving an ack.
|
||||
cryptoCount uint32
|
||||
|
||||
// The number of times a TLP has been sent without receiving an ack.
|
||||
tlpCount uint32
|
||||
@@ -108,21 +108,21 @@ func (h *sentPacketHandler) lowestUnacked() protocol.PacketNumber {
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) SetHandshakeComplete() {
|
||||
h.logger.Debugf("Handshake complete. Discarding all outstanding handshake packets.")
|
||||
h.logger.Debugf("Handshake complete. Discarding all outstanding crypto packets.")
|
||||
var queue []*Packet
|
||||
for _, packet := range h.retransmissionQueue {
|
||||
if packet.EncryptionLevel == protocol.Encryption1RTT {
|
||||
queue = append(queue, packet)
|
||||
}
|
||||
}
|
||||
var handshakePackets []*Packet
|
||||
var cryptoPackets []*Packet
|
||||
h.packetHistory.Iterate(func(p *Packet) (bool, error) {
|
||||
if p.EncryptionLevel != protocol.Encryption1RTT {
|
||||
handshakePackets = append(handshakePackets, p)
|
||||
cryptoPackets = append(cryptoPackets, p)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
for _, p := range handshakePackets {
|
||||
for _, p := range cryptoPackets {
|
||||
h.packetHistory.Remove(p.PacketNumber)
|
||||
}
|
||||
h.retransmissionQueue = queue
|
||||
@@ -167,7 +167,7 @@ func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* isRetransmitt
|
||||
|
||||
if isRetransmittable {
|
||||
if packet.EncryptionLevel != protocol.Encryption1RTT {
|
||||
h.lastSentHandshakePacketTime = packet.SendTime
|
||||
h.lastSentCryptoPacketTime = packet.SendTime
|
||||
}
|
||||
h.lastSentRetransmittablePacketTime = packet.SendTime
|
||||
packet.includedInBytesInFlight = true
|
||||
@@ -305,8 +305,8 @@ func (h *sentPacketHandler) updateLossDetectionAlarm() {
|
||||
return
|
||||
}
|
||||
|
||||
if h.packetHistory.HasOutstandingHandshakePackets() {
|
||||
h.alarm = h.lastSentHandshakePacketTime.Add(h.computeHandshakeTimeout())
|
||||
if h.packetHistory.HasOutstandingCryptoPackets() {
|
||||
h.alarm = h.lastSentCryptoPacketTime.Add(h.computeCryptoTimeout())
|
||||
} else if !h.lossTime.IsZero() {
|
||||
// Early retransmit timer or time loss detection.
|
||||
h.alarm = h.lossTime
|
||||
@@ -387,12 +387,12 @@ func (h *sentPacketHandler) OnAlarm() error {
|
||||
|
||||
func (h *sentPacketHandler) onVerifiedAlarm() error {
|
||||
var err error
|
||||
if h.packetHistory.HasOutstandingHandshakePackets() {
|
||||
if h.packetHistory.HasOutstandingCryptoPackets() {
|
||||
if h.logger.Debug() {
|
||||
h.logger.Debugf("Loss detection alarm fired in handshake mode. Handshake count: %d", h.handshakeCount)
|
||||
h.logger.Debugf("Loss detection alarm fired in crypto mode. Crypto count: %d", h.cryptoCount)
|
||||
}
|
||||
h.handshakeCount++
|
||||
err = h.queueHandshakePacketsForRetransmission()
|
||||
h.cryptoCount++
|
||||
err = h.queueCryptoPacketsForRetransmission()
|
||||
} else if !h.lossTime.IsZero() {
|
||||
if h.logger.Debug() {
|
||||
h.logger.Debugf("Loss detection alarm fired in loss timer mode. Loss time: %s", h.lossTime)
|
||||
@@ -462,7 +462,7 @@ func (h *sentPacketHandler) onPacketAcked(p *Packet, rcvTime time.Time) error {
|
||||
}
|
||||
h.rtoCount = 0
|
||||
h.tlpCount = 0
|
||||
h.handshakeCount = 0
|
||||
h.cryptoCount = 0
|
||||
return h.packetHistory.Remove(p.PacketNumber)
|
||||
}
|
||||
|
||||
@@ -581,16 +581,16 @@ func (h *sentPacketHandler) ShouldSendNumPackets() int {
|
||||
return int(math.Ceil(float64(protocol.MinPacingDelay) / float64(delay)))
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) queueHandshakePacketsForRetransmission() error {
|
||||
var handshakePackets []*Packet
|
||||
func (h *sentPacketHandler) queueCryptoPacketsForRetransmission() error {
|
||||
var cryptoPackets []*Packet
|
||||
h.packetHistory.Iterate(func(p *Packet) (bool, error) {
|
||||
if p.canBeRetransmitted && p.EncryptionLevel != protocol.Encryption1RTT {
|
||||
handshakePackets = append(handshakePackets, p)
|
||||
cryptoPackets = append(cryptoPackets, p)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
for _, p := range handshakePackets {
|
||||
h.logger.Debugf("Queueing packet %#x as a handshake retransmission", p.PacketNumber)
|
||||
for _, p := range cryptoPackets {
|
||||
h.logger.Debugf("Queueing packet %#x as a crypto retransmission", p.PacketNumber)
|
||||
if err := h.queuePacketForRetransmission(p); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -609,11 +609,11 @@ func (h *sentPacketHandler) queuePacketForRetransmission(p *Packet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) computeHandshakeTimeout() time.Duration {
|
||||
func (h *sentPacketHandler) computeCryptoTimeout() time.Duration {
|
||||
duration := utils.MaxDuration(2*h.rttStats.SmoothedOrInitialRTT(), minTPLTimeout)
|
||||
// exponential backoff
|
||||
// There's an implicit limit to this set by the handshake timeout.
|
||||
return duration << h.handshakeCount
|
||||
// There's an implicit limit to this set by the crypto timeout.
|
||||
return duration << h.cryptoCount
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) computeTLPTimeout() time.Duration {
|
||||
|
||||
@@ -35,7 +35,7 @@ func nonRetransmittablePacket(p *Packet) *Packet {
|
||||
return p
|
||||
}
|
||||
|
||||
func handshakePacket(p *Packet) *Packet {
|
||||
func cryptoPacket(p *Packet) *Packet {
|
||||
p = retransmittablePacket(p)
|
||||
p.EncryptionLevel = protocol.EncryptionInitial
|
||||
return p
|
||||
@@ -113,11 +113,11 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
Expect(handler.lastSentRetransmittablePacketTime).To(Equal(sendTime))
|
||||
})
|
||||
|
||||
It("stores the sent time of handshake packets", func() {
|
||||
It("stores the sent time of crypto packets", func() {
|
||||
sendTime := time.Now().Add(-time.Minute)
|
||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: sendTime.Add(time.Hour), EncryptionLevel: protocol.Encryption1RTT}))
|
||||
Expect(handler.lastSentHandshakePacketTime).To(Equal(sendTime))
|
||||
Expect(handler.lastSentCryptoPacketTime).To(Equal(sendTime))
|
||||
})
|
||||
|
||||
It("does not store non-retransmittable packets", func() {
|
||||
@@ -901,20 +901,20 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("handshake packets", func() {
|
||||
Context("crypto packets", func() {
|
||||
BeforeEach(func() {
|
||||
handler.handshakeComplete = false
|
||||
})
|
||||
|
||||
It("detects the handshake timeout", func() {
|
||||
It("detects the crypto timeout", func() {
|
||||
now := time.Now()
|
||||
sendTime := now.Add(-time.Minute)
|
||||
lastHandshakePacketSendTime := now.Add(-30 * time.Second)
|
||||
// send handshake packets: 1, 3
|
||||
lastCryptoPacketSendTime := now.Add(-30 * time.Second)
|
||||
// send crypto packets: 1, 3
|
||||
// send a forward-secure packet: 2
|
||||
handler.SentPacket(handshakePacket(&Packet{PacketNumber: 1, SendTime: sendTime}))
|
||||
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 1, SendTime: sendTime}))
|
||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: sendTime}))
|
||||
handler.SentPacket(handshakePacket(&Packet{PacketNumber: 3, SendTime: sendTime}))
|
||||
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 3, SendTime: sendTime}))
|
||||
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
|
||||
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, now)
|
||||
@@ -929,10 +929,10 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
p := handler.DequeuePacketForRetransmission()
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(p.PacketNumber).To(Equal(protocol.PacketNumber(3)))
|
||||
Expect(handler.handshakeCount).To(BeEquivalentTo(1))
|
||||
handler.SentPacket(handshakePacket(&Packet{PacketNumber: 4, SendTime: lastHandshakePacketSendTime}))
|
||||
Expect(handler.cryptoCount).To(BeEquivalentTo(1))
|
||||
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 4, SendTime: lastCryptoPacketSendTime}))
|
||||
// make sure the exponential backoff is used
|
||||
Expect(handler.GetAlarmTimeout().Sub(lastHandshakePacketSendTime)).To(Equal(4 * time.Minute))
|
||||
Expect(handler.GetAlarmTimeout().Sub(lastCryptoPacketSendTime)).To(Equal(4 * time.Minute))
|
||||
})
|
||||
|
||||
// TODO(#1534): also check the encryption level for IETF QUIC
|
||||
@@ -948,7 +948,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
Expect(err).To(MatchError("Received ACK with encryption level encrypted (not forward-secure) that acks a packet 13 (encryption level forward-secure)"))
|
||||
})
|
||||
|
||||
It("deletes non handshake packets when the handshake completes", func() {
|
||||
It("deletes crypto packets when the handshake completes", func() {
|
||||
for i := protocol.PacketNumber(1); i <= 6; i++ {
|
||||
p := retransmittablePacket(&Packet{PacketNumber: i})
|
||||
p.EncryptionLevel = protocol.EncryptionHandshake
|
||||
|
||||
@@ -10,8 +10,8 @@ type sentPacketHistory struct {
|
||||
packetList *PacketList
|
||||
packetMap map[protocol.PacketNumber]*PacketElement
|
||||
|
||||
numOutstandingPackets int
|
||||
numOutstandingHandshakePackets int
|
||||
numOutstandingPackets int
|
||||
numOutstandingCryptoPackets int
|
||||
|
||||
firstOutstanding *PacketElement
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (h *sentPacketHistory) sentPacketImpl(p *Packet) *PacketElement {
|
||||
if p.canBeRetransmitted {
|
||||
h.numOutstandingPackets++
|
||||
if p.EncryptionLevel != protocol.Encryption1RTT {
|
||||
h.numOutstandingHandshakePackets++
|
||||
h.numOutstandingCryptoPackets++
|
||||
}
|
||||
}
|
||||
return el
|
||||
@@ -107,8 +107,8 @@ func (h *sentPacketHistory) MarkCannotBeRetransmitted(pn protocol.PacketNumber)
|
||||
panic("numOutstandingHandshakePackets negative")
|
||||
}
|
||||
if el.Value.EncryptionLevel != protocol.Encryption1RTT {
|
||||
h.numOutstandingHandshakePackets--
|
||||
if h.numOutstandingHandshakePackets < 0 {
|
||||
h.numOutstandingCryptoPackets--
|
||||
if h.numOutstandingCryptoPackets < 0 {
|
||||
panic("numOutstandingHandshakePackets negative")
|
||||
}
|
||||
}
|
||||
@@ -148,8 +148,8 @@ func (h *sentPacketHistory) Remove(p protocol.PacketNumber) error {
|
||||
panic("numOutstandingHandshakePackets negative")
|
||||
}
|
||||
if el.Value.EncryptionLevel != protocol.Encryption1RTT {
|
||||
h.numOutstandingHandshakePackets--
|
||||
if h.numOutstandingHandshakePackets < 0 {
|
||||
h.numOutstandingCryptoPackets--
|
||||
if h.numOutstandingCryptoPackets < 0 {
|
||||
panic("numOutstandingHandshakePackets negative")
|
||||
}
|
||||
}
|
||||
@@ -163,6 +163,6 @@ func (h *sentPacketHistory) HasOutstandingPackets() bool {
|
||||
return h.numOutstandingPackets > 0
|
||||
}
|
||||
|
||||
func (h *sentPacketHistory) HasOutstandingHandshakePackets() bool {
|
||||
return h.numOutstandingHandshakePackets > 0
|
||||
func (h *sentPacketHistory) HasOutstandingCryptoPackets() bool {
|
||||
return h.numOutstandingCryptoPackets > 0
|
||||
}
|
||||
|
||||
@@ -199,23 +199,23 @@ var _ = Describe("SentPacketHistory", func() {
|
||||
})
|
||||
|
||||
Context("outstanding packets", func() {
|
||||
It("says if it has outstanding handshake packets", func() {
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeFalse())
|
||||
It("says if it has outstanding crypto packets", func() {
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeFalse())
|
||||
hist.SentPacket(&Packet{
|
||||
EncryptionLevel: protocol.EncryptionInitial,
|
||||
canBeRetransmitted: true,
|
||||
})
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeTrue())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("says if it has outstanding packets", func() {
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingPackets()).To(BeFalse())
|
||||
hist.SentPacket(&Packet{
|
||||
EncryptionLevel: protocol.Encryption1RTT,
|
||||
canBeRetransmitted: true,
|
||||
})
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingPackets()).To(BeTrue())
|
||||
})
|
||||
|
||||
@@ -223,20 +223,20 @@ var _ = Describe("SentPacketHistory", func() {
|
||||
hist.SentPacket(&Packet{
|
||||
EncryptionLevel: protocol.EncryptionInitial,
|
||||
})
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingPackets()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("accounts for deleted handshake packets", func() {
|
||||
It("accounts for deleted crypto packets", func() {
|
||||
hist.SentPacket(&Packet{
|
||||
PacketNumber: 5,
|
||||
EncryptionLevel: protocol.EncryptionHandshake,
|
||||
canBeRetransmitted: true,
|
||||
})
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeTrue())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeTrue())
|
||||
err := hist.Remove(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("accounts for deleted packets", func() {
|
||||
@@ -251,16 +251,16 @@ var _ = Describe("SentPacketHistory", func() {
|
||||
Expect(hist.HasOutstandingPackets()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("doesn't count handshake packets marked as non-retransmittable", func() {
|
||||
It("doesn't count crypto packets marked as non-retransmittable", func() {
|
||||
hist.SentPacket(&Packet{
|
||||
PacketNumber: 5,
|
||||
EncryptionLevel: protocol.EncryptionInitial,
|
||||
canBeRetransmitted: true,
|
||||
})
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeTrue())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeTrue())
|
||||
err := hist.MarkCannotBeRetransmitted(5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hist.HasOutstandingHandshakePackets()).To(BeFalse())
|
||||
Expect(hist.HasOutstandingCryptoPackets()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("doesn't count packets marked as non-retransmittable", func() {
|
||||
|
||||
Reference in New Issue
Block a user