autorelay: ensure candidate relays can hop
@@ -12,7 +12,7 @@ import (
"github.com/libp2p/go-libp2p-core/routing"
autonat "github.com/libp2p/go-libp2p-autonat"
- _ "github.com/libp2p/go-libp2p-circuit"
+ circuit "github.com/libp2p/go-libp2p-circuit"
discovery "github.com/libp2p/go-libp2p-discovery"
basic "github.com/libp2p/go-libp2p/p2p/host/basic"
@@ -197,6 +197,17 @@ func (ar *AutoRelay) tryRelay(ctx context.Context, pi peer.AddrInfo) bool {
return false
}
+ ok, err := circuit.CanHop(ctx, ar.host, pi.ID)
+ if err != nil {
+ log.Debugf("error querying relay: %s", err.Error())
+ return false
+ }
+
+ if !ok {
+ // not a hop relay
+ return false
+ }
+
ar.mx.Lock()
defer ar.mx.Unlock()
