Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for custom p2p node listen maddrs and dht announce maddrs #799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading