implement timeout-based retransmission (RTO)

fixes #56
This commit is contained in:
Lucas Clemente
2016-05-18 23:21:33 +02:00
parent 0a233a39b9
commit 4822def788
6 changed files with 170 additions and 8 deletions

View File

@@ -251,6 +251,8 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *frames.AckFrame) error {
}
func (h *sentPacketHandler) HasPacketForRetransmission() bool {
h.queuePacketsRTO()
if len(h.retransmissionQueue) > 0 {
return true
}
@@ -288,3 +290,33 @@ func (h *sentPacketHandler) getRTO() time.Duration {
}
return utils.MaxDuration(rto, protocol.MinRetransmissionTime)
}
func (h *sentPacketHandler) queuePacketsRTO() {
queued := false
now := time.Now()
for _, p := range h.packetHistory {
if p == nil || p.Retransmitted || p.rtoTime.After(now) {
continue
}
h.queuePacketForRetransmission(p)
queued = true
}
if queued {
h.congestion.OnRetransmissionTimeout(true)
}
}
func (h *sentPacketHandler) TimeToFirstRTO() time.Duration {
now := time.Now()
min := utils.InfDuration
for _, p := range h.packetHistory {
if p == nil || p.Retransmitted {
continue
}
if now.After(p.rtoTime) {
return 0
}
min = utils.MinDuration(min, p.rtoTime.Sub(now))
}
return min
}