From 64646de761fe2cfdf6a007910e9eb714204b0711 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 6 Mar 2021 20:05:32 +0200 Subject: [PATCH] add configuration option for pubsub IPColocationWhitelist subnets --- node/config/def.go | 7 ++++--- node/modules/lp2p/pubsub.go | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/node/config/def.go b/node/config/def.go index 579f123c8..fa4ed412e 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -114,9 +114,10 @@ type Libp2p struct { } type Pubsub struct { - Bootstrapper bool - DirectPeers []string - RemoteTracer string + Bootstrapper bool + DirectPeers []string + IPColocationWhitelist []string + RemoteTracer string } // // Full Node diff --git a/node/modules/lp2p/pubsub.go b/node/modules/lp2p/pubsub.go index 9724eb3b4..748167d95 100644 --- a/node/modules/lp2p/pubsub.go +++ b/node/modules/lp2p/pubsub.go @@ -3,6 +3,7 @@ package lp2p import ( "context" "encoding/json" + "net" "time" host "github.com/libp2p/go-libp2p-core/host" @@ -198,6 +199,16 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) { drandTopics = append(drandTopics, topic) } + // IP colocation whitelist + var ipcoloWhitelist []*net.IPNet + for _, cidr := range in.Cfg.IPColocationWhitelist { + _, ipnet, err := net.ParseCIDR(cidr) + if err != nil { + return nil, xerrors.Errorf("error parsing IPColocation subnet %s: %w", cidr, err) + } + ipcoloWhitelist = append(ipcoloWhitelist, ipnet) + } + options := []pubsub.Option{ // Gossipsubv1.1 configuration pubsub.WithFloodPublish(true), @@ -228,8 +239,7 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) { // This sets the IP colocation threshold to 5 peers before we apply penalties IPColocationFactorThreshold: 5, IPColocationFactorWeight: -100, - // TODO we want to whitelist IPv6 /64s that belong to datacenters etc - // IPColocationFactorWhitelist: map[string]struct{}{}, + IPColocationFactorWhitelist: ipcoloWhitelist, // P7: behavioural penalties, decay after 1hr BehaviourPenaltyThreshold: 6,