Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

update quic-go to v0.27.0 #264

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type conn struct {
sess quic.Session
quicConn quic.Connection
pconn *reuseConn
transport *transport
scope network.ConnManagementScope
Expand All @@ -33,16 +33,16 @@ var _ tpt.CapableConn = &conn{}
// It must be called even if the peer closed the connection in order for
// garbage collection to properly work in this package.
func (c *conn) Close() error {
c.transport.removeConn(c.sess)
err := c.sess.CloseWithError(0, "")
c.transport.removeConn(c.quicConn)
err := c.quicConn.CloseWithError(0, "")
c.pconn.DecreaseCount()
c.scope.Done()
return err
}

// IsClosed returns whether a connection is fully closed.
func (c *conn) IsClosed() bool {
return c.sess.Context().Err() != nil
return c.quicConn.Context().Err() != nil
}

func (c *conn) allowWindowIncrease(size uint64) bool {
Expand All @@ -51,13 +51,13 @@ func (c *conn) allowWindowIncrease(size uint64) bool {

// OpenStream creates a new stream.
func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) {
qstr, err := c.sess.OpenStreamSync(ctx)
qstr, err := c.quicConn.OpenStreamSync(ctx)
return &stream{Stream: qstr}, err
}

// AcceptStream accepts a stream opened by the other side.
func (c *conn) AcceptStream() (network.MuxedStream, error) {
qstr, err := c.sess.AcceptStream(context.Background())
qstr, err := c.quicConn.AcceptStream(context.Background())
return &stream{Stream: qstr}, err
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/libp2p/go-libp2p-testing v0.7.0
github.com/libp2p/go-libp2p-tls v0.3.0
github.com/libp2p/go-netroute v0.2.0
github.com/lucas-clemente/quic-go v0.26.0
github.com/lucas-clemente/quic-go v0.27.0
github.com/minio/sha256-simd v0.1.1
github.com/multiformats/go-multiaddr v0.4.1
github.com/multiformats/go-multiaddr-fmt v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ github.com/libp2p/go-openssl v0.0.7 h1:eCAzdLejcNVBzP/iZM9vqHnQm+XyCEbSSIheIPRGN
github.com/libp2p/go-openssl v0.0.7/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc=
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.26.0 h1:ALBQXr9UJ8A1LyzvceX4jd9QFsHvlI0RR6BkV16o00A=
github.com/lucas-clemente/quic-go v0.26.0/go.mod h1:AzgQoPda7N+3IqMMMkywBKggIFo2KT6pfnlrQ2QieeI=
github.com/lucas-clemente/quic-go v0.27.0 h1:v6WY87q9zD4dKASbG8hy/LpzAVNzEQzw8sEIeloJsc4=
github.com/lucas-clemente/quic-go v0.27.0/go.mod h1:AzgQoPda7N+3IqMMMkywBKggIFo2KT6pfnlrQ2QieeI=
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=
Expand Down
24 changes: 12 additions & 12 deletions listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ func newListener(rconn *reuseConn, t *transport, localPeer peer.ID, key ic.PrivK
// Accept accepts new connections.
func (l *listener) Accept() (tpt.CapableConn, error) {
for {
sess, err := l.quicListener.Accept(context.Background())
qconn, err := l.quicListener.Accept(context.Background())
if err != nil {
return nil, err
}
c, err := l.setupConn(sess)
c, err := l.setupConn(qconn)
if err != nil {
sess.CloseWithError(0, err.Error())
qconn.CloseWithError(0, err.Error())
continue
}
if l.transport.gater != nil && !(l.transport.gater.InterceptAccept(c) && l.transport.gater.InterceptSecured(network.DirInbound, c.remotePeerID, c)) {
c.scope.Done()
sess.CloseWithError(errorCodeConnectionGating, "connection gated")
qconn.CloseWithError(errorCodeConnectionGating, "connection gated")
continue
}
l.transport.addConn(sess, c)
l.transport.addConn(qconn, c)

// return through active hole punching if any
key := holePunchKey{addr: sess.RemoteAddr().String(), peer: c.remotePeerID}
key := holePunchKey{addr: qconn.RemoteAddr().String(), peer: c.remotePeerID}
var wasHolePunch bool
l.transport.holePunchingMx.Lock()
holePunch, ok := l.transport.holePunching[key]
Expand All @@ -97,17 +97,17 @@ func (l *listener) Accept() (tpt.CapableConn, error) {
}
}

func (l *listener) setupConn(sess quic.Session) (*conn, error) {
func (l *listener) setupConn(qconn quic.Connection) (*conn, error) {
connScope, err := l.rcmgr.OpenConnection(network.DirInbound, false)
if err != nil {
log.Debugw("resource manager blocked incoming connection", "addr", sess.RemoteAddr(), "error", err)
log.Debugw("resource manager blocked incoming connection", "addr", qconn.RemoteAddr(), "error", err)
return nil, err
}
// The tls.Config used to establish this connection already verified the certificate chain.
// Since we don't have any way of knowing which tls.Config was used though,
// we have to re-determine the peer's identity here.
// Therefore, this is expected to never fail.
remotePubKey, err := p2ptls.PubKeyFromCertChain(sess.ConnectionState().TLS.PeerCertificates)
remotePubKey, err := p2ptls.PubKeyFromCertChain(qconn.ConnectionState().TLS.PeerCertificates)
if err != nil {
connScope.Done()
return nil, err
Expand All @@ -118,19 +118,19 @@ func (l *listener) setupConn(sess quic.Session) (*conn, error) {
return nil, err
}
if err := connScope.SetPeer(remotePeerID); err != nil {
log.Debugw("resource manager blocked incoming connection for peer", "peer", remotePeerID, "addr", sess.RemoteAddr(), "error", err)
log.Debugw("resource manager blocked incoming connection for peer", "peer", remotePeerID, "addr", qconn.RemoteAddr(), "error", err)
connScope.Done()
return nil, err
}
remoteMultiaddr, err := toQuicMultiaddr(sess.RemoteAddr())
remoteMultiaddr, err := toQuicMultiaddr(qconn.RemoteAddr())
if err != nil {
connScope.Done()
return nil, err
}

l.conn.IncreaseCount()
return &conn{
sess: sess,
quicConn: qconn,
pconn: l.conn,
transport: l.transport,
scope: connScope,
Expand Down
30 changes: 15 additions & 15 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type transport struct {
holePunching map[holePunchKey]*activeHolePunch

connMx sync.Mutex
conns map[quic.Session]*conn
conns map[quic.Connection]*conn
}

var _ tpt.Transport = &transport{}
Expand Down Expand Up @@ -173,7 +173,7 @@ func NewTransport(key ic.PrivKey, psk pnet.PSK, gater connmgr.ConnectionGater, r
connManager: connManager,
gater: gater,
rcmgr: rcmgr,
conns: make(map[quic.Session]*conn),
conns: make(map[quic.Connection]*conn),
holePunching: make(map[holePunchKey]*activeHolePunch),
}
config.AllowConnectionWindowIncrease = tr.allowWindowIncrease
Expand Down Expand Up @@ -215,7 +215,7 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
if err != nil {
return nil, err
}
sess, err := quicDialContext(ctx, pconn, addr, host, tlsConf, t.clientConfig)
qconn, err := quicDialContext(ctx, pconn, addr, host, tlsConf, t.clientConfig)
if err != nil {
scope.Done()
pconn.DecreaseCount()
Expand All @@ -235,11 +235,11 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp

localMultiaddr, err := toQuicMultiaddr(pconn.LocalAddr())
if err != nil {
sess.CloseWithError(0, "")
qconn.CloseWithError(0, "")
return nil, err
}
c := &conn{
sess: sess,
quicConn: qconn,
pconn: pconn,
transport: t,
scope: scope,
Expand All @@ -251,22 +251,22 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
remoteMultiaddr: remoteMultiaddr,
}
if t.gater != nil && !t.gater.InterceptSecured(network.DirOutbound, p, c) {
sess.CloseWithError(errorCodeConnectionGating, "connection gated")
qconn.CloseWithError(errorCodeConnectionGating, "connection gated")
return nil, fmt.Errorf("secured connection gated")
}
t.addConn(sess, c)
t.addConn(qconn, c)
return c, nil
}

func (t *transport) addConn(sess quic.Session, c *conn) {
func (t *transport) addConn(conn quic.Connection, c *conn) {
t.connMx.Lock()
t.conns[sess] = c
t.conns[conn] = c
t.connMx.Unlock()
}

func (t *transport) removeConn(sess quic.Session) {
func (t *transport) removeConn(conn quic.Connection) {
t.connMx.Lock()
delete(t.conns, sess)
delete(t.conns, conn)
t.connMx.Unlock()
}

Expand Down Expand Up @@ -376,13 +376,13 @@ func (t *transport) Listen(addr ma.Multiaddr) (tpt.Listener, error) {
return ln, nil
}

func (t *transport) allowWindowIncrease(sess quic.Session, size uint64) bool {
// If the QUIC session tries to increase the window before we've inserted it
func (t *transport) allowWindowIncrease(conn quic.Connection, size uint64) bool {
// If the QUIC connection tries to increase the window before we've inserted it
// into our connections map (which we do right after dialing / accepting it),
// we have no way to account for that memory. This should be very rare.
// Block this attempt. The session can request more memory later.
// Block this attempt. The connection can request more memory later.
t.connMx.Lock()
c, ok := t.conns[sess]
c, ok := t.conns[conn]
t.connMx.Unlock()
if !ok {
return false
Expand Down
2 changes: 1 addition & 1 deletion transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestConnectionPassedToQUIC(t *testing.T) {
defer func() { quicDialContext = origQuicDialContext }()

var conn net.PacketConn
quicDialContext = func(_ context.Context, c net.PacketConn, _ net.Addr, _ string, _ *tls.Config, _ *quic.Config) (quic.Session, error) {
quicDialContext = func(_ context.Context, c net.PacketConn, _ net.Addr, _ string, _ *tls.Config, _ *quic.Config) (quic.Connection, error) {
conn = c
return nil, errors.New("listen error")
}
Expand Down