diff --git a/congestion/bandwidth_test.go b/congestion/bandwidth_test.go index b29058b94..031627476 100644 --- a/congestion/bandwidth_test.go +++ b/congestion/bandwidth_test.go @@ -1,15 +1,14 @@ -package congestion_test +package congestion import ( "time" - "github.com/lucas-clemente/quic-go/congestion" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Bandwidth", func() { It("converts from time delta", func() { - Expect(congestion.BandwidthFromDelta(1, time.Millisecond)).To(Equal(1000 * congestion.BytesPerSecond)) + Expect(BandwidthFromDelta(1, time.Millisecond)).To(Equal(1000 * BytesPerSecond)) }) }) diff --git a/congestion/cubic_sender_test.go b/congestion/cubic_sender_test.go index 480ebf4b4..7477aed59 100644 --- a/congestion/cubic_sender_test.go +++ b/congestion/cubic_sender_test.go @@ -1,9 +1,8 @@ -package congestion_test +package congestion import ( "time" - "github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -11,7 +10,6 @@ import ( const initialCongestionWindowPackets protocol.PacketNumber = 10 const defaultWindowTCP = protocol.ByteCount(initialCongestionWindowPackets) * protocol.DefaultTCPMSS -const renoBeta float32 = 0.7 // Reno backoff factor. type mockClock time.Time @@ -25,12 +23,12 @@ func (c *mockClock) Advance(d time.Duration) { var _ = Describe("Cubic Sender", func() { var ( - sender congestion.SendAlgorithmWithDebugInfo + sender SendAlgorithmWithDebugInfo clock mockClock bytesInFlight protocol.ByteCount packetNumber protocol.PacketNumber ackedPacketNumber protocol.PacketNumber - rttStats *congestion.RTTStats + rttStats *RTTStats ) BeforeEach(func() { @@ -38,8 +36,8 @@ var _ = Describe("Cubic Sender", func() { packetNumber = 1 ackedPacketNumber = 0 clock = mockClock{} - rttStats = congestion.NewRTTStats() - sender = congestion.NewCubicSender(&clock, rttStats, true /*reno*/, initialCongestionWindowPackets, protocol.MaxCongestionWindow) + rttStats = NewRTTStats() + sender = NewCubicSender(&clock, rttStats, true /*reno*/, initialCongestionWindowPackets, protocol.MaxCongestionWindow) }) SendAvailableSendWindowLen := func(packetLength protocol.ByteCount) int { @@ -59,11 +57,11 @@ var _ = Describe("Cubic Sender", func() { // Normal is that TCP acks every other segment. AckNPacketsLen := func(n int, packetLength protocol.ByteCount) { rttStats.UpdateRTT(60*time.Millisecond, 0, clock.Now()) - var ackedPackets congestion.PacketVector - var lostPackets congestion.PacketVector + var ackedPackets PacketVector + var lostPackets PacketVector for i := 0; i < n; i++ { ackedPacketNumber++ - ackedPackets = append(ackedPackets, congestion.PacketInfo{Number: ackedPacketNumber, Length: packetLength}) + ackedPackets = append(ackedPackets, PacketInfo{Number: ackedPacketNumber, Length: packetLength}) } sender.OnCongestionEvent(true, bytesInFlight, ackedPackets, lostPackets) bytesInFlight -= protocol.ByteCount(n) * packetLength @@ -71,11 +69,11 @@ var _ = Describe("Cubic Sender", func() { } LoseNPacketsLen := func(n int, packetLength protocol.ByteCount) { - var ackedPackets congestion.PacketVector - var lostPackets congestion.PacketVector + var ackedPackets PacketVector + var lostPackets PacketVector for i := 0; i < n; i++ { ackedPacketNumber++ - lostPackets = append(lostPackets, congestion.PacketInfo{Number: ackedPacketNumber, Length: packetLength}) + lostPackets = append(lostPackets, PacketInfo{Number: ackedPacketNumber, Length: packetLength}) } sender.OnCongestionEvent(false, bytesInFlight, ackedPackets, lostPackets) bytesInFlight -= protocol.ByteCount(n) * packetLength @@ -83,8 +81,8 @@ var _ = Describe("Cubic Sender", func() { // Does not increment acked_packet_number_. LosePacket := func(number protocol.PacketNumber) { - var ackedPackets congestion.PacketVector - var lostPackets congestion.PacketVector = congestion.PacketVector([]congestion.PacketInfo{ + var ackedPackets PacketVector + var lostPackets PacketVector = PacketVector([]PacketInfo{ {Number: number, Length: protocol.DefaultTCPMSS}, }) sender.OnCongestionEvent(false, bytesInFlight, ackedPackets, lostPackets) @@ -143,7 +141,7 @@ var _ = Describe("Cubic Sender", func() { } cwnd := sender.GetCongestionWindow() Expect(cwnd).To(Equal(defaultWindowTCP + protocol.DefaultTCPMSS*2*kNumberOfAcks)) - Expect(sender.BandwidthEstimate()).To(Equal(congestion.BandwidthFromDelta(cwnd, rttStats.SmoothedRTT()))) + Expect(sender.BandwidthEstimate()).To(Equal(BandwidthFromDelta(cwnd, rttStats.SmoothedRTT()))) }) It("slow start packet loss", func() { @@ -422,7 +420,7 @@ var _ = Describe("Cubic Sender", func() { Expect(rttStats.SmoothedRTT()).To(BeNumerically("~", kRttMs, time.Millisecond)) Expect(sender.RetransmissionDelay()).To(BeNumerically("~", expected_delay, time.Millisecond)) - Expect(sender.BandwidthEstimate() / congestion.BytesPerSecond).To(Equal(congestion.Bandwidth( + Expect(sender.BandwidthEstimate() / BytesPerSecond).To(Equal(Bandwidth( sender.GetCongestionWindow() * protocol.ByteCount(time.Second) / protocol.ByteCount(rttStats.SmoothedRTT()), ))) }) @@ -430,7 +428,7 @@ var _ = Describe("Cubic Sender", func() { It("slow start max send window", func() { const kMaxCongestionWindowTCP = 50 const kNumberOfAcks = 100 - sender = congestion.NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) for i := 0; i < kNumberOfAcks; i++ { // Send our full send window. @@ -444,7 +442,7 @@ var _ = Describe("Cubic Sender", func() { It("tcp reno max congestion window", func() { const kMaxCongestionWindowTCP = 50 const kNumberOfAcks = 1000 - sender = congestion.NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) SendAvailableSendWindow() AckNPackets(2) @@ -466,7 +464,7 @@ var _ = Describe("Cubic Sender", func() { // Set to 10000 to compensate for small cubic alpha. const kNumberOfAcks = 10000 - sender = congestion.NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) SendAvailableSendWindow() AckNPackets(2) @@ -486,7 +484,7 @@ var _ = Describe("Cubic Sender", func() { It("tcp cubic reset epoch on quiescence", func() { const kMaxCongestionWindow = 50 const kMaxCongestionWindowBytes = kMaxCongestionWindow * protocol.DefaultTCPMSS - sender = congestion.NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindow) + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindow) num_sent := SendAvailableSendWindow() @@ -526,7 +524,7 @@ var _ = Describe("Cubic Sender", func() { It("tcp cubic shifted epoch on quiescence", func() { const kMaxCongestionWindow = 50 const kMaxCongestionWindowBytes = kMaxCongestionWindow * protocol.DefaultTCPMSS - sender = congestion.NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindow) + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindow) num_sent := SendAvailableSendWindow() diff --git a/congestion/cubic_test.go b/congestion/cubic_test.go index f7f5182a0..e98a05d99 100644 --- a/congestion/cubic_test.go +++ b/congestion/cubic_test.go @@ -1,9 +1,8 @@ -package congestion_test +package congestion import ( "time" - "github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -17,12 +16,12 @@ const kNConnectionAlpha float32 = 3 * float32(kNumConnections) * float32(kNumCon var _ = Describe("Cubic", func() { var ( clock mockClock - cubic *congestion.Cubic + cubic *Cubic ) BeforeEach(func() { clock = mockClock{} - cubic = congestion.NewCubic(&clock) + cubic = NewCubic(&clock) }) It("works above origin", func() { diff --git a/congestion/hybrid_slow_start_test.go b/congestion/hybrid_slow_start_test.go index 553555849..43379f5c6 100644 --- a/congestion/hybrid_slow_start_test.go +++ b/congestion/hybrid_slow_start_test.go @@ -1,9 +1,8 @@ -package congestion_test +package congestion import ( "time" - "github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -11,11 +10,11 @@ import ( var _ = Describe("Hybrid slow start", func() { var ( - slowStart congestion.HybridSlowStart + slowStart HybridSlowStart ) BeforeEach(func() { - slowStart = congestion.HybridSlowStart{} + slowStart = HybridSlowStart{} }) It("works in a simple case", func() { diff --git a/congestion/prr_sender_test.go b/congestion/prr_sender_test.go index 5af07b776..0a6aa630f 100644 --- a/congestion/prr_sender_test.go +++ b/congestion/prr_sender_test.go @@ -1,21 +1,20 @@ -package congestion_test +package congestion import ( . "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() { var ( - prr congestion.PrrSender + prr PrrSender ) BeforeEach(func() { - prr = congestion.PrrSender{} + prr = PrrSender{} }) It("single loss results in send on every other ack", func() { diff --git a/congestion/rtt_stats_test.go b/congestion/rtt_stats_test.go index b0e0aeae1..3b722a605 100644 --- a/congestion/rtt_stats_test.go +++ b/congestion/rtt_stats_test.go @@ -1,9 +1,8 @@ -package congestion_test +package congestion import ( "time" - "github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/utils" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -11,11 +10,11 @@ import ( var _ = Describe("RTT stats", func() { var ( - rttStats *congestion.RTTStats + rttStats *RTTStats ) BeforeEach(func() { - rttStats = congestion.NewRTTStats() + rttStats = NewRTTStats() }) It("DefaultsBeforeUpdate", func() { diff --git a/protocol/packet_number_test.go b/protocol/packet_number_test.go index 0c071629d..88539b941 100644 --- a/protocol/packet_number_test.go +++ b/protocol/packet_number_test.go @@ -1,11 +1,9 @@ -package protocol_test +package protocol import ( "fmt" "math" - . "github.com/lucas-clemente/quic-go/protocol" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/protocol/protocol_suite_test.go b/protocol/protocol_suite_test.go index 8e38c4c82..204a3680e 100644 --- a/protocol/protocol_suite_test.go +++ b/protocol/protocol_suite_test.go @@ -1,4 +1,4 @@ -package protocol_test +package protocol import ( . "github.com/onsi/ginkgo" diff --git a/protocol/version_test.go b/protocol/version_test.go index 727148b34..89b2dddab 100644 --- a/protocol/version_test.go +++ b/protocol/version_test.go @@ -1,33 +1,31 @@ -package protocol_test +package protocol import ( - "github.com/lucas-clemente/quic-go/protocol" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Version", func() { It("converts tags to numbers", func() { - Expect(protocol.VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(protocol.VersionNumber(123))) - Expect(protocol.VersionTagToNumber('Q' + '0'<<8 + '3'<<16 + '0'<<24)).To(Equal(protocol.Version30)) + Expect(VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(VersionNumber(123))) + Expect(VersionTagToNumber('Q' + '0'<<8 + '3'<<16 + '0'<<24)).To(Equal(Version30)) }) It("converts number to tag", func() { - Expect(protocol.VersionNumberToTag(protocol.VersionNumber(123))).To(Equal(uint32('Q' + '1'<<8 + '2'<<16 + '3'<<24))) - Expect(protocol.VersionNumberToTag(protocol.Version30)).To(Equal(uint32('Q' + '0'<<8 + '3'<<16 + '0'<<24))) + Expect(VersionNumberToTag(VersionNumber(123))).To(Equal(uint32('Q' + '1'<<8 + '2'<<16 + '3'<<24))) + Expect(VersionNumberToTag(Version30)).To(Equal(uint32('Q' + '0'<<8 + '3'<<16 + '0'<<24))) }) It("has proper tag list", func() { - Expect(protocol.SupportedVersionsAsTags).To(Equal([]byte("Q030Q031Q032Q033"))) + Expect(SupportedVersionsAsTags).To(Equal([]byte("Q030Q031Q032Q033"))) }) It("has proper version list", func() { - Expect(protocol.SupportedVersionsAsString).To(Equal("33,32,31,30")) + Expect(SupportedVersionsAsString).To(Equal("33,32,31,30")) }) It("recognizes supported versions", func() { - Expect(protocol.IsSupportedVersion(0)).To(BeFalse()) - Expect(protocol.IsSupportedVersion(protocol.SupportedVersions[0])).To(BeTrue()) + Expect(IsSupportedVersion(0)).To(BeFalse()) + Expect(IsSupportedVersion(SupportedVersions[0])).To(BeTrue()) }) }) diff --git a/qerr/errorcodes_test.go b/qerr/errorcodes_test.go index a998866e5..63bf487dc 100644 --- a/qerr/errorcodes_test.go +++ b/qerr/errorcodes_test.go @@ -1,4 +1,4 @@ -package qerr_test +package qerr import ( "go/ast" @@ -7,8 +7,6 @@ import ( "os" "strconv" - "github.com/lucas-clemente/quic-go/qerr" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -28,8 +26,8 @@ var _ = Describe("error codes", func() { valString := c.(*ast.ValueSpec).Values[0].(*ast.BasicLit).Value val, err := strconv.Atoi(valString) Expect(err).NotTo(HaveOccurred()) - Expect(qerr.ErrorCode(val).String()).To(Equal(name)) + Expect(ErrorCode(val).String()).To(Equal(name)) } - Expect(qerr.ErrorCode(0).String()).To(Equal("ErrorCode(0)")) + Expect(ErrorCode(0).String()).To(Equal("ErrorCode(0)")) }) }) diff --git a/qerr/errors_suite_test.go b/qerr/errors_suite_test.go index f941890e6..749cdedcf 100644 --- a/qerr/errors_suite_test.go +++ b/qerr/errors_suite_test.go @@ -1,4 +1,4 @@ -package qerr_test +package qerr import ( "testing" diff --git a/qerr/quic_error_test.go b/qerr/quic_error_test.go index 922a66a6b..5c84a75f0 100644 --- a/qerr/quic_error_test.go +++ b/qerr/quic_error_test.go @@ -1,10 +1,8 @@ -package qerr_test +package qerr import ( "io" - "github.com/lucas-clemente/quic-go/qerr" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -12,31 +10,31 @@ import ( var _ = Describe("Quic error", func() { Context("QuicError", func() { It("has a string representation", func() { - err := qerr.Error(qerr.DecryptionFailure, "foobar") + err := Error(DecryptionFailure, "foobar") Expect(err.Error()).To(Equal("DecryptionFailure: foobar")) }) }) Context("ErrorCode", func() { It("works as error", func() { - var err error = qerr.DecryptionFailure + var err error = DecryptionFailure Expect(err).To(MatchError("DecryptionFailure")) }) }) Context("ToQuicError", func() { It("leaves QuicError unchanged", func() { - err := qerr.Error(qerr.DecryptionFailure, "foo") - Expect(qerr.ToQuicError(err)).To(Equal(err)) + err := Error(DecryptionFailure, "foo") + Expect(ToQuicError(err)).To(Equal(err)) }) It("wraps ErrorCode properly", func() { - var err error = qerr.DecryptionFailure - Expect(qerr.ToQuicError(err)).To(Equal(qerr.Error(qerr.DecryptionFailure, ""))) + var err error = DecryptionFailure + Expect(ToQuicError(err)).To(Equal(Error(DecryptionFailure, ""))) }) It("changes default errors to InternalError", func() { - Expect(qerr.ToQuicError(io.EOF)).To(Equal(qerr.Error(qerr.InternalError, "EOF"))) + Expect(ToQuicError(io.EOF)).To(Equal(Error(InternalError, "EOF"))) }) }) })