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

identify: Don't filter addr if remote is neither public nor private #2820

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo
ids.Host.Peerstore().UpdateAddrs(p, peerstore.TempAddrTTL, 0)
ids.addrMu.Unlock()

log.Debugf("%s received listen addrs for %s: %s", c.LocalPeer(), c.RemotePeer(), lmaddrs)
log.Debugf("%s received listen addrs for %s: %s", c.LocalPeer(), c.RemotePeer(), addrs)

// get protocol versions
pv := mes.GetProtocolVersion()
Expand Down Expand Up @@ -1064,18 +1064,23 @@ func (nn *netNotifiee) Disconnected(_ network.Network, c network.Conn) {
func (nn *netNotifiee) Listen(n network.Network, a ma.Multiaddr) {}
func (nn *netNotifiee) ListenClose(n network.Network, a ma.Multiaddr) {}

// filterAddrs filters the address slice based on the remove multiaddr:
// * if it's a localhost address, no filtering is applied
// * if it's a local network address, all localhost addresses are filtered out
// * if it's a public address, all localhost and local network addresses are filtered out
// filterAddrs filters the address slice based on the remote multiaddr:
// - if it's a localhost address, no filtering is applied
// - if it's a private network address, all localhost addresses are filtered out
// - if it's a public address, all non-public addresses are filtered out
// - if none of the above, (e.g. discard prefix), no filtering is applied.
// We can't do anything meaningful here so we do nothing.
func filterAddrs(addrs []ma.Multiaddr, remote ma.Multiaddr) []ma.Multiaddr {
if manet.IsIPLoopback(remote) {
switch {
case manet.IsIPLoopback(remote):
return addrs
}
if manet.IsPrivateAddr(remote) {
case manet.IsPrivateAddr(remote):
return ma.FilterAddrs(addrs, func(a ma.Multiaddr) bool { return !manet.IsIPLoopback(a) })
case manet.IsPublicAddr(remote):
return ma.FilterAddrs(addrs, manet.IsPublicAddr)
default:
return addrs
}
return ma.FilterAddrs(addrs, manet.IsPublicAddr)
}

func trimHostAddrList(addrs []ma.Multiaddr, maxSize int) []ma.Multiaddr {
Expand Down