From 3a21c6dea31ead2c24df6a21e9867e8cc387d06e Mon Sep 17 00:00:00 2001 From: Will Scott Date: Wed, 26 Feb 2020 17:29:10 -0800 Subject: [PATCH] skip locally held addresses fix #44 --- p2p/host/autonat/svc.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/p2p/host/autonat/svc.go b/p2p/host/autonat/svc.go index 8c1191e3c3..6835e4d486 100644 --- a/p2p/host/autonat/svc.go +++ b/p2p/host/autonat/svc.go @@ -32,6 +32,7 @@ var ( // AutoNATService provides NAT autodetection services to other peers type AutoNATService struct { ctx context.Context + h host.Host dialer host.Host // rate limiter @@ -49,6 +50,7 @@ func NewAutoNATService(ctx context.Context, h host.Host, forceEnabled bool, opts as := &AutoNATService{ ctx: ctx, + h: h, dialer: dialer, reqs: make(map[peer.ID]int), } @@ -178,6 +180,13 @@ func (as *AutoNATService) skipDial(addr ma.Multiaddr) bool { return true } + // Skip dialing addresses we believe are the local node's + for _, localAddr := range as.h.Addrs() { + if localAddr.Equal(addr) { + return true + } + } + return false }