From 1e920ed42634d707f5d835f5e09f204800820cc2 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 14 Apr 2020 19:11:12 +0300 Subject: [PATCH] fix IPv4 -vs- IPv6 address handling in peer address tracking --- score.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/score.go b/score.go index 88c92cc..6b1e5d6 100644 --- a/score.go +++ b/score.go @@ -769,30 +769,22 @@ func (ps *peerScore) getIPs(p peer.ID) []string { continue } - // ignore those; loopback for unit testing and unspecified because gremlins - // seem give us an unspecified IPv6 conn everywhere in testground testing! - if ip.IsUnspecified() || ip.IsLoopback() { + // ignore those; loopback is used for unit testing + if ip.IsLoopback() { continue } - if len(ip) == 4 { + if len(ip.To4()) == 4 { // IPv4 address ip4 := ip.String() res = append(res, ip4) - continue - } - - if len(ip) == 16 { + } else { // IPv6 address -- we add both the actual address and the /64 subnet ip6 := ip.String() res = append(res, ip6) - ip6mask := ip.Mask(net.CIDRMask(64, 128)) - // this seems necessary to defeat the unspecfied address gremlins -- plus it is in the - // IANA reserved address space anyway, so it doesn't hurt. - if !ip6mask.IsUnspecified() { - res = append(res, ip6mask.String()) - } + ip6mask := ip.Mask(net.CIDRMask(64, 128)).String() + res = append(res, ip6mask) } }