From ab2b26a5cb9a9f876bfbb3598cae54a6a76874f9 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 13 Sep 2019 13:29:12 +0700 Subject: [PATCH] add the unparam linter --- .golangci.yml | 1 + client.go | 2 +- closed_session.go | 2 +- internal/ackhandler/sent_packet_handler.go | 4 ++-- internal/congestion/cubic_sender.go | 2 +- .../flowcontrol/base_flow_controller_test.go | 1 + internal/handshake/crypto_setup.go | 4 ++-- internal/wire/ack_frame.go | 2 +- internal/wire/connection_close_frame.go | 2 +- internal/wire/extended_header.go | 8 ++++---- internal/wire/header_test.go | 2 +- internal/wire/max_data_frame.go | 2 +- internal/wire/max_stream_data_frame.go | 2 +- internal/wire/path_challenge_frame.go | 2 +- internal/wire/path_response_frame.go | 2 +- internal/wire/ping_frame.go | 2 +- internal/wire/reset_stream_frame.go | 4 ++-- internal/wire/stream_frame.go | 2 +- packet_handler_map.go | 6 +++--- packet_packer.go | 9 +++------ session.go | 18 ++++++++---------- session_test.go | 11 ++++------- streams_map_generic_helper.go | 1 + streams_map_incoming_generic.go | 1 + streams_map_outgoing_generic.go | 1 + 25 files changed, 45 insertions(+), 48 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 45725699..95a8e5e2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,6 +21,7 @@ linters: - staticcheck - structcheck - unconvert + - unparam - unused - varcheck - vet diff --git a/client.go b/client.go index 9b0fd7c3..9cd9390b 100644 --- a/client.go +++ b/client.go @@ -356,7 +356,7 @@ func (c *client) handleVersionNegotiationPacket(p *receivedPacket) { c.initialPacketNumber = c.session.closeForRecreating() } -func (c *client) createNewTLSSession(version protocol.VersionNumber) error { +func (c *client) createNewTLSSession(_ protocol.VersionNumber) error { params := &handshake.TransportParameters{ InitialMaxStreamDataBidiRemote: protocol.InitialMaxStreamData, InitialMaxStreamDataBidiLocal: protocol.InitialMaxStreamData, diff --git a/closed_session.go b/closed_session.go index 3a0728f1..96a22182 100644 --- a/closed_session.go +++ b/closed_session.go @@ -64,7 +64,7 @@ func (s *closedLocalSession) handlePacket(p *receivedPacket) { } } -func (s *closedLocalSession) handlePacketImpl(p *receivedPacket) { +func (s *closedLocalSession) handlePacketImpl(_ *receivedPacket) { s.counter++ // exponential backoff // only send a CONNECTION_CLOSE for the 1st, 2nd, 4th, 8th, 16th, ... packet arriving diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index f542db32..2d76b7c7 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -210,7 +210,7 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumbe if p.LargestAcked != protocol.InvalidPacketNumber && encLevel == protocol.Encryption1RTT { h.lowestNotConfirmedAcked = utils.MaxPacketNumber(h.lowestNotConfirmedAcked, p.LargestAcked+1) } - if err := h.onPacketAcked(p, rcvTime); err != nil { + if err := h.onPacketAcked(p); err != nil { return err } if p.includedInBytesInFlight { @@ -438,7 +438,7 @@ func (h *sentPacketHandler) GetLossDetectionTimeout() time.Time { return h.alarm } -func (h *sentPacketHandler) onPacketAcked(p *Packet, rcvTime time.Time) error { +func (h *sentPacketHandler) onPacketAcked(p *Packet) error { pnSpace := h.getPacketNumberSpace(p.EncryptionLevel) if packet := pnSpace.history.GetPacket(p.PacketNumber); packet == nil { return nil diff --git a/internal/congestion/cubic_sender.go b/internal/congestion/cubic_sender.go index 71bebe71..3e3a884d 100644 --- a/internal/congestion/cubic_sender.go +++ b/internal/congestion/cubic_sender.go @@ -231,7 +231,7 @@ func (c *cubicSender) RenoBeta() float32 { // Called when we receive an ack. Normal TCP tracks how many packets one ack // represents, but quic has a separate ack for each packet. func (c *cubicSender) maybeIncreaseCwnd( - ackedPacketNumber protocol.PacketNumber, + _ protocol.PacketNumber, ackedBytes protocol.ByteCount, priorInFlight protocol.ByteCount, eventTime time.Time, diff --git a/internal/flowcontrol/base_flow_controller_test.go b/internal/flowcontrol/base_flow_controller_test.go index cc2434ec..741caae5 100644 --- a/internal/flowcontrol/base_flow_controller_test.go +++ b/internal/flowcontrol/base_flow_controller_test.go @@ -12,6 +12,7 @@ import ( ) // on the CIs, the timing is a lot less precise, so scale every duration by this factor +//nolint:unparam func scaleDuration(t time.Duration) time.Duration { scaleFactor := 1 if f, err := strconv.Atoi(os.Getenv("TIMESCALE_FACTOR")); err == nil { // parsing "" errors, so this works fine if the env is not set diff --git a/internal/handshake/crypto_setup.go b/internal/handshake/crypto_setup.go index 91f555a3..5508cfdc 100644 --- a/internal/handshake/crypto_setup.go +++ b/internal/handshake/crypto_setup.go @@ -307,7 +307,7 @@ func (h *cryptoSetup) HandleMessage(data []byte, encLevel protocol.EncryptionLev } h.messageChan <- data if encLevel == protocol.Encryption1RTT { - h.handlePostHandshakeMessage(data) + h.handlePostHandshakeMessage() } switch h.perspective { case protocol.PerspectiveClient: @@ -456,7 +456,7 @@ func (h *cryptoSetup) maybeSendSessionTicket() { } } -func (h *cryptoSetup) handlePostHandshakeMessage(data []byte) { +func (h *cryptoSetup) handlePostHandshakeMessage() { // make sure the handshake has already completed <-h.handshakeDone diff --git a/internal/wire/ack_frame.go b/internal/wire/ack_frame.go index 378ff668..0f9b2d22 100644 --- a/internal/wire/ack_frame.go +++ b/internal/wire/ack_frame.go @@ -19,7 +19,7 @@ type AckFrame struct { } // parseAckFrame reads an ACK frame -func parseAckFrame(r *bytes.Reader, ackDelayExponent uint8, version protocol.VersionNumber) (*AckFrame, error) { +func parseAckFrame(r *bytes.Reader, ackDelayExponent uint8, _ protocol.VersionNumber) (*AckFrame, error) { typeByte, err := r.ReadByte() if err != nil { return nil, err diff --git a/internal/wire/connection_close_frame.go b/internal/wire/connection_close_frame.go index 9d59f370..48ced7af 100644 --- a/internal/wire/connection_close_frame.go +++ b/internal/wire/connection_close_frame.go @@ -17,7 +17,7 @@ type ConnectionCloseFrame struct { ReasonPhrase string } -func parseConnectionCloseFrame(r *bytes.Reader, version protocol.VersionNumber) (*ConnectionCloseFrame, error) { +func parseConnectionCloseFrame(r *bytes.Reader, _ protocol.VersionNumber) (*ConnectionCloseFrame, error) { typeByte, err := r.ReadByte() if err != nil { return nil, err diff --git a/internal/wire/extended_header.go b/internal/wire/extended_header.go index a8387b71..af9b94bb 100644 --- a/internal/wire/extended_header.go +++ b/internal/wire/extended_header.go @@ -44,7 +44,7 @@ func (h *ExtendedHeader) parse(b *bytes.Reader, v protocol.VersionNumber) (*Exte return h.parseShortHeader(b, v) } -func (h *ExtendedHeader) parseLongHeader(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) { +func (h *ExtendedHeader) parseLongHeader(b *bytes.Reader, _ protocol.VersionNumber) (*ExtendedHeader, error) { if err := h.readPacketNumber(b); err != nil { return nil, err } @@ -55,7 +55,7 @@ func (h *ExtendedHeader) parseLongHeader(b *bytes.Reader, v protocol.VersionNumb return h, err } -func (h *ExtendedHeader) parseShortHeader(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) { +func (h *ExtendedHeader) parseShortHeader(b *bytes.Reader, _ protocol.VersionNumber) (*ExtendedHeader, error) { h.KeyPhase = protocol.KeyPhaseZero if h.typeByte&0x4 > 0 { h.KeyPhase = protocol.KeyPhaseOne @@ -121,7 +121,7 @@ func (h *ExtendedHeader) Write(b *bytes.Buffer, ver protocol.VersionNumber) erro return h.writeShortHeader(b, ver) } -func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumber) error { +func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, _ protocol.VersionNumber) error { var packetType uint8 switch h.Type { case protocol.PacketTypeInitial: @@ -161,7 +161,7 @@ func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumb return h.writePacketNumber(b) } -func (h *ExtendedHeader) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) error { +func (h *ExtendedHeader) writeShortHeader(b *bytes.Buffer, _ protocol.VersionNumber) error { typeByte := 0x40 | uint8(h.PacketNumberLen-1) if h.KeyPhase == protocol.KeyPhaseOne { typeByte |= byte(1 << 2) diff --git a/internal/wire/header_test.go b/internal/wire/header_test.go index 3e93c98c..8b790a23 100644 --- a/internal/wire/header_test.go +++ b/internal/wire/header_test.go @@ -14,7 +14,7 @@ var _ = Describe("Header Parsing", func() { appendVersion := func(data []byte, v protocol.VersionNumber) []byte { offset := len(data) data = append(data, []byte{0, 0, 0, 0}...) - binary.BigEndian.PutUint32(data[offset:], uint32(versionIETFFrames)) + binary.BigEndian.PutUint32(data[offset:], uint32(v)) return data } diff --git a/internal/wire/max_data_frame.go b/internal/wire/max_data_frame.go index c4a9be0d..60051bd7 100644 --- a/internal/wire/max_data_frame.go +++ b/internal/wire/max_data_frame.go @@ -13,7 +13,7 @@ type MaxDataFrame struct { } // parseMaxDataFrame parses a MAX_DATA frame -func parseMaxDataFrame(r *bytes.Reader, version protocol.VersionNumber) (*MaxDataFrame, error) { +func parseMaxDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxDataFrame, error) { if _, err := r.ReadByte(); err != nil { return nil, err } diff --git a/internal/wire/max_stream_data_frame.go b/internal/wire/max_stream_data_frame.go index 2566f1c9..e5f4a2cd 100644 --- a/internal/wire/max_stream_data_frame.go +++ b/internal/wire/max_stream_data_frame.go @@ -13,7 +13,7 @@ type MaxStreamDataFrame struct { ByteOffset protocol.ByteCount } -func parseMaxStreamDataFrame(r *bytes.Reader, version protocol.VersionNumber) (*MaxStreamDataFrame, error) { +func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStreamDataFrame, error) { if _, err := r.ReadByte(); err != nil { return nil, err } diff --git a/internal/wire/path_challenge_frame.go b/internal/wire/path_challenge_frame.go index d35ee3b5..5ec82177 100644 --- a/internal/wire/path_challenge_frame.go +++ b/internal/wire/path_challenge_frame.go @@ -12,7 +12,7 @@ type PathChallengeFrame struct { Data [8]byte } -func parsePathChallengeFrame(r *bytes.Reader, version protocol.VersionNumber) (*PathChallengeFrame, error) { +func parsePathChallengeFrame(r *bytes.Reader, _ protocol.VersionNumber) (*PathChallengeFrame, error) { if _, err := r.ReadByte(); err != nil { return nil, err } diff --git a/internal/wire/path_response_frame.go b/internal/wire/path_response_frame.go index 20d8fd72..262819f8 100644 --- a/internal/wire/path_response_frame.go +++ b/internal/wire/path_response_frame.go @@ -12,7 +12,7 @@ type PathResponseFrame struct { Data [8]byte } -func parsePathResponseFrame(r *bytes.Reader, version protocol.VersionNumber) (*PathResponseFrame, error) { +func parsePathResponseFrame(r *bytes.Reader, _ protocol.VersionNumber) (*PathResponseFrame, error) { if _, err := r.ReadByte(); err != nil { return nil, err } diff --git a/internal/wire/ping_frame.go b/internal/wire/ping_frame.go index aed6857b..dc029e45 100644 --- a/internal/wire/ping_frame.go +++ b/internal/wire/ping_frame.go @@ -9,7 +9,7 @@ import ( // A PingFrame is a PING frame type PingFrame struct{} -func parsePingFrame(r *bytes.Reader, version protocol.VersionNumber) (*PingFrame, error) { +func parsePingFrame(r *bytes.Reader, _ protocol.VersionNumber) (*PingFrame, error) { if _, err := r.ReadByte(); err != nil { return nil, err } diff --git a/internal/wire/reset_stream_frame.go b/internal/wire/reset_stream_frame.go index b743e046..b93a705e 100644 --- a/internal/wire/reset_stream_frame.go +++ b/internal/wire/reset_stream_frame.go @@ -14,7 +14,7 @@ type ResetStreamFrame struct { ByteOffset protocol.ByteCount } -func parseResetStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*ResetStreamFrame, error) { +func parseResetStreamFrame(r *bytes.Reader, _ protocol.VersionNumber) (*ResetStreamFrame, error) { if _, err := r.ReadByte(); err != nil { // read the TypeByte return nil, err } @@ -43,7 +43,7 @@ func parseResetStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*Re }, nil } -func (f *ResetStreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error { +func (f *ResetStreamFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) error { b.WriteByte(0x4) utils.WriteVarInt(b, uint64(f.StreamID)) utils.WriteVarInt(b, uint64(f.ErrorCode)) diff --git a/internal/wire/stream_frame.go b/internal/wire/stream_frame.go index 0217cc83..47fb2a1e 100644 --- a/internal/wire/stream_frame.go +++ b/internal/wire/stream_frame.go @@ -21,7 +21,7 @@ type StreamFrame struct { fromPool bool } -func parseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamFrame, error) { +func parseStreamFrame(r *bytes.Reader, _ protocol.VersionNumber) (*StreamFrame, error) { typeByte, err := r.ReadByte() if err != nil { return nil, err diff --git a/packet_handler_map.go b/packet_handler_map.go index 1475bc14..a64bd2ed 100644 --- a/packet_handler_map.go +++ b/packet_handler_map.go @@ -125,14 +125,14 @@ func (h *packetHandlerMap) CloseServer() { h.mutex.Lock() h.server = nil var wg sync.WaitGroup - for id, handler := range h.handlers { + for _, handler := range h.handlers { if handler.getPerspective() == protocol.PerspectiveServer { wg.Add(1) - go func(id string, handler packetHandler) { + go func(handler packetHandler) { // session.Close() blocks until the CONNECTION_CLOSE has been sent and the run-loop has stopped _ = handler.Close() wg.Done() - }(id, handler) + }(handler) } } h.mutex.Unlock() diff --git a/packet_packer.go b/packet_packer.go index adaced6e..9b1b3803 100644 --- a/packet_packer.go +++ b/packet_packer.go @@ -275,10 +275,7 @@ func (p *packetPacker) PackPacket() (*packedPacket, error) { headerLen := header.GetLength(p.version) maxSize := p.maxPacketSize - protocol.ByteCount(sealer.Overhead()) - headerLen - payload, err := p.composeNextPacket(maxSize) - if err != nil { - return nil, err - } + payload := p.composeNextPacket(maxSize) // check if we have anything to send if len(payload.frames) == 0 && payload.ack == nil { @@ -372,7 +369,7 @@ func (p *packetPacker) maybePackCryptoPacket() (*packedPacket, error) { return p.writeAndSealPacket(hdr, payload, encLevel, sealer) } -func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount) (payload, error) { +func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount) payload { var payload payload if ack := p.acks.GetAckFrame(protocol.Encryption1RTT); ack != nil { @@ -399,7 +396,7 @@ func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount) (paylo payload.frames, lengthAdded = p.framer.AppendStreamFrames(payload.frames, maxFrameSize-payload.length) payload.length += lengthAdded - return payload, nil + return payload } func (p *packetPacker) getSealerAndHeader(encLevel protocol.EncryptionLevel) (sealer, *wire.ExtendedHeader, error) { diff --git a/session.go b/session.go index 8d98d48f..e305b282 100644 --- a/session.go +++ b/session.go @@ -250,9 +250,7 @@ var newSession = func( ) s.cryptoStreamManager = newCryptoStreamManager(cs, initialStream, handshakeStream, oneRTTStream) - if err := s.postSetup(); err != nil { - return nil, err - } + s.postSetup() s.unpacker = newPacketUnpacker(cs, s.version) return s, nil } @@ -345,7 +343,8 @@ var newClientSession = func( s.packer.SetToken(token.data) } } - return s, s.postSetup() + s.postSetup() + return s, nil } func (s *session) preSetup() { @@ -369,7 +368,7 @@ func (s *session) preSetup() { } } -func (s *session) postSetup() error { +func (s *session) postSetup() { s.receivedPackets = make(chan *receivedPacket, protocol.MaxSessionUnprocessedPackets) s.closeChan = make(chan closeError, 1) s.sendingScheduled = make(chan struct{}, 1) @@ -383,7 +382,6 @@ func (s *session) postSetup() error { s.sessionCreationTime = now s.windowUpdateQueue = newWindowUpdateQueue(s.streamsMap, s.connFlowController, s.framer.QueueControlFrame) - return nil } // run the session main loop @@ -608,7 +606,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool / }() if hdr.Type == protocol.PacketTypeRetry { - return s.handleRetryPacket(p, hdr) + return s.handleRetryPacket(hdr) } // The server can change the source connection ID with the first Handshake packet. @@ -654,7 +652,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool / return true } -func (s *session) handleRetryPacket(p *receivedPacket, hdr *wire.Header) bool /* was this a valid Retry */ { +func (s *session) handleRetryPacket(hdr *wire.Header) bool /* was this a valid Retry */ { if s.perspective == protocol.PerspectiveServer { s.logger.Debugf("Ignoring Retry.") return false @@ -761,7 +759,7 @@ func (s *session) handleFrame(f wire.Frame, pn protocol.PacketNumber, encLevel p case *wire.CryptoFrame: err = s.handleCryptoFrame(frame, encLevel) case *wire.StreamFrame: - err = s.handleStreamFrame(frame, encLevel) + err = s.handleStreamFrame(frame) case *wire.AckFrame: err = s.handleAckFrame(frame, pn, encLevel) case *wire.ConnectionCloseFrame: @@ -829,7 +827,7 @@ func (s *session) handleCryptoFrame(frame *wire.CryptoFrame, encLevel protocol.E return nil } -func (s *session) handleStreamFrame(frame *wire.StreamFrame, encLevel protocol.EncryptionLevel) error { +func (s *session) handleStreamFrame(frame *wire.StreamFrame) error { str, err := s.streamsMap.GetOrOpenReceiveStream(frame.StreamID) if err != nil { return err diff --git a/session_test.go b/session_test.go index b9a8a6f4..d18cdf04 100644 --- a/session_test.go +++ b/session_test.go @@ -144,8 +144,7 @@ var _ = Describe("Session", func() { str := NewMockReceiveStreamI(mockCtrl) str.EXPECT().handleStreamFrame(f) streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(5)).Return(str, nil) - err := sess.handleStreamFrame(f, protocol.Encryption1RTT) - Expect(err).ToNot(HaveOccurred()) + Expect(sess.handleStreamFrame(f)).To(Succeed()) }) It("returns errors", func() { @@ -157,17 +156,15 @@ var _ = Describe("Session", func() { str := NewMockReceiveStreamI(mockCtrl) str.EXPECT().handleStreamFrame(f).Return(testErr) streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(5)).Return(str, nil) - err := sess.handleStreamFrame(f, protocol.Encryption1RTT) - Expect(err).To(MatchError(testErr)) + Expect(sess.handleStreamFrame(f)).To(MatchError(testErr)) }) It("ignores STREAM frames for closed streams", func() { streamManager.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(5)).Return(nil, nil) // for closed streams, the streamManager returns nil - err := sess.handleStreamFrame(&wire.StreamFrame{ + Expect(sess.handleStreamFrame(&wire.StreamFrame{ StreamID: 5, Data: []byte("foobar"), - }, protocol.Encryption1RTT) - Expect(err).ToNot(HaveOccurred()) + })).To(Succeed()) }) }) diff --git a/streams_map_generic_helper.go b/streams_map_generic_helper.go index 692f093e..b17b7ca1 100644 --- a/streams_map_generic_helper.go +++ b/streams_map_generic_helper.go @@ -1,3 +1,4 @@ +//nolint:unused package quic import ( diff --git a/streams_map_incoming_generic.go b/streams_map_incoming_generic.go index f8ace8bf..84a5dcc8 100644 --- a/streams_map_incoming_generic.go +++ b/streams_map_incoming_generic.go @@ -1,3 +1,4 @@ +//nolint:unused package quic import ( diff --git a/streams_map_outgoing_generic.go b/streams_map_outgoing_generic.go index 6b620640..00914d9f 100644 --- a/streams_map_outgoing_generic.go +++ b/streams_map_outgoing_generic.go @@ -1,3 +1,4 @@ +//nolint:unused package quic import (