Skip to content

Commit

Permalink
🔧 Allow to set default bootstrap peers
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Nov 8, 2021
1 parent 6e14df6 commit 7c118e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ipfs/go-log"
"github.com/mudler/edgevpn/internal"
"github.com/mudler/edgevpn/pkg/blockchain"
"github.com/mudler/edgevpn/pkg/discovery"
"github.com/mudler/edgevpn/pkg/edgevpn"
"github.com/mudler/edgevpn/pkg/logger"
"github.com/peterbourgon/diskv"
Expand Down Expand Up @@ -60,6 +61,11 @@ var CommonFlags []cli.Flag = []cli.Flag{
EnvVar: "EDGEVPNLIBP2PLOGLEVEL",
Value: "fatal",
},
&cli.StringSliceFlag{
Name: "discovery-bootstrap-peers",
Usage: "List of discovery peers to use",
EnvVar: "EDGEVPNBOOTSTRAPPEERS",
},
&cli.StringFlag{
Name: "token",
Usage: "Specify an edgevpn token in place of a config file",
Expand All @@ -81,6 +87,9 @@ func cliToOpts(c *cli.Context) []edgevpn.Option {

ledgerState := c.String("ledger-state")

addrsList := discovery.AddrList{}
peers := c.StringSlice("discovery-bootstrap-peers")

lvl, err := log.LevelFromString(logLevel)
if err != nil {
lvl = log.LevelError
Expand All @@ -99,11 +108,18 @@ func cliToOpts(c *cli.Context) []edgevpn.Option {
llger.Fatal("EDGEVPNCONFIG or EDGEVPNTOKEN not supplied. At least a config file is required")
}

for _, p := range peers {
if err := addrsList.Set(p); err != nil {
llger.Fatal("Failed reading bootstrap peer list", err.Error())
}
}

opts := []edgevpn.Option{
edgevpn.WithDiscoveryInterval(time.Duration(c.Int("discovery-interval")) * time.Second),
edgevpn.WithLedgerAnnounceTime(time.Duration(c.Int("ledger-announce-interval")) * time.Second),
edgevpn.WithLedgerInterval(time.Duration(c.Int("ledger-syncronization-interval")) * time.Second),
edgevpn.Logger(llger),
edgevpn.WithDiscoveryBootstrapPeers(addrsList),
edgevpn.LibP2PLogLevel(libp2plvl),
edgevpn.WithInterfaceMTU(c.Int("mtu")),
edgevpn.WithPacketMTU(1420),
Expand Down
1 change: 1 addition & 0 deletions pkg/edgevpn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Config struct {
AdditionalOptions, Options []libp2p.Option

DiscoveryInterval, LedgerSyncronizationTime, LedgerAnnounceTime time.Duration
DiscoveryBootstrapPeers discovery.AddrList
}

type StreamHandler func(stream network.Stream)
Expand Down
8 changes: 8 additions & 0 deletions pkg/edgevpn/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ func WithDiscoveryInterval(t time.Duration) func(cfg *Config) error {
}
}

func WithDiscoveryBootstrapPeers(a discovery.AddrList) func(cfg *Config) error {
return func(cfg *Config) error {
cfg.DiscoveryBootstrapPeers = a
return nil
}
}

type OTPConfig struct {
Interval int `yaml:"interval"`
Key string `yaml:"key"`
Expand Down Expand Up @@ -230,6 +237,7 @@ func (y YAMLConnectionConfig) copy(cfg *Config) {
OTPKey: y.OTP.DHT.Key,
KeyLength: y.OTP.DHT.Length,
RendezvousString: y.Rendezvous,
BootstrapPeers: cfg.DiscoveryBootstrapPeers,
}
m := &discovery.MDNS{DiscoveryServiceTag: y.MDNS}
cfg.ExchangeKey = y.OTP.Crypto.Key
Expand Down

0 comments on commit 7c118e8

Please sign in to comment.