mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 20:57:36 +03:00
add the unparam linter
This commit is contained in:
parent
c8aed2861f
commit
ab2b26a5cb
25 changed files with 45 additions and 48 deletions
|
@ -21,6 +21,7 @@ linters:
|
|||
- staticcheck
|
||||
- structcheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
- vet
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
18
session.go
18
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
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint:unused
|
||||
package quic
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint:unused
|
||||
package quic
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint:unused
|
||||
package quic
|
||||
|
||||
import (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue