From 144c18cf986b4048184813db3dee4f716edcccde Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 4 May 2021 23:24:01 +0700 Subject: [PATCH] update quic-go to v0.21.0-rc1 --- go.mod | 2 +- go.sum | 4 +-- stream.go | 12 ++++----- tracer_metrics.go | 66 ++++++++++++++++++++++++++--------------------- transport.go | 2 +- 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/go.mod b/go.mod index 3b29af3..011ffae 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/libp2p/go-libp2p-core v0.8.0 github.com/libp2p/go-libp2p-tls v0.1.3 github.com/libp2p/go-netroute v0.1.3 - github.com/lucas-clemente/quic-go v0.20.1 + github.com/lucas-clemente/quic-go v0.21.0-rc.1 github.com/minio/sha256-simd v0.1.1 github.com/multiformats/go-multiaddr v0.3.1 github.com/multiformats/go-multiaddr-fmt v0.1.0 diff --git a/go.sum b/go.sum index 9fc83e0..12cc5cb 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,8 @@ github.com/libp2p/go-sockaddr v0.0.2 h1:tCuXfpA9rq7llM/v834RKc/Xvovy/AqM9kHvTV/j github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lucas-clemente/quic-go v0.20.1 h1:hb5m76V8QS/8Nw/suHvXqo3BMHAozvIkcnzpJdpanSk= -github.com/lucas-clemente/quic-go v0.20.1/go.mod h1:fZq/HUDIM+mW6X6wtzORjC0E/WDBMKe5Hf9bgjISwLk= +github.com/lucas-clemente/quic-go v0.21.0-rc.1 h1:RtmBqOc4AUWsjyDIMBp7Lk+f6wcEOS/HXaVMQWZk3eY= +github.com/lucas-clemente/quic-go v0.21.0-rc.1/go.mod h1:T+SpiNEBFsIo/TO6N8XDIhpnx3LMlNL/b9vyQtuvj1M= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= diff --git a/stream.go b/stream.go index 57ca2e9..62ef0e0 100644 --- a/stream.go +++ b/stream.go @@ -1,13 +1,15 @@ package libp2pquic import ( + "errors" + "github.com/libp2p/go-libp2p-core/mux" - quic "github.com/lucas-clemente/quic-go" + "github.com/lucas-clemente/quic-go" ) const ( - reset quic.ErrorCode = 0 + reset quic.StreamErrorCode = 0 ) type stream struct { @@ -16,19 +18,17 @@ type stream struct { func (s *stream) Read(b []byte) (n int, err error) { n, err = s.Stream.Read(b) - if serr, ok := err.(quic.StreamError); ok && serr.Canceled() { + if errors.Is(err, &quic.StreamError{}) { err = mux.ErrReset } - return n, err } func (s *stream) Write(b []byte) (n int, err error) { n, err = s.Stream.Write(b) - if serr, ok := err.(quic.StreamError); ok && serr.Canceled() { + if errors.Is(err, &quic.StreamError{}) { err = mux.ErrReset } - return n, err } diff --git a/tracer_metrics.go b/tracer_metrics.go index 929619d..c348341 100644 --- a/tracer_metrics.go +++ b/tracer_metrics.go @@ -1,12 +1,17 @@ package libp2pquic import ( + "context" + "errors" + "fmt" "net" "sync" "time" - "github.com/lucas-clemente/quic-go/logging" "github.com/prometheus/client_golang/prometheus" + + "github.com/lucas-clemente/quic-go" + "github.com/lucas-clemente/quic-go/logging" ) var ( @@ -164,7 +169,9 @@ func init() { type metricsTracer struct{} -func (m *metricsTracer) TracerForConnection(p logging.Perspective, connID logging.ConnectionID) logging.ConnectionTracer { +var _ logging.Tracer = &metricsTracer{} + +func (m *metricsTracer) TracerForConnection(_ context.Context, p logging.Perspective, connID logging.ConnectionID) logging.ConnectionTracer { return &metricsConnTracer{perspective: p, connID: connID} } @@ -217,37 +224,38 @@ func (m *metricsConnTracer) StartedConnection(net.Addr, net.Addr, logging.Connec collector.AddConn(m.connID.String(), m) } -func (m *metricsConnTracer) ClosedConnection(r logging.CloseReason) { - if _, _, ok := r.ApplicationError(); ok { +func (m *metricsConnTracer) NegotiatedVersion(chosen quic.VersionNumber, clientVersions []quic.VersionNumber, serverVersions []quic.VersionNumber) { +} + +func (m *metricsConnTracer) ClosedConnection(e error) { + var ( + transportErr *quic.TransportError + remote bool + desc string + ) + + switch { + case errors.Is(e, &quic.ApplicationError{}): return - } - var desc string - side := "local" - if _, ok := r.StatelessReset(); ok { - side = "remote" + case errors.As(e, &transportErr): + remote = transportErr.Remote + desc = transportErr.ErrorCode.String() + case errors.Is(e, &quic.StatelessResetError{}): + remote = true desc = "stateless_reset" - } - if _, ok := r.VersionNegotiation(); ok { + case errors.Is(e, &quic.VersionNegotiationError{}): desc = "version_negotiation" + case errors.Is(e, &quic.IdleTimeoutError{}): + desc = "idle_timeout" + case errors.Is(e, &quic.HandshakeTimeoutError{}): + desc = "handshake_timeout" + default: + desc = fmt.Sprintf("unknown error: %v", e) } - if timeout, ok := r.Timeout(); ok { - switch timeout { - case logging.TimeoutReasonHandshake: - desc = "handshake_timeout" - case logging.TimeoutReasonIdle: - desc = "idle_timeout" - default: - desc = "unknown timeout" - } - } - if code, remote, ok := r.TransportError(); ok { - if code == 0xc { // ignore APPLICATION_ERROR - return - } - if remote { - side = "remote" - } - desc = code.String() + + side := "local" + if remote { + side = "remote" } connErrors.WithLabelValues(side, desc).Inc() } diff --git a/transport.go b/transport.go index 17ee0c1..63e9362 100644 --- a/transport.go +++ b/transport.go @@ -39,7 +39,7 @@ var quicConfig = &quic.Config{ return true }, KeepAlive: true, - Versions: []quic.VersionNumber{quic.VersionDraft29, quic.VersionDraft32}, + Versions: []quic.VersionNumber{quic.VersionDraft29}, } const statelessResetKeyInfo = "libp2p quic stateless reset key"