Browse Source

use a dedicated error code when a connection is gated

0x47415445 is GATE in ASCII.
pull/1424/head
Marten Seemann 4 years ago
parent
commit
3b88f7bbcc
  1. 12
      p2p/transport/quic/listener.go
  2. 3
      p2p/transport/quic/transport.go

12
p2p/transport/quic/listener.go

@ -3,7 +3,6 @@ package libp2pquic
import ( import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt"
"net" "net"
ic "github.com/libp2p/go-libp2p-core/crypto" ic "github.com/libp2p/go-libp2p-core/crypto"
@ -69,11 +68,15 @@ func (l *listener) Accept() (tpt.CapableConn, error) {
sess.CloseWithError(0, err.Error()) sess.CloseWithError(0, err.Error())
continue continue
} }
if l.transport.gater != nil && !l.transport.gater.InterceptSecured(n.DirInbound, conn.remotePeerID, conn) {
sess.CloseWithError(errorCodeConnectionGating, "connection gated")
continue
}
return conn, nil return conn, nil
} }
} }
func (l *listener) setupConn(sess quic.Session) (tpt.CapableConn, error) { func (l *listener) setupConn(sess quic.Session) (*conn, error) {
// The tls.Config used to establish this connection already verified the certificate chain. // 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, // 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. // we have to re-determine the peer's identity here.
@ -92,11 +95,6 @@ func (l *listener) setupConn(sess quic.Session) (tpt.CapableConn, error) {
return nil, err return nil, err
} }
connaddrs := &connAddrs{lmAddr: l.localMultiaddr, rmAddr: remoteMultiaddr}
if l.transport.gater != nil && !l.transport.gater.InterceptSecured(n.DirInbound, remotePeerID, connaddrs) {
return nil, fmt.Errorf("secured connection gated")
}
return &conn{ return &conn{
sess: sess, sess: sess,
transport: l.transport, transport: l.transport,

3
p2p/transport/quic/transport.go

@ -40,6 +40,7 @@ var quicConfig = &quic.Config{
} }
const statelessResetKeyInfo = "libp2p quic stateless reset key" const statelessResetKeyInfo = "libp2p quic stateless reset key"
const errorCodeConnectionGating = 0x47415445 // GATE in ASCII
type connManager struct { type connManager struct {
reuseUDP4 *reuse reuseUDP4 *reuse
@ -184,7 +185,7 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
connaddrs := &connAddrs{lmAddr: localMultiaddr, rmAddr: remoteMultiaddr} connaddrs := &connAddrs{lmAddr: localMultiaddr, rmAddr: remoteMultiaddr}
if t.gater != nil && !t.gater.InterceptSecured(n.DirOutbound, p, connaddrs) { if t.gater != nil && !t.gater.InterceptSecured(n.DirOutbound, p, connaddrs) {
sess.CloseWithError(0, "") sess.CloseWithError(errorCodeConnectionGating, "connection gated")
return nil, fmt.Errorf("secured connection gated") return nil, fmt.Errorf("secured connection gated")
} }

Loading…
Cancel
Save