From e482b45c6660ddc85a8ed4958478116ac6ff1d70 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 4 May 2021 20:21:22 -0700 Subject: [PATCH] fix: re-expose AutoNAT service on BasicHost Unfortunately, lotus relies on this and we don't have a good alternative at the moment. 1. The "correct" way to get the status is to subscribe to the "discoverability" events and read the first event (you're guaranteed to see a "current status" event). However, this is a bit annoying. 2. Ideally, you'd call host.Addrs() to get the list of "good" addresses. Unfortunately, we don't feed enough information back into the Host from AutoNAT for this to be truly useful (yet). --- p2p/host/basic/basic_host.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index aac8e46b1b..d0c23af9aa 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -1007,6 +1007,13 @@ func (h *BasicHost) SetAutoNat(a autonat.AutoNAT) { } } +// Return the host's AutoNAT service, if AutoNAT is enabled. +func (h *BasicHost) GetAutoNat() autonat.AutoNAT { + h.addrMu.Lock() + defer h.addrMu.Unlock() + return h.autoNat +} + // Close shuts down the Host's services (network, etc). func (h *BasicHost) Close() error { h.closeSync.Do(func() {