From 6a6463b3f7ab573f4a3ac8a002b1559b3cf2e0f8 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-rc2 --- go.mod | 5 ++-- go.sum | 23 ++++++++++++----- stream.go | 12 ++++----- tracer_metrics.go | 66 ++++++++++++++++++++++++++--------------------- transport.go | 2 +- 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/go.mod b/go.mod index 3b29af3..e7b6efb 100644 --- a/go.mod +++ b/go.mod @@ -9,13 +9,14 @@ 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.2 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 github.com/onsi/ginkgo v1.14.0 github.com/onsi/gomega v1.10.1 github.com/prometheus/client_golang v1.9.0 - golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a + golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e + golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect ) diff --git a/go.sum b/go.sum index 9fc83e0..20b7fa4 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,12 @@ 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.7.1-0.20210511194632-59a20f39267c h1:D/fA+mEIU8J4ulWagCb2X4M8e7+givY189/yaAkac0Y= +github.com/lucas-clemente/quic-go v0.7.1-0.20210511194632-59a20f39267c/go.mod h1:T+SpiNEBFsIo/TO6N8XDIhpnx3LMlNL/b9vyQtuvj1M= +github.com/lucas-clemente/quic-go v0.7.1-0.20210511200117-f4f391260f61 h1:hEkFLJzzTPrbOzOox6Y9bYfiw0+py8zHxV3thm70wv8= +github.com/lucas-clemente/quic-go v0.7.1-0.20210511200117-f4f391260f61/go.mod h1:T+SpiNEBFsIo/TO6N8XDIhpnx3LMlNL/b9vyQtuvj1M= +github.com/lucas-clemente/quic-go v0.21.0-rc.2 h1:HWPytXS1LueuD6vIHwSMW0FQkmf4Rb4Keyk9Vvapm1A= +github.com/lucas-clemente/quic-go v0.21.0-rc.2/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= @@ -486,8 +490,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf h1:B2n+Zi5QeYRDAEodEu72OS36gmTWjgpXr2+cWcBW90o= +golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -520,8 +524,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -565,13 +570,17 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 h1:joucsQqXmyBVxViHCPFjG3hx8JzIFSaym3l3MM/Jsdg= golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q= +golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/stream.go b/stream.go index 57ca2e9..0c92020 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 err != nil && 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 err != nil && 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"