mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 13:17:36 +03:00
rename retransmittable to ack-eliciting
This commit is contained in:
parent
9ad6a7b59d
commit
b5336be518
14 changed files with 178 additions and 177 deletions
34
internal/ackhandler/ack_eliciting.go
Normal file
34
internal/ackhandler/ack_eliciting.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package ackhandler
|
||||||
|
|
||||||
|
import "github.com/lucas-clemente/quic-go/internal/wire"
|
||||||
|
|
||||||
|
// Returns a new slice with all non-ack-eliciting frames deleted.
|
||||||
|
func stripNonAckElicitingFrames(fs []wire.Frame) []wire.Frame {
|
||||||
|
res := make([]wire.Frame, 0, len(fs))
|
||||||
|
for _, f := range fs {
|
||||||
|
if IsFrameAckEliciting(f) {
|
||||||
|
res = append(res, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsFrameAckEliciting returns true if the frame is ack-eliciting.
|
||||||
|
func IsFrameAckEliciting(f wire.Frame) bool {
|
||||||
|
switch f.(type) {
|
||||||
|
case *wire.AckFrame:
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAckElicitingFrames returns true if at least one frame is ack-eliciting.
|
||||||
|
func HasAckElicitingFrames(fs []wire.Frame) bool {
|
||||||
|
for _, f := range fs {
|
||||||
|
if IsFrameAckEliciting(f) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import (
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("retransmittable frames", func() {
|
var _ = Describe("ack-eliciting frames", func() {
|
||||||
for fl, el := range map[wire.Frame]bool{
|
for fl, el := range map[wire.Frame]bool{
|
||||||
&wire.AckFrame{}: false,
|
&wire.AckFrame{}: false,
|
||||||
&wire.DataBlockedFrame{}: true,
|
&wire.DataBlockedFrame{}: true,
|
||||||
|
@ -24,20 +24,20 @@ var _ = Describe("retransmittable frames", func() {
|
||||||
fName := reflect.ValueOf(f).Elem().Type().Name()
|
fName := reflect.ValueOf(f).Elem().Type().Name()
|
||||||
|
|
||||||
It("works for "+fName, func() {
|
It("works for "+fName, func() {
|
||||||
Expect(IsFrameRetransmittable(f)).To(Equal(e))
|
Expect(IsFrameAckEliciting(f)).To(Equal(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("stripping non-retransmittable frames works for "+fName, func() {
|
It("stripping non-ack-elicinting frames works for "+fName, func() {
|
||||||
s := []wire.Frame{f}
|
s := []wire.Frame{f}
|
||||||
if e {
|
if e {
|
||||||
Expect(stripNonRetransmittableFrames(s)).To(Equal([]wire.Frame{f}))
|
Expect(stripNonAckElicitingFrames(s)).To(Equal([]wire.Frame{f}))
|
||||||
} else {
|
} else {
|
||||||
Expect(stripNonRetransmittableFrames(s)).To(BeEmpty())
|
Expect(stripNonAckElicitingFrames(s)).To(BeEmpty())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("HasRetransmittableFrames works for "+fName, func() {
|
It("HasAckElicitingFrames works for "+fName, func() {
|
||||||
Expect(HasRetransmittableFrames([]wire.Frame{f})).To(Equal(e))
|
Expect(HasAckElicitingFrames([]wire.Frame{f})).To(Equal(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
|
@ -11,12 +11,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// maximum delay that can be applied to an ACK for a retransmittable packet
|
// maximum delay that can be applied to an ACK for an ack-eliciting packet
|
||||||
ackSendDelay = 25 * time.Millisecond
|
ackSendDelay = 25 * time.Millisecond
|
||||||
// initial maximum number of retransmittable packets received before sending an ack.
|
// initial maximum number of ack-eliciting packets received before sending an ack.
|
||||||
initialRetransmittablePacketsBeforeAck = 2
|
initialAckElicitingPacketsBeforeAck = 2
|
||||||
// number of retransmittable that an ACK is sent for
|
// number of ack-eliciting that an ACK is sent for
|
||||||
retransmittablePacketsBeforeAck = 10
|
ackElicitingPacketsBeforeAck = 10
|
||||||
// 1/5 RTT delay when doing ack decimation
|
// 1/5 RTT delay when doing ack decimation
|
||||||
ackDecimationDelay = 1.0 / 4
|
ackDecimationDelay = 1.0 / 4
|
||||||
// 1/8 RTT delay when doing ack decimation
|
// 1/8 RTT delay when doing ack decimation
|
||||||
|
|
|
@ -20,7 +20,7 @@ type receivedPacketTracker struct {
|
||||||
rttStats *congestion.RTTStats
|
rttStats *congestion.RTTStats
|
||||||
|
|
||||||
packetsReceivedSinceLastAck int
|
packetsReceivedSinceLastAck int
|
||||||
retransmittablePacketsReceivedSinceLastAck int
|
ackElicitingPacketsReceivedSinceLastAck int
|
||||||
ackQueued bool
|
ackQueued bool
|
||||||
ackAlarm time.Time
|
ackAlarm time.Time
|
||||||
lastAck *wire.AckFrame
|
lastAck *wire.AckFrame
|
||||||
|
@ -115,14 +115,14 @@ func (h *receivedPacketTracker) maybeQueueAck(packetNumber protocol.PacketNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
if !h.ackQueued && shouldInstigateAck {
|
if !h.ackQueued && shouldInstigateAck {
|
||||||
h.retransmittablePacketsReceivedSinceLastAck++
|
h.ackElicitingPacketsReceivedSinceLastAck++
|
||||||
|
|
||||||
if packetNumber > minReceivedBeforeAckDecimation {
|
if packetNumber > minReceivedBeforeAckDecimation {
|
||||||
// ack up to 10 packets at once
|
// ack up to 10 packets at once
|
||||||
if h.retransmittablePacketsReceivedSinceLastAck >= retransmittablePacketsBeforeAck {
|
if h.ackElicitingPacketsReceivedSinceLastAck >= ackElicitingPacketsBeforeAck {
|
||||||
h.ackQueued = true
|
h.ackQueued = true
|
||||||
if h.logger.Debug() {
|
if h.logger.Debug() {
|
||||||
h.logger.Debugf("\tQueueing ACK because packet %d packets were received after the last ACK (using threshold: %d).", h.retransmittablePacketsReceivedSinceLastAck, retransmittablePacketsBeforeAck)
|
h.logger.Debugf("\tQueueing ACK because packet %d packets were received after the last ACK (using threshold: %d).", h.ackElicitingPacketsReceivedSinceLastAck, ackElicitingPacketsBeforeAck)
|
||||||
}
|
}
|
||||||
} else if h.ackAlarm.IsZero() {
|
} else if h.ackAlarm.IsZero() {
|
||||||
// wait for the minimum of the ack decimation delay or the delayed ack time before sending an ack
|
// wait for the minimum of the ack decimation delay or the delayed ack time before sending an ack
|
||||||
|
@ -133,10 +133,10 @@ func (h *receivedPacketTracker) maybeQueueAck(packetNumber protocol.PacketNumber
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// send an ACK every 2 retransmittable packets
|
// send an ACK every 2 ack-eliciting packets
|
||||||
if h.retransmittablePacketsReceivedSinceLastAck >= initialRetransmittablePacketsBeforeAck {
|
if h.ackElicitingPacketsReceivedSinceLastAck >= initialAckElicitingPacketsBeforeAck {
|
||||||
if h.logger.Debug() {
|
if h.logger.Debug() {
|
||||||
h.logger.Debugf("\tQueueing ACK because packet %d packets were received after the last ACK (using initial threshold: %d).", h.retransmittablePacketsReceivedSinceLastAck, initialRetransmittablePacketsBeforeAck)
|
h.logger.Debugf("\tQueueing ACK because packet %d packets were received after the last ACK (using initial threshold: %d).", h.ackElicitingPacketsReceivedSinceLastAck, initialAckElicitingPacketsBeforeAck)
|
||||||
}
|
}
|
||||||
h.ackQueued = true
|
h.ackQueued = true
|
||||||
} else if h.ackAlarm.IsZero() {
|
} else if h.ackAlarm.IsZero() {
|
||||||
|
@ -184,7 +184,7 @@ func (h *receivedPacketTracker) GetAckFrame() *wire.AckFrame {
|
||||||
h.ackAlarm = time.Time{}
|
h.ackAlarm = time.Time{}
|
||||||
h.ackQueued = false
|
h.ackQueued = false
|
||||||
h.packetsReceivedSinceLastAck = 0
|
h.packetsReceivedSinceLastAck = 0
|
||||||
h.retransmittablePacketsReceivedSinceLastAck = 0
|
h.ackElicitingPacketsReceivedSinceLastAck = 0
|
||||||
return ack
|
return ack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ var _ = Describe("Received Packet Tracker", func() {
|
||||||
Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
|
Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("queues an ACK for every second retransmittable packet at the beginning", func() {
|
It("queues an ACK for every second ack-eliciting packet at the beginning", func() {
|
||||||
receiveAndAck10Packets()
|
receiveAndAck10Packets()
|
||||||
p := protocol.PacketNumber(11)
|
p := protocol.PacketNumber(11)
|
||||||
for i := 0; i <= 20; i++ {
|
for i := 0; i <= 20; i++ {
|
||||||
|
@ -125,7 +125,7 @@ var _ = Describe("Received Packet Tracker", func() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("queues an ACK for every 10 retransmittable packet, if they are arriving fast", func() {
|
It("queues an ACK for every 10 ack-eliciting packet, if they are arriving fast", func() {
|
||||||
receiveAndAck10Packets()
|
receiveAndAck10Packets()
|
||||||
p := protocol.PacketNumber(10000)
|
p := protocol.PacketNumber(10000)
|
||||||
for i := 0; i < 9; i++ {
|
for i := 0; i < 9; i++ {
|
||||||
|
@ -141,7 +141,7 @@ var _ = Describe("Received Packet Tracker", func() {
|
||||||
Expect(tracker.GetAlarmTimeout()).To(BeZero())
|
Expect(tracker.GetAlarmTimeout()).To(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("only sets the timer when receiving a retransmittable packets", func() {
|
It("only sets the timer when receiving a ack-eliciting packets", func() {
|
||||||
receiveAndAck10Packets()
|
receiveAndAck10Packets()
|
||||||
err := tracker.ReceivedPacket(11, time.Now(), false)
|
err := tracker.ReceivedPacket(11, time.Now(), false)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -350,7 +350,7 @@ var _ = Describe("Received Packet Tracker", func() {
|
||||||
Expect(tracker.GetAckFrame()).ToNot(BeNil())
|
Expect(tracker.GetAckFrame()).ToNot(BeNil())
|
||||||
Expect(tracker.packetsReceivedSinceLastAck).To(BeZero())
|
Expect(tracker.packetsReceivedSinceLastAck).To(BeZero())
|
||||||
Expect(tracker.GetAlarmTimeout()).To(BeZero())
|
Expect(tracker.GetAlarmTimeout()).To(BeZero())
|
||||||
Expect(tracker.retransmittablePacketsReceivedSinceLastAck).To(BeZero())
|
Expect(tracker.ackElicitingPacketsReceivedSinceLastAck).To(BeZero())
|
||||||
Expect(tracker.ackQueued).To(BeFalse())
|
Expect(tracker.ackQueued).To(BeFalse())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
package ackhandler
|
|
||||||
|
|
||||||
import "github.com/lucas-clemente/quic-go/internal/wire"
|
|
||||||
|
|
||||||
// Returns a new slice with all non-retransmittable frames deleted.
|
|
||||||
func stripNonRetransmittableFrames(fs []wire.Frame) []wire.Frame {
|
|
||||||
res := make([]wire.Frame, 0, len(fs))
|
|
||||||
for _, f := range fs {
|
|
||||||
if IsFrameRetransmittable(f) {
|
|
||||||
res = append(res, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsFrameRetransmittable returns true if the frame should be retransmitted.
|
|
||||||
func IsFrameRetransmittable(f wire.Frame) bool {
|
|
||||||
switch f.(type) {
|
|
||||||
case *wire.AckFrame:
|
|
||||||
return false
|
|
||||||
default:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasRetransmittableFrames returns true if at least one frame is retransmittable.
|
|
||||||
func HasRetransmittableFrames(fs []wire.Frame) bool {
|
|
||||||
for _, f := range fs {
|
|
||||||
if IsFrameRetransmittable(f) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
|
@ -37,7 +37,7 @@ func newPacketNumberSpace(initialPN protocol.PacketNumber) *packetNumberSpace {
|
||||||
}
|
}
|
||||||
|
|
||||||
type sentPacketHandler struct {
|
type sentPacketHandler struct {
|
||||||
lastSentRetransmittablePacketTime time.Time // only applies to the application-data packet number space
|
lastSentAckElicitingPacketTime time.Time // only applies to the application-data packet number space
|
||||||
lastSentCryptoPacketTime time.Time
|
lastSentCryptoPacketTime time.Time
|
||||||
|
|
||||||
nextSendTime time.Time
|
nextSendTime time.Time
|
||||||
|
@ -125,7 +125,7 @@ func (h *sentPacketHandler) SetHandshakeComplete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *sentPacketHandler) SentPacket(packet *Packet) {
|
func (h *sentPacketHandler) SentPacket(packet *Packet) {
|
||||||
if isRetransmittable := h.sentPacketImpl(packet); isRetransmittable {
|
if isAckEliciting := h.sentPacketImpl(packet); isAckEliciting {
|
||||||
h.getPacketNumberSpace(packet.EncryptionLevel).history.SentPacket(packet)
|
h.getPacketNumberSpace(packet.EncryptionLevel).history.SentPacket(packet)
|
||||||
h.updateLossDetectionAlarm()
|
h.updateLossDetectionAlarm()
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func (h *sentPacketHandler) SentPacket(packet *Packet) {
|
||||||
func (h *sentPacketHandler) SentPacketsAsRetransmission(packets []*Packet, retransmissionOf protocol.PacketNumber) {
|
func (h *sentPacketHandler) SentPacketsAsRetransmission(packets []*Packet, retransmissionOf protocol.PacketNumber) {
|
||||||
var p []*Packet
|
var p []*Packet
|
||||||
for _, packet := range packets {
|
for _, packet := range packets {
|
||||||
if isRetransmittable := h.sentPacketImpl(packet); isRetransmittable {
|
if isAckEliciting := h.sentPacketImpl(packet); isAckEliciting {
|
||||||
p = append(p, packet)
|
p = append(p, packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ func (h *sentPacketHandler) getPacketNumberSpace(encLevel protocol.EncryptionLev
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* isRetransmittable */ {
|
func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* is ack-eliciting */ {
|
||||||
pnSpace := h.getPacketNumberSpace(packet.EncryptionLevel)
|
pnSpace := h.getPacketNumberSpace(packet.EncryptionLevel)
|
||||||
|
|
||||||
if h.logger.Debug() && pnSpace.largestSent != 0 {
|
if h.logger.Debug() && pnSpace.largestSent != 0 {
|
||||||
|
@ -172,14 +172,14 @@ func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* isRetransmitt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
packet.Frames = stripNonRetransmittableFrames(packet.Frames)
|
packet.Frames = stripNonAckElicitingFrames(packet.Frames)
|
||||||
isRetransmittable := len(packet.Frames) != 0
|
isAckEliciting := len(packet.Frames) != 0
|
||||||
|
|
||||||
if isRetransmittable {
|
if isAckEliciting {
|
||||||
if packet.EncryptionLevel != protocol.Encryption1RTT {
|
if packet.EncryptionLevel != protocol.Encryption1RTT {
|
||||||
h.lastSentCryptoPacketTime = packet.SendTime
|
h.lastSentCryptoPacketTime = packet.SendTime
|
||||||
}
|
}
|
||||||
h.lastSentRetransmittablePacketTime = packet.SendTime
|
h.lastSentAckElicitingPacketTime = packet.SendTime
|
||||||
packet.includedInBytesInFlight = true
|
packet.includedInBytesInFlight = true
|
||||||
h.bytesInFlight += packet.Length
|
h.bytesInFlight += packet.Length
|
||||||
packet.canBeRetransmitted = true
|
packet.canBeRetransmitted = true
|
||||||
|
@ -187,10 +187,10 @@ func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* isRetransmitt
|
||||||
h.numProbesToSend--
|
h.numProbesToSend--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.congestion.OnPacketSent(packet.SendTime, h.bytesInFlight, packet.PacketNumber, packet.Length, isRetransmittable)
|
h.congestion.OnPacketSent(packet.SendTime, h.bytesInFlight, packet.PacketNumber, packet.Length, isAckEliciting)
|
||||||
|
|
||||||
h.nextSendTime = utils.MaxTime(h.nextSendTime, packet.SendTime).Add(h.congestion.TimeUntilSend(h.bytesInFlight))
|
h.nextSendTime = utils.MaxTime(h.nextSendTime, packet.SendTime).Add(h.congestion.TimeUntilSend(h.bytesInFlight))
|
||||||
return isRetransmittable
|
return isAckEliciting
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumber protocol.PacketNumber, encLevel protocol.EncryptionLevel, rcvTime time.Time) error {
|
func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumber protocol.PacketNumber, encLevel protocol.EncryptionLevel, rcvTime time.Time) error {
|
||||||
|
@ -325,7 +325,7 @@ func (h *sentPacketHandler) updateLossDetectionAlarm() {
|
||||||
// Early retransmit timer or time loss detection.
|
// Early retransmit timer or time loss detection.
|
||||||
h.alarm = h.lossTime
|
h.alarm = h.lossTime
|
||||||
} else { // PTO alarm
|
} else { // PTO alarm
|
||||||
h.alarm = h.lastSentRetransmittablePacketTime.Add(h.computePTOTimeout())
|
h.alarm = h.lastSentAckElicitingPacketTime.Add(h.computePTOTimeout())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +438,7 @@ func (h *sentPacketHandler) onPacketAcked(p *Packet, rcvTime time.Time) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only report the acking of this packet to the congestion controller if:
|
// only report the acking of this packet to the congestion controller if:
|
||||||
// * it is a retransmittable packet
|
// * it is an ack-eliciting packet
|
||||||
// * this packet wasn't retransmitted yet
|
// * this packet wasn't retransmitted yet
|
||||||
if p.isRetransmission {
|
if p.isRetransmission {
|
||||||
// that the parent doesn't exist is expected to happen every time the original packet was already acked
|
// that the parent doesn't exist is expected to happen every time the original packet was already acked
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func retransmittablePacket(p *Packet) *Packet {
|
func ackElicitingPacket(p *Packet) *Packet {
|
||||||
if p.EncryptionLevel == protocol.EncryptionUnspecified {
|
if p.EncryptionLevel == protocol.EncryptionUnspecified {
|
||||||
p.EncryptionLevel = protocol.Encryption1RTT
|
p.EncryptionLevel = protocol.Encryption1RTT
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ func retransmittablePacket(p *Packet) *Packet {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func nonRetransmittablePacket(p *Packet) *Packet {
|
func nonAckElicitingPacket(p *Packet) *Packet {
|
||||||
p = retransmittablePacket(p)
|
p = ackElicitingPacket(p)
|
||||||
p.Frames = []wire.Frame{
|
p.Frames = []wire.Frame{
|
||||||
&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}},
|
&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}},
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func nonRetransmittablePacket(p *Packet) *Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cryptoPacket(p *Packet) *Packet {
|
func cryptoPacket(p *Packet) *Packet {
|
||||||
p = retransmittablePacket(p)
|
p = ackElicitingPacket(p)
|
||||||
p.EncryptionLevel = protocol.EncryptionInitial
|
p.EncryptionLevel = protocol.EncryptionInitial
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
@ -92,17 +92,17 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
|
|
||||||
Context("registering sent packets", func() {
|
Context("registering sent packets", func() {
|
||||||
It("accepts two consecutive packets", func() {
|
It("accepts two consecutive packets", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, EncryptionLevel: protocol.EncryptionHandshake}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, EncryptionLevel: protocol.EncryptionHandshake}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, EncryptionLevel: protocol.EncryptionHandshake}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, EncryptionLevel: protocol.EncryptionHandshake}))
|
||||||
Expect(handler.handshakePackets.largestSent).To(Equal(protocol.PacketNumber(2)))
|
Expect(handler.handshakePackets.largestSent).To(Equal(protocol.PacketNumber(2)))
|
||||||
expectInPacketHistory([]protocol.PacketNumber{1, 2}, protocol.EncryptionHandshake)
|
expectInPacketHistory([]protocol.PacketNumber{1, 2}, protocol.EncryptionHandshake)
|
||||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
|
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("accepts packet number 0", func() {
|
It("accepts packet number 0", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 0, EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 0, EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
Expect(handler.oneRTTPackets.largestSent).To(BeZero())
|
Expect(handler.oneRTTPackets.largestSent).To(BeZero())
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
Expect(handler.oneRTTPackets.largestSent).To(Equal(protocol.PacketNumber(1)))
|
Expect(handler.oneRTTPackets.largestSent).To(Equal(protocol.PacketNumber(1)))
|
||||||
expectInPacketHistory([]protocol.PacketNumber{0, 1}, protocol.Encryption1RTT)
|
expectInPacketHistory([]protocol.PacketNumber{0, 1}, protocol.Encryption1RTT)
|
||||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
|
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
|
||||||
|
@ -110,21 +110,21 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
|
|
||||||
It("stores the sent time", func() {
|
It("stores the sent time", func() {
|
||||||
sendTime := time.Now().Add(-time.Minute)
|
sendTime := time.Now().Add(-time.Minute)
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: sendTime}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: sendTime}))
|
||||||
Expect(handler.lastSentRetransmittablePacketTime).To(Equal(sendTime))
|
Expect(handler.lastSentAckElicitingPacketTime).To(Equal(sendTime))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("stores the sent time of crypto packets", func() {
|
It("stores the sent time of crypto packets", func() {
|
||||||
sendTime := time.Now().Add(-time.Minute)
|
sendTime := time.Now().Add(-time.Minute)
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: sendTime.Add(time.Hour), EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: sendTime.Add(time.Hour), EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
Expect(handler.lastSentCryptoPacketTime).To(Equal(sendTime))
|
Expect(handler.lastSentCryptoPacketTime).To(Equal(sendTime))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("does not store non-retransmittable packets", func() {
|
It("does not store non-ack-eliciting packets", func() {
|
||||||
handler.SentPacket(nonRetransmittablePacket(&Packet{PacketNumber: 1, EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(nonAckElicitingPacket(&Packet{PacketNumber: 1, EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
Expect(handler.oneRTTPackets.history.Len()).To(BeZero())
|
Expect(handler.oneRTTPackets.history.Len()).To(BeZero())
|
||||||
Expect(handler.lastSentRetransmittablePacketTime).To(BeZero())
|
Expect(handler.lastSentAckElicitingPacketTime).To(BeZero())
|
||||||
Expect(handler.bytesInFlight).To(BeZero())
|
Expect(handler.bytesInFlight).To(BeZero())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -132,7 +132,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
Context("ACK processing", func() {
|
Context("ACK processing", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
for i := protocol.PacketNumber(0); i < 10; i++ {
|
for i := protocol.PacketNumber(0); i < 10; i++ {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: i}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: i}))
|
||||||
}
|
}
|
||||||
// Increase RTT, because the tests would be flaky otherwise
|
// Increase RTT, because the tests would be flaky otherwise
|
||||||
updateRTT(time.Hour)
|
updateRTT(time.Hour)
|
||||||
|
@ -351,19 +351,19 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
Context("ACK processing, for retransmitted packets", func() {
|
Context("ACK processing, for retransmitted packets", func() {
|
||||||
It("sends a packet as retransmission", func() {
|
It("sends a packet as retransmission", func() {
|
||||||
// packet 5 was retransmitted as packet 6
|
// packet 5 was retransmitted as packet 6
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, Length: 10, EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 5, Length: 10, EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(10)))
|
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(10)))
|
||||||
losePacket(5, protocol.Encryption1RTT)
|
losePacket(5, protocol.Encryption1RTT)
|
||||||
Expect(handler.bytesInFlight).To(BeZero())
|
Expect(handler.bytesInFlight).To(BeZero())
|
||||||
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 6, Length: 11})}, 5)
|
handler.SentPacketsAsRetransmission([]*Packet{ackElicitingPacket(&Packet{PacketNumber: 6, Length: 11})}, 5)
|
||||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(11)))
|
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(11)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes a packet when it is acked", func() {
|
It("removes a packet when it is acked", func() {
|
||||||
// packet 5 was retransmitted as packet 6
|
// packet 5 was retransmitted as packet 6
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, Length: 10}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 5, Length: 10}))
|
||||||
losePacket(5, protocol.Encryption1RTT)
|
losePacket(5, protocol.Encryption1RTT)
|
||||||
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 6, Length: 11})}, 5)
|
handler.SentPacketsAsRetransmission([]*Packet{ackElicitingPacket(&Packet{PacketNumber: 6, Length: 11})}, 5)
|
||||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(11)))
|
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(11)))
|
||||||
// ack 5
|
// ack 5
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
|
||||||
|
@ -375,9 +375,9 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
|
|
||||||
It("handles ACKs that ack the original packet as well as the retransmission", func() {
|
It("handles ACKs that ack the original packet as well as the retransmission", func() {
|
||||||
// packet 5 was retransmitted as packet 7
|
// packet 5 was retransmitted as packet 7
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, Length: 10}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 5, Length: 10}))
|
||||||
losePacket(5, protocol.Encryption1RTT)
|
losePacket(5, protocol.Encryption1RTT)
|
||||||
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 7, Length: 11})}, 5)
|
handler.SentPacketsAsRetransmission([]*Packet{ackElicitingPacket(&Packet{PacketNumber: 7, Length: 11})}, 5)
|
||||||
// ack 5 and 7
|
// ack 5 and 7
|
||||||
ack := &wire.AckFrame{
|
ack := &wire.AckFrame{
|
||||||
AckRanges: []wire.AckRange{
|
AckRanges: []wire.AckRange{
|
||||||
|
@ -431,9 +431,9 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(1), protocol.ByteCount(1), protocol.ByteCount(3), rcvTime),
|
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(1), protocol.ByteCount(1), protocol.ByteCount(3), rcvTime),
|
||||||
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(2), protocol.ByteCount(1), protocol.ByteCount(3), rcvTime),
|
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(2), protocol.ByteCount(1), protocol.ByteCount(3), rcvTime),
|
||||||
)
|
)
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 3}))
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 2}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 2}}}
|
||||||
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, rcvTime)
|
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, rcvTime)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
@ -442,8 +442,8 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
It("doesn't call OnPacketAcked when a retransmitted packet is acked", func() {
|
It("doesn't call OnPacketAcked when a retransmitted packet is acked", func() {
|
||||||
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(2)
|
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(2)
|
||||||
cong.EXPECT().TimeUntilSend(gomock.Any()).Times(2)
|
cong.EXPECT().TimeUntilSend(gomock.Any()).Times(2)
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2}))
|
||||||
// lose packet 1
|
// lose packet 1
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
cong.EXPECT().MaybeExitSlowStart(),
|
cong.EXPECT().MaybeExitSlowStart(),
|
||||||
|
@ -462,10 +462,10 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
It("calls OnPacketAcked and OnPacketLost with the right bytes_in_flight value", func() {
|
It("calls OnPacketAcked and OnPacketLost with the right bytes_in_flight value", func() {
|
||||||
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(4)
|
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(4)
|
||||||
cong.EXPECT().TimeUntilSend(gomock.Any()).Times(4)
|
cong.EXPECT().TimeUntilSend(gomock.Any()).Times(4)
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: time.Now().Add(-30 * time.Minute)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: time.Now().Add(-30 * time.Minute)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3, SendTime: time.Now().Add(-30 * time.Minute)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 3, SendTime: time.Now().Add(-30 * time.Minute)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 4, SendTime: time.Now()}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 4, SendTime: time.Now()}))
|
||||||
// receive the first ACK
|
// receive the first ACK
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
cong.EXPECT().MaybeExitSlowStart(),
|
cong.EXPECT().MaybeExitSlowStart(),
|
||||||
|
@ -499,10 +499,10 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
cong.EXPECT().TimeUntilSend(gomock.Any()).AnyTimes()
|
cong.EXPECT().TimeUntilSend(gomock.Any()).AnyTimes()
|
||||||
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
|
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
|
||||||
for i := protocol.PacketNumber(1); i < protocol.MaxOutstandingSentPackets; i++ {
|
for i := protocol.PacketNumber(1); i < protocol.MaxOutstandingSentPackets; i++ {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: i}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: i}))
|
||||||
Expect(handler.SendMode()).To(Equal(SendAny))
|
Expect(handler.SendMode()).To(Equal(SendAny))
|
||||||
}
|
}
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: protocol.MaxOutstandingSentPackets}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: protocol.MaxOutstandingSentPackets}))
|
||||||
Expect(handler.SendMode()).To(Equal(SendAck))
|
Expect(handler.SendMode()).To(Equal(SendAck))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -569,8 +569,8 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't set an alarm if there are no outstanding packets", func() {
|
It("doesn't set an alarm if there are no outstanding packets", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 10}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 10}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 11}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 11}))
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 11}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 11}}}
|
||||||
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())
|
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -608,34 +608,34 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("sets the TPO send mode until two packets is sent", func() {
|
It("sets the TPO send mode until two packets is sent", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.OnAlarm()
|
handler.OnAlarm()
|
||||||
Expect(handler.SendMode()).To(Equal(SendPTO))
|
Expect(handler.SendMode()).To(Equal(SendPTO))
|
||||||
Expect(handler.ShouldSendNumPackets()).To(Equal(2))
|
Expect(handler.ShouldSendNumPackets()).To(Equal(2))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2}))
|
||||||
Expect(handler.SendMode()).To(Equal(SendPTO))
|
Expect(handler.SendMode()).To(Equal(SendPTO))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 3}))
|
||||||
Expect(handler.SendMode()).ToNot(Equal(SendPTO))
|
Expect(handler.SendMode()).ToNot(Equal(SendPTO))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("only counts retransmittable packets as probe packets", func() {
|
It("only counts ack-eliciting packets as probe packets", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.OnAlarm()
|
handler.OnAlarm()
|
||||||
Expect(handler.SendMode()).To(Equal(SendPTO))
|
Expect(handler.SendMode()).To(Equal(SendPTO))
|
||||||
Expect(handler.ShouldSendNumPackets()).To(Equal(2))
|
Expect(handler.ShouldSendNumPackets()).To(Equal(2))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2}))
|
||||||
Expect(handler.SendMode()).To(Equal(SendPTO))
|
Expect(handler.SendMode()).To(Equal(SendPTO))
|
||||||
for p := protocol.PacketNumber(3); p < 30; p++ {
|
for p := protocol.PacketNumber(3); p < 30; p++ {
|
||||||
handler.SentPacket(nonRetransmittablePacket(&Packet{PacketNumber: p}))
|
handler.SentPacket(nonAckElicitingPacket(&Packet{PacketNumber: p}))
|
||||||
Expect(handler.SendMode()).To(Equal(SendPTO))
|
Expect(handler.SendMode()).To(Equal(SendPTO))
|
||||||
}
|
}
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 30}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 30}))
|
||||||
Expect(handler.SendMode()).ToNot(Equal(SendPTO))
|
Expect(handler.SendMode()).ToNot(Equal(SendPTO))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("gets two probe packets if RTO expires", func() {
|
It("gets two probe packets if RTO expires", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2}))
|
||||||
|
|
||||||
updateRTT(time.Hour)
|
updateRTT(time.Hour)
|
||||||
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
||||||
|
@ -657,8 +657,8 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't delete packets transmitted as PTO from the history", func() {
|
It("doesn't delete packets transmitted as PTO from the history", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
||||||
handler.OnAlarm() // TLP
|
handler.OnAlarm() // TLP
|
||||||
handler.OnAlarm() // TLP
|
handler.OnAlarm() // TLP
|
||||||
|
@ -671,7 +671,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
|
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
|
||||||
// Send a probe packet and receive an ACK for it.
|
// Send a probe packet and receive an ACK for it.
|
||||||
// This verifies the RTO.
|
// This verifies the RTO.
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 3}))
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 3, Largest: 3}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 3, Largest: 3}}}
|
||||||
Expect(handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())).To(Succeed())
|
Expect(handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())).To(Succeed())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -681,7 +681,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("resets the send mode when it receives an acknowledgement after queueing probe packets", func() {
|
It("resets the send mode when it receives an acknowledgement after queueing probe packets", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
||||||
handler.OnAlarm()
|
handler.OnAlarm()
|
||||||
Expect(handler.SendMode()).To(Equal(SendPTO))
|
Expect(handler.SendMode()).To(Equal(SendPTO))
|
||||||
|
@ -691,11 +691,11 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("gets packets sent before the probe packet for retransmission", func() {
|
It("gets packets sent before the probe packet for retransmission", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 3, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 4, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 4, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 5, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.OnAlarm() // TLP
|
handler.OnAlarm() // TLP
|
||||||
handler.OnAlarm() // TLP
|
handler.OnAlarm() // TLP
|
||||||
handler.OnAlarm() // RTO
|
handler.OnAlarm() // RTO
|
||||||
|
@ -706,7 +706,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
expectInPacketHistory([]protocol.PacketNumber{1, 2, 3, 4, 5}, protocol.Encryption1RTT)
|
expectInPacketHistory([]protocol.PacketNumber{1, 2, 3, 4, 5}, protocol.Encryption1RTT)
|
||||||
// Send a probe packet and receive an ACK for it.
|
// Send a probe packet and receive an ACK for it.
|
||||||
// This verifies the RTO.
|
// This verifies the RTO.
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 6}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 6}))
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 6, Largest: 6}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 6, Largest: 6}}}
|
||||||
err = handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())
|
err = handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -716,12 +716,12 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("handles ACKs for the original packet", func() {
|
It("handles ACKs for the original packet", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 5, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
||||||
handler.OnAlarm() // TLP
|
handler.OnAlarm() // TLP
|
||||||
handler.OnAlarm() // TLP
|
handler.OnAlarm() // TLP
|
||||||
handler.OnAlarm() // RTO
|
handler.OnAlarm() // RTO
|
||||||
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 6})}, 5)
|
handler.SentPacketsAsRetransmission([]*Packet{ackElicitingPacket(&Packet{PacketNumber: 6})}, 5)
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
|
||||||
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())
|
err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -730,7 +730,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("handles ACKs for the original packet", func() {
|
It("handles ACKs for the original packet", func() {
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, SendTime: time.Now().Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 5, SendTime: time.Now().Add(-time.Hour)}))
|
||||||
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
handler.rttStats.UpdateRTT(time.Second, 0, time.Now())
|
||||||
err := handler.OnAlarm()
|
err := handler.OnAlarm()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -742,8 +742,8 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
Context("Delay-based loss detection", func() {
|
Context("Delay-based loss detection", func() {
|
||||||
It("immediately detects old packets as lost when receiving an ACK", func() {
|
It("immediately detects old packets as lost when receiving an ACK", func() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: now.Add(-time.Hour)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: now.Add(-time.Hour)}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: now.Add(-time.Second)}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: now.Add(-time.Second)}))
|
||||||
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
||||||
|
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
|
||||||
|
@ -758,9 +758,9 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
|
|
||||||
It("sets the early retransmit alarm", func() {
|
It("sets the early retransmit alarm", func() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1, SendTime: now.Add(-2 * time.Second), EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: now.Add(-2 * time.Second), EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: now.Add(-2 * time.Second), EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: now.Add(-2 * time.Second), EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3, SendTime: now.Add(-time.Second), EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 3, SendTime: now.Add(-time.Second), EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
Expect(handler.lossTime.IsZero()).To(BeTrue())
|
||||||
|
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
|
||||||
|
@ -791,7 +791,7 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
// send 1-RTT packet: 100
|
// send 1-RTT packet: 100
|
||||||
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 1, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 1, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
||||||
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 3, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 3, SendTime: sendTime, EncryptionLevel: protocol.EncryptionInitial}))
|
||||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 100, SendTime: sendTime, EncryptionLevel: protocol.Encryption1RTT}))
|
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 100, SendTime: sendTime, EncryptionLevel: protocol.Encryption1RTT}))
|
||||||
|
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
|
||||||
Expect(handler.ReceivedAck(ack, 1, protocol.EncryptionInitial, now)).To(Succeed())
|
Expect(handler.ReceivedAck(ack, 1, protocol.EncryptionInitial, now)).To(Succeed())
|
||||||
|
@ -824,11 +824,11 @@ var _ = Describe("SentPacketHandler", func() {
|
||||||
|
|
||||||
It("deletes crypto packets when the handshake completes", func() {
|
It("deletes crypto packets when the handshake completes", func() {
|
||||||
for i := protocol.PacketNumber(0); i < 6; i++ {
|
for i := protocol.PacketNumber(0); i < 6; i++ {
|
||||||
p := retransmittablePacket(&Packet{PacketNumber: i, EncryptionLevel: protocol.EncryptionInitial})
|
p := ackElicitingPacket(&Packet{PacketNumber: i, EncryptionLevel: protocol.EncryptionInitial})
|
||||||
handler.SentPacket(p)
|
handler.SentPacket(p)
|
||||||
}
|
}
|
||||||
for i := protocol.PacketNumber(0); i <= 6; i++ {
|
for i := protocol.PacketNumber(0); i <= 6; i++ {
|
||||||
p := retransmittablePacket(&Packet{PacketNumber: i, EncryptionLevel: protocol.EncryptionHandshake})
|
p := ackElicitingPacket(&Packet{PacketNumber: i, EncryptionLevel: protocol.EncryptionHandshake})
|
||||||
handler.SentPacket(p)
|
handler.SentPacket(p)
|
||||||
}
|
}
|
||||||
handler.queuePacketForRetransmission(getPacket(1, protocol.EncryptionInitial), handler.getPacketNumberSpace(protocol.EncryptionInitial))
|
handler.queuePacketForRetransmission(getPacket(1, protocol.EncryptionInitial), handler.getPacketNumberSpace(protocol.EncryptionInitial))
|
||||||
|
|
|
@ -208,7 +208,7 @@ var _ = Describe("SentPacketHistory", func() {
|
||||||
Expect(hist.HasOutstandingPackets()).To(BeTrue())
|
Expect(hist.HasOutstandingPackets()).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't consider non-retransmittable packets as outstanding", func() {
|
It("doesn't consider non-ack-eliciting packets as outstanding", func() {
|
||||||
hist.SentPacket(&Packet{
|
hist.SentPacket(&Packet{
|
||||||
EncryptionLevel: protocol.EncryptionInitial,
|
EncryptionLevel: protocol.EncryptionInitial,
|
||||||
})
|
})
|
||||||
|
@ -227,7 +227,7 @@ var _ = Describe("SentPacketHistory", func() {
|
||||||
Expect(hist.HasOutstandingPackets()).To(BeFalse())
|
Expect(hist.HasOutstandingPackets()).To(BeFalse())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't count packets marked as non-retransmittable", func() {
|
It("doesn't count packets marked as non-ack-eliciting", func() {
|
||||||
hist.SentPacket(&Packet{
|
hist.SentPacket(&Packet{
|
||||||
PacketNumber: 10,
|
PacketNumber: 10,
|
||||||
EncryptionLevel: protocol.Encryption1RTT,
|
EncryptionLevel: protocol.Encryption1RTT,
|
||||||
|
|
|
@ -73,8 +73,9 @@ const MaxTrackedSentPackets = MaxOutstandingSentPackets * 5 / 4
|
||||||
// MaxTrackedReceivedAckRanges is the maximum number of ACK ranges tracked
|
// MaxTrackedReceivedAckRanges is the maximum number of ACK ranges tracked
|
||||||
const MaxTrackedReceivedAckRanges = defaultMaxCongestionWindowPackets
|
const MaxTrackedReceivedAckRanges = defaultMaxCongestionWindowPackets
|
||||||
|
|
||||||
// MaxNonRetransmittableAcks is the maximum number of packets containing an ACK, but no retransmittable frames, that we send in a row
|
// MaxNonAckElicitingAcks is the maximum number of packets containing an ACK,
|
||||||
const MaxNonRetransmittableAcks = 19
|
// but no ack-eliciting frames, that we send in a row
|
||||||
|
const MaxNonAckElicitingAcks = 19
|
||||||
|
|
||||||
// MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames
|
// MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames
|
||||||
// prevents DoS attacks against the streamFrameSorter
|
// prevents DoS attacks against the streamFrameSorter
|
||||||
|
|
|
@ -47,8 +47,8 @@ func (p *packedPacket) EncryptionLevel() protocol.EncryptionLevel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *packedPacket) IsRetransmittable() bool {
|
func (p *packedPacket) IsAckEliciting() bool {
|
||||||
return ackhandler.HasRetransmittableFrames(p.frames)
|
return ackhandler.HasAckElicitingFrames(p.frames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *packedPacket) ToAckHandlerPacket() *ackhandler.Packet {
|
func (p *packedPacket) ToAckHandlerPacket() *ackhandler.Packet {
|
||||||
|
@ -116,7 +116,7 @@ type packetPacker struct {
|
||||||
acks ackFrameSource
|
acks ackFrameSource
|
||||||
|
|
||||||
maxPacketSize protocol.ByteCount
|
maxPacketSize protocol.ByteCount
|
||||||
numNonRetransmittableAcks int
|
numNonAckElicitingAcks int
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ packer = &packetPacker{}
|
var _ packer = &packetPacker{}
|
||||||
|
@ -271,15 +271,15 @@ func (p *packetPacker) PackPacket() (*packedPacket, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
// check if this packet only contains an ACK
|
// check if this packet only contains an ACK
|
||||||
if !ackhandler.HasRetransmittableFrames(frames) {
|
if !ackhandler.HasAckElicitingFrames(frames) {
|
||||||
if p.numNonRetransmittableAcks >= protocol.MaxNonRetransmittableAcks {
|
if p.numNonAckElicitingAcks >= protocol.MaxNonAckElicitingAcks {
|
||||||
frames = append(frames, &wire.PingFrame{})
|
frames = append(frames, &wire.PingFrame{})
|
||||||
p.numNonRetransmittableAcks = 0
|
p.numNonAckElicitingAcks = 0
|
||||||
} else {
|
} else {
|
||||||
p.numNonRetransmittableAcks++
|
p.numNonAckElicitingAcks++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.numNonRetransmittableAcks = 0
|
p.numNonAckElicitingAcks = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.writeAndSealPacket(header, frames, encLevel, sealer)
|
return p.writeAndSealPacket(header, frames, encLevel, sealer)
|
||||||
|
|
|
@ -340,9 +340,9 @@ var _ = Describe("Packet packer", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("making ACK packets retransmittable", func() {
|
Context("making ACK packets ack-eliciting", func() {
|
||||||
sendMaxNumNonRetransmittableAcks := func() {
|
sendMaxNumNonAckElicitingAcks := func() {
|
||||||
for i := 0; i < protocol.MaxNonRetransmittableAcks; i++ {
|
for i := 0; i < protocol.MaxNonAckElicitingAcks; i++ {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||||
|
@ -356,8 +356,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
It("adds a PING frame when it's supposed to send a retransmittable packet", func() {
|
It("adds a PING frame when it's supposed to send a ack-eliciting packet", func() {
|
||||||
sendMaxNumNonRetransmittableAcks()
|
sendMaxNumNonAckElicitingAcks()
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||||
|
@ -382,7 +382,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("waits until there's something to send before adding a PING frame", func() {
|
It("waits until there's something to send before adding a PING frame", func() {
|
||||||
sendMaxNumNonRetransmittableAcks()
|
sendMaxNumNonAckElicitingAcks()
|
||||||
// nothing to send
|
// nothing to send
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||||
|
@ -405,8 +405,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(p.frames).To(ContainElement(&wire.PingFrame{}))
|
Expect(p.frames).To(ContainElement(&wire.PingFrame{}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't send a PING if it already sent another retransmittable frame", func() {
|
It("doesn't send a PING if it already sent another ack-elicitng frame", func() {
|
||||||
sendMaxNumNonRetransmittableAcks()
|
sendMaxNumNonAckElicitingAcks()
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||||
|
|
24
session.go
24
session.go
|
@ -136,8 +136,8 @@ type session struct {
|
||||||
sessionCreationTime time.Time
|
sessionCreationTime time.Time
|
||||||
// The idle timeout is set based on the max of the time we received the last packet...
|
// The idle timeout is set based on the max of the time we received the last packet...
|
||||||
lastPacketReceivedTime time.Time
|
lastPacketReceivedTime time.Time
|
||||||
// ... and the time we sent a new retransmittable packet after receiving a packet.
|
// ... and the time we sent a new ack-eliciting packet after receiving a packet.
|
||||||
firstRetransmittablePacketAfterIdleSentTime time.Time
|
firstAckElicitingPacketAfterIdleSentTime time.Time
|
||||||
// pacingDeadline is the time when the next packet should be sent
|
// pacingDeadline is the time when the next packet should be sent
|
||||||
pacingDeadline time.Time
|
pacingDeadline time.Time
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ runLoop:
|
||||||
if s.pacingDeadline.IsZero() { // the timer didn't have a pacing deadline set
|
if s.pacingDeadline.IsZero() { // the timer didn't have a pacing deadline set
|
||||||
pacingDeadline = s.sentPacketHandler.TimeUntilSend()
|
pacingDeadline = s.sentPacketHandler.TimeUntilSend()
|
||||||
}
|
}
|
||||||
if s.config.KeepAlive && !s.keepAlivePingSent && s.handshakeComplete && s.firstRetransmittablePacketAfterIdleSentTime.IsZero() && time.Since(s.lastPacketReceivedTime) >= s.peerParams.IdleTimeout/2 {
|
if s.config.KeepAlive && !s.keepAlivePingSent && s.handshakeComplete && s.firstAckElicitingPacketAfterIdleSentTime.IsZero() && time.Since(s.lastPacketReceivedTime) >= s.peerParams.IdleTimeout/2 {
|
||||||
// send a PING frame since there is no activity in the session
|
// send a PING frame since there is no activity in the session
|
||||||
s.logger.Debugf("Sending a keep-alive ping to keep the connection alive.")
|
s.logger.Debugf("Sending a keep-alive ping to keep the connection alive.")
|
||||||
s.framer.QueueControlFrame(&wire.PingFrame{})
|
s.framer.QueueControlFrame(&wire.PingFrame{})
|
||||||
|
@ -469,7 +469,7 @@ func (s *session) maybeResetTimer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) idleTimeoutStartTime() time.Time {
|
func (s *session) idleTimeoutStartTime() time.Time {
|
||||||
return utils.MaxTime(s.lastPacketReceivedTime, s.firstRetransmittablePacketAfterIdleSentTime)
|
return utils.MaxTime(s.lastPacketReceivedTime, s.firstAckElicitingPacketAfterIdleSentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) handleHandshakeComplete() {
|
func (s *session) handleHandshakeComplete() {
|
||||||
|
@ -481,7 +481,7 @@ func (s *session) handleHandshakeComplete() {
|
||||||
// We need to make sure they learn about the peer completing the handshake,
|
// We need to make sure they learn about the peer completing the handshake,
|
||||||
// in order to stop retransmitting handshake packets.
|
// in order to stop retransmitting handshake packets.
|
||||||
// They will stop retransmitting handshake packets when receiving the first forward-secure packet.
|
// They will stop retransmitting handshake packets when receiving the first forward-secure packet.
|
||||||
// We need to make sure that a retransmittable forward-secure packet is sent,
|
// We need to make sure that an ack-eliciting 1-RTT packet is sent,
|
||||||
// independent from the application protocol.
|
// independent from the application protocol.
|
||||||
if s.perspective == protocol.PerspectiveServer {
|
if s.perspective == protocol.PerspectiveServer {
|
||||||
s.queueControlFrame(&wire.PingFrame{})
|
s.queueControlFrame(&wire.PingFrame{})
|
||||||
|
@ -638,7 +638,7 @@ func (s *session) handleUnpackedPacket(packet *unpackedPacket, rcvTime time.Time
|
||||||
|
|
||||||
s.receivedFirstPacket = true
|
s.receivedFirstPacket = true
|
||||||
s.lastPacketReceivedTime = rcvTime
|
s.lastPacketReceivedTime = rcvTime
|
||||||
s.firstRetransmittablePacketAfterIdleSentTime = time.Time{}
|
s.firstAckElicitingPacketAfterIdleSentTime = time.Time{}
|
||||||
s.keepAlivePingSent = false
|
s.keepAlivePingSent = false
|
||||||
|
|
||||||
// The client completes the handshake first (after sending the CFIN).
|
// The client completes the handshake first (after sending the CFIN).
|
||||||
|
@ -651,7 +651,7 @@ func (s *session) handleUnpackedPacket(packet *unpackedPacket, rcvTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
r := bytes.NewReader(packet.data)
|
r := bytes.NewReader(packet.data)
|
||||||
var isRetransmittable bool
|
var isAckEliciting bool
|
||||||
for {
|
for {
|
||||||
frame, err := s.frameParser.ParseNext(r, packet.encryptionLevel)
|
frame, err := s.frameParser.ParseNext(r, packet.encryptionLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -660,15 +660,15 @@ func (s *session) handleUnpackedPacket(packet *unpackedPacket, rcvTime time.Time
|
||||||
if frame == nil {
|
if frame == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if ackhandler.IsFrameRetransmittable(frame) {
|
if ackhandler.IsFrameAckEliciting(frame) {
|
||||||
isRetransmittable = true
|
isAckEliciting = true
|
||||||
}
|
}
|
||||||
if err := s.handleFrame(frame, packet.packetNumber, packet.encryptionLevel); err != nil {
|
if err := s.handleFrame(frame, packet.packetNumber, packet.encryptionLevel); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.receivedPacketHandler.ReceivedPacket(packet.packetNumber, packet.encryptionLevel, rcvTime, isRetransmittable); err != nil {
|
if err := s.receivedPacketHandler.ReceivedPacket(packet.packetNumber, packet.encryptionLevel, rcvTime, isAckEliciting); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -1113,8 +1113,8 @@ func (s *session) sendPacket() (bool, error) {
|
||||||
|
|
||||||
func (s *session) sendPackedPacket(packet *packedPacket) error {
|
func (s *session) sendPackedPacket(packet *packedPacket) error {
|
||||||
defer packet.buffer.Release()
|
defer packet.buffer.Release()
|
||||||
if s.firstRetransmittablePacketAfterIdleSentTime.IsZero() && packet.IsRetransmittable() {
|
if s.firstAckElicitingPacketAfterIdleSentTime.IsZero() && packet.IsAckEliciting() {
|
||||||
s.firstRetransmittablePacketAfterIdleSentTime = time.Now()
|
s.firstAckElicitingPacketAfterIdleSentTime = time.Now()
|
||||||
}
|
}
|
||||||
s.logPacket(packet)
|
s.logPacket(packet)
|
||||||
return s.conn.Write(packet.raw)
|
return s.conn.Write(packet.raw)
|
||||||
|
|
|
@ -493,7 +493,7 @@ var _ = Describe("Session", func() {
|
||||||
Expect(sess.handlePacketImpl(getPacket(&wire.ExtendedHeader{Header: hdr}, nil))).To(BeFalse())
|
Expect(sess.handlePacketImpl(getPacket(&wire.ExtendedHeader{Header: hdr}, nil))).To(BeFalse())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("informs the ReceivedPacketHandler about non-retransmittable packets", func() {
|
It("informs the ReceivedPacketHandler about non-ack-eliciting packets", func() {
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{DestConnectionID: sess.srcConnID},
|
Header: wire.Header{DestConnectionID: sess.srcConnID},
|
||||||
PacketNumber: 0x37,
|
PacketNumber: 0x37,
|
||||||
|
@ -514,7 +514,7 @@ var _ = Describe("Session", func() {
|
||||||
Expect(sess.handlePacketImpl(packet)).To(BeTrue())
|
Expect(sess.handlePacketImpl(packet)).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("informs the ReceivedPacketHandler about retransmittable packets", func() {
|
It("informs the ReceivedPacketHandler about ack-eliciting packets", func() {
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{DestConnectionID: sess.srcConnID},
|
Header: wire.Header{DestConnectionID: sess.srcConnID},
|
||||||
PacketNumber: 0x37,
|
PacketNumber: 0x37,
|
||||||
|
@ -1403,7 +1403,7 @@ var _ = Describe("Session", func() {
|
||||||
It("doesn't time out when it just sent a packet", func() {
|
It("doesn't time out when it just sent a packet", func() {
|
||||||
sess.handshakeComplete = true
|
sess.handshakeComplete = true
|
||||||
sess.lastPacketReceivedTime = time.Now().Add(-time.Hour)
|
sess.lastPacketReceivedTime = time.Now().Add(-time.Hour)
|
||||||
sess.firstRetransmittablePacketAfterIdleSentTime = time.Now().Add(-time.Second)
|
sess.firstAckElicitingPacketAfterIdleSentTime = time.Now().Add(-time.Second)
|
||||||
sess.config.IdleTimeout = 30 * time.Second
|
sess.config.IdleTimeout = 30 * time.Second
|
||||||
go func() {
|
go func() {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue