Skip to content

Commit

Permalink
swarm: remove localhost udp ports check
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Jun 5, 2023
1 parent 6f27081 commit ecb0db4
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions p2p/net/swarm/swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,8 @@ func (s *Swarm) filterKnownUndialables(p peer.ID, addrs []ma.Multiaddr) []ma.Mul
})
}

// Make a map of udp ports we are listening on to filter peers web transport addresses
ourLocalHostUDPPorts := make(map[string]bool, 2)
for _, a := range ourAddrs {
if !manet.IsIPLoopback(a) {
continue
}
if p, err := a.ValueForProtocol(ma.P_UDP); err == nil {
ourLocalHostUDPPorts[p] = true
}
}

return ma.FilterAddrs(addrs,
func(addr ma.Multiaddr) bool { return !ma.Contains(ourAddrs, addr) },
func(addr ma.Multiaddr) bool { return checkLocalHostUDPAddrs(addr, ourLocalHostUDPPorts) },
s.canDial,
// TODO: Consider allowing link-local addresses
func(addr ma.Multiaddr) bool { return !manet.IsIP6LinkLocal(addr) },
Expand Down Expand Up @@ -558,16 +546,3 @@ func isRelayAddr(addr ma.Multiaddr) bool {
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
return err == nil
}

// checkLocalHostUDPAddrs returns false for addresses that have the same localhost port
// as the one we are listening on
// This is useful for filtering out peer's localhost webtransport addresses.
func checkLocalHostUDPAddrs(addr ma.Multiaddr, ourUDPPorts map[string]bool) bool {
if !manet.IsIPLoopback(addr) {
return true
}
if p, err := addr.ValueForProtocol(ma.P_UDP); err == nil {
return !ourUDPPorts[p]
}
return true
}

0 comments on commit ecb0db4

Please sign in to comment.