diff --git a/internal/ackhandler/ackhandler.go b/internal/ackhandler/ackhandler.go index 262c0156..5f50dff9 100644 --- a/internal/ackhandler/ackhandler.go +++ b/internal/ackhandler/ackhandler.go @@ -1,7 +1,6 @@ package ackhandler import ( - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/logging" @@ -11,7 +10,7 @@ import ( // NewAckHandler creates a new SentPacketHandler and a new ReceivedPacketHandler func NewAckHandler( initialPacketNumber protocol.PacketNumber, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, pers protocol.Perspective, traceCallback func(quictrace.Event), tracer logging.ConnectionTracer, diff --git a/internal/ackhandler/received_packet_handler.go b/internal/ackhandler/received_packet_handler.go index 1b707639..fc74ba2b 100644 --- a/internal/ackhandler/received_packet_handler.go +++ b/internal/ackhandler/received_packet_handler.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" @@ -45,7 +44,7 @@ var _ ReceivedPacketHandler = &receivedPacketHandler{} func newReceivedPacketHandler( sentPackets sentPacketTracker, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, logger utils.Logger, version protocol.VersionNumber, ) ReceivedPacketHandler { diff --git a/internal/ackhandler/received_packet_handler_test.go b/internal/ackhandler/received_packet_handler_test.go index 7fbf2119..e3f4bd64 100644 --- a/internal/ackhandler/received_packet_handler_test.go +++ b/internal/ackhandler/received_packet_handler_test.go @@ -5,7 +5,6 @@ import ( "github.com/golang/mock/gomock" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" @@ -22,7 +21,7 @@ var _ = Describe("Received Packet Handler", func() { sentPackets = NewMockSentPacketTracker(mockCtrl) handler = newReceivedPacketHandler( sentPackets, - &congestion.RTTStats{}, + &utils.RTTStats{}, utils.DefaultLogger, protocol.VersionWhatever, ) diff --git a/internal/ackhandler/received_packet_tracker.go b/internal/ackhandler/received_packet_tracker.go index c6fc57c9..3f4310e5 100644 --- a/internal/ackhandler/received_packet_tracker.go +++ b/internal/ackhandler/received_packet_tracker.go @@ -3,7 +3,6 @@ package ackhandler import ( "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" @@ -17,7 +16,7 @@ type receivedPacketTracker struct { packetHistory *receivedPacketHistory maxAckDelay time.Duration - rttStats *congestion.RTTStats + rttStats *utils.RTTStats hasNewAck bool // true as soon as we received an ack-eliciting new packet ackQueued bool // true once we received more than 2 (or later in the connection 10) ack-eliciting packets @@ -32,7 +31,7 @@ type receivedPacketTracker struct { } func newReceivedPacketTracker( - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, logger utils.Logger, version protocol.VersionNumber, ) *receivedPacketTracker { diff --git a/internal/ackhandler/received_packet_tracker_test.go b/internal/ackhandler/received_packet_tracker_test.go index fab8c700..7de9cda4 100644 --- a/internal/ackhandler/received_packet_tracker_test.go +++ b/internal/ackhandler/received_packet_tracker_test.go @@ -3,7 +3,6 @@ package ackhandler import ( "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" @@ -15,11 +14,11 @@ import ( var _ = Describe("Received Packet Tracker", func() { var ( tracker *receivedPacketTracker - rttStats *congestion.RTTStats + rttStats *utils.RTTStats ) BeforeEach(func() { - rttStats = &congestion.RTTStats{} + rttStats = &utils.RTTStats{} tracker = newReceivedPacketTracker(rttStats, utils.DefaultLogger, protocol.VersionWhatever) }) diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index 58a784d7..b22cafd9 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -69,7 +69,7 @@ type sentPacketHandler struct { bytesInFlight protocol.ByteCount congestion congestion.SendAlgorithmWithDebugInfos - rttStats *congestion.RTTStats + rttStats *utils.RTTStats // The number of times a PTO has been sent without receiving an ack. ptoCount uint32 @@ -93,7 +93,7 @@ var _ sentPacketTracker = &sentPacketHandler{} func newSentPacketHandler( initialPacketNumber protocol.PacketNumber, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, pers protocol.Perspective, traceCallback func(quictrace.Event), tracer logging.ConnectionTracer, diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index ee034e2d..fc0cafdd 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/mocks" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" @@ -27,7 +26,7 @@ var _ = Describe("SentPacketHandler", func() { JustBeforeEach(func() { lostPackets = nil - rttStats := &congestion.RTTStats{} + rttStats := &utils.RTTStats{} handler = newSentPacketHandler(42, rttStats, perspective, nil, nil, utils.DefaultLogger) streamFrame = wire.StreamFrame{ StreamID: 5, diff --git a/internal/congestion/cubic_sender.go b/internal/congestion/cubic_sender.go index d2a3e49a..2279c331 100644 --- a/internal/congestion/cubic_sender.go +++ b/internal/congestion/cubic_sender.go @@ -20,7 +20,7 @@ const ( type cubicSender struct { hybridSlowStart HybridSlowStart - rttStats *RTTStats + rttStats *utils.RTTStats cubic *Cubic pacer *pacer clock Clock @@ -63,11 +63,11 @@ var _ SendAlgorithm = &cubicSender{} var _ SendAlgorithmWithDebugInfos = &cubicSender{} // NewCubicSender makes a new cubic sender -func NewCubicSender(clock Clock, rttStats *RTTStats, reno bool) *cubicSender { +func NewCubicSender(clock Clock, rttStats *utils.RTTStats, reno bool) *cubicSender { return newCubicSender(clock, rttStats, reno, initialCongestionWindow, maxCongestionWindow) } -func newCubicSender(clock Clock, rttStats *RTTStats, reno bool, initialCongestionWindow, initialMaxCongestionWindow protocol.ByteCount) *cubicSender { +func newCubicSender(clock Clock, rttStats *utils.RTTStats, reno bool, initialCongestionWindow, initialMaxCongestionWindow protocol.ByteCount) *cubicSender { c := &cubicSender{ rttStats: rttStats, largestSentPacketNumber: protocol.InvalidPacketNumber, diff --git a/internal/congestion/cubic_sender_test.go b/internal/congestion/cubic_sender_test.go index 088dd158..6490a3d8 100644 --- a/internal/congestion/cubic_sender_test.go +++ b/internal/congestion/cubic_sender_test.go @@ -31,7 +31,7 @@ var _ = Describe("Cubic Sender", func() { bytesInFlight protocol.ByteCount packetNumber protocol.PacketNumber ackedPacketNumber protocol.PacketNumber - rttStats *RTTStats + rttStats *utils.RTTStats ) BeforeEach(func() { @@ -39,7 +39,7 @@ var _ = Describe("Cubic Sender", func() { packetNumber = 1 ackedPacketNumber = 0 clock = mockClock{} - rttStats = NewRTTStats() + rttStats = utils.NewRTTStats() sender = newCubicSender(&clock, rttStats, true /*reno*/, initialCongestionWindowPackets*maxDatagramSize, MaxCongestionWindow) }) diff --git a/internal/flowcontrol/base_flow_controller.go b/internal/flowcontrol/base_flow_controller.go index 71acf86a..46825c42 100644 --- a/internal/flowcontrol/base_flow_controller.go +++ b/internal/flowcontrol/base_flow_controller.go @@ -4,7 +4,6 @@ import ( "sync" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" ) @@ -25,7 +24,7 @@ type baseFlowController struct { epochStartTime time.Time epochStartOffset protocol.ByteCount - rttStats *congestion.RTTStats + rttStats *utils.RTTStats logger utils.Logger } diff --git a/internal/flowcontrol/base_flow_controller_test.go b/internal/flowcontrol/base_flow_controller_test.go index 273b9a2b..8e20072d 100644 --- a/internal/flowcontrol/base_flow_controller_test.go +++ b/internal/flowcontrol/base_flow_controller_test.go @@ -5,7 +5,8 @@ import ( "strconv" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" + "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/lucas-clemente/quic-go/internal/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -27,7 +28,7 @@ var _ = Describe("Base Flow controller", func() { BeforeEach(func() { controller = &baseFlowController{} - controller.rttStats = &congestion.RTTStats{} + controller.rttStats = &utils.RTTStats{} }) Context("send flow control", func() { diff --git a/internal/flowcontrol/connection_flow_controller.go b/internal/flowcontrol/connection_flow_controller.go index 19de1c77..0c42c800 100644 --- a/internal/flowcontrol/connection_flow_controller.go +++ b/internal/flowcontrol/connection_flow_controller.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/utils" @@ -24,7 +23,7 @@ func NewConnectionFlowController( receiveWindow protocol.ByteCount, maxReceiveWindow protocol.ByteCount, queueWindowUpdate func(), - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, logger utils.Logger, ) ConnectionFlowController { return &connectionFlowController{ diff --git a/internal/flowcontrol/connection_flow_controller_test.go b/internal/flowcontrol/connection_flow_controller_test.go index e03cbf07..4dc1b692 100644 --- a/internal/flowcontrol/connection_flow_controller_test.go +++ b/internal/flowcontrol/connection_flow_controller_test.go @@ -3,7 +3,6 @@ package flowcontrol import ( "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" . "github.com/onsi/ginkgo" @@ -25,13 +24,13 @@ var _ = Describe("Connection Flow controller", func() { BeforeEach(func() { queuedWindowUpdate = false controller = &connectionFlowController{} - controller.rttStats = &congestion.RTTStats{} + controller.rttStats = &utils.RTTStats{} controller.logger = utils.DefaultLogger controller.queueWindowUpdate = func() { queuedWindowUpdate = true } }) Context("Constructor", func() { - rttStats := &congestion.RTTStats{} + rttStats := &utils.RTTStats{} It("sets the send and receive windows", func() { receiveWindow := protocol.ByteCount(2000) diff --git a/internal/flowcontrol/stream_flow_controller.go b/internal/flowcontrol/stream_flow_controller.go index 26460e8c..90b04e72 100644 --- a/internal/flowcontrol/stream_flow_controller.go +++ b/internal/flowcontrol/stream_flow_controller.go @@ -3,7 +3,6 @@ package flowcontrol import ( "fmt" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/utils" @@ -31,7 +30,7 @@ func NewStreamFlowController( maxReceiveWindow protocol.ByteCount, initialSendWindow protocol.ByteCount, queueWindowUpdate func(protocol.StreamID), - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, logger utils.Logger, ) StreamFlowController { return &streamFlowController{ diff --git a/internal/flowcontrol/stream_flow_controller_test.go b/internal/flowcontrol/stream_flow_controller_test.go index cfb26655..fca80949 100644 --- a/internal/flowcontrol/stream_flow_controller_test.go +++ b/internal/flowcontrol/stream_flow_controller_test.go @@ -3,7 +3,6 @@ package flowcontrol import ( "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" . "github.com/onsi/ginkgo" @@ -18,7 +17,7 @@ var _ = Describe("Stream Flow controller", func() { BeforeEach(func() { queuedWindowUpdate = false - rttStats := &congestion.RTTStats{} + rttStats := &utils.RTTStats{} controller = &streamFlowController{ streamID: 10, connection: NewConnectionFlowController(1000, 1000, func() {}, rttStats, utils.DefaultLogger).(*connectionFlowController), @@ -30,7 +29,7 @@ var _ = Describe("Stream Flow controller", func() { }) Context("Constructor", func() { - rttStats := &congestion.RTTStats{} + rttStats := &utils.RTTStats{} receiveWindow := protocol.ByteCount(2000) maxReceiveWindow := protocol.ByteCount(3000) sendWindow := protocol.ByteCount(4000) diff --git a/internal/handshake/crypto_setup.go b/internal/handshake/crypto_setup.go index d2ce23a6..04cab43c 100644 --- a/internal/handshake/crypto_setup.go +++ b/internal/handshake/crypto_setup.go @@ -10,7 +10,6 @@ import ( "sync" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/utils" @@ -92,7 +91,7 @@ type cryptoSetup struct { // for clients: to see if a ServerHello is a HelloRetryRequest writeRecord chan struct{} - rttStats *congestion.RTTStats + rttStats *utils.RTTStats tracer logging.ConnectionTracer logger utils.Logger @@ -136,7 +135,7 @@ func NewCryptoSetupClient( runner handshakeRunner, tlsConf *tls.Config, enable0RTT bool, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, tracer logging.ConnectionTracer, logger utils.Logger, ) (CryptoSetup, <-chan *wire.TransportParameters /* ClientHello written. Receive nil for non-0-RTT */) { @@ -168,7 +167,7 @@ func NewCryptoSetupServer( runner handshakeRunner, tlsConf *tls.Config, enable0RTT bool, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, tracer logging.ConnectionTracer, logger utils.Logger, ) CryptoSetup { @@ -197,7 +196,7 @@ func newCryptoSetup( runner handshakeRunner, tlsConf *tls.Config, enable0RTT bool, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, tracer logging.ConnectionTracer, logger utils.Logger, perspective protocol.Perspective, diff --git a/internal/handshake/crypto_setup_test.go b/internal/handshake/crypto_setup_test.go index 3bf8f826..2b085c67 100644 --- a/internal/handshake/crypto_setup_test.go +++ b/internal/handshake/crypto_setup_test.go @@ -11,7 +11,6 @@ import ( "math/big" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/testdata" @@ -99,7 +98,7 @@ var _ = Describe("Crypto Setup TLS", func() { NewMockHandshakeRunner(mockCtrl), tlsConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -133,7 +132,7 @@ var _ = Describe("Crypto Setup TLS", func() { runner, testdata.GetTLSConfig(), false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -173,7 +172,7 @@ var _ = Describe("Crypto Setup TLS", func() { runner, testdata.GetTLSConfig(), false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -216,7 +215,7 @@ var _ = Describe("Crypto Setup TLS", func() { runner, serverConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -252,7 +251,7 @@ var _ = Describe("Crypto Setup TLS", func() { NewMockHandshakeRunner(mockCtrl), serverConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -287,8 +286,8 @@ var _ = Describe("Crypto Setup TLS", func() { } } - newRTTStatsWithRTT := func(rtt time.Duration) *congestion.RTTStats { - rttStats := &congestion.RTTStats{} + newRTTStatsWithRTT := func(rtt time.Duration) *utils.RTTStats { + rttStats := &utils.RTTStats{} rttStats.UpdateRTT(rtt, 0, time.Now()) ExpectWithOffset(1, rttStats.SmoothedRTT()).To(Equal(rtt)) return rttStats @@ -328,7 +327,7 @@ var _ = Describe("Crypto Setup TLS", func() { handshakeWithTLSConf := func( clientConf, serverConf *tls.Config, - clientRTTStats, serverRTTStats *congestion.RTTStats, + clientRTTStats, serverRTTStats *utils.RTTStats, clientTransportParameters, serverTransportParameters *wire.TransportParameters, enable0RTT bool, ) (<-chan *wire.TransportParameters /* clientHelloWrittenChan */, CryptoSetup /* client */, error /* client error */, CryptoSetup /* server */, error /* server error */) { @@ -399,7 +398,7 @@ var _ = Describe("Crypto Setup TLS", func() { It("handshakes", func() { _, _, clientErr, _, serverErr := handshakeWithTLSConf( clientConf, serverConf, - &congestion.RTTStats{}, &congestion.RTTStats{}, + &utils.RTTStats{}, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -411,7 +410,7 @@ var _ = Describe("Crypto Setup TLS", func() { serverConf.CurvePreferences = []tls.CurveID{tls.CurveP384} _, _, clientErr, _, serverErr := handshakeWithTLSConf( clientConf, serverConf, - &congestion.RTTStats{}, &congestion.RTTStats{}, + &utils.RTTStats{}, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -424,7 +423,7 @@ var _ = Describe("Crypto Setup TLS", func() { serverConf.ClientAuth = qtls.RequireAnyClientCert _, _, clientErr, _, serverErr := handshakeWithTLSConf( clientConf, serverConf, - &congestion.RTTStats{}, &congestion.RTTStats{}, + &utils.RTTStats{}, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -445,7 +444,7 @@ var _ = Describe("Crypto Setup TLS", func() { runner, &tls.Config{InsecureSkipVerify: true}, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("client"), ) @@ -487,7 +486,7 @@ var _ = Describe("Crypto Setup TLS", func() { cRunner, clientConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("client"), ) @@ -511,7 +510,7 @@ var _ = Describe("Crypto Setup TLS", func() { sRunner, serverConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -544,7 +543,7 @@ var _ = Describe("Crypto Setup TLS", func() { cRunner, clientConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("client"), ) @@ -564,7 +563,7 @@ var _ = Describe("Crypto Setup TLS", func() { sRunner, serverConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -604,7 +603,7 @@ var _ = Describe("Crypto Setup TLS", func() { cRunner, clientConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("client"), ) @@ -624,7 +623,7 @@ var _ = Describe("Crypto Setup TLS", func() { sRunner, serverConf, false, - &congestion.RTTStats{}, + &utils.RTTStats{}, nil, utils.DefaultLogger.WithPrefix("server"), ) @@ -661,7 +660,7 @@ var _ = Describe("Crypto Setup TLS", func() { clientOrigRTTStats := newRTTStatsWithRTT(clientRTT) clientHelloWrittenChan, client, clientErr, server, serverErr := handshakeWithTLSConf( clientConf, serverConf, - clientOrigRTTStats, &congestion.RTTStats{}, + clientOrigRTTStats, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -674,10 +673,10 @@ var _ = Describe("Crypto Setup TLS", func() { csc.EXPECT().Get(gomock.Any()).Return(state, true) csc.EXPECT().Put(gomock.Any(), gomock.Any()).MaxTimes(1) - clientRTTStats := &congestion.RTTStats{} + clientRTTStats := &utils.RTTStats{} clientHelloWrittenChan, client, clientErr, server, serverErr = handshakeWithTLSConf( clientConf, serverConf, - clientRTTStats, &congestion.RTTStats{}, + clientRTTStats, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -702,7 +701,7 @@ var _ = Describe("Crypto Setup TLS", func() { clientConf.ClientSessionCache = csc _, client, clientErr, server, serverErr := handshakeWithTLSConf( clientConf, serverConf, - &congestion.RTTStats{}, &congestion.RTTStats{}, + &utils.RTTStats{}, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -716,7 +715,7 @@ var _ = Describe("Crypto Setup TLS", func() { csc.EXPECT().Get(gomock.Any()).Return(state, true) _, client, clientErr, server, serverErr = handshakeWithTLSConf( clientConf, serverConf, - &congestion.RTTStats{}, &congestion.RTTStats{}, + &utils.RTTStats{}, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{}, false, ) @@ -759,8 +758,8 @@ var _ = Describe("Crypto Setup TLS", func() { csc.EXPECT().Put(gomock.Any(), nil) csc.EXPECT().Put(gomock.Any(), gomock.Any()).MaxTimes(1) - clientRTTStats := &congestion.RTTStats{} - serverRTTStats := &congestion.RTTStats{} + clientRTTStats := &utils.RTTStats{} + serverRTTStats := &utils.RTTStats{} clientHelloWrittenChan, client, clientErr, server, serverErr = handshakeWithTLSConf( clientConf, serverConf, clientRTTStats, serverRTTStats, @@ -797,7 +796,7 @@ var _ = Describe("Crypto Setup TLS", func() { const initialMaxData protocol.ByteCount = 1337 clientHelloWrittenChan, client, clientErr, server, serverErr := handshakeWithTLSConf( clientConf, serverConf, - clientOrigRTTStats, &congestion.RTTStats{}, + clientOrigRTTStats, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{InitialMaxData: initialMaxData}, true, ) @@ -812,10 +811,10 @@ var _ = Describe("Crypto Setup TLS", func() { csc.EXPECT().Put(gomock.Any(), nil) csc.EXPECT().Put(gomock.Any(), gomock.Any()).MaxTimes(1) - clientRTTStats := &congestion.RTTStats{} + clientRTTStats := &utils.RTTStats{} clientHelloWrittenChan, client, clientErr, server, serverErr = handshakeWithTLSConf( clientConf, serverConf, - clientRTTStats, &congestion.RTTStats{}, + clientRTTStats, &utils.RTTStats{}, &wire.TransportParameters{}, &wire.TransportParameters{InitialMaxData: initialMaxData + 1}, true, ) diff --git a/internal/handshake/qtls.go b/internal/handshake/qtls.go index a0508277..7a5bc274 100644 --- a/internal/handshake/qtls.go +++ b/internal/handshake/qtls.go @@ -6,9 +6,9 @@ import ( "time" "unsafe" - "github.com/marten-seemann/qtls" + "github.com/lucas-clemente/quic-go/internal/utils" - "github.com/lucas-clemente/quic-go/internal/congestion" + "github.com/marten-seemann/qtls" ) func init() { @@ -46,7 +46,7 @@ func tlsConfigToQtlsConfig( c *tls.Config, recordLayer qtls.RecordLayer, extHandler tlsExtensionHandler, - rttStats *congestion.RTTStats, + rttStats *utils.RTTStats, getDataForSessionState func() []byte, setDataFromSessionState func([]byte), accept0RTT func([]byte) bool, diff --git a/internal/handshake/qtls_test.go b/internal/handshake/qtls_test.go index 2733c0f2..fe83dc57 100644 --- a/internal/handshake/qtls_test.go +++ b/internal/handshake/qtls_test.go @@ -6,7 +6,8 @@ import ( "net" "unsafe" - "github.com/lucas-clemente/quic-go/internal/congestion" + "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/marten-seemann/qtls" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -30,19 +31,19 @@ func (*mockExtensionHandler) TransportParameters() <-chan []byte { panic("not im var _ = Describe("qtls.Config", func() { It("sets MinVersion and MaxVersion", func() { tlsConf := &tls.Config{MinVersion: tls.VersionTLS11, MaxVersion: tls.VersionTLS12} - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.MinVersion).To(BeEquivalentTo(tls.VersionTLS13)) Expect(qtlsConf.MaxVersion).To(BeEquivalentTo(tls.VersionTLS13)) }) It("works when called with a nil config", func() { - qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf).ToNot(BeNil()) }) It("sets the setter and getter function for TLS extensions", func() { extHandler := &mockExtensionHandler{} - qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, extHandler, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, extHandler, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(extHandler.get).To(BeFalse()) qtlsConf.GetExtensions(10) Expect(extHandler.get).To(BeTrue()) @@ -53,7 +54,7 @@ var _ = Describe("qtls.Config", func() { It("sets the Accept0RTT callback", func() { accept0RTT := func([]byte) bool { return true } - qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, accept0RTT, nil, false) + qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, accept0RTT, nil, false) Expect(qtlsConf.Accept0RTT).ToNot(BeNil()) Expect(qtlsConf.Accept0RTT(nil)).To(BeTrue()) }) @@ -61,32 +62,32 @@ var _ = Describe("qtls.Config", func() { It("sets the Accept0RTT callback", func() { var called bool rejected0RTT := func() { called = true } - qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, rejected0RTT, false) + qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, rejected0RTT, false) Expect(qtlsConf.Rejected0RTT).ToNot(BeNil()) qtlsConf.Rejected0RTT() Expect(called).To(BeTrue()) }) It("enables 0-RTT", func() { - qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.Enable0RTT).To(BeFalse()) Expect(qtlsConf.MaxEarlyData).To(BeZero()) - qtlsConf = tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, true) + qtlsConf = tlsConfigToQtlsConfig(nil, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, true) Expect(qtlsConf.Enable0RTT).To(BeTrue()) Expect(qtlsConf.MaxEarlyData).To(Equal(uint32(0xffffffff))) }) It("initializes such that the session ticket key remains constant", func() { tlsConf := &tls.Config{} - qtlsConf1 := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) - qtlsConf2 := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf1 := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf2 := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf1.SessionTicketKey).ToNot(BeZero()) // should now contain a random value Expect(qtlsConf1.SessionTicketKey).To(Equal(qtlsConf2.SessionTicketKey)) }) Context("GetConfigForClient callback", func() { It("doesn't set it if absent", func() { - qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.GetConfigForClient).To(BeNil()) }) @@ -97,7 +98,7 @@ var _ = Describe("qtls.Config", func() { }, } extHandler := &mockExtensionHandler{} - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, extHandler, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, extHandler, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.GetConfigForClient).ToNot(BeNil()) confForClient, err := qtlsConf.GetConfigForClient(nil) Expect(err).ToNot(HaveOccurred()) @@ -117,7 +118,7 @@ var _ = Describe("qtls.Config", func() { return nil, testErr }, } - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) _, err := qtlsConf.GetConfigForClient(nil) Expect(err).To(MatchError(testErr)) }) @@ -128,7 +129,7 @@ var _ = Describe("qtls.Config", func() { return nil, nil }, } - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.GetConfigForClient(nil)).To(BeNil()) }) }) @@ -140,7 +141,7 @@ var _ = Describe("qtls.Config", func() { return &tls.Certificate{Certificate: [][]byte{[]byte("foo"), []byte("bar")}}, nil }, } - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) qtlsCert, err := qtlsConf.GetCertificate(nil) Expect(err).ToNot(HaveOccurred()) Expect(qtlsCert).ToNot(BeNil()) @@ -148,7 +149,7 @@ var _ = Describe("qtls.Config", func() { }) It("doesn't set it if absent", func() { - qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.GetCertificate).To(BeNil()) }) @@ -158,7 +159,7 @@ var _ = Describe("qtls.Config", func() { return nil, errors.New("test") }, } - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) _, err := qtlsConf.GetCertificate(nil) Expect(err).To(MatchError("test")) }) @@ -169,21 +170,21 @@ var _ = Describe("qtls.Config", func() { return nil, nil }, } - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.GetCertificate(nil)).To(BeNil()) }) }) Context("ClientSessionCache", func() { It("doesn't set if absent", func() { - qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(&tls.Config{}, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) Expect(qtlsConf.ClientSessionCache).To(BeNil()) }) It("puts a nil session state", func() { csc := NewMockClientSessionCache(mockCtrl) tlsConf := &tls.Config{ClientSessionCache: csc} - qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, congestion.NewRTTStats(), nil, nil, nil, nil, false) + qtlsConf := tlsConfigToQtlsConfig(tlsConf, nil, &mockExtensionHandler{}, utils.NewRTTStats(), nil, nil, nil, nil, false) // put something csc.EXPECT().Put("foobar", nil) qtlsConf.ClientSessionCache.Put("foobar", nil) diff --git a/internal/handshake/updatable_aead.go b/internal/handshake/updatable_aead.go index 2da4d9c5..11c0accb 100644 --- a/internal/handshake/updatable_aead.go +++ b/internal/handshake/updatable_aead.go @@ -9,7 +9,6 @@ import ( "strconv" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/logging" @@ -72,7 +71,7 @@ type updatableAEAD struct { headerDecrypter headerProtector headerEncrypter headerProtector - rttStats *congestion.RTTStats + rttStats *utils.RTTStats tracer logging.ConnectionTracer logger utils.Logger @@ -84,7 +83,7 @@ type updatableAEAD struct { var _ ShortHeaderOpener = &updatableAEAD{} var _ ShortHeaderSealer = &updatableAEAD{} -func newUpdatableAEAD(rttStats *congestion.RTTStats, tracer logging.ConnectionTracer, logger utils.Logger) *updatableAEAD { +func newUpdatableAEAD(rttStats *utils.RTTStats, tracer logging.ConnectionTracer, logger utils.Logger) *updatableAEAD { return &updatableAEAD{ firstPacketNumber: protocol.InvalidPacketNumber, largestAcked: protocol.InvalidPacketNumber, diff --git a/internal/handshake/updatable_aead_test.go b/internal/handshake/updatable_aead_test.go index f48f6370..013b9ff6 100644 --- a/internal/handshake/updatable_aead_test.go +++ b/internal/handshake/updatable_aead_test.go @@ -6,7 +6,6 @@ import ( "os" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/marten-seemann/qtls" @@ -18,7 +17,7 @@ import ( var _ = Describe("Updatable AEAD", func() { It("ChaCha test vector from the draft", func() { secret := splitHexString("9ac312a7f877468ebe69422748ad00a1 5443f18203a07d6060f688f30f21632b") - aead := newUpdatableAEAD(&congestion.RTTStats{}, nil, nil) + aead := newUpdatableAEAD(&utils.RTTStats{}, nil, nil) chacha := cipherSuites[2] Expect(chacha.ID).To(Equal(qtls.TLS_CHACHA20_POLY1305_SHA256)) aead.SetWriteKey(chacha, secret) @@ -37,7 +36,7 @@ var _ = Describe("Updatable AEAD", func() { cs := cipherSuites[i] Context(fmt.Sprintf("using %s", qtls.CipherSuiteName(cs.ID)), func() { - getPeers := func(rttStats *congestion.RTTStats) (client, server *updatableAEAD) { + getPeers := func(rttStats *utils.RTTStats) (client, server *updatableAEAD) { trafficSecret1 := make([]byte, 16) trafficSecret2 := make([]byte, 16) rand.Read(trafficSecret1) @@ -54,7 +53,7 @@ var _ = Describe("Updatable AEAD", func() { Context("header protection", func() { It("encrypts and decrypts the header", func() { - server, client := getPeers(&congestion.RTTStats{}) + server, client := getPeers(&utils.RTTStats{}) var lastFiveBitsDifferent int for i := 0; i < 100; i++ { sample := make([]byte, 16) @@ -77,10 +76,10 @@ var _ = Describe("Updatable AEAD", func() { Context("message encryption", func() { var msg, ad []byte var server, client *updatableAEAD - var rttStats *congestion.RTTStats + var rttStats *utils.RTTStats BeforeEach(func() { - rttStats = &congestion.RTTStats{} + rttStats = &utils.RTTStats{} server, client = getPeers(rttStats) msg = []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") ad = []byte("Donec in velit neque.") diff --git a/internal/mocks/connection_tracer.go b/internal/mocks/connection_tracer.go index 73e63d8b..5581db74 100644 --- a/internal/mocks/connection_tracer.go +++ b/internal/mocks/connection_tracer.go @@ -5,15 +5,16 @@ package mocks import ( - net "net" - reflect "reflect" - time "time" + "net" + "reflect" + "time" - gomock "github.com/golang/mock/gomock" - congestion "github.com/lucas-clemente/quic-go/internal/congestion" - protocol "github.com/lucas-clemente/quic-go/internal/protocol" - wire "github.com/lucas-clemente/quic-go/internal/wire" - logging "github.com/lucas-clemente/quic-go/logging" + "github.com/lucas-clemente/quic-go/internal/utils" + + "github.com/golang/mock/gomock" + "github.com/lucas-clemente/quic-go/internal/protocol" + "github.com/lucas-clemente/quic-go/internal/wire" + "github.com/lucas-clemente/quic-go/logging" ) // MockConnectionTracer is a mock of ConnectionTracer interface @@ -256,7 +257,7 @@ func (mr *MockConnectionTracerMockRecorder) UpdatedKeyFromTLS(arg0, arg1 interfa } // UpdatedMetrics mocks base method -func (m *MockConnectionTracer) UpdatedMetrics(arg0 *congestion.RTTStats, arg1, arg2 protocol.ByteCount, arg3 int) { +func (m *MockConnectionTracer) UpdatedMetrics(arg0 *utils.RTTStats, arg1, arg2 protocol.ByteCount, arg3 int) { m.ctrl.T.Helper() m.ctrl.Call(m, "UpdatedMetrics", arg0, arg1, arg2, arg3) } diff --git a/internal/congestion/rtt_stats.go b/internal/utils/rtt_stats.go similarity index 87% rename from internal/congestion/rtt_stats.go rename to internal/utils/rtt_stats.go index 2021f7de..66642ba8 100644 --- a/internal/congestion/rtt_stats.go +++ b/internal/utils/rtt_stats.go @@ -1,10 +1,9 @@ -package congestion +package utils import ( "time" "github.com/lucas-clemente/quic-go/internal/protocol" - "github.com/lucas-clemente/quic-go/internal/utils" ) const ( @@ -56,7 +55,7 @@ func (r *RTTStats) PTO(includeMaxAckDelay bool) time.Duration { if r.SmoothedRTT() == 0 { return 2 * defaultInitialRTT } - pto := r.SmoothedRTT() + utils.MaxDuration(4*r.MeanDeviation(), protocol.TimerGranularity) + pto := r.SmoothedRTT() + MaxDuration(4*r.MeanDeviation(), protocol.TimerGranularity) if includeMaxAckDelay { pto += r.MaxAckDelay() } @@ -65,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 == utils.InfDuration || sendDelta <= 0 { + if sendDelta == InfDuration || sendDelta <= 0 { return } @@ -91,7 +90,7 @@ func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) { r.smoothedRTT = sample r.meanDeviation = sample / 2 } else { - r.meanDeviation = time.Duration(oneMinusBeta*float32(r.meanDeviation/time.Microsecond)+rttBeta*float32(utils.AbsDuration(r.smoothedRTT-sample)/time.Microsecond)) * time.Microsecond + r.meanDeviation = time.Duration(oneMinusBeta*float32(r.meanDeviation/time.Microsecond)+rttBeta*float32(AbsDuration(r.smoothedRTT-sample)/time.Microsecond)) * time.Microsecond r.smoothedRTT = time.Duration((float32(r.smoothedRTT/time.Microsecond)*oneMinusAlpha)+(float32(sample/time.Microsecond)*rttAlpha)) * time.Microsecond } } @@ -123,6 +122,6 @@ func (r *RTTStats) OnConnectionMigration() { // is larger. The mean deviation is increased to the most recent deviation if // it's larger. func (r *RTTStats) ExpireSmoothedMetrics() { - r.meanDeviation = utils.MaxDuration(r.meanDeviation, utils.AbsDuration(r.smoothedRTT-r.latestRTT)) - r.smoothedRTT = utils.MaxDuration(r.smoothedRTT, r.latestRTT) + r.meanDeviation = MaxDuration(r.meanDeviation, AbsDuration(r.smoothedRTT-r.latestRTT)) + r.smoothedRTT = MaxDuration(r.smoothedRTT, r.latestRTT) } diff --git a/internal/congestion/rtt_stats_test.go b/internal/utils/rtt_stats_test.go similarity index 98% rename from internal/congestion/rtt_stats_test.go rename to internal/utils/rtt_stats_test.go index 88cc2528..7a29518c 100644 --- a/internal/congestion/rtt_stats_test.go +++ b/internal/utils/rtt_stats_test.go @@ -1,10 +1,10 @@ -package congestion +package utils import ( "time" "github.com/lucas-clemente/quic-go/internal/protocol" - "github.com/lucas-clemente/quic-go/internal/utils" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -113,7 +113,7 @@ var _ = Describe("RTT stats", func() { badSendDeltas := []time.Duration{ 0, - utils.InfDuration, + InfDuration, -1000 * time.Microsecond, } // log.StartCapturingLogs(); diff --git a/logging/interface.go b/logging/interface.go index d5d251c4..8db05b90 100644 --- a/logging/interface.go +++ b/logging/interface.go @@ -6,7 +6,8 @@ import ( "net" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" + "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/wire" @@ -49,7 +50,7 @@ type ( ApplicationError = qerr.ErrorCode // The RTTStats contain statistics used by the congestion controller. - RTTStats = congestion.RTTStats + RTTStats = utils.RTTStats ) const ( diff --git a/logging/mock_connection_tracer_test.go b/logging/mock_connection_tracer_test.go index 79ab1774..8cba7d4c 100644 --- a/logging/mock_connection_tracer_test.go +++ b/logging/mock_connection_tracer_test.go @@ -5,13 +5,14 @@ package logging import ( - gomock "github.com/golang/mock/gomock" - congestion "github.com/lucas-clemente/quic-go/internal/congestion" - protocol "github.com/lucas-clemente/quic-go/internal/protocol" - wire "github.com/lucas-clemente/quic-go/internal/wire" - net "net" - reflect "reflect" - time "time" + "net" + "reflect" + "time" + + "github.com/golang/mock/gomock" + "github.com/lucas-clemente/quic-go/internal/protocol" + "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/lucas-clemente/quic-go/internal/wire" ) // MockConnectionTracer is a mock of ConnectionTracer interface @@ -254,7 +255,7 @@ func (mr *MockConnectionTracerMockRecorder) UpdatedKeyFromTLS(arg0, arg1 interfa } // UpdatedMetrics mocks base method -func (m *MockConnectionTracer) UpdatedMetrics(arg0 *congestion.RTTStats, arg1, arg2 protocol.ByteCount, arg3 int) { +func (m *MockConnectionTracer) UpdatedMetrics(arg0 *utils.RTTStats, arg1, arg2 protocol.ByteCount, arg3 int) { m.ctrl.T.Helper() m.ctrl.Call(m, "UpdatedMetrics", arg0, arg1, arg2, arg3) } diff --git a/qlog/qlog.go b/qlog/qlog.go index c3127445..6ec2eff1 100644 --- a/qlog/qlog.go +++ b/qlog/qlog.go @@ -9,7 +9,8 @@ import ( "sync" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" + "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/wire" "github.com/lucas-clemente/quic-go/logging" @@ -286,7 +287,7 @@ func (t *connectionTracer) DroppedPacket(pt logging.PacketType, size protocol.By t.mutex.Unlock() } -func (t *connectionTracer) UpdatedMetrics(rttStats *congestion.RTTStats, cwnd, bytesInFlight protocol.ByteCount, packetsInFlight int) { +func (t *connectionTracer) UpdatedMetrics(rttStats *utils.RTTStats, cwnd, bytesInFlight protocol.ByteCount, packetsInFlight int) { m := &metrics{ MinRTT: rttStats.MinRTT(), SmoothedRTT: rttStats.SmoothedRTT(), diff --git a/qlog/qlog_test.go b/qlog/qlog_test.go index 19a241a6..0128429d 100644 --- a/qlog/qlog_test.go +++ b/qlog/qlog_test.go @@ -10,7 +10,8 @@ import ( "os" "time" - "github.com/lucas-clemente/quic-go/internal/congestion" + "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/logging" @@ -438,7 +439,7 @@ var _ = Describe("Tracing", func() { It("records metrics updates", func() { now := time.Now() - rttStats := congestion.NewRTTStats() + rttStats := utils.NewRTTStats() rttStats.UpdateRTT(15*time.Millisecond, 0, now) rttStats.UpdateRTT(20*time.Millisecond, 0, now) rttStats.UpdateRTT(25*time.Millisecond, 0, now) @@ -472,13 +473,13 @@ var _ = Describe("Tracing", func() { It("only logs the diff between two metrics updates", func() { now := time.Now() - rttStats := congestion.NewRTTStats() + rttStats := utils.NewRTTStats() rttStats.UpdateRTT(15*time.Millisecond, 0, now) rttStats.UpdateRTT(20*time.Millisecond, 0, now) rttStats.UpdateRTT(25*time.Millisecond, 0, now) Expect(rttStats.MinRTT()).To(Equal(15 * time.Millisecond)) - rttStats2 := congestion.NewRTTStats() + rttStats2 := utils.NewRTTStats() rttStats2.UpdateRTT(15*time.Millisecond, 0, now) rttStats2.UpdateRTT(15*time.Millisecond, 0, now) rttStats2.UpdateRTT(15*time.Millisecond, 0, now) diff --git a/session.go b/session.go index b02d0704..d25a684b 100644 --- a/session.go +++ b/session.go @@ -13,7 +13,6 @@ import ( "time" "github.com/lucas-clemente/quic-go/internal/ackhandler" - "github.com/lucas-clemente/quic-go/internal/congestion" "github.com/lucas-clemente/quic-go/internal/flowcontrol" "github.com/lucas-clemente/quic-go/internal/handshake" "github.com/lucas-clemente/quic-go/internal/logutils" @@ -144,7 +143,7 @@ type session struct { connIDManager *connIDManager connIDGenerator *connIDGenerator - rttStats *congestion.RTTStats + rttStats *utils.RTTStats cryptoStreamManager *cryptoStreamManager sentPacketHandler ackhandler.SentPacketHandler @@ -472,7 +471,7 @@ func (s *session) preSetup() { s.sendQueue = newSendQueue(s.conn) s.retransmissionQueue = newRetransmissionQueue(s.version) s.frameParser = wire.NewFrameParser(s.version) - s.rttStats = &congestion.RTTStats{} + s.rttStats = &utils.RTTStats{} s.connFlowController = flowcontrol.NewConnectionFlowController( protocol.InitialMaxData, protocol.ByteCount(s.config.MaxReceiveConnectionFlowControlWindow),