From ce854a76bd26983a1ca574d4cf438703597b2ce6 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 23 May 2018 12:04:27 +0100 Subject: [PATCH] Add -normaliseconf option and temporarily correct old config item names in running config --- src/yggdrasil/debug.go | 2 +- src/yggdrasil/multicast.go | 2 +- yggdrasil.go | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index 3106691f..a86f2225 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -391,7 +391,7 @@ func (c *Core) DEBUG_setupAndStartMulticastInterface() { m := multicast{} m.init(c) c.multicast = m - m.Start() + m.start() } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/yggdrasil/multicast.go b/src/yggdrasil/multicast.go index a37b022d..afcf8b7f 100644 --- a/src/yggdrasil/multicast.go +++ b/src/yggdrasil/multicast.go @@ -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 { diff --git a/yggdrasil.go b/yggdrasil.go index 900f3a92..5dbc1b65 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -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: