@ -752,14 +752,6 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
localIPv6Addr := h . localIPv6Addr
localIPv6Addr := h . localIPv6Addr
h . lipMu . RUnlock ( )
h . lipMu . RUnlock ( )
var finalAddrs [ ] ma . Multiaddr
listenAddrs := h . Network ( ) . ListenAddresses ( )
for _ , addr := range listenAddrs {
if ! manet . IsIPUnspecified ( addr ) {
finalAddrs = append ( finalAddrs , addr )
continue
}
ifaceAddrs := [ ] ma . Multiaddr { manet . IP4Loopback , manet . IP6Loopback }
ifaceAddrs := [ ] ma . Multiaddr { manet . IP4Loopback , manet . IP6Loopback }
if localIPv4Addr != nil {
if localIPv4Addr != nil {
ifaceAddrs = append ( ifaceAddrs , localIPv4Addr )
ifaceAddrs = append ( ifaceAddrs , localIPv4Addr )
@ -768,6 +760,16 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
ifaceAddrs = append ( ifaceAddrs , localIPv6Addr )
ifaceAddrs = append ( ifaceAddrs , localIPv6Addr )
}
}
// 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
for _ , addr := range listenAddrs {
if ! manet . IsIPUnspecified ( addr ) {
finalAddrs = append ( finalAddrs , addr )
continue
}
resolved , err := addrutil . ResolveUnspecifiedAddress ( addr , ifaceAddrs )
resolved , err := addrutil . ResolveUnspecifiedAddress ( addr , ifaceAddrs )
if err == nil {
if err == nil {
for _ , r := range resolved {
for _ , r := range resolved {
@ -848,8 +850,9 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
continue
continue
}
}
if ! ip . IsGlobalUnicast ( ) {
if ! ip . IsGlobalUnicast ( ) && ! ip . IsUnspecified ( ) {
// We only map global unicast ports.
// We only map global unicast & unspecified addresses ports.
// Not broadcast, multicast, etc.
continue
continue
}
}