From 0a233a39b94c0b3b0cd871c1dcc4ab4851bba76a Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Wed, 18 May 2016 22:43:32 +0200 Subject: [PATCH] add utils.InfDuration constant --- congestion/cubic_sender.go | 3 +-- congestion/prr_sender.go | 6 +++--- congestion/prr_sender_test.go | 12 +++++------- congestion/rtt_stats.go | 7 +++---- congestion/rtt_stats_test.go | 4 ++-- utils/minmax.go | 4 ++++ 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/congestion/cubic_sender.go b/congestion/cubic_sender.go index 8e8285c1..a34a69df 100644 --- a/congestion/cubic_sender.go +++ b/congestion/cubic_sender.go @@ -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 { diff --git a/congestion/prr_sender.go b/congestion/prr_sender.go index f9f6db23..f8e6d59c 100644 --- a/congestion/prr_sender.go +++ b/congestion/prr_sender.go @@ -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 } diff --git a/congestion/prr_sender_test.go b/congestion/prr_sender_test.go index 66ad5881..5af07b77 100644 --- a/congestion/prr_sender_test.go +++ b/congestion/prr_sender_test.go @@ -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. diff --git a/congestion/rtt_stats.go b/congestion/rtt_stats.go index 0a319337..0bf7b05d 100644 --- a/congestion/rtt_stats.go +++ b/congestion/rtt_stats.go @@ -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{} diff --git a/congestion/rtt_stats_test.go b/congestion/rtt_stats_test.go index f28a9235..b0e0aeae 100644 --- a/congestion/rtt_stats_test.go +++ b/congestion/rtt_stats_test.go @@ -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(); diff --git a/utils/minmax.go b/utils/minmax.go index 55796504..e8eee589 100644 --- a/utils/minmax.go +++ b/utils/minmax.go @@ -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 {