fix IPv4 -vs- IPv6 address handling in peer address tracking

This commit is contained in:
vyzo 2020-04-14 19:11:12 +03:00
parent 432caf4fdf
commit 1e920ed426

View File

@ -769,30 +769,22 @@ func (ps *peerScore) getIPs(p peer.ID) []string {
continue continue
} }
// ignore those; loopback for unit testing and unspecified because gremlins // ignore those; loopback is used for unit testing
// seem give us an unspecified IPv6 conn everywhere in testground testing! if ip.IsLoopback() {
if ip.IsUnspecified() || ip.IsLoopback() {
continue continue
} }
if len(ip) == 4 { if len(ip.To4()) == 4 {
// IPv4 address // IPv4 address
ip4 := ip.String() ip4 := ip.String()
res = append(res, ip4) res = append(res, ip4)
continue } else {
}
if len(ip) == 16 {
// IPv6 address -- we add both the actual address and the /64 subnet // IPv6 address -- we add both the actual address and the /64 subnet
ip6 := ip.String() ip6 := ip.String()
res = append(res, ip6) res = append(res, ip6)
ip6mask := ip.Mask(net.CIDRMask(64, 128)) ip6mask := ip.Mask(net.CIDRMask(64, 128)).String()
// this seems necessary to defeat the unspecfied address gremlins -- plus it is in the res = append(res, ip6mask)
// IANA reserved address space anyway, so it doesn't hurt.
if !ip6mask.IsUnspecified() {
res = append(res, ip6mask.String())
}
} }
} }