add configuration option for pubsub IPColocationWhitelist subnets

This commit is contained in:
vyzo 2021-03-06 20:05:32 +02:00
parent 667fffb302
commit 64646de761
2 changed files with 16 additions and 5 deletions

View File

@ -114,9 +114,10 @@ type Libp2p struct {
} }
type Pubsub struct { type Pubsub struct {
Bootstrapper bool Bootstrapper bool
DirectPeers []string DirectPeers []string
RemoteTracer string IPColocationWhitelist []string
RemoteTracer string
} }
// // Full Node // // Full Node

View File

@ -3,6 +3,7 @@ package lp2p
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"net"
"time" "time"
host "github.com/libp2p/go-libp2p-core/host" 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) 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{ options := []pubsub.Option{
// Gossipsubv1.1 configuration // Gossipsubv1.1 configuration
pubsub.WithFloodPublish(true), 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 // This sets the IP colocation threshold to 5 peers before we apply penalties
IPColocationFactorThreshold: 5, IPColocationFactorThreshold: 5,
IPColocationFactorWeight: -100, IPColocationFactorWeight: -100,
// TODO we want to whitelist IPv6 /64s that belong to datacenters etc IPColocationFactorWhitelist: ipcoloWhitelist,
// IPColocationFactorWhitelist: map[string]struct{}{},
// P7: behavioural penalties, decay after 1hr // P7: behavioural penalties, decay after 1hr
BehaviourPenaltyThreshold: 6, BehaviourPenaltyThreshold: 6,