From 667fffb302a0cdfc6d4184c416728db5fa46eff0 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 6 Mar 2021 19:54:25 +0200 Subject: [PATCH 1/2] go get go-libp2p-pubsub@master --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 54d6b42ed..8ed943bd8 100644 --- a/go.mod +++ b/go.mod @@ -106,7 +106,7 @@ require ( github.com/libp2p/go-libp2p-mplex v0.3.0 github.com/libp2p/go-libp2p-noise v0.1.2 github.com/libp2p/go-libp2p-peerstore v0.2.6 - github.com/libp2p/go-libp2p-pubsub v0.4.1 + github.com/libp2p/go-libp2p-pubsub v0.4.2-0.20210212194758-6c1addf493eb github.com/libp2p/go-libp2p-quic-transport v0.9.0 github.com/libp2p/go-libp2p-record v0.1.3 github.com/libp2p/go-libp2p-routing-helpers v0.2.3 diff --git a/go.sum b/go.sum index c1e5494ee..202fcef65 100644 --- a/go.sum +++ b/go.sum @@ -923,8 +923,8 @@ github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1 github.com/libp2p/go-libp2p-protocol v0.1.0/go.mod h1:KQPHpAabB57XQxGrXCNvbL6UEXfQqUgC/1adR2Xtflk= github.com/libp2p/go-libp2p-pubsub v0.1.1/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= github.com/libp2p/go-libp2p-pubsub v0.3.2-0.20200527132641-c0712c6e92cf/go.mod h1:TxPOBuo1FPdsTjFnv+FGZbNbWYsp74Culx+4ViQpato= -github.com/libp2p/go-libp2p-pubsub v0.4.1 h1:j4umIg5nyus+sqNfU+FWvb9aeYFQH/A+nDFhWj+8yy8= -github.com/libp2p/go-libp2p-pubsub v0.4.1/go.mod h1:izkeMLvz6Ht8yAISXjx60XUQZMq9ZMe5h2ih4dLIBIQ= +github.com/libp2p/go-libp2p-pubsub v0.4.2-0.20210212194758-6c1addf493eb h1:HExLcdXn8fgtXPciUw97O5NNhBn31dt6d9fVUD4cngo= +github.com/libp2p/go-libp2p-pubsub v0.4.2-0.20210212194758-6c1addf493eb/go.mod h1:izkeMLvz6Ht8yAISXjx60XUQZMq9ZMe5h2ih4dLIBIQ= github.com/libp2p/go-libp2p-quic-transport v0.1.1/go.mod h1:wqG/jzhF3Pu2NrhJEvE+IE0NTHNXslOPn9JQzyCAxzU= github.com/libp2p/go-libp2p-quic-transport v0.5.0/go.mod h1:IEcuC5MLxvZ5KuHKjRu+dr3LjCT1Be3rcD/4d8JrX8M= github.com/libp2p/go-libp2p-quic-transport v0.9.0 h1:WPuq5nV/chmIZIzvrkC2ulSdAQ0P0BDvgvAhZFOZ59E= From 64646de761fe2cfdf6a007910e9eb714204b0711 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 6 Mar 2021 20:05:32 +0200 Subject: [PATCH 2/2] 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,