From 57ade250aff86cea5d661d5a6e7a67b9e52a36a0 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 2 Oct 2019 12:19:37 -0700 Subject: [PATCH] . --- go/Makefile | 2 +- go/cmd/zerotier/cli/addroot.go | 10 +++++++--- go/cmd/zerotier/cli/misc.go | 2 +- go/cmd/zerotier/cli/network.go | 4 ++-- go/cmd/zerotier/cli/networks.go | 2 +- go/cmd/zerotier/cli/roots.go | 4 ++-- go/cmd/zerotier/cli/status.go | 11 ++++++----- go/pkg/zerotier/api.go | 2 +- go/pkg/zerotier/identity.go | 1 - go/pkg/zerotier/node.go | 10 ++++------ 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/go/Makefile b/go/Makefile index 5afd85a9f..e5b5ed79e 100644 --- a/go/Makefile +++ b/go/Makefile @@ -1,2 +1,2 @@ all: - go build -o zerotier cmd/zerotier/zerotier.go + go build -trimpath -ldflags -s -o ../build/zerotier cmd/zerotier/zerotier.go diff --git a/go/cmd/zerotier/cli/addroot.go b/go/cmd/zerotier/cli/addroot.go index b0cafcd74..098d800fc 100644 --- a/go/cmd/zerotier/cli/addroot.go +++ b/go/cmd/zerotier/cli/addroot.go @@ -14,6 +14,7 @@ package cli import ( + "encoding/base64" "fmt" "io/ioutil" "net/url" @@ -32,12 +33,15 @@ func AddRoot(basePath, authToken string, args []string) { locData, err := ioutil.ReadFile(args[0]) if err != nil { - fmt.Printf("ERROR: unable to read locator: %s\n", err.Error()) - os.Exit(1) + locData, err2 := base64.StdEncoding.DecodeString(strings.TrimSpace(args[0])) + if err2 != nil || len(locData) == 0 { + fmt.Printf("ERROR: unable to read locator: %s\n", err.Error()) + os.Exit(1) + } } loc, err := zerotier.NewLocatorFromBytes(locData) if err != nil { - fmt.Printf("ERROR: invalid locator in file '%s': %s\n", args[0], err.Error()) + fmt.Printf("ERROR: invalid locator '%s' (tried as file and base64 literal): %s\n", args[0], err.Error()) os.Exit(1) } diff --git a/go/cmd/zerotier/cli/misc.go b/go/cmd/zerotier/cli/misc.go index 8f140f328..816b386e6 100644 --- a/go/cmd/zerotier/cli/misc.go +++ b/go/cmd/zerotier/cli/misc.go @@ -107,7 +107,7 @@ func readIdentity(s string) *zerotier.Identity { return id } -func networkStatusStr(int status) string { +func networkStatusStr(status int) string { switch status { case zerotier.NetworkStatusNotFound: return "NOTFOUND" diff --git a/go/cmd/zerotier/cli/network.go b/go/cmd/zerotier/cli/network.go index 54bb7683b..23f797fb4 100644 --- a/go/cmd/zerotier/cli/network.go +++ b/go/cmd/zerotier/cli/network.go @@ -63,14 +63,14 @@ func Network(basePath, authToken string, args []string, jsonOutput bool) { fmt.Printf("\tmanaged addresses:\t") for i, a := range network.Config.AssignedAddresses { if i > 0 { - fmt.Print(' ') + fmt.Print(" ") } fmt.Print(a.String()) } fmt.Printf("\n\tmanaged routes:\t") for i, r := range network.Config.Routes { if i > 0 { - fmt.Print(' ') + fmt.Print(" ") } fmt.Print(r.Target.String()) if r.Via == nil { diff --git a/go/cmd/zerotier/cli/networks.go b/go/cmd/zerotier/cli/networks.go index 46d39e728..00b0ba29c 100644 --- a/go/cmd/zerotier/cli/networks.go +++ b/go/cmd/zerotier/cli/networks.go @@ -37,7 +37,7 @@ func Networks(basePath, authToken string, args []string, jsonOutput bool) { fmt.Printf("%.16x %-24s %-17s %-16s %-7s %-16s ", uint64(nw.ID), nw.Config.Name, nw.Config.MAC.String(), networkStatusStr(nw.Config.Status), t, nw.PortName) for i, ip := range nw.Config.AssignedAddresses { if i > 0 { - fmt.Print(',') + fmt.Print(",") } fmt.Print(ip.String()) } diff --git a/go/cmd/zerotier/cli/roots.go b/go/cmd/zerotier/cli/roots.go index a2755f5db..97c4f4280 100644 --- a/go/cmd/zerotier/cli/roots.go +++ b/go/cmd/zerotier/cli/roots.go @@ -41,13 +41,13 @@ func Roots(basePath, authToken string, args []string, jsonOutput bool) { fmt.Printf("%32s %.10x ", rn, uint64(r.Locator.Identity.Address())) for i, a := range r.Locator.Physical { if i > 0 { - fmt.Print(',') + fmt.Print(",") } fmt.Print(a.String()) } for i, a := range r.Locator.Virtual { if i > 0 || len(r.Locator.Physical) > 0 { - fmt.Print(',') + fmt.Print(",") } fmt.Print(a.String()) } diff --git a/go/cmd/zerotier/cli/status.go b/go/cmd/zerotier/cli/status.go index c705a7ad1..41ef3e44e 100644 --- a/go/cmd/zerotier/cli/status.go +++ b/go/cmd/zerotier/cli/status.go @@ -33,6 +33,7 @@ func Status(basePath, authToken string, args []string, jsonOutput bool) { online = "OFFLINE" } fmt.Printf("%.10x: %s %s\n", uint64(status.Address), online, status.Version) + fmt.Printf("\tidentity:\t%s\n", status.Identity.String()) fmt.Printf("\tports:\t%d %d %d\n", status.Config.Settings.PrimaryPort, status.Config.Settings.SecondaryPort, status.Config.Settings.TertiaryPort) fmt.Printf("\tport search:\t%s\n", enabledDisabled(status.Config.Settings.PortSearch)) fmt.Printf("\tport mapping (uPnP/NAT-PMP):\t%s\n", enabledDisabled(status.Config.Settings.PortMapping)) @@ -40,32 +41,32 @@ func Status(basePath, authToken string, args []string, jsonOutput bool) { fmt.Printf("\tblacklisted interface prefixes:\t") for i, bl := range status.Config.Settings.InterfacePrefixBlacklist { if i > 0 { - fmt.Print(' ') + fmt.Print(" ") } fmt.Print(bl) } fmt.Printf("\n\texplicit external addresses: ") for i, ea := range status.Config.Settings.ExplicitAddresses { if i > 0 { - fmt.Print(' ') + fmt.Print(" ") } fmt.Print(ea.String()) } fmt.Printf("\n\tsystem interface addresses: ") for i, a := range status.InterfaceAddresses { if i > 0 { - fmt.Print(' ') + fmt.Print(" ") } fmt.Print(a.String()) } fmt.Printf("\n\tmapped external addresses: ") for i, a := range status.MappedExternalAddresses { if i > 0 { - fmt.Print(' ') + fmt.Print(" ") } fmt.Print(a.String()) } - fmt.Printf("\n\tidentity:\t%s\n", status.Identity.String()) + fmt.Printf("\n") } os.Exit(0) diff --git a/go/pkg/zerotier/api.go b/go/pkg/zerotier/api.go index 5d72f8ddc..79b484b76 100644 --- a/go/pkg/zerotier/api.go +++ b/go/pkg/zerotier/api.go @@ -126,7 +126,7 @@ type APIStatus struct { VersionBuild int `json:"versionBuild"` OS string `json:"os"` Architecture string `json:"architecture"` - Concurrency int `json:"cpus"` + Concurrency int `json:"concurrency"` Runtime string `json:"runtimeVersion"` } diff --git a/go/pkg/zerotier/identity.go b/go/pkg/zerotier/identity.go index 89afec263..24d8f6c4c 100644 --- a/go/pkg/zerotier/identity.go +++ b/go/pkg/zerotier/identity.go @@ -204,7 +204,6 @@ func (id *Identity) UnmarshalJSON(j []byte) error { if err != nil { return err } - fmt.Println(s) nid, err := NewIdentityFromString(s) if err != nil { return err diff --git a/go/pkg/zerotier/node.go b/go/pkg/zerotier/node.go index 848a71fc5..793407b03 100644 --- a/go/pkg/zerotier/node.go +++ b/go/pkg/zerotier/node.go @@ -327,12 +327,10 @@ func NewNode(basePath string) (*Node, error) { m, _ := NewMACFromBytes(i.HardwareAddr) if _, isZeroTier := n.networksByMAC[m]; !isZeroTier { addrs, _ := i.Addrs() - if len(addrs) > 0 { - for _, a := range addrs { - ipn, _ := a.(*net.IPNet) - if ipn != nil { - interfaceAddresses[ipn.IP.String()] = ipn.IP - } + for _, a := range addrs { + ipn, _ := a.(*net.IPNet) + if ipn != nil && len(ipn.IP) > 0 && !ipn.IP.IsLinkLocalUnicast() && !ipn.IP.IsMulticast() { + interfaceAddresses[ipn.IP.String()] = ipn.IP } } }