From 609d9db4f2f397a828f6e4d56497e1eadc67f64e Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 12 Sep 2020 19:48:23 +0300 Subject: [PATCH 1/2] make IPv6 subnet colocation optional, default to false --- score.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/score.go b/score.go index d2e54528..f00a09cd 100644 --- a/score.go +++ b/score.go @@ -14,6 +14,9 @@ import ( manet "github.com/multiformats/go-multiaddr-net" ) +// IPv6SubnetColocation controls whether /64 IPv6 subnets should be considered colocated. +var IPv6SubnetColocation = false + type peerStats struct { // true if the peer is currently connected connected bool @@ -976,12 +979,14 @@ func (ps *peerScore) getIPs(p peer.ID) []string { ip4 := ip.String() res = append(res, ip4) } else { - // IPv6 address -- we add both the actual address and the /64 subnet + // IPv6 address -- we add both the actual address and (optionally) the /64 subnet ip6 := ip.String() res = append(res, ip6) - ip6mask := ip.Mask(net.CIDRMask(64, 128)).String() - res = append(res, ip6mask) + if IPv6SubnetColocation { + ip6mask := ip.Mask(net.CIDRMask(64, 128)).String() + res = append(res, ip6mask) + } } } From 30aa734a178c7adbe2c699e210901955793952e6 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 12 Sep 2020 19:56:15 +0300 Subject: [PATCH 2/2] make IPv6SubnetColocation a peer score parameter --- score.go | 5 +---- score_params.go | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/score.go b/score.go index f00a09cd..048cba20 100644 --- a/score.go +++ b/score.go @@ -14,9 +14,6 @@ import ( manet "github.com/multiformats/go-multiaddr-net" ) -// IPv6SubnetColocation controls whether /64 IPv6 subnets should be considered colocated. -var IPv6SubnetColocation = false - type peerStats struct { // true if the peer is currently connected connected bool @@ -983,7 +980,7 @@ func (ps *peerScore) getIPs(p peer.ID) []string { ip6 := ip.String() res = append(res, ip6) - if IPv6SubnetColocation { + if ps.params.IPv6SubnetColocation { ip6mask := ip.Mask(net.CIDRMask(64, 128)).String() res = append(res, ip6mask) } diff --git a/score_params.go b/score_params.go index 3a205840..099165d6 100644 --- a/score_params.go +++ b/score_params.go @@ -73,6 +73,9 @@ type PeerScoreParams struct { IPColocationFactorThreshold int IPColocationFactorWhitelist map[string]struct{} + // IPv6SubnetColocation controls whether /64 IPv6 subnets should be considered colocated. + IPv6SubnetColocation bool + // P7: behavioural pattern penalties. // This parameter has an associated counter which tracks misbehaviour as detected by the // router. The router currently applies penalties for the following behaviors: