From f791df4977fc3fb4ab4c884d187d1b4edd7ac744 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 00:00:23 +0000 Subject: [PATCH 01/12] Try to chmod 660 the admin socket if using AF_UNIX --- src/yggdrasil/admin.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index dea4577a..50fdcf90 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -344,6 +344,11 @@ func (a *admin) listen() { switch strings.ToLower(u.Scheme) { case "unix": a.listener, err = net.Listen("unix", a.listenaddr[7:]) + if err == nil { + if err := os.Chmod(a.listenaddr[7:], 0660); err != nil { + a.core.log.Printf("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") + } + } case "tcp": a.listener, err = net.Listen("tcp", u.Host) default: From 06c6dfc67f3c5aa90356e3ccf2ca326f7d8cfa62 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 00:19:21 +0000 Subject: [PATCH 02/12] Complain if socket file already exists --- src/yggdrasil/admin.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 50fdcf90..720c30f8 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -343,11 +343,14 @@ func (a *admin) listen() { if err == nil { switch strings.ToLower(u.Scheme) { case "unix": + if _, err := os.Stat(a.listenaddr[7:]); err == nil { + a.core.log.Println("WARNING:", a.listenaddr[7:], "already exists and may be in use by another process") + } a.listener, err = net.Listen("unix", a.listenaddr[7:]) if err == nil { if err := os.Chmod(a.listenaddr[7:], 0660); err != nil { - a.core.log.Printf("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") - } + a.core.log.Println("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") + } } case "tcp": a.listener, err = net.Listen("tcp", u.Host) From 74a904d04cca967c3a3b8b88f775fecdf07b6514 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 00:26:12 +0000 Subject: [PATCH 03/12] Don't os.Chmod if we suspect the socket belongs to an abstract namespace --- src/yggdrasil/admin.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 720c30f8..2c3dc345 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -348,8 +348,12 @@ func (a *admin) listen() { } a.listener, err = net.Listen("unix", a.listenaddr[7:]) if err == nil { - if err := os.Chmod(a.listenaddr[7:], 0660); err != nil { - a.core.log.Println("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") + switch a.listenaddr[7:8] { + case "@": // maybe abstract namespace + default: + if err := os.Chmod(a.listenaddr[7:], 0660); err != nil { + a.core.log.Println("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") + } } } case "tcp": From bbe2f56b74ba7632de990361640dc7b3751300dd Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 00:31:31 +0000 Subject: [PATCH 04/12] Default to /var/run/yggdrasil.sock for admin on darwin/macOS --- src/defaults/defaults_darwin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/defaults/defaults_darwin.go b/src/defaults/defaults_darwin.go index 778162c0..68a13931 100644 --- a/src/defaults/defaults_darwin.go +++ b/src/defaults/defaults_darwin.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "tcp://localhost:9001", + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", // TUN/TAP MaximumIfMTU: 65535, From 8aaaeb26eb5d80ef753a64e14108ed5cfedf5880 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 00:37:32 +0000 Subject: [PATCH 05/12] Default to /var/run/yggdrasil.sock for admin on Linux, BSDs --- src/defaults/defaults_freebsd.go | 2 +- src/defaults/defaults_linux.go | 2 +- src/defaults/defaults_netbsd.go | 2 +- src/defaults/defaults_openbsd.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/defaults/defaults_freebsd.go b/src/defaults/defaults_freebsd.go index 7c5c7752..4ba7face 100644 --- a/src/defaults/defaults_freebsd.go +++ b/src/defaults/defaults_freebsd.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "tcp://localhost:9001", + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", // TUN/TAP MaximumIfMTU: 32767, diff --git a/src/defaults/defaults_linux.go b/src/defaults/defaults_linux.go index 85287eeb..e3e23e20 100644 --- a/src/defaults/defaults_linux.go +++ b/src/defaults/defaults_linux.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "tcp://localhost:9001", + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", // TUN/TAP MaximumIfMTU: 65535, diff --git a/src/defaults/defaults_netbsd.go b/src/defaults/defaults_netbsd.go index 8e8f7b5f..7879a415 100644 --- a/src/defaults/defaults_netbsd.go +++ b/src/defaults/defaults_netbsd.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "tcp://localhost:9001", + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", // TUN/TAP MaximumIfMTU: 9000, diff --git a/src/defaults/defaults_openbsd.go b/src/defaults/defaults_openbsd.go index 8b3e2bbc..7bfd30e6 100644 --- a/src/defaults/defaults_openbsd.go +++ b/src/defaults/defaults_openbsd.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "tcp://localhost:9001", + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", // TUN/TAP MaximumIfMTU: 16384, From 2928fcb046a2ab1e1c525e3aa491730a2523b138 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 00:42:56 +0000 Subject: [PATCH 06/12] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8501f3e9..da8c7022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Switched to Chord DHT (instead of Kademlia, although still compatible at the protocol level) +- The `AdminListen` option and `yggdrasilctl` now default to `unix:///var/run/yggdrasil.sock` on BSDs, macOS and Linux - Cleaned up some of the parameter naming in the admin socket - Latency-based parent selection for the switch instead of uptime-based (should help to avoid high latency links somewhat) - Real peering endpoints now shown in the admin socket `getPeers` call to help identify peerings From dff1dca19c8f713d0f2167ff0ed93cbea27fcae1 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 10:20:59 +0000 Subject: [PATCH 07/12] Add DefaultConfigFile to defaults for yggdrasilctl --- src/defaults/defaults.go | 3 +++ src/defaults/defaults_darwin.go | 3 +++ src/defaults/defaults_freebsd.go | 3 +++ src/defaults/defaults_linux.go | 3 +++ src/defaults/defaults_netbsd.go | 3 +++ src/defaults/defaults_openbsd.go | 3 +++ src/defaults/defaults_other.go | 3 +++ src/defaults/defaults_windows.go | 3 +++ 8 files changed, 24 insertions(+) diff --git a/src/defaults/defaults.go b/src/defaults/defaults.go index 753efc53..3834990e 100644 --- a/src/defaults/defaults.go +++ b/src/defaults/defaults.go @@ -7,6 +7,9 @@ type platformDefaultParameters struct { // Admin socket DefaultAdminListen string + // Configuration (used for yggdrasilctl) + DefaultConfigFile string + // TUN/TAP MaximumIfMTU int DefaultIfMTU int diff --git a/src/defaults/defaults_darwin.go b/src/defaults/defaults_darwin.go index 68a13931..9bac3aad 100644 --- a/src/defaults/defaults_darwin.go +++ b/src/defaults/defaults_darwin.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "/etc/yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 65535, DefaultIfMTU: 65535, diff --git a/src/defaults/defaults_freebsd.go b/src/defaults/defaults_freebsd.go index 4ba7face..df1a3c65 100644 --- a/src/defaults/defaults_freebsd.go +++ b/src/defaults/defaults_freebsd.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "/etc/yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 32767, DefaultIfMTU: 32767, diff --git a/src/defaults/defaults_linux.go b/src/defaults/defaults_linux.go index e3e23e20..2f3459ca 100644 --- a/src/defaults/defaults_linux.go +++ b/src/defaults/defaults_linux.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "/etc/yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 65535, DefaultIfMTU: 65535, diff --git a/src/defaults/defaults_netbsd.go b/src/defaults/defaults_netbsd.go index 7879a415..40476dcb 100644 --- a/src/defaults/defaults_netbsd.go +++ b/src/defaults/defaults_netbsd.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "/etc/yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 9000, DefaultIfMTU: 9000, diff --git a/src/defaults/defaults_openbsd.go b/src/defaults/defaults_openbsd.go index 7bfd30e6..cd6d202a 100644 --- a/src/defaults/defaults_openbsd.go +++ b/src/defaults/defaults_openbsd.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "/etc/yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 16384, DefaultIfMTU: 16384, diff --git a/src/defaults/defaults_other.go b/src/defaults/defaults_other.go index d780872b..a01ab7af 100644 --- a/src/defaults/defaults_other.go +++ b/src/defaults/defaults_other.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "tcp://localhost:9001", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "/etc/yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 65535, DefaultIfMTU: 65535, diff --git a/src/defaults/defaults_windows.go b/src/defaults/defaults_windows.go index 83877d62..3b04783a 100644 --- a/src/defaults/defaults_windows.go +++ b/src/defaults/defaults_windows.go @@ -9,6 +9,9 @@ func GetDefaults() platformDefaultParameters { // Admin DefaultAdminListen: "tcp://localhost:9001", + // Configuration (used for yggdrasilctl) + DefaultConfigFile: "C:\\Program Files\\Yggdrasil\\yggdrasil.conf", + // TUN/TAP MaximumIfMTU: 65535, DefaultIfMTU: 65535, From cd11d2eccded97cd0454d2d2918a4725d1baae74 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 10:54:41 +0000 Subject: [PATCH 08/12] Produce more meaningful logging from yggdrasilctl when things go wrong --- cmd/yggdrasilctl/main.go | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index ab8ee595..5b6784c3 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -1,10 +1,12 @@ package main import ( + "bytes" "encoding/json" "errors" "flag" "fmt" + "log" "net" "net/url" "os" @@ -18,10 +20,15 @@ import ( type admin_info map[string]interface{} func main() { + logbuffer := &bytes.Buffer{} + logger := log.New(logbuffer, "", log.Flags()) + + defaultEndpoint := defaults.GetDefaults().DefaultAdminListen + flag.Usage = func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n", os.Args[0]) + fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n", os.Args[0]) fmt.Println("Options:") - flag.PrintDefaults() + flag.PrintDefaults() fmt.Println("Commands:\n - Use \"list\" for a list of available commands") fmt.Println("Examples:") fmt.Println(" - ", os.Args[0], "list") @@ -30,7 +37,7 @@ func main() { fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT") fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT") } - server := flag.String("endpoint", defaults.GetDefaults().DefaultAdminListen, "Admin socket endpoint") + server := flag.String("endpoint", defaultEndpoint, "Admin socket endpoint") injson := flag.Bool("json", false, "Output in JSON format (as opposed to pretty-print)") verbose := flag.Bool("v", false, "Verbose output (includes public keys)") flag.Parse() @@ -46,18 +53,24 @@ func main() { if err == nil { switch strings.ToLower(u.Scheme) { case "unix": + logger.Println("Connecting to UNIX socket", (*server)[7:]) conn, err = net.Dial("unix", (*server)[7:]) case "tcp": + logger.Println("Connecting to TCP socket", u.Host) conn, err = net.Dial("tcp", u.Host) default: + logger.Println("Unknown protocol", u.Scheme, "- please check your endpoint") err = errors.New("protocol not supported") } } else { + logger.Println("Connecting to TCP socket", u.Host) conn, err = net.Dial("tcp", *server) } if err != nil { + fmt.Print(logbuffer) panic(err) } + logger.Println("Connected") defer conn.Close() decoder := json.NewDecoder(conn) @@ -67,11 +80,13 @@ func main() { for c, a := range args { if c == 0 { + logger.Printf("Sending request: %v\n", a) send["request"] = a continue } tokens := strings.Split(a, "=") if i, err := strconv.Atoi(tokens[1]); err == nil { + logger.Printf("Sending parameter %s: %d\n", tokens[0], i) send[tokens[0]] = i } else { switch strings.ToLower(tokens[1]) { @@ -82,28 +97,32 @@ func main() { default: send[tokens[0]] = tokens[1] } + logger.Printf("Sending parameter %s: %v\n", tokens[0], send[tokens[0]]) } } if err := encoder.Encode(&send); err != nil { + fmt.Print(logbuffer) panic(err) } + logger.Printf("Request sent") if err := decoder.Decode(&recv); err == nil { + logger.Printf("Response received") if recv["status"] == "error" { if err, ok := recv["error"]; ok { - fmt.Println("Error:", err) + fmt.Println("Admin socket returned an error:", err) } else { - fmt.Println("Unspecified error occured") + fmt.Println("Admin socket returned an error but didn't specify any error text") } os.Exit(1) } if _, ok := recv["request"]; !ok { fmt.Println("Missing request in response (malformed response?)") - return + os.Exit(1) } if _, ok := recv["response"]; !ok { fmt.Println("Missing response body (malformed response?)") - return + os.Exit(1) } req := recv["request"].(map[string]interface{}) res := recv["response"].(map[string]interface{}) @@ -243,7 +262,7 @@ func main() { queuesize := v.(map[string]interface{})["queue_size"].(float64) queuepackets := v.(map[string]interface{})["queue_packets"].(float64) queueid := v.(map[string]interface{})["queue_id"].(string) - portqueues[queueport] += 1 + portqueues[queueport]++ portqueuesize[queueport] += queuesize portqueuepackets[queueport] += queuepackets queuesizepercent := (100 / maximumqueuesize) * queuesize @@ -331,9 +350,11 @@ func main() { fmt.Println(string(json)) } } + } else { + logger.Println("Error receiving response:", err) } - if v, ok := recv["status"]; ok && v == "error" { + if v, ok := recv["status"]; ok && v != "success" { os.Exit(1) } os.Exit(0) From d29b5a074a7cba359e9478fba0d40490c457fa31 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 11:09:10 +0000 Subject: [PATCH 09/12] Try to use default config file location to find AdminListen when yggdrasilctl is not given an endpoint --- cmd/yggdrasilctl/main.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 5b6784c3..1fdf1bcd 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -6,6 +6,7 @@ import ( "errors" "flag" "fmt" + "io/ioutil" "log" "net" "net/url" @@ -14,6 +15,9 @@ import ( "strconv" "strings" + "golang.org/x/text/encoding/unicode" + + "github.com/neilalexander/hjson-go" "github.com/yggdrasil-network/yggdrasil-go/src/defaults" ) @@ -48,6 +52,37 @@ func main() { return } + if *server == defaultEndpoint { + if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil { + if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 || + bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 { + utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM) + decoder := utf.NewDecoder() + config, err = decoder.Bytes(config) + if err != nil { + panic(err) + } + } + var dat map[string]interface{} + if err := hjson.Unmarshal(config, &dat); err != nil { + panic(err) + } + if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") { + defaultEndpoint = ep + logger.Println("Found platform default config file", defaults.GetDefaults().DefaultConfigFile) + logger.Println("Using endpoint", defaultEndpoint, "from AdminListen") + } else { + logger.Println("Configuration file doesn't contain appropriate AdminListen option") + logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen) + } + } else { + logger.Println("Can't open config file from default location", defaults.GetDefaults().DefaultConfigFile) + logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen) + } + } else { + logger.Println("Using endpoint", *server, "from command line") + } + var conn net.Conn u, err := url.Parse(*server) if err == nil { @@ -59,7 +94,7 @@ func main() { logger.Println("Connecting to TCP socket", u.Host) conn, err = net.Dial("tcp", u.Host) default: - logger.Println("Unknown protocol", u.Scheme, "- please check your endpoint") + logger.Println("Unknown protocol or malformed address - check your endpoint") err = errors.New("protocol not supported") } } else { From b4b3609678942f0fac200595b66c440295a6f472 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 11:12:40 +0000 Subject: [PATCH 10/12] Really use the correct endpoint --- cmd/yggdrasilctl/main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 1fdf1bcd..9646f6c1 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -27,7 +27,7 @@ func main() { logbuffer := &bytes.Buffer{} logger := log.New(logbuffer, "", log.Flags()) - defaultEndpoint := defaults.GetDefaults().DefaultAdminListen + endpoint := defaults.GetDefaults().DefaultAdminListen flag.Usage = func() { fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n", os.Args[0]) @@ -41,7 +41,7 @@ func main() { fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT") fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT") } - server := flag.String("endpoint", defaultEndpoint, "Admin socket endpoint") + server := flag.String("endpoint", endpoint, "Admin socket endpoint") injson := flag.Bool("json", false, "Output in JSON format (as opposed to pretty-print)") verbose := flag.Bool("v", false, "Verbose output (includes public keys)") flag.Parse() @@ -52,7 +52,7 @@ func main() { return } - if *server == defaultEndpoint { + if *server == endpoint { if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil { if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 || bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 { @@ -68,9 +68,9 @@ func main() { panic(err) } if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") { - defaultEndpoint = ep + endpoint = ep logger.Println("Found platform default config file", defaults.GetDefaults().DefaultConfigFile) - logger.Println("Using endpoint", defaultEndpoint, "from AdminListen") + logger.Println("Using endpoint", endpoint, "from AdminListen") } else { logger.Println("Configuration file doesn't contain appropriate AdminListen option") logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen) @@ -80,16 +80,16 @@ func main() { logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen) } } else { - logger.Println("Using endpoint", *server, "from command line") + logger.Println("Using endpoint", endpoint, "from command line") } var conn net.Conn - u, err := url.Parse(*server) + u, err := url.Parse(endpoint) if err == nil { switch strings.ToLower(u.Scheme) { case "unix": - logger.Println("Connecting to UNIX socket", (*server)[7:]) - conn, err = net.Dial("unix", (*server)[7:]) + logger.Println("Connecting to UNIX socket", endpoint[7:]) + conn, err = net.Dial("unix", endpoint[7:]) case "tcp": logger.Println("Connecting to TCP socket", u.Host) conn, err = net.Dial("tcp", u.Host) @@ -99,7 +99,7 @@ func main() { } } else { logger.Println("Connecting to TCP socket", u.Host) - conn, err = net.Dial("tcp", *server) + conn, err = net.Dial("tcp", endpoint) } if err != nil { fmt.Print(logbuffer) From c78e1b98cccdfe1e83dddabdc95b849d2ef7aac2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 11:29:42 +0000 Subject: [PATCH 11/12] Show yggdrasilctl log buffer on panic --- cmd/yggdrasilctl/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 9646f6c1..b37c2561 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -26,6 +26,13 @@ type admin_info map[string]interface{} func main() { logbuffer := &bytes.Buffer{} logger := log.New(logbuffer, "", log.Flags()) + defer func() { + if r := recover(); r != nil { + logger.Println("Fatal error:", r) + fmt.Print(logbuffer) + os.Exit(1) + } + }() endpoint := defaults.GetDefaults().DefaultAdminListen @@ -102,7 +109,6 @@ func main() { conn, err = net.Dial("tcp", endpoint) } if err != nil { - fmt.Print(logbuffer) panic(err) } logger.Println("Connected") @@ -137,7 +143,6 @@ func main() { } if err := encoder.Encode(&send); err != nil { - fmt.Print(logbuffer) panic(err) } logger.Printf("Request sent") From 3eb1a40c684b32f07ef485b44723323c5db6c73f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 11:34:37 +0000 Subject: [PATCH 12/12] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da8c7022..2db4dde1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `-json` command line flag for generating and normalising configuration in plain JSON instead of HJSON - Build name and version numbers are now imprinted onto the build, accessible through `yggdrasil -version` and `yggdrasilctl getSelf` - Add ability to disable admin socket by setting `AdminListen` to `"none"` +- `yggdrasilctl` now tries to look for the default configuration file to find `AdminListen` if `-endpoint` is not specified +- `yggdrasilctl` now returns more useful logging in the event of a fatal error ### Changed - Switched to Chord DHT (instead of Kademlia, although still compatible at the protocol level)