add utils.InfDuration constant

This commit is contained in:
Lucas Clemente
2016-05-18 22:43:32 +02:00
parent 753f219638
commit 0a233a39b9
6 changed files with 18 additions and 18 deletions

View File

@@ -1,7 +1,6 @@
package congestion
import (
"math"
"time"
"github.com/lucas-clemente/quic-go/protocol"
@@ -85,7 +84,7 @@ func (c *cubicSender) TimeUntilSend(now time.Time, bytesInFlight protocol.ByteCo
if c.GetCongestionWindow() > bytesInFlight {
return 0
}
return math.MaxInt64
return utils.InfDuration
}
func (c *cubicSender) OnPacketSent(sentTime time.Time, bytesInFlight protocol.ByteCount, packetNumber protocol.PacketNumber, bytes protocol.ByteCount, isRetransmittable bool) bool {

View File

@@ -1,10 +1,10 @@
package congestion
import (
"math"
"time"
"github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/utils"
)
// PrrSender implements the Proportional Rate Reduction (PRR) per RFC 6937
@@ -48,7 +48,7 @@ func (p *PrrSender) TimeUntilSend(congestionWindow, bytesInFlight, slowstartThre
// when more packets are lost than the CWND reduction.
// limit = MAX(prr_delivered - prr_out, DeliveredData) + MSS
if p.bytesDeliveredSinceLoss+p.ackCountSinceLoss*protocol.DefaultTCPMSS <= p.bytesSentSinceLoss {
return math.MaxInt64
return utils.InfDuration
}
return 0
}
@@ -59,5 +59,5 @@ func (p *PrrSender) TimeUntilSend(congestionWindow, bytesInFlight, slowstartThre
if p.bytesDeliveredSinceLoss*slowstartThreshold > p.bytesSentSinceLoss*p.bytesInFlightBeforeLoss {
return 0
}
return math.MaxInt64
return utils.InfDuration
}

View File

@@ -1,14 +1,12 @@
package congestion_test
import (
"math"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/lucas-clemente/quic-go/congestion"
"github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/utils"
)
var _ = Describe("PRR sender", func() {
@@ -34,7 +32,7 @@ var _ = Describe("PRR sender", func() {
// Send retransmission.
prr.OnPacketSent(protocol.DefaultTCPMSS)
// PRR shouldn't allow sending any more packets.
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(time.Duration(math.MaxInt64)))
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration))
// One packet is lost, and one ack was consumed above. PRR now paces
// transmissions through the remaining 48 acks. PRR will alternatively
@@ -43,7 +41,7 @@ var _ = Describe("PRR sender", func() {
// Ack a packet. PRR shouldn't allow sending a packet in response.
prr.OnPacketAcked(protocol.DefaultTCPMSS)
bytes_in_flight -= protocol.DefaultTCPMSS
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(time.Duration(math.MaxInt64)))
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration))
// Ack another packet. PRR should now allow sending a packet in response.
prr.OnPacketAcked(protocol.DefaultTCPMSS)
bytes_in_flight -= protocol.DefaultTCPMSS
@@ -68,7 +66,7 @@ var _ = Describe("PRR sender", func() {
// Since bytes_in_flight is equal to the congestion_window,
// PRR disallows sending.
Expect(bytes_in_flight).To(Equal(congestion_window))
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(time.Duration(math.MaxInt64)))
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration))
}
})
@@ -95,7 +93,7 @@ var _ = Describe("PRR sender", func() {
bytes_in_flight += protocol.DefaultTCPMSS
}
// PRR should allow no more than 2 packets in response to an ack.
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(time.Duration(math.MaxInt64)))
Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration))
}
// Out of SSRB mode, PRR allows one send in response to each ack.

View File

@@ -1,7 +1,6 @@
package congestion
import (
"math"
"time"
"github.com/lucas-clemente/quic-go/utils"
@@ -44,7 +43,7 @@ type RTTStats struct {
func NewRTTStats() *RTTStats {
return &RTTStats{
initialRTTus: initialRTTus,
recentMinRTTwindow: math.MaxInt64,
recentMinRTTwindow: utils.InfDuration,
}
}
@@ -83,7 +82,7 @@ func (r *RTTStats) SetRecentMinRTTwindow(recentMinRTTwindow time.Duration) {
// UpdateRTT updates the RTT based on a new sample.
func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) {
if sendDelta == math.MaxInt64 || sendDelta <= 0 {
if sendDelta == utils.InfDuration || sendDelta <= 0 {
utils.Debugf("Ignoring measured sendDelta, because it's is either infinite, zero, or negative: %d", sendDelta/time.Microsecond)
return
}
@@ -168,7 +167,7 @@ func (r *RTTStats) OnConnectionMigration() {
r.meanDeviation = 0
r.initialRTTus = initialRTTus
r.numMinRTTsamplesRemaining = 0
r.recentMinRTTwindow = math.MaxInt64
r.recentMinRTTwindow = utils.InfDuration
r.recentMinRTT = rttSample{}
r.halfWindowRTT = rttSample{}
r.quarterWindowRTT = rttSample{}

View File

@@ -1,10 +1,10 @@
package congestion_test
import (
"math"
"time"
"github.com/lucas-clemente/quic-go/congestion"
"github.com/lucas-clemente/quic-go/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@@ -181,7 +181,7 @@ var _ = Describe("RTT stats", func() {
bad_send_deltas := []time.Duration{
0,
math.MaxInt64,
utils.InfDuration,
-1000 * time.Microsecond,
}
// log.StartCapturingLogs();

View File

@@ -1,11 +1,15 @@
package utils
import (
"math"
"time"
"github.com/lucas-clemente/quic-go/protocol"
)
// InfDuration is a duration of infinite length
const InfDuration = time.Duration(math.MaxInt64)
// Max returns the maximum of two Ints
func Max(a, b int) int {
if a < b {