Skip to content

Commit

Permalink
run gofumpt, enable the gofumpt linter
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 26, 2020
1 parent 598f975 commit 8752576
Show file tree
Hide file tree
Showing 50 changed files with 132 additions and 109 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ linters:
- exportloopref
- goconst
- goimports
- gofmt
- gofmt # redundant, since gofmt *should* be a no-op after gofumpt
- gofumpt
- gosimple
- ineffassign
- misspell
Expand Down
7 changes: 2 additions & 5 deletions benchmark/benchmark_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ package benchmark
import (
"flag"
"math/rand"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestBenchmark(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Benchmark Suite")
}

var (
size int // file size in MB, will be read from flags
)
var size int // file size in MB, will be read from flags

func init() {
flag.IntVar(&size, "size", 50, "data length (in MB)")
Expand Down
1 change: 0 additions & 1 deletion conn_id_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ var _ = Describe("Connection ID Manager", func() {
StatelessResetToken: protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
})).To(Succeed())
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))

})

It("initiates subsequent updates when enough packets are sent", func() {
Expand Down
4 changes: 1 addition & 3 deletions crypto_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ func createHandshakeMessage(len int) []byte {
}

var _ = Describe("Crypto Stream", func() {
var (
str cryptoStream
)
var str cryptoStream

BeforeEach(func() {
str = newCryptoStream()
Expand Down
21 changes: 14 additions & 7 deletions fuzzing/handshake/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"github.com/lucas-clemente/quic-go/internal/wire"
)

var cert, clientCert *tls.Certificate
var certPool, clientCertPool *x509.CertPool
var sessionTicketKey = [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
var (
cert, clientCert *tls.Certificate
certPool, clientCertPool *x509.CertPool
sessionTicketKey = [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
)

func init() {
priv, err := rsa.GenerateKey(rand.Reader, 1024)
Expand Down Expand Up @@ -183,15 +185,18 @@ func (r *runner) OnError(err error) {
(*r.client).Close()
(*r.server).Close()
}

func (r *runner) Errored() bool {
r.Lock()
defer r.Unlock()
return r.errored
}
func (r *runner) DropKeys(protocol.EncryptionLevel) {}

const alpn = "fuzzing"
const alpnWrong = "wrong"
const (
alpn = "fuzzing"
alpnWrong = "wrong"
)

func toEncryptionLevel(n uint8) protocol.EncryptionLevel {
switch n % 3 {
Expand Down Expand Up @@ -238,8 +243,10 @@ func getTransportParameters(seed uint8) *wire.TransportParameters {
}

// PrefixLen is the number of bytes used for configuration
const PrefixLen = 12
const confLen = 5
const (
PrefixLen = 12
confLen = 5
)

// Fuzz fuzzes the TLS 1.3 handshake used by QUIC.
//go:generate go run ./cmd/corpus.go
Expand Down
2 changes: 1 addition & 1 deletion fuzzing/internal/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func WriteCorpusFile(path string, data []byte) error {
}
}
hash := sha1.Sum(data)
return ioutil.WriteFile(filepath.Join(path, hex.EncodeToString(hash[:])), data, 0644)
return ioutil.WriteFile(filepath.Join(path, hex.EncodeToString(hash[:])), data, 0o644)
}

// WriteCorpusFileWithPrefix writes data to a corpus file in directory path.
Expand Down
6 changes: 4 additions & 2 deletions http3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
// Note that 0-RTT data doesn't provide replay protection.
const MethodGet0RTT = "GET_0RTT"

const defaultUserAgent = "quic-go HTTP/3"
const defaultMaxResponseHeaderBytes = 10 * 1 << 20 // 10 MB
const (
defaultUserAgent = "quic-go HTTP/3"
defaultMaxResponseHeaderBytes = 10 * 1 << 20 // 10 MB
)

var defaultQuicConfig = &quic.Config{
MaxIncomingStreams: -1, // don't allow the server to create bidirectional streams
Expand Down
6 changes: 4 additions & 2 deletions http3/response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ type responseWriter struct {
logger utils.Logger
}

var _ http.ResponseWriter = &responseWriter{}
var _ http.Flusher = &responseWriter{}
var (
_ http.ResponseWriter = &responseWriter{}
_ http.Flusher = &responseWriter{}
)

func newResponseWriter(stream io.Writer, logger utils.Logger) *responseWriter {
return &responseWriter{
Expand Down
1 change: 1 addition & 0 deletions http3/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type mockClient struct {
func (m *mockClient) RoundTrip(req *http.Request) (*http.Response, error) {
return &http.Response{Request: req}, nil
}

func (m *mockClient) Close() error {
m.closed = true
return nil
Expand Down
12 changes: 5 additions & 7 deletions http3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ type contextKey struct {

func (k *contextKey) String() string { return "quic-go/http3 context value " + k.name }

var (
// ServerContextKey is a context key. It can be used in HTTP
// handlers with Context.Value to access the server that
// started the handler. The associated value will be of
// type *http3.Server.
ServerContextKey = &contextKey{"http3-server"}
)
// ServerContextKey is a context key. It can be used in HTTP
// handlers with Context.Value to access the server that
// started the handler. The associated value will be of
// type *http3.Server.
var ServerContextKey = &contextKey{"http3-server"}

type requestError struct {
err error
Expand Down
1 change: 0 additions & 1 deletion integrationtests/self/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ var _ = Describe("Handshake tests", func() {
Expect(err).To(HaveOccurred())
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.ConnectionRefused))
})

})

Context("ALPN", func() {
Expand Down
7 changes: 5 additions & 2 deletions integrationtests/self/key_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
. "github.com/onsi/gomega"
)

var sentHeaders []*logging.ExtendedHeader
var receivedHeaders []*logging.ExtendedHeader
var (
sentHeaders []*logging.ExtendedHeader
receivedHeaders []*logging.ExtendedHeader
)

func countKeyPhases() (sent, received int) {
lastKeyPhase := protocol.KeyPhaseOne
Expand Down Expand Up @@ -75,6 +77,7 @@ func (t *connTracer) BufferedPacket(logging.PacketType)
func (t *connTracer) DroppedPacket(logging.PacketType, logging.ByteCount, logging.PacketDropReason) {}
func (t *connTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) {
}

func (t *connTracer) LostPacket(logging.EncryptionLevel, logging.PacketNumber, logging.PacketLossReason) {
}
func (t *connTracer) UpdatedCongestionState(logging.CongestionState) {}
Expand Down
4 changes: 2 additions & 2 deletions integrationtests/tools/proxy/proxy_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package quicproxy

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestQuicGo(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/ackhandler/ackhandler_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ackhandler

import (
"testing"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestCrypto(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions internal/ackhandler/received_packet_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
)

var _ = Describe("receivedPacketHistory", func() {
var (
hist *receivedPacketHistory
)
var hist *receivedPacketHistory

BeforeEach(func() {
hist = newReceivedPacketHistory()
Expand Down
6 changes: 4 additions & 2 deletions internal/ackhandler/sent_packet_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ type sentPacketHandler struct {
logger utils.Logger
}

var _ SentPacketHandler = &sentPacketHandler{}
var _ sentPacketTracker = &sentPacketHandler{}
var (
_ SentPacketHandler = &sentPacketHandler{}
_ sentPacketTracker = &sentPacketHandler{}
)

func newSentPacketHandler(
initialPacketNumber protocol.PacketNumber,
Expand Down
9 changes: 5 additions & 4 deletions internal/ackhandler/sent_packet_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ var _ = Describe("SentPacketHandler", func() {
ping := &wire.PingFrame{}
handler.SentPacket(ackElicitingPacket(&Packet{
PacketNumber: 13,
Frames: []Frame{{Frame: ping, OnAcked: func(f wire.Frame) {
Expect(f).To(Equal(ping))
acked = true
},
Frames: []Frame{{
Frame: ping, OnAcked: func(f wire.Frame) {
Expect(f).To(Equal(ping))
acked = true
},
}},
}))
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 13, Largest: 13}}}
Expand Down
4 changes: 2 additions & 2 deletions internal/congestion/congestion_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package congestion

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestCongestion(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions internal/congestion/cubic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (

// 1024*1024^3 (first 1024 is from 0.100^3)
// where 0.100 is 100 ms which is the scaling round trip time.
const cubeScale = 40
const cubeCongestionWindowScale = 410
const cubeFactor protocol.ByteCount = 1 << cubeScale / cubeCongestionWindowScale / maxDatagramSize
const (
cubeScale = 40
cubeCongestionWindowScale = 410
cubeFactor protocol.ByteCount = 1 << cubeScale / cubeCongestionWindowScale / maxDatagramSize
)

const defaultNumConnections = 1

Expand Down
6 changes: 4 additions & 2 deletions internal/congestion/cubic_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ type cubicSender struct {
tracer logging.ConnectionTracer
}

var _ SendAlgorithm = &cubicSender{}
var _ SendAlgorithmWithDebugInfos = &cubicSender{}
var (
_ SendAlgorithm = &cubicSender{}
_ SendAlgorithmWithDebugInfos = &cubicSender{}
)

// NewCubicSender makes a new cubic sender
func NewCubicSender(clock Clock, rttStats *utils.RTTStats, reno bool, tracer logging.ConnectionTracer) *cubicSender {
Expand Down
6 changes: 4 additions & 2 deletions internal/congestion/cubic_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
. "github.com/onsi/gomega"
)

const initialCongestionWindowPackets = 10
const defaultWindowTCP = protocol.ByteCount(initialCongestionWindowPackets) * maxDatagramSize
const (
initialCongestionWindowPackets = 10
defaultWindowTCP = protocol.ByteCount(initialCongestionWindowPackets) * maxDatagramSize
)

type mockClock time.Time

Expand Down
12 changes: 7 additions & 5 deletions internal/congestion/cubic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
. "github.com/onsi/gomega"
)

const numConnections uint32 = 2
const nConnectionBeta float32 = (float32(numConnections) - 1 + beta) / float32(numConnections)
const nConnectionBetaLastMax float32 = (float32(numConnections) - 1 + betaLastMax) / float32(numConnections)
const nConnectionAlpha float32 = 3 * float32(numConnections) * float32(numConnections) * (1 - nConnectionBeta) / (1 + nConnectionBeta)
const maxCubicTimeInterval = 30 * time.Millisecond
const (
numConnections uint32 = 2
nConnectionBeta float32 = (float32(numConnections) - 1 + beta) / float32(numConnections)
nConnectionBetaLastMax float32 = (float32(numConnections) - 1 + betaLastMax) / float32(numConnections)
nConnectionAlpha float32 = 3 * float32(numConnections) * float32(numConnections) * (1 - nConnectionBeta) / (1 + nConnectionBeta)
maxCubicTimeInterval = 30 * time.Millisecond
)

var _ = Describe("Cubic", func() {
var (
Expand Down
6 changes: 4 additions & 2 deletions internal/congestion/hybrid_slow_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const hybridStartMinSamples = uint32(8)
// Exit slow start if the min rtt has increased by more than 1/8th.
const hybridStartDelayFactorExp = 3 // 2^3 = 8
// The original paper specifies 2 and 8ms, but those have changed over time.
const hybridStartDelayMinThresholdUs = int64(4000)
const hybridStartDelayMaxThresholdUs = int64(16000)
const (
hybridStartDelayMinThresholdUs = int64(4000)
hybridStartDelayMaxThresholdUs = int64(16000)
)

// HybridSlowStart implements the TCP hybrid slow start algorithm
type HybridSlowStart struct {
Expand Down
5 changes: 1 addition & 4 deletions internal/congestion/hybrid_slow_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
)

var _ = Describe("Hybrid slow start", func() {
var (
slowStart HybridSlowStart
)
var slowStart HybridSlowStart

BeforeEach(func() {
slowStart = HybridSlowStart{}
Expand Down Expand Up @@ -71,5 +69,4 @@ var _ = Describe("Hybrid slow start", func() {
// RTT provided.
Expect(slowStart.ShouldExitSlowStart(rtt+10*time.Millisecond, rtt, 100)).To(BeTrue())
})

})
4 changes: 2 additions & 2 deletions internal/flowcontrol/flowcontrol_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package flowcontrol

import (
"testing"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestCrypto(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions internal/handshake/crypto_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ type cryptoSetup struct {
has1RTTOpener bool
}

var _ qtls.RecordLayer = &cryptoSetup{}
var _ CryptoSetup = &cryptoSetup{}
var (
_ qtls.RecordLayer = &cryptoSetup{}
_ CryptoSetup = &cryptoSetup{}
)

// NewCryptoSetupClient creates a new crypto setup for the client
func NewCryptoSetupClient(
Expand Down
Loading

0 comments on commit 8752576

Please sign in to comment.