OutgoingPacketAckHandler queues packets for retransmission

This commit is contained in:
Marten Seemann 2016-04-24 20:28:37 +07:00
parent 76d4b7a931
commit 7467e7ebff
2 changed files with 38 additions and 3 deletions

View file

@ -11,6 +11,7 @@ import (
var (
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
}

View file

@ -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)))
})
})
})
})