Skip to content

Commit

Permalink
use advertised addrs for autonat dial back, not all addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Nov 2, 2018
1 parent cf1e44b commit 1e9829e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions p2p/host/relay/autorelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ type AutoRelayHost struct {
}

func NewAutoRelayHost(ctx context.Context, bhost *basic.BasicHost, discover discovery.Discoverer) *AutoRelayHost {
autonat := autonat.NewAutoNAT(ctx, bhost, bhost.AllAddrs)
h := &AutoRelayHost{
BasicHost: bhost,
discover: discover,
autonat: autonat,
addrsF: bhost.AddrsFactory,
relays: make(map[peer.ID]pstore.PeerInfo),
disconnect: make(chan struct{}, 1),
}
h.autonat = autonat.NewAutoNAT(ctx, bhost, h.baseAddrs)
bhost.AddrsFactory = h.hostAddrs
bhost.Network().Notify(h)
go h.background(ctx)
Expand All @@ -80,6 +79,10 @@ func (h *AutoRelayHost) hostAddrs(addrs []ma.Multiaddr) []ma.Multiaddr {
}
}

func (h *AutoRelayHost) baseAddrs() []ma.Multiaddr {
return filterUnspecificRelay(h.addrsF(h.AllAddrs()))
}

func (h *AutoRelayHost) background(ctx context.Context) {
select {
case <-time.After(autonat.AutoNATBootDelay + BootDelay):
Expand Down Expand Up @@ -197,7 +200,7 @@ func (h *AutoRelayHost) doUpdateAddrs() {
h.mx.Lock()
defer h.mx.Unlock()

addrs := filterUnspecificRelay(h.addrsF(h.AllAddrs()))
addrs := h.baseAddrs()
raddrs := make([]ma.Multiaddr, 0, len(addrs)+len(h.relays))

// remove our public addresses from the list and replace them by just the public IP
Expand Down

0 comments on commit 1e9829e

Please sign in to comment.