Merge pull request #2138 from lucas-clemente/linting

update GolangCI-Lint, add some more linters
This commit is contained in:
Marten Seemann 2019-09-17 15:06:20 +07:00 committed by GitHub
commit 9e6bff0b98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 82 additions and 73 deletions

View file

@ -16,9 +16,13 @@ linters:
- gosimple
- ineffassign
- misspell
- prealloc
- scopelint
- staticcheck
- stylecheck
- structcheck
- unconvert
- unparam
- unused
- varcheck
- vet

View file

@ -39,7 +39,7 @@ before_install:
script:
- |
if [ ${TESTMODE} == "lint" ]; then
travis_retry curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.15.0
travis_retry curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.18.0
fi
- .travis/script.sh

View file

@ -341,6 +341,7 @@ func (c *client) handleVersionNegotiationPacket(p *receivedPacket) {
c.logger.Infof("Received a Version Negotiation packet. Supported Versions: %s", hdr.SupportedVersions)
newVersion, ok := protocol.ChooseSupportedVersion(c.config.Versions, hdr.SupportedVersions)
if !ok {
//nolint:stylecheck
c.session.destroy(fmt.Errorf("No compatible QUIC version found. We support %s, server offered %s", c.config.Versions, hdr.SupportedVersions))
c.logger.Debugf("No compatible QUIC version found.")
return
@ -356,7 +357,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,

View file

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

View file

@ -18,7 +18,7 @@ type frameSorter struct {
gaps *utils.ByteIntervalList
}
var errDuplicateStreamData = errors.New("Duplicate Stream Data")
var errDuplicateStreamData = errors.New("duplicate stream data")
func newFrameSorter() *frameSorter {
s := frameSorter{
@ -146,7 +146,7 @@ func (s *frameSorter) push(data []byte, offset protocol.ByteCount, doneCb func()
}
if s.gaps.Len() > protocol.MaxStreamFrameSorterGaps {
return errors.New("Too many gaps in received data")
return errors.New("too many gaps in received data")
}
if wasCut && len(data) < protocol.MinStreamFrameBufferSize {

View file

@ -555,7 +555,7 @@ var _ = Describe("frame sorter", func() {
}
Expect(s.gaps.Len()).To(Equal(protocol.MaxStreamFrameSorterGaps))
err := s.Push([]byte("foobar"), protocol.ByteCount(protocol.MaxStreamFrameSorterGaps*7)+100, nil)
Expect(err).To(MatchError("Too many gaps in received data"))
Expect(err).To(MatchError("too many gaps in received data"))
})
})
})

View file

@ -44,7 +44,7 @@ var _ = Describe("Stream Cancelations", func() {
str, err := sess.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
if _, err = str.Write(testserver.PRData); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
atomic.AddInt32(&canceledCounter, 1)
return
}
@ -174,7 +174,7 @@ var _ = Describe("Stream Cancelations", func() {
data, err := ioutil.ReadAll(str)
if err != nil {
atomic.AddInt32(&counter, 1)
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(data).To(Equal(testserver.PRData))
@ -281,7 +281,7 @@ var _ = Describe("Stream Cancelations", func() {
return
}
if _, err = str.Write(testserver.PRData); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(str.Close()).To(Succeed())
@ -314,7 +314,7 @@ var _ = Describe("Stream Cancelations", func() {
}
data, err := ioutil.ReadAll(str)
if err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
atomic.AddInt32(&counter, 1)
@ -355,7 +355,7 @@ var _ = Describe("Stream Cancelations", func() {
length = int(rand.Int31n(int32(len(testserver.PRData) - 1)))
}
if _, err = str.Write(testserver.PRData[:length]); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
if length < len(testserver.PRData) {
@ -396,7 +396,7 @@ var _ = Describe("Stream Cancelations", func() {
}
data, err := ioutil.ReadAll(r)
if err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(data).To(Equal(testserver.PRData[:length]))

View file

@ -161,7 +161,7 @@ var _ = Describe("Handshake drop tests", func() {
app := a
Context(app.name, func() {
It(fmt.Sprintf("establishes a connection when the first packet is lost in %s direction", d), func() {
It(fmt.Sprintf("establishes a connection when the first packet is lost in %s direction", direction), func() {
var incoming, outgoing int32
startListenerAndProxy(func(d quicproxy.Direction, _ []byte) bool {
var p int32
@ -176,7 +176,7 @@ var _ = Describe("Handshake drop tests", func() {
app.run(version)
})
It(fmt.Sprintf("establishes a connection when the second packet is lost in %s direction", d), func() {
It(fmt.Sprintf("establishes a connection when the second packet is lost in %s direction", direction), func() {
var incoming, outgoing int32
startListenerAndProxy(func(d quicproxy.Direction, _ []byte) bool {
var p int32
@ -191,7 +191,7 @@ var _ = Describe("Handshake drop tests", func() {
app.run(version)
})
It(fmt.Sprintf("establishes a connection when 1/5 of the packets are lost in %s direction", d), func() {
It(fmt.Sprintf("establishes a connection when 1/5 of the packets are lost in %s direction", direction), func() {
startListenerAndProxy(func(d quicproxy.Direction, _ []byte) bool {
return d.Is(direction) && stochasticDropper(5)
}, version)

View file

@ -109,7 +109,7 @@ var _ = Describe("MITM test", func() {
payloadLen := mrand.Int31n(100)
replyHdr.Length = protocol.ByteCount(mrand.Int31n(payloadLen + 1))
buf := &bytes.Buffer{}
Expect(replyHdr.Write(buf, v)).To(Succeed())
Expect(replyHdr.Write(buf, version)).To(Succeed())
b := make([]byte, payloadLen)
mrand.Read(b)
buf.Write(b)

View file

@ -9,7 +9,9 @@ import (
"github.com/lucas-clemente/quic-go/internal/utils"
//nolint:stylecheck
. "github.com/onsi/ginkgo"
//nolint:stylecheck
. "github.com/onsi/gomega"
)

View file

@ -12,7 +12,9 @@ import (
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"
//nolint:stylecheck
. "github.com/onsi/ginkgo"
//nolint:stylecheck
. "github.com/onsi/gomega"
)

View file

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

View file

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

View file

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

View file

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

View file

@ -54,7 +54,7 @@ func (s *tokenProtectorImpl) NewToken(data []byte) ([]byte, error) {
// DecodeToken decodes a token.
func (s *tokenProtectorImpl) DecodeToken(p []byte) ([]byte, error) {
if len(p) < tokenNonceSize {
return nil, fmt.Errorf("Token too short: %d", len(p))
return nil, fmt.Errorf("token too short: %d", len(p))
}
nonce := p[:tokenNonceSize]
aead, aeadNonce, err := s.createAEAD(nonce)

View file

@ -34,6 +34,6 @@ var _ = Describe("Token Protector", func() {
It("errors when decoding too short tokens", func() {
_, err := tp.DecodeToken([]byte("foobar"))
Expect(err).To(MatchError("Token too short: 6"))
Expect(err).To(MatchError("token too short: 6"))
})
})

View file

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

View file

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

View file

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

View file

@ -215,9 +215,11 @@ func (h *Header) parseLongHeader(b *bytes.Reader) error {
func (h *Header) parseVersionNegotiationPacket(b *bytes.Reader) error {
if b.Len() == 0 {
//nolint:stylecheck
return errors.New("Version Negotiation packet has empty version list")
}
if b.Len()%4 != 0 {
//nolint:stylecheck
return errors.New("Version Negotiation packet has a version list with an invalid length")
}
h.SupportedVersions = make([]protocol.VersionNumber, b.Len()/4)

View file

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

View file

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

View file

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

View file

@ -32,6 +32,7 @@ func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewC
return nil, err
}
if ret > seq {
//nolint:stylecheck
return nil, fmt.Errorf("Retire Prior To value (%d) larger than Sequence Number (%d)", ret, seq)
}
connIDLen, err := r.ReadByte()

View file

@ -26,7 +26,7 @@ func parseNewTokenFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewTokenFra
return nil, io.EOF
}
if tokenLen == 0 {
return nil, errors.New("Token must not be empty.")
return nil, errors.New("token must not be empty")
}
token := make([]byte, int(tokenLen))
if _, err := io.ReadFull(r, token); err != nil {

View file

@ -29,7 +29,7 @@ var _ = Describe("NEW_TOKEN frame", func() {
data = append(data, encodeVarInt(uint64(0))...)
b := bytes.NewReader(data)
_, err := parseNewTokenFrame(b, protocol.VersionWhatever)
Expect(err).To(MatchError("Token must not be empty."))
Expect(err).To(MatchError("token must not be empty"))
})
It("errors on EOFs", func() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -139,6 +139,7 @@ func (u *packetUnpacker) unpack(hd headerDecryptor, hdr *wire.Header, data []byt
hdrLen := int(hdr.ParsedLen())
if len(data) < hdrLen+4+16 {
//nolint:stylecheck
return nil, fmt.Errorf("Packet too small. Expected at least 20 bytes after the header, got %d", len(data)-hdrLen)
}
// The packet number can be up to 4 bytes long, but we won't know the length until we decrypt it.

View file

@ -70,7 +70,7 @@ func (t *tracer) Emit(connID protocol.ConnectionID) ([]byte, error) {
func (t *tracer) emitByConnIDAsString(connID string) ([]byte, error) {
events, ok := t.events[connID]
if !ok {
return nil, fmt.Errorf("No trace found for connection ID %s", connID)
return nil, fmt.Errorf("no trace found for connection ID %s", connID)
}
trace := &pb.Trace{
DestinationConnectionId: []byte{1, 2, 3, 4, 5, 6, 7, 8},

View file

@ -276,7 +276,7 @@ func (s *receiveStream) handleResetStreamFrameImpl(frame *wire.ResetStreamFrame)
s.resetRemotely = true
s.resetRemotelyErr = streamCanceledError{
errorCode: frame.ErrorCode,
error: fmt.Errorf("Stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
error: fmt.Errorf("stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
}
s.signalRead()
return true, nil

View file

@ -552,7 +552,7 @@ var _ = Describe("Receive Stream", func() {
go func() {
defer GinkgoRecover()
_, err := strWithTimeout.Read([]byte{0})
Expect(err).To(MatchError("Stream 1337 was reset with error code 1234"))
Expect(err).To(MatchError("stream 1337 was reset with error code 1234"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(1234)))
@ -576,7 +576,7 @@ var _ = Describe("Receive Stream", func() {
)
Expect(str.handleResetStreamFrame(rst)).To(Succeed())
_, err := strWithTimeout.Read([]byte{0})
Expect(err).To(MatchError("Stream 1337 was reset with error code 1234"))
Expect(err).To(MatchError("stream 1337 was reset with error code 1234"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(1234)))

View file

@ -366,7 +366,7 @@ func (s *sendStream) handleMaxStreamDataFrame(frame *wire.MaxStreamDataFrame) {
func (s *sendStream) handleStopSendingFrame(frame *wire.StopSendingFrame) {
writeErr := streamCanceledError{
errorCode: frame.ErrorCode,
error: fmt.Errorf("Stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
error: fmt.Errorf("stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
}
s.cancelWriteImpl(frame.ErrorCode, writeErr)
}

View file

@ -641,7 +641,7 @@ var _ = Describe("Send Stream", func() {
go func() {
defer GinkgoRecover()
_, err := str.Write([]byte("foobar"))
Expect(err).To(MatchError("Stream 1337 was reset with error code 123"))
Expect(err).To(MatchError("stream 1337 was reset with error code 123"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(123)))
@ -663,7 +663,7 @@ var _ = Describe("Send Stream", func() {
ErrorCode: 123,
})
_, err := str.Write([]byte("foobar"))
Expect(err).To(MatchError("Stream 1337 was reset with error code 123"))
Expect(err).To(MatchError("stream 1337 was reset with error code 123"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(123)))

View file

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

View file

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

View file

@ -1,3 +1,4 @@
//nolint:unused
package quic
import (

View file

@ -1,3 +1,4 @@
//nolint:unused
package quic
import (

View file

@ -1,3 +1,4 @@
//nolint:unused
package quic
import (