From b83b15dd3df96906bb933bee004bc6f3e7bdeb28 Mon Sep 17 00:00:00 2001 From: mintyleaf Date: Sat, 16 Nov 2024 23:10:28 +0400 Subject: [PATCH] add support for custom p2p node listen maddrs and dht announce maddrs --- cmd/util.go | 12 ++++++++++++ pkg/config/config.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/util.go b/cmd/util.go index 20ee6152..58aa2622 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -45,6 +45,16 @@ var CommonFlags []cli.Flag = []cli.Flag{ Usage: "Specify a path to a edgevpn config file", EnvVars: []string{"EDGEVPNCONFIG"}, }, + &cli.StringSliceFlag{ + Name: "listen-maddrs", + Usage: "Override default 0.0.0.0 listen multiaddresses", + EnvVars: []string{"EDGEVPNLISTENMADDRS"}, + }, + &cli.StringSliceFlag{ + Name: "dht-announce-maddrs", + Usage: "Override listen-maddrs on DHT announce", + EnvVars: []string{"EDGEVPNDHTANNOUNCEMADDRS"}, + }, &cli.StringFlag{ Name: "timeout", Usage: "Specify a default timeout for connection stream", @@ -407,6 +417,8 @@ func ConfigFromContext(c *cli.Context) *config.Config { return &config.Config{ NetworkConfig: c.String("config"), NetworkToken: c.String("token"), + ListenMaddrs: (c.StringSlice("listen-maddrs")), + DHTAnnounceMaddrs: stringsToMultiAddr(c.StringSlice("dht-announce-maddrs")), Address: c.String("address"), Router: c.String("router"), Interface: c.String("interface"), diff --git a/pkg/config/config.go b/pkg/config/config.go index 7d71425f..1ae5bd7d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -47,6 +47,8 @@ import ( type Config struct { NetworkConfig, NetworkToken string Address string + ListenMaddrs []string + DHTAnnounceMaddrs []multiaddr.Multiaddr Router string Interface string Libp2pLogLevel, LogLevel string @@ -204,10 +206,20 @@ func (c Config) ToOpts(l *logger.Logger) ([]node.Option, []vpn.Option, error) { if c.LowProfile { dhtOpts = append(dhtOpts, dht.BucketSize(20)) } + if len(c.DHTAnnounceMaddrs) > 0 { + dhtOpts = append(dhtOpts, dht.AddressFilter( + func(m []multiaddr.Multiaddr) []multiaddr.Multiaddr { + return c.DHTAnnounceMaddrs + }, + ), + ) + } + d := discovery.NewDHT(dhtOpts...) m := &discovery.MDNS{} opts := []node.Option{ + node.ListenAddresses(c.ListenMaddrs...), node.WithDiscoveryInterval(c.Discovery.Interval), node.WithLedgerAnnounceTime(c.Ledger.AnnounceInterval), node.WithLedgerInterval(c.Ledger.SyncInterval),