Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm: remove /ip6zone component from listen addresses #2662

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions p2p/net/swarm/swarm_addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ func (s *Swarm) ListenAddresses() []ma.Multiaddr {
func (s *Swarm) listenAddressesNoLock() []ma.Multiaddr {
addrs := make([]ma.Multiaddr, 0, len(s.listeners.m)+10) // A bit extra so we may avoid an extra allocation in the for loop below.
for l := range s.listeners.m {
addrs = append(addrs, l.Multiaddr())
a := l.Multiaddr()
// remove ip6zone from the addresses
ma.ForEach(a, func(c ma.Component) bool {
if c.Protocol().Code == ma.P_IP6ZONE {
_, a = ma.SplitFirst(a)
}
return false
})
if a != nil {
addrs = append(addrs, a)
}
}
return addrs
}
Expand All @@ -29,25 +39,21 @@ const ifaceAddrsCacheDuration = 1 * time.Minute
// listens. It expands "any interface" addresses (/ip4/0.0.0.0, /ip6/::) to
// use the known local interfaces.
func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
s.listeners.RLock() // RLock start

s.listeners.RLock()
ifaceListenAddres := s.listeners.ifaceListenAddres
isEOL := time.Now().After(s.listeners.cacheEOL)
s.listeners.RUnlock() // RLock end
s.listeners.RUnlock()

if !isEOL {
// Cache is valid, clone the slice
return append(ifaceListenAddres[:0:0], ifaceListenAddres...), nil
}

// Cache is not valid
// Perfrom double checked locking

s.listeners.Lock() // Lock start

ifaceListenAddres = s.listeners.ifaceListenAddres
isEOL = time.Now().After(s.listeners.cacheEOL)
if isEOL {
if time.Now().After(s.listeners.cacheEOL) {
// Cache is still invalid
listenAddres := s.listenAddressesNoLock()
if len(listenAddres) > 0 {
Expand Down
1 change: 1 addition & 0 deletions p2p/net/swarm/swarm_addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestDialBadAddrs(t *testing.T) {

test(m("/ip6/fe80::1")) // link local
test(m("/ip6/fe80::100")) // link local
test(m("/ip6zone/eth0/ip6/fe80::100")) // ip6zone
test(m("/ip4/127.0.0.1/udp/1234/utp")) // utp
}

Expand Down
Loading