Skip to content

Commit

Permalink
remove obsolete explicit IP whitelisting in favor of subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Feb 12, 2021
1 parent 84f577b commit 69868db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
9 changes: 2 additions & 7 deletions score.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,9 @@ func (ps *peerScore) ipColocationFactor(p peer.ID) float64 {
var result float64
loop:
for _, ip := range pstats.ips {
_, whitelisted := ps.params.IPColocationFactorWhitelist[ip]
if whitelisted {
continue
}

if len(ps.params.IPColocationFactorWhitelistSubnets) > 0 {
if len(ps.params.IPColocationFactorWhitelist) > 0 {
ipObj := net.ParseIP(ip)
for _, ipNet := range ps.params.IPColocationFactorWhitelistSubnets {
for _, ipNet := range ps.params.IPColocationFactorWhitelist {
if ipNet.Contains(ipObj) {
continue loop
}
Expand Down
7 changes: 3 additions & 4 deletions score_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ type PeerScoreParams struct {
// The weight of the parameter MUST be negative, unless you want to disable for testing.
// Note: In order to simulate many IPs in a managable manner when testing, you can set the weight to 0
// thus disabling the IP colocation penalty.
IPColocationFactorWeight float64
IPColocationFactorThreshold int
IPColocationFactorWhitelist map[string]struct{}
IPColocationFactorWhitelistSubnets []*net.IPNet
IPColocationFactorWeight float64
IPColocationFactorThreshold int
IPColocationFactorWhitelist []*net.IPNet

// P7: behavioural pattern penalties.
// This parameter has an associated counter which tracks misbehaviour as detected by the
Expand Down
12 changes: 6 additions & 6 deletions score_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ func TestScoreIPColocation(t *testing.T) {
}
}

func TestScoreIPColocationWhitelistSubnet(t *testing.T) {
func TestScoreIPColocationWhitelist(t *testing.T) {
// Create parameters with reasonable default values
mytopic := "mytopic"

Expand All @@ -753,11 +753,11 @@ func TestScoreIPColocationWhitelistSubnet(t *testing.T) {
}

params := &PeerScoreParams{
AppSpecificScore: func(peer.ID) float64 { return 0 },
IPColocationFactorThreshold: 1,
IPColocationFactorWeight: -1,
IPColocationFactorWhitelistSubnets: []*net.IPNet{ipNet},
Topics: make(map[string]*TopicScoreParams),
AppSpecificScore: func(peer.ID) float64 { return 0 },
IPColocationFactorThreshold: 1,
IPColocationFactorWeight: -1,
IPColocationFactorWhitelist: []*net.IPNet{ipNet},
Topics: make(map[string]*TopicScoreParams),
}

peerA := peer.ID("A")
Expand Down

0 comments on commit 69868db

Please sign in to comment.