From 7467e7ebff40e66ed9d2fb1aa5ab4efbd511332d Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 24 Apr 2016 20:28:37 +0700 Subject: [PATCH] OutgoingPacketAckHandler queues packets for retransmission --- ackhandler/outgoing_packet_ack_handler.go | 13 +++++++-- .../outgoing_packet_ack_handler_test.go | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ackhandler/outgoing_packet_ack_handler.go b/ackhandler/outgoing_packet_ack_handler.go index 1f5698d6..bdbc9349 100644 --- a/ackhandler/outgoing_packet_ack_handler.go +++ b/ackhandler/outgoing_packet_ack_handler.go @@ -9,8 +9,9 @@ import ( ) var ( - errEntropy = errors.New("OutgoingPacketAckHandler: Wrong entropy") - errMapAccess = errors.New("OutgoingPacketAckHandler: Packet does not exist in PacketHistory") + errEntropy = errors.New("OutgoingPacketAckHandler: Wrong entropy") + errMapAccess = errors.New("OutgoingPacketAckHandler: Packet does not exist in PacketHistory") + retransmissionThreshold = uint8(1) // ToDo: use 3 as recommended in the RFC here ) type outgoingPacketAckHandler struct { @@ -20,6 +21,7 @@ type outgoingPacketAckHandler struct { LargestObserved protocol.PacketNumber packetHistory map[protocol.PacketNumber]*Packet packetHistoryMutex sync.Mutex + retransmissionQueue []*Packet // ToDo: use better data structure } // NewOutgoingPacketAckHandler creates a new outgoingPacketAckHandler @@ -164,7 +166,12 @@ func (h *outgoingPacketAckHandler) ReceivedAck(ackFrame *frames.AckFrame) error return errMapAccess } packet.MissingReports++ - // ToDo: do something as when packet.MissionReports > threshold + // send out the packet again when it has been NACK more than retransmissionThreshold times + if packet.MissingReports > retransmissionThreshold { + fmt.Printf("Should retransmit packet %d\n", packet.PacketNumber) + h.retransmissionQueue = append(h.retransmissionQueue, packet) + // ToDo: delete the packet from the history, as if it had been acked + } } // ToDo: delete packet from history, since it already has been ACKed } diff --git a/ackhandler/outgoing_packet_ack_handler_test.go b/ackhandler/outgoing_packet_ack_handler_test.go index 3c55a02a..899cd92a 100644 --- a/ackhandler/outgoing_packet_ack_handler_test.go +++ b/ackhandler/outgoing_packet_ack_handler_test.go @@ -310,5 +310,33 @@ var _ = Describe("AckHandler", func() { Expect(handler.packetHistory[4].MissingReports).To(Equal(uint8(1))) }) }) + + Context("Retransmission handler", func() { + It("queues a packet for retransmission", func() { + retransmissionThreshold = 1 + nackRange1 := frames.NackRange{FirstPacketNumber: 4, LastPacketNumber: 4} + nackRange2 := frames.NackRange{FirstPacketNumber: 2, LastPacketNumber: 2} + entropy := EntropyAccumulator(0) + entropy.Add(1, packets[0].EntropyBit) + entropy.Add(3, packets[2].EntropyBit) + ack1 := frames.AckFrame{ + LargestObserved: 3, + Entropy: byte(entropy), + NackRanges: []frames.NackRange{nackRange2}, + } + err := handler.ReceivedAck(&ack1) + Expect(err).ToNot(HaveOccurred()) + entropy.Add(5, packets[4].EntropyBit) + ack2 := frames.AckFrame{ + LargestObserved: 5, + Entropy: byte(entropy), + NackRanges: []frames.NackRange{nackRange1, nackRange2}, + } + err = handler.ReceivedAck(&ack2) + Expect(err).ToNot(HaveOccurred()) + Expect(len(handler.retransmissionQueue)).To(Equal(1)) + Expect(handler.retransmissionQueue[0].PacketNumber).To(Equal(protocol.PacketNumber(2))) + }) + }) }) })