@@ -769,7 +769,7 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo
769
769
log .Debugf ("error adding signed addrs to peerstore: %v" , err )
770
770
}
771
771
} else {
772
- ids .Host .Peerstore ().AddAddrs (p , lmaddrs , ttl )
772
+ ids .Host .Peerstore ().AddAddrs (p , filterAddrs ( lmaddrs , c . RemoteMultiaddr ()) , ttl )
773
773
}
774
774
775
775
// Finally, expire all temporary addrs.
@@ -959,3 +959,17 @@ func (nn *netNotifiee) Disconnected(_ network.Network, c network.Conn) {
959
959
960
960
func (nn * netNotifiee ) Listen (n network.Network , a ma.Multiaddr ) {}
961
961
func (nn * netNotifiee ) ListenClose (n network.Network , a ma.Multiaddr ) {}
962
+
963
+ // filterAddrs filters the address slice based on the remove multiaddr:
964
+ // * if it's a localhost address, no filtering is applied
965
+ // * if it's a local network address, all localhost addresses are filtered out
966
+ // * if it's a public address, all localhost and local network addresses are filtered out
967
+ func filterAddrs (addrs []ma.Multiaddr , remote ma.Multiaddr ) []ma.Multiaddr {
968
+ if manet .IsIPLoopback (remote ) {
969
+ return addrs
970
+ }
971
+ if manet .IsPrivateAddr (remote ) {
972
+ return ma .FilterAddrs (addrs , func (a ma.Multiaddr ) bool { return ! manet .IsIPLoopback (a ) })
973
+ }
974
+ return ma .FilterAddrs (addrs , manet .IsPublicAddr )
975
+ }
0 commit comments