Merge pull request #1115 from snyh/nolistener
perf/basic_host: Don't handle address change if we hasn't anyone
This commit is contained in:
commit
e5d5d443ff
|
@ -520,7 +520,11 @@ func (h *BasicHost) background() {
|
|||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
h.updateLocalIpAddr()
|
||||
if len(h.network.ListenAddresses()) > 0 {
|
||||
h.updateLocalIpAddr()
|
||||
}
|
||||
// Request addresses anyways because, technically, address filters still apply.
|
||||
// The underlying AllAddrs call is effectivley a no-op.
|
||||
curr := h.Addrs()
|
||||
emitAddrChange(curr, lastAddrs)
|
||||
lastAddrs = curr
|
||||
|
@ -813,6 +817,11 @@ func dedupAddrs(addrs []ma.Multiaddr) (uniqueAddrs []ma.Multiaddr) {
|
|||
// AllAddrs returns all the addresses of BasicHost at this moment in time.
|
||||
// It's ok to not include addresses if they're not available to be used now.
|
||||
func (h *BasicHost) AllAddrs() []ma.Multiaddr {
|
||||
listenAddrs := h.Network().ListenAddresses()
|
||||
if len(listenAddrs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
h.addrMu.RLock()
|
||||
filteredIfaceAddrs := h.filteredInterfaceAddrs
|
||||
allIfaceAddrs := h.allInterfaceAddrs
|
||||
|
@ -821,7 +830,6 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
|
|||
|
||||
// Iterate over all _unresolved_ listen addresses, resolving our primary
|
||||
// interface only to avoid advertising too many addresses.
|
||||
listenAddrs := h.Network().ListenAddresses()
|
||||
var finalAddrs []ma.Multiaddr
|
||||
if resolved, err := addrutil.ResolveUnspecifiedAddresses(listenAddrs, filteredIfaceAddrs); err != nil {
|
||||
// This can happen if we're listening on no addrs, or listening
|
||||
|
|
Loading…
Reference in New Issue