simplify pacing logic by introducing a SendPacingLimited send mode

This commit is contained in:
Marten Seemann
2023-04-30 11:44:43 +02:00
parent 470ae7b39b
commit 9d70bc24a5
8 changed files with 28 additions and 47 deletions

View File

@@ -24,8 +24,6 @@ type SentPacketHandler interface {
// TimeUntilSend is the time when the next packet should be sent.
// It is used for pacing packets.
TimeUntilSend() time.Time
// HasPacingBudget says if the pacer allows sending of a (full size) packet at this moment.
HasPacingBudget() bool
SetMaxDatagramSize(count protocol.ByteCount)
// only to be called once the handshake is complete

View File

@@ -16,6 +16,10 @@ const (
SendPTOHandshake
// SendPTOAppData means that an Application data probe packet should be sent
SendPTOAppData
// SendPacingLimited means that the pacer doesn't allow sending of a packet right now,
// but will do in a little while.
// The timestamp when sending is allowed again can be obtained via the SentPacketHandler.TimeUntilSend.
SendPacingLimited
// SendAny means that any packet should be sent
SendAny
)
@@ -34,6 +38,8 @@ func (s SendMode) String() string {
return "pto (Application Data)"
case SendAny:
return "any"
case SendPacingLimited:
return "pacing limited"
default:
return fmt.Sprintf("invalid send mode: %d", s)
}

View File

@@ -9,6 +9,7 @@ var _ = Describe("Send Mode", func() {
It("has a string representation", func() {
Expect(SendNone.String()).To(Equal("none"))
Expect(SendAny.String()).To(Equal("any"))
Expect(SendPacingLimited.String()).To(Equal("pacing limited"))
Expect(SendAck.String()).To(Equal("ack"))
Expect(SendPTOInitial.String()).To(Equal("pto (Initial)"))
Expect(SendPTOHandshake.String()).To(Equal("pto (Handshake)"))

View File

@@ -756,6 +756,9 @@ func (h *sentPacketHandler) SendMode() SendMode {
}
return SendAck
}
if !h.congestion.HasPacingBudget() {
return SendPacingLimited
}
return SendAny
}

View File

@@ -599,12 +599,14 @@ var _ = Describe("SentPacketHandler", func() {
SendTime: time.Now(),
})
cong.EXPECT().CanSend(protocol.ByteCount(42)).Return(true)
cong.EXPECT().HasPacingBudget().Return(true)
handler.SendMode()
})
It("allows sending of ACKs when congestion limited", func() {
handler.ReceivedPacket(protocol.EncryptionHandshake)
cong.EXPECT().CanSend(gomock.Any()).Return(true)
cong.EXPECT().HasPacingBudget().Return(true)
Expect(handler.SendMode()).To(Equal(SendAny))
cong.EXPECT().CanSend(gomock.Any()).Return(false)
Expect(handler.SendMode()).To(Equal(SendAck))
@@ -613,6 +615,7 @@ var _ = Describe("SentPacketHandler", func() {
It("allows sending of ACKs when we're keeping track of MaxOutstandingSentPackets packets", func() {
handler.ReceivedPacket(protocol.EncryptionHandshake)
cong.EXPECT().CanSend(gomock.Any()).Return(true).AnyTimes()
cong.EXPECT().HasPacingBudget().Return(true).AnyTimes()
cong.EXPECT().OnPacketSent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
for i := protocol.PacketNumber(0); i < protocol.MaxOutstandingSentPackets; i++ {
Expect(handler.SendMode()).To(Equal(SendAny))
@@ -889,6 +892,7 @@ var _ = Describe("SentPacketHandler", func() {
Context("amplification limit, for the server", func() {
It("limits the window to 3x the bytes received, to avoid amplification attacks", func() {
now := time.Now()
handler.ReceivedPacket(protocol.EncryptionInitial) // receiving an Initial packet doesn't validate the client's address
handler.ReceivedBytes(200)
handler.SentPacket(&Packet{
@@ -896,7 +900,7 @@ var _ = Describe("SentPacketHandler", func() {
Length: 599,
EncryptionLevel: protocol.EncryptionInitial,
Frames: []Frame{{Frame: &wire.PingFrame{}}},
SendTime: time.Now(),
SendTime: now,
})
Expect(handler.SendMode()).To(Equal(SendAny))
handler.SentPacket(&Packet{
@@ -904,7 +908,7 @@ var _ = Describe("SentPacketHandler", func() {
Length: 1,
EncryptionLevel: protocol.EncryptionInitial,
Frames: []Frame{{Frame: &wire.PingFrame{}}},
SendTime: time.Now(),
SendTime: now,
})
Expect(handler.SendMode()).To(Equal(SendNone))
})