Browse Source

update quic-go to v0.21.0-rc2

pull/1424/head
Marten Seemann 4 years ago
parent
commit
cc611a6881
  1. 12
      p2p/transport/quic/stream.go
  2. 66
      p2p/transport/quic/tracer_metrics.go
  3. 2
      p2p/transport/quic/transport.go

12
p2p/transport/quic/stream.go

@ -1,13 +1,15 @@
package libp2pquic package libp2pquic
import ( import (
"errors"
"github.com/libp2p/go-libp2p-core/mux" "github.com/libp2p/go-libp2p-core/mux"
quic "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
) )
const ( const (
reset quic.ErrorCode = 0 reset quic.StreamErrorCode = 0
) )
type stream struct { type stream struct {
@ -16,19 +18,17 @@ type stream struct {
func (s *stream) Read(b []byte) (n int, err error) { func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.Stream.Read(b) 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 err = mux.ErrReset
} }
return n, err return n, err
} }
func (s *stream) Write(b []byte) (n int, err error) { func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.Stream.Write(b) 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 err = mux.ErrReset
} }
return n, err return n, err
} }

66
p2p/transport/quic/tracer_metrics.go

@ -1,12 +1,17 @@
package libp2pquic package libp2pquic
import ( import (
"context"
"errors"
"fmt"
"net" "net"
"sync" "sync"
"time" "time"
"github.com/lucas-clemente/quic-go/logging"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/logging"
) )
var ( var (
@ -164,7 +169,9 @@ func init() {
type metricsTracer struct{} 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} 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) collector.AddConn(m.connID.String(), m)
} }
func (m *metricsConnTracer) ClosedConnection(r logging.CloseReason) { func (m *metricsConnTracer) NegotiatedVersion(chosen quic.VersionNumber, clientVersions []quic.VersionNumber, serverVersions []quic.VersionNumber) {
if _, _, ok := r.ApplicationError(); ok { }
func (m *metricsConnTracer) ClosedConnection(e error) {
var (
transportErr *quic.TransportError
remote bool
desc string
)
switch {
case errors.Is(e, &quic.ApplicationError{}):
return return
} case errors.As(e, &transportErr):
var desc string remote = transportErr.Remote
side := "local" desc = transportErr.ErrorCode.String()
if _, ok := r.StatelessReset(); ok { case errors.Is(e, &quic.StatelessResetError{}):
side = "remote" remote = true
desc = "stateless_reset" desc = "stateless_reset"
} case errors.Is(e, &quic.VersionNegotiationError{}):
if _, ok := r.VersionNegotiation(); ok {
desc = "version_negotiation" 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 { side := "local"
case logging.TimeoutReasonHandshake: if remote {
desc = "handshake_timeout" side = "remote"
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()
} }
connErrors.WithLabelValues(side, desc).Inc() connErrors.WithLabelValues(side, desc).Inc()
} }

2
p2p/transport/quic/transport.go

@ -39,7 +39,7 @@ var quicConfig = &quic.Config{
return true return true
}, },
KeepAlive: true, KeepAlive: true,
Versions: []quic.VersionNumber{quic.VersionDraft29, quic.VersionDraft32}, Versions: []quic.VersionNumber{quic.VersionDraft29},
} }
const statelessResetKeyInfo = "libp2p quic stateless reset key" const statelessResetKeyInfo = "libp2p quic stateless reset key"

Loading…
Cancel
Save