Commit 4f35b852 authored by Andrew Huang's avatar Andrew Huang

Add ability to restrict the networks that op-node discovers peers on

parent 0f0d85ba
...@@ -152,6 +152,13 @@ var ( ...@@ -152,6 +152,13 @@ var (
Value: "", Value: "",
EnvVars: p2pEnv("STATIC"), EnvVars: p2pEnv("STATIC"),
} }
NetRestrict = &cli.StringFlag{
Name: "p2p.netrestrict",
Usage: "Comma-separated list of CIDR masks. P2P will only try to connect on these networks",
Required: false,
Value: "",
EnvVars: p2pEnv("NETRESTRICT"),
}
HostMux = &cli.StringFlag{ HostMux = &cli.StringFlag{
Name: "p2p.mux", Name: "p2p.mux",
Usage: "Comma-separated list of multiplexing protocols in order of preference. At least 1 required. Options: 'yamux','mplex'.", Usage: "Comma-separated list of multiplexing protocols in order of preference. At least 1 required. Options: 'yamux','mplex'.",
...@@ -322,6 +329,7 @@ var p2pFlags = []cli.Flag{ ...@@ -322,6 +329,7 @@ var p2pFlags = []cli.Flag{
AdvertiseUDPPort, AdvertiseUDPPort,
Bootnodes, Bootnodes,
StaticPeers, StaticPeers,
NetRestrict,
HostMux, HostMux,
HostSecurity, HostSecurity,
PeersLo, PeersLo,
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/netutil"
) )
func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error) { func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error) {
...@@ -193,6 +194,13 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -193,6 +194,13 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
conf.Bootnodes = p2p.DefaultBootnodes conf.Bootnodes = p2p.DefaultBootnodes
} }
netRestrict, err := netutil.ParseNetlist(ctx.String(flags.NetRestrict.Name))
if err != nil {
return fmt.Errorf("failed to parse net list: %w", err)
}
conf.NetRestrict = netRestrict
return nil return nil
} }
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/netutil"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
...@@ -84,6 +85,7 @@ type Config struct { ...@@ -84,6 +85,7 @@ type Config struct {
AdvertiseUDPPort uint16 AdvertiseUDPPort uint16
Bootnodes []*enode.Node Bootnodes []*enode.Node
DiscoveryDB *enode.DB DiscoveryDB *enode.DB
NetRestrict *netutil.Netlist
StaticPeers []core.Multiaddr StaticPeers []core.Multiaddr
......
...@@ -97,7 +97,7 @@ func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort ...@@ -97,7 +97,7 @@ func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort
cfg := discover.Config{ cfg := discover.Config{
PrivateKey: priv, PrivateKey: priv,
NetRestrict: nil, NetRestrict: conf.NetRestrict,
Bootnodes: conf.Bootnodes, Bootnodes: conf.Bootnodes,
Unhandled: nil, // Not used in dv5 Unhandled: nil, // Not used in dv5
Log: log, Log: log,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment