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 (
"context"
"crypto/tls"
"fmt"
"net"
ic "github.com/libp2p/go-libp2p-core/crypto"
@ -69,11 +68,15 @@ func (l *listener) Accept() (tpt.CapableConn, error) {
sess.CloseWithError(0, err.Error())
continue
}
if l.transport.gater != nil && !l.transport.gater.InterceptSecured(n.DirInbound, conn.remotePeerID, conn) {
sess.CloseWithError(errorCodeConnectionGating, "connection gated")
continue
}
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.
// 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.
@ -92,11 +95,6 @@ func (l *listener) setupConn(sess quic.Session) (tpt.CapableConn, error) {
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{
sess: sess,
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 errorCodeConnectionGating = 0x47415445 // GATE in ASCII
type connManager struct {
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}
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")
}

Loading…
Cancel
Save