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

66
p2p/transport/quic/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()
}

2
p2p/transport/quic/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"

Loading…
Cancel
Save