mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-10 07:20:39 +03:00
Add GenerateConfigJSON, fix StartJSON
This commit is contained in:
parent
f7b0a85b5e
commit
d10a0d6137
@ -3,6 +3,7 @@
|
||||
package yggdrasil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
@ -23,7 +24,7 @@ func (c *Core) StartAutoconfigure() error {
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
nc := config.GenerateConfig(true)
|
||||
nc.IfName = "dummy"
|
||||
nc.AdminListen = "tcp://[::]:9001"
|
||||
nc.AdminListen = "tcp://localhost:9001"
|
||||
nc.Peers = []string{}
|
||||
if hostname, err := os.Hostname(); err == nil {
|
||||
nc.NodeInfo = map[string]interface{}{"name": hostname}
|
||||
@ -49,12 +50,29 @@ func (c *Core) StartJSON(configjson []byte) error {
|
||||
return err
|
||||
}
|
||||
nc.IfName = "dummy"
|
||||
for _, ll := range nc.MulticastInterfaces {
|
||||
ifceExpr, err := regexp.Compile(ll)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.AddMulticastInterfaceExpr(ifceExpr)
|
||||
}
|
||||
if err := c.Start(nc, logger); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GenerateConfigJSON() []byte {
|
||||
nc := config.GenerateConfig(false)
|
||||
nc.IfName = "dummy"
|
||||
if json, err := json.Marshal(nc); err == nil {
|
||||
return json
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Core) GetAddressString() string {
|
||||
return c.GetAddress().String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user