don't send more packets when there are too many unacked

fixes #249, fixes #322
This commit is contained in:
Lucas Clemente
2016-09-08 11:21:03 +02:00
parent 2ca0fb7d21
commit a0fb14381e
5 changed files with 18 additions and 10 deletions

View File

@@ -20,7 +20,7 @@ type SentPacketHandler interface {
BytesInFlight() protocol.ByteCount
GetLeastUnacked() protocol.PacketNumber
CongestionAllowsSending() bool
SendingAllowed() bool
CheckForError() error
TimeOfFirstRTO() time.Time

View File

@@ -269,8 +269,10 @@ func (h *sentPacketHandler) GetStopWaitingFrame(force bool) *frames.StopWaitingF
return h.stopWaitingManager.GetStopWaitingFrame(force)
}
func (h *sentPacketHandler) CongestionAllowsSending() bool {
return h.BytesInFlight() <= h.congestion.GetCongestionWindow()
func (h *sentPacketHandler) SendingAllowed() bool {
congestionLimited := h.BytesInFlight() > h.congestion.GetCongestionWindow()
maxTrackedLimited := protocol.PacketNumber(len(h.retransmissionQueue)+h.packetHistory.Len()) >= protocol.MaxTrackedSentPackets
return !(congestionLimited || maxTrackedLimited)
}
func (h *sentPacketHandler) CheckForError() error {

View File

@@ -741,11 +741,17 @@ var _ = Describe("SentPacketHandler", func() {
Expect(cong.argsOnCongestionEvent[3]).To(Equal(congestion.PacketVector{{Number: 2, Length: 2}}))
})
It("allows or denies sending", func() {
Expect(handler.CongestionAllowsSending()).To(BeTrue())
It("allows or denies sending based on congestion", func() {
Expect(handler.SendingAllowed()).To(BeTrue())
err := handler.SentPacket(&Packet{PacketNumber: 1, Frames: []frames.Frame{}, Length: protocol.DefaultTCPMSS + 1})
Expect(err).NotTo(HaveOccurred())
Expect(handler.CongestionAllowsSending()).To(BeFalse())
Expect(handler.SendingAllowed()).To(BeFalse())
})
It("allows or denies sending based on the number of tracked packets", func() {
Expect(handler.SendingAllowed()).To(BeTrue())
handler.retransmissionQueue = make([]*Packet, protocol.MaxTrackedSentPackets)
Expect(handler.SendingAllowed()).To(BeFalse())
})
It("should call OnRetransmissionTimeout", func() {

View File

@@ -444,7 +444,7 @@ func (s *Session) sendPacket() error {
// Do this before checking the congestion, since we might de-congestionize here :)
s.sentPacketHandler.MaybeQueueRTOs()
if !s.sentPacketHandler.CongestionAllowsSending() {
if !s.sentPacketHandler.SendingAllowed() {
return nil
}

View File

@@ -67,9 +67,9 @@ func (h *mockSentPacketHandler) GetStopWaitingFrame(force bool) *frames.StopWait
h.requestedStopWaiting = true
return &frames.StopWaitingFrame{LeastUnacked: 0x1337}
}
func (h *mockSentPacketHandler) CongestionAllowsSending() bool { return !h.congestionLimited }
func (h *mockSentPacketHandler) CheckForError() error { return nil }
func (h *mockSentPacketHandler) TimeOfFirstRTO() time.Time { panic("not implemented") }
func (h *mockSentPacketHandler) SendingAllowed() bool { return !h.congestionLimited }
func (h *mockSentPacketHandler) CheckForError() error { return nil }
func (h *mockSentPacketHandler) TimeOfFirstRTO() time.Time { panic("not implemented") }
func (h *mockSentPacketHandler) MaybeQueueRTOs() {
h.maybeQueueRTOsCalled = true