5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 07:35:39 +00:00

Add -normaliseconf option and temporarily correct old config item names in running config

This commit is contained in:
Neil Alexander 2018-05-23 12:04:27 +01:00
parent 9d9083e373
commit ce854a76bd
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 37 additions and 2 deletions

View File

@ -391,7 +391,7 @@ func (c *Core) DEBUG_setupAndStartMulticastInterface() {
m := multicast{}
m.init(c)
c.multicast = m
m.Start()
m.start()
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -44,7 +44,7 @@ func (m *multicast) init(core *Core) {
m.core.log.Println("Found", len(m.interfaces), "multicast interface(s)")
}
func (m *multicast) Start() {
func (m *multicast) start() {
if len(m.core.ifceExpr) == 0 {
m.core.log.Println("Multicast discovery is disabled")
} else {

View File

@ -123,6 +123,7 @@ var pprof = flag.Bool("pprof", false, "Run pprof, see http://localhost:6060/debu
var genconf = flag.Bool("genconf", false, "print a new config to stdout")
var useconf = flag.Bool("useconf", false, "read config from stdin")
var useconffile = flag.String("useconffile", "", "read config from specified file path")
var normaliseconf = flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
var autoconf = flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
func main() {
@ -147,9 +148,43 @@ func main() {
if err := hjson.Unmarshal(config, &dat); err != nil {
panic(err)
}
// For now we will do a little bit to help the user adjust their
// configuration to match the new configuration format
changes := map[string]string{
"Multicast": "",
"LinkLocal": "MulticastInterfaces",
"BoxPub": "EncryptionPublicKey",
"BoxPriv": "EncryptionPrivateKey",
"SigPub": "SigningPublicKey",
"SigPriv": "SigningPrivateKey",
}
for from, to := range changes {
if val, ok := dat[from]; ok {
if val == "" {
if !*normaliseconf {
log.Println("Warning: Deprecated config option", from, " - please remove")
}
} else {
if !*normaliseconf {
log.Println("Warning: Deprecated config option", from, " - please rename to", to)
}
if _, ok := dat[to]; !ok {
dat[to] = dat[from]
}
}
}
}
if err = mapstructure.Decode(dat, &cfg); err != nil {
panic(err)
}
if *normaliseconf {
bs, err := hjson.Marshal(cfg)
if err != nil {
panic(err)
}
fmt.Println(string(bs))
return
}
case *genconf:
fmt.Println(doGenconf())
default: