From ccf6ce07a444f8acdc3cba86db16ff89c59d1c43 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 14 Dec 2018 17:49:42 +0000 Subject: [PATCH] Fix Peers and InterfacePeers when not in correct format --- cmd/yggdrasil/main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 5b75690..ec8c712 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -12,6 +12,7 @@ import ( "os" "os/signal" "regexp" + "strings" "syscall" "time" @@ -188,6 +189,25 @@ func main() { } } } + // Check to see if the peers are in a parsable format, if not then default + // them to the TCP scheme + for index, peer := range dat["Peers"].([]interface{}) { + uri := peer.(string) + if strings.HasPrefix(uri, "tcp://") || strings.HasPrefix(uri, "socks://") { + continue + } + (dat["Peers"].([]interface{}))[index] = "tcp://" + uri + } + // Now do the same with the interface peers + for intf, peers := range dat["InterfacePeers"].(map[string]interface{}) { + for index, peer := range peers.([]interface{}) { + uri := peer.(string) + if strings.HasPrefix(uri, "tcp://") || strings.HasPrefix(uri, "socks://") { + continue + } + ((dat["InterfacePeers"].(map[string]interface{}))[intf]).([]interface{})[index] = "tcp://" + uri + } + } // Overlay our newly mapped configuration onto the autoconf node config that // we generated above. if err = mapstructure.Decode(dat, &cfg); err != nil {