forked from quic-go/quic-go
utils: remove scarcely used time helper functions (#4593)
This commit is contained in:
@@ -706,10 +706,10 @@ func (s *connection) nextKeepAliveTime() time.Time {
|
||||
func (s *connection) maybeResetTimer() {
|
||||
var deadline time.Time
|
||||
if !s.handshakeComplete {
|
||||
deadline = utils.MinTime(
|
||||
s.creationTime.Add(s.config.handshakeTimeout()),
|
||||
s.idleTimeoutStartTime().Add(s.config.HandshakeIdleTimeout),
|
||||
)
|
||||
deadline = s.creationTime.Add(s.config.handshakeTimeout())
|
||||
if t := s.idleTimeoutStartTime().Add(s.config.HandshakeIdleTimeout); t.Before(deadline) {
|
||||
deadline = t
|
||||
}
|
||||
} else {
|
||||
if keepAliveTime := s.nextKeepAliveTime(); !keepAliveTime.IsZero() {
|
||||
deadline = keepAliveTime
|
||||
@@ -727,7 +727,11 @@ func (s *connection) maybeResetTimer() {
|
||||
}
|
||||
|
||||
func (s *connection) idleTimeoutStartTime() time.Time {
|
||||
return utils.MaxTime(s.lastPacketReceivedTime, s.firstAckElicitingPacketAfterIdleSentTime)
|
||||
startTime := s.lastPacketReceivedTime
|
||||
if t := s.firstAckElicitingPacketAfterIdleSentTime; t.After(startTime) {
|
||||
startTime = t
|
||||
}
|
||||
return startTime
|
||||
}
|
||||
|
||||
func (s *connection) handleHandshakeComplete() error {
|
||||
@@ -1767,7 +1771,10 @@ func (s *connection) checkTransportParameters(params *wire.TransportParameters)
|
||||
func (s *connection) applyTransportParameters() {
|
||||
params := s.peerParams
|
||||
// Our local idle timeout will always be > 0.
|
||||
s.idleTimeout = utils.MinNonZeroDuration(s.config.MaxIdleTimeout, params.MaxIdleTimeout)
|
||||
s.idleTimeout = s.config.MaxIdleTimeout
|
||||
if s.idleTimeout > 0 && params.MaxIdleTimeout < s.idleTimeout {
|
||||
s.idleTimeout = params.MaxIdleTimeout
|
||||
}
|
||||
s.keepAliveInterval = min(s.config.KeepAlivePeriod, min(s.idleTimeout/2, protocol.MaxKeepAliveInterval))
|
||||
s.streamsMap.UpdateLimits(params)
|
||||
s.frameParser.SetAckDelayExponent(params.AckDelayExponent)
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
|
||||
"github.com/quic-go/quic-go/internal/utils"
|
||||
"github.com/quic-go/quic-go/logging"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -235,7 +234,7 @@ var _ = Describe("Timeout tests", func() {
|
||||
// We're ignoring here that only the first ack-eliciting packet sent resets the idle timeout.
|
||||
// This is ok since we're dealing with a lossless connection here,
|
||||
// and we'd expect to receive an ACK for additional other ack-eliciting packet sent.
|
||||
Expect(time.Since(utils.MaxTime(lastAckElicitingPacketSentAt, lastPacketRcvdAt))).To(And(
|
||||
Expect(max(time.Since(lastAckElicitingPacketSentAt), time.Since(lastPacketRcvdAt))).To(And(
|
||||
BeNumerically(">=", idleTimeout),
|
||||
BeNumerically("<", idleTimeout*6/5),
|
||||
))
|
||||
|
||||
@@ -116,7 +116,7 @@ var _ = Describe("Cubic Sender", func() {
|
||||
AckNPackets(1)
|
||||
delay := sender.TimeUntilSend(bytesInFlight)
|
||||
Expect(delay).ToNot(BeZero())
|
||||
Expect(delay).ToNot(Equal(utils.InfDuration))
|
||||
Expect(delay.Sub(clock.Now())).To(BeNumerically("<", time.Hour))
|
||||
})
|
||||
|
||||
It("application limited slow start", func() {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// InfDuration is a duration of infinite length
|
||||
const InfDuration = time.Duration(math.MaxInt64)
|
||||
|
||||
// MinNonZeroDuration return the minimum duration that's not zero.
|
||||
func MinNonZeroDuration(a, b time.Duration) time.Duration {
|
||||
if a == 0 {
|
||||
return b
|
||||
}
|
||||
if b == 0 {
|
||||
return a
|
||||
}
|
||||
return min(a, b)
|
||||
}
|
||||
|
||||
// MinTime returns the earlier time
|
||||
func MinTime(a, b time.Time) time.Time {
|
||||
if a.After(b) {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// MaxTime returns the later time
|
||||
func MaxTime(a, b time.Time) time.Time {
|
||||
if a.After(b) {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Min / Max", func() {
|
||||
It("returns the maximum time", func() {
|
||||
a := time.Now()
|
||||
b := a.Add(time.Second)
|
||||
Expect(MaxTime(a, b)).To(Equal(b))
|
||||
Expect(MaxTime(b, a)).To(Equal(b))
|
||||
})
|
||||
|
||||
It("returns the minimum duration", func() {
|
||||
a := time.Now()
|
||||
b := a.Add(time.Second)
|
||||
Expect(MinTime(a, b)).To(Equal(a))
|
||||
Expect(MinTime(b, a)).To(Equal(a))
|
||||
})
|
||||
|
||||
It("returns the minium non-zero duration", func() {
|
||||
var a time.Duration
|
||||
b := time.Second
|
||||
Expect(MinNonZeroDuration(0, 0)).To(BeZero())
|
||||
Expect(MinNonZeroDuration(a, b)).To(Equal(b))
|
||||
Expect(MinNonZeroDuration(b, a)).To(Equal(b))
|
||||
Expect(MinNonZeroDuration(time.Minute, time.Hour)).To(Equal(time.Minute))
|
||||
})
|
||||
})
|
||||
@@ -64,7 +64,7 @@ func (r *RTTStats) PTO(includeMaxAckDelay bool) time.Duration {
|
||||
|
||||
// UpdateRTT updates the RTT based on a new sample.
|
||||
func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) {
|
||||
if sendDelta == InfDuration || sendDelta <= 0 {
|
||||
if sendDelta <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -101,25 +101,17 @@ var _ = Describe("RTT stats", func() {
|
||||
})
|
||||
|
||||
It("UpdateRTTWithBadSendDeltas", func() {
|
||||
// Make sure we ignore bad RTTs.
|
||||
// base::test::MockLog log;
|
||||
|
||||
initialRtt := (10 * time.Millisecond)
|
||||
initialRtt := 10 * time.Millisecond
|
||||
rttStats.UpdateRTT(initialRtt, 0, time.Time{})
|
||||
Expect(rttStats.MinRTT()).To(Equal(initialRtt))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt))
|
||||
|
||||
badSendDeltas := []time.Duration{
|
||||
0,
|
||||
InfDuration,
|
||||
-1000 * time.Microsecond,
|
||||
}
|
||||
// log.StartCapturingLogs();
|
||||
|
||||
for _, badSendDelta := range badSendDeltas {
|
||||
// SCOPED_TRACE(Message() << "bad_send_delta = "
|
||||
// << bad_send_delta.ToMicroseconds());
|
||||
// EXPECT_CALL(log, Log(LOG_WARNING, _, _, _, HasSubstr("Ignoring")));
|
||||
rttStats.UpdateRTT(badSendDelta, 0, time.Time{})
|
||||
Expect(rttStats.MinRTT()).To(Equal(initialRtt))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt))
|
||||
|
||||
@@ -2,11 +2,11 @@ package wire
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
"github.com/quic-go/quic-go/internal/utils"
|
||||
"github.com/quic-go/quic-go/quicvarint"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ func parseAckFrame(frame *AckFrame, b []byte, typ uint64, ackDelayExponent uint8
|
||||
delayTime := time.Duration(delay*1<<ackDelayExponent) * time.Microsecond
|
||||
if delayTime < 0 {
|
||||
// If the delay time overflows, set it to the maximum encode-able value.
|
||||
delayTime = utils.InfDuration
|
||||
delayTime = time.Duration(math.MaxInt64)
|
||||
}
|
||||
frame.DelayTime = delayTime
|
||||
|
||||
|
||||
Reference in New Issue
Block a user