Merge pull request #2839 from lucas-clemente/gofumpt

run gofumpt, enable the gofumpt linter
This commit is contained in:
Marten Seemann 2020-10-26 09:54:55 +07:00 committed by GitHub
commit b7652887d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 132 additions and 109 deletions

View file

@ -24,7 +24,8 @@ linters:
- exportloopref
- goconst
- goimports
- gofmt
- gofmt # redundant, since gofmt *should* be a no-op after gofumpt
- gofumpt
- gosimple
- ineffassign
- misspell

View file

@ -3,11 +3,10 @@ package benchmark
import (
"flag"
"math/rand"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestBenchmark(t *testing.T) {
@ -15,9 +14,7 @@ func TestBenchmark(t *testing.T) {
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)")

View file

@ -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() {

View file

@ -22,9 +22,7 @@ func createHandshakeMessage(len int) []byte {
}
var _ = Describe("Crypto Stream", func() {
var (
str cryptoStream
)
var str cryptoStream
BeforeEach(func() {
str = newCryptoStream()

View file

@ -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)
@ -183,6 +185,7 @@ func (r *runner) OnError(err error) {
(*r.client).Close()
(*r.server).Close()
}
func (r *runner) Errored() bool {
r.Lock()
defer r.Unlock()
@ -190,8 +193,10 @@ func (r *runner) Errored() bool {
}
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 {
@ -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

View file

@ -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.

View file

@ -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

View file

@ -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{

View file

@ -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

View file

@ -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

View file

@ -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() {

View file

@ -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
@ -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) {}

View file

@ -1,10 +1,10 @@
package quicproxy
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestQuicGo(t *testing.T) {

View file

@ -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) {

View file

@ -9,9 +9,7 @@ import (
)
var _ = Describe("receivedPacketHistory", func() {
var (
hist *receivedPacketHistory
)
var hist *receivedPacketHistory
BeforeEach(func() {
hist = newReceivedPacketHistory()

View file

@ -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,

View file

@ -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}}}

View file

@ -1,10 +1,10 @@
package congestion
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestCongestion(t *testing.T) {

View file

@ -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

View file

@ -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 {

View file

@ -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

View file

@ -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 (

View file

@ -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 {

View file

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

View file

@ -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) {

View file

@ -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(

View file

@ -4,6 +4,7 @@ import (
"crypto/tls"
"encoding/hex"
"strings"
"testing"
"github.com/lucas-clemente/quic-go/internal/qtls"
@ -11,8 +12,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestHandshake(t *testing.T) {

View file

@ -26,7 +26,6 @@ func newHeaderProtector(suite *qtls.CipherSuiteTLS13, trafficSecret []byte, isLo
default:
panic(fmt.Sprintf("Invalid cipher suite id: %d", suite.ID))
}
}
type aesHeaderProtector struct {

View file

@ -13,7 +13,7 @@ import (
var retryAEAD cipher.AEAD
func init() {
var key = [16]byte{0xcc, 0xce, 0x18, 0x7e, 0xd0, 0x9a, 0x09, 0xd0, 0x57, 0x28, 0x15, 0x5a, 0x6c, 0xb9, 0x6b, 0xe1}
key := [16]byte{0xcc, 0xce, 0x18, 0x7e, 0xd0, 0x9a, 0x09, 0xd0, 0x57, 0x28, 0x15, 0x5a, 0x6c, 0xb9, 0x6b, 0xe1}
aes, err := aes.NewCipher(key[:])
if err != nil {
@ -26,9 +26,11 @@ func init() {
retryAEAD = aead
}
var retryBuf bytes.Buffer
var retryMutex sync.Mutex
var retryNonce = [12]byte{0xe5, 0x49, 0x30, 0xf9, 0x7f, 0x21, 0x36, 0xf0, 0x53, 0x0a, 0x8c, 0x1c}
var (
retryBuf bytes.Buffer
retryMutex sync.Mutex
retryNonce = [12]byte{0xe5, 0x49, 0x30, 0xf9, 0x7f, 0x21, 0x36, 0xf0, 0x53, 0x0a, 0x8c, 0x1c}
)
// GetRetryIntegrityTag calculates the integrity tag on a Retry packet
func GetRetryIntegrityTag(retry []byte, origDestConnID protocol.ConnectionID) *[16]byte {

View file

@ -61,8 +61,10 @@ type updatableAEAD struct {
nonceBuf []byte
}
var _ ShortHeaderOpener = &updatableAEAD{}
var _ ShortHeaderSealer = &updatableAEAD{}
var (
_ ShortHeaderOpener = &updatableAEAD{}
_ ShortHeaderSealer = &updatableAEAD{}
)
func newUpdatableAEAD(rttStats *utils.RTTStats, tracer logging.ConnectionTracer, logger utils.Logger) *updatableAEAD {
return &updatableAEAD{

View file

@ -1,10 +1,10 @@
package protocol
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestProtocol(t *testing.T) {

View file

@ -61,7 +61,7 @@ func (s StreamID) InitiatedBy() Perspective {
return PerspectiveServer
}
//Type says if this is a unidirectional or bidirectional stream
// Type says if this is a unidirectional or bidirectional stream
func (s StreamID) Type() StreamType {
if s%4 >= 2 {
return StreamTypeUni

View file

@ -52,7 +52,6 @@ var _ = Describe("QUIC Transport Errors", func() {
err := NewCryptoError(42, "")
Expect(err.IsCryptoError()).To(BeTrue())
Expect(err.IsApplicationError()).To(BeFalse())
})
})

View file

@ -10,9 +10,7 @@ import (
)
var _ = Describe("RTT stats", func() {
var (
rttStats *RTTStats
)
var rttStats *RTTStats
BeforeEach(func() {
rttStats = NewRTTStats()

View file

@ -1,10 +1,10 @@
package utils
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestCrypto(t *testing.T) {

View file

@ -197,7 +197,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
Expect(err).To(MatchError(io.EOF))
}
})
})
})

View file

@ -53,7 +53,6 @@ var _ = Describe("Frame logging", func() {
}
LogFrame(logger, frame, false)
Expect(buf.String()).To(ContainSubstring("\t<- &wire.CryptoFrame{Offset: 42, Data length: 123, Offset + Data length: 165}\n"))
})
It("logs STREAM frames", func() {

View file

@ -27,7 +27,7 @@ func parseMaxDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxDataFrame
return frame, nil
}
//Write writes a MAX_STREAM_DATA frame
// Write writes a MAX_STREAM_DATA frame
func (f *MaxDataFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
b.WriteByte(0x10)
utils.WriteVarInt(b, uint64(f.MaximumData))

View file

@ -315,7 +315,7 @@ func (p *TransportParameters) readNumericTransportParameter(
func (p *TransportParameters) Marshal(pers protocol.Perspective) []byte {
b := &bytes.Buffer{}
//add a greased value
// add a greased value
utils.WriteVarInt(b, uint64(27+31*rand.Intn(100)))
length := rand.Intn(16)
randomData := make([]byte, length)

View file

@ -2,13 +2,12 @@ package wire
import (
"bytes"
"testing"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestWire(t *testing.T) {

View file

@ -33,7 +33,7 @@ func GetQLOGWriter() (func(perspective logging.Perspective, connID []byte) io.Wr
return nil, nil
}
if _, err := os.Stat(qlogDir); os.IsNotExist(err) {
if err := os.MkdirAll(qlogDir, 0666); err != nil {
if err := os.MkdirAll(qlogDir, 0o666); err != nil {
return nil, fmt.Errorf("failed to create qlog dir %s: %s", qlogDir, err.Error())
}
}

View file

@ -196,6 +196,7 @@ func (t *connTracer) LostPacket(encLevel logging.EncryptionLevel, _ logging.Pack
lostPackets.M(1),
)
}
func (t *connTracer) UpdatedPTOCount(value uint32) {
if value == 0 {
return

View file

@ -89,7 +89,8 @@ func (t *connectionTracer) run() {
},
EventFields: eventFields[:],
},
}}
},
}
if err := enc.Encode(tl); err != nil {
panic(fmt.Sprintf("qlog encoding into a bytes.Buffer failed: %s", err))
}

View file

@ -2,12 +2,11 @@ package quic
import (
"sync"
"testing"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestQuicGo(t *testing.T) {

View file

@ -52,8 +52,10 @@ type receiveStream struct {
version protocol.VersionNumber
}
var _ ReceiveStream = &receiveStream{}
var _ receiveStreamI = &receiveStream{}
var (
_ ReceiveStream = &receiveStream{}
_ receiveStreamI = &receiveStream{}
)
func newReceiveStream(
streamID protocol.StreamID,

View file

@ -57,8 +57,10 @@ type sendStream struct {
version protocol.VersionNumber
}
var _ SendStream = &sendStream{}
var _ sendStreamI = &sendStream{}
var (
_ SendStream = &sendStream{}
_ sendStreamI = &sendStream{}
)
func newSendStream(
streamID protocol.StreamID,

View file

@ -103,8 +103,10 @@ type baseServer struct {
logger utils.Logger
}
var _ Listener = &baseServer{}
var _ unknownPacketHandler = &baseServer{}
var (
_ Listener = &baseServer{}
_ unknownPacketHandler = &baseServer{}
)
type earlyServer struct{ *baseServer }

View file

@ -213,9 +213,11 @@ type session struct {
logger utils.Logger
}
var _ Session = &session{}
var _ EarlySession = &session{}
var _ streamSender = &session{}
var (
_ Session = &session{}
_ EarlySession = &session{}
_ streamSender = &session{}
)
var newSession = func(
conn sendConn,

View file

@ -2701,6 +2701,5 @@ var _ = Describe("Client Session", func() {
tracer.EXPECT().DroppedPacket(gomock.Any(), gomock.Any(), gomock.Any())
Expect(sess.handlePacketImpl(wrapPacket(initialPacket))).To(BeFalse())
})
})
})

View file

@ -53,8 +53,10 @@ type streamI interface {
handleMaxStreamDataFrame(*wire.MaxStreamDataFrame)
}
var _ receiveStreamI = (streamI)(nil)
var _ sendStreamI = (streamI)(nil)
var (
_ receiveStreamI = (streamI)(nil)
_ sendStreamI = (streamI)(nil)
)
// A Stream assembles the data from StreamFrames and provides a super-convenient Read-Interface
//