diff --git a/common/config.go b/common/config.go index 373f396..1085cb1 100644 --- a/common/config.go +++ b/common/config.go @@ -1,6 +1,7 @@ package common type Config struct { - SecretKey string - NetworkID string + SecretKey string + NetworkID string + BootstrapNodes string } diff --git a/common/discovery_dht.go b/common/discovery_dht.go index d988b56..c8d088f 100644 --- a/common/discovery_dht.go +++ b/common/discovery_dht.go @@ -45,6 +45,9 @@ func (d *DiscoveryDHT) Run() error { } config := dht.NewConfig() config.Port = d.localNode.State().ListenPort + if d.localNode.config.BootstrapNodes != "" { + config.DHTRouters = d.localNode.config.BootstrapNodes + } d.node, err = dht.New(config) if err != nil { return fmt.Errorf("new dht init err: %s", err) diff --git a/main.go b/main.go index f53632f..10768b2 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,13 @@ func main() { Aliases: []string{"j"}, Usage: "join network", Action: actionJoin, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "bootstrap", + Value: "", + Usage: "Define bootstrap nodes for DHT", + }, + }, }, { Name: "ip", @@ -104,7 +111,8 @@ func actionJoin(ctx *cli.Context) { } nodeConfig := &common.Config{ - SecretKey: key, + SecretKey: key, + BootstrapNodes: ctx.String("bootstrap"), } node, err := common.NewLocalNode(nodeConfig) if err != nil {