Skip to content

Commit

Permalink
add support for custom p2p node listen maddrs and dht announce maddrs (
Browse files Browse the repository at this point in the history
  • Loading branch information
mintyleaf authored Nov 18, 2024
1 parent dc85272 commit adcf68b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"),
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit adcf68b

Please sign in to comment.