Browse Source

Bunch of small warnings and stylistic things...

Adam Ierymenko 5 years ago
parent
commit
e4799ff8c4

+ 3 - 0
.idea/.gitignore

@@ -0,0 +1,3 @@
+
+# Default ignored files
+/workspace.xml

+ 9 - 0
.idea/ZeroTierOne.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 5 - 0
.idea/codeStyles/codeStyleConfig.xml

@@ -0,0 +1,5 @@
+<component name="ProjectCodeStyleConfiguration">
+  <state>
+    <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
+  </state>
+</component>

+ 11 - 0
.idea/dictionaries/api.xml

@@ -0,0 +1,11 @@
+<component name="ProjectDictionaryState">
+  <dictionary name="api">
+    <words>
+      <w>apisocket</w>
+      <w>nwid</w>
+      <w>secrand</w>
+      <w>sockaddr</w>
+      <w>unmarshals</w>
+    </words>
+  </dictionary>
+</component>

+ 10 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,10 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
+      <option name="processCode" value="true" />
+      <option name="processLiterals" value="true" />
+      <option name="processComments" value="true" />
+    </inspection_tool>
+  </profile>
+</component>

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="JavaScriptSettings">
+    <option name="languageLevel" value="ES6" />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/ZeroTierOne.iml" filepath="$PROJECT_DIR$/.idea/ZeroTierOne.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 29 - 0
.idea/watcherTasks.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectTasksOptions">
+    <TaskOptions isEnabled="true">
+      <option name="arguments" value="fmt $FilePath$" />
+      <option name="checkSyntaxErrors" value="true" />
+      <option name="description" />
+      <option name="exitCodeBehavior" value="ERROR" />
+      <option name="fileExtension" value="go" />
+      <option name="immediateSync" value="false" />
+      <option name="name" value="go fmt" />
+      <option name="output" value="$FilePath$" />
+      <option name="outputFilters">
+        <array />
+      </option>
+      <option name="outputFromStdout" value="false" />
+      <option name="program" value="$GoExecPath$" />
+      <option name="runOnExternalChanges" value="false" />
+      <option name="scopeName" value="Project Files" />
+      <option name="trackOnlyRoot" value="true" />
+      <option name="workingDir" value="$ProjectFileDir$" />
+      <envs>
+        <env name="GOROOT" value="$GOROOT$" />
+        <env name="GOPATH" value="$GOPATH$" />
+        <env name="PATH" value="$GoBinDirs$" />
+      </envs>
+    </TaskOptions>
+  </component>
+</project>

+ 32 - 29
go/pkg/zerotier/api.go

@@ -25,7 +25,7 @@ import (
 	"strings"
 	"time"
 
-	acl "github.com/hectane/go-acl"
+	"github.com/hectane/go-acl"
 )
 
 // APISocketName is the default socket name for accessing the API
@@ -151,7 +151,7 @@ func apiSendObj(out http.ResponseWriter, req *http.Request, httpStatusCode int,
 func apiReadObj(out http.ResponseWriter, req *http.Request, dest interface{}) (err error) {
 	err = json.NewDecoder(req.Body).Decode(&dest)
 	if err != nil {
-		apiSendObj(out, req, http.StatusBadRequest, nil)
+		_ = apiSendObj(out, req, http.StatusBadRequest, nil)
 	}
 	return
 }
@@ -165,7 +165,7 @@ func apiCheckAuth(out http.ResponseWriter, req *http.Request, token string) bool
 	if len(ah) > 0 && strings.TrimSpace(ah) == token {
 		return true
 	}
-	apiSendObj(out, req, http.StatusUnauthorized, nil)
+	_ = apiSendObj(out, req, http.StatusUnauthorized, nil)
 	return false
 }
 
@@ -182,13 +182,13 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 			return nil, err
 		}
 		for i := 0; i < 20; i++ {
-			atb[i] = byte("abcdefghijklmnopqrstuvwxyz0123456789"[atb[i]%36])
+			atb[i] = "abcdefghijklmnopqrstuvwxyz0123456789"[atb[i]%36]
 		}
 		err = ioutil.WriteFile(authTokenFile, atb[:], 0600)
 		if err != nil {
 			return nil, err
 		}
-		acl.Chmod(authTokenFile, 0600)
+		_ = acl.Chmod(authTokenFile, 0600)
 		authToken = string(atb[:])
 	} else {
 		authToken = strings.TrimSpace(string(authTokenB))
@@ -202,7 +202,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 		}
 		apiSetStandardHeaders(out)
 		if req.Method == http.MethodGet || req.Method == http.MethodHead {
-			apiSendObj(out, req, http.StatusOK, &APIStatus{
+			_ = apiSendObj(out, req, http.StatusOK, &APIStatus{
 				Address:                 node.Address(),
 				Clock:                   TimeMs(),
 				Config:                  node.LocalConfig(),
@@ -218,7 +218,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 			})
 		} else {
 			out.Header().Set("Allow", "GET, HEAD")
-			apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
+			_ = apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
 		}
 	})
 
@@ -230,14 +230,14 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 		if req.Method == http.MethodPost || req.Method == http.MethodPut {
 			var c LocalConfig
 			if apiReadObj(out, req, &c) == nil {
-				node.SetLocalConfig(&c)
-				apiSendObj(out, req, http.StatusOK, node.LocalConfig())
+				_, _ = node.SetLocalConfig(&c)
+				_ = apiSendObj(out, req, http.StatusOK, node.LocalConfig())
 			}
 		} else if req.Method == http.MethodGet || req.Method == http.MethodHead {
-			apiSendObj(out, req, http.StatusOK, node.LocalConfig())
+			_ = apiSendObj(out, req, http.StatusOK, node.LocalConfig())
 		} else {
 			out.Header().Set("Allow", "GET, HEAD, PUT, POST")
-			apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
+			_ = apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
 		}
 	})
 
@@ -252,7 +252,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 			var err error
 			queriedID, err = NewAddressFromString(req.URL.Path[6:])
 			if err != nil {
-				apiSendObj(out, req, http.StatusNotFound, nil)
+				_ = apiSendObj(out, req, http.StatusNotFound, nil)
 				return
 			}
 		}
@@ -266,13 +266,13 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 						p2 = append(p2, p)
 					}
 				}
-				apiSendObj(out, req, http.StatusOK, p2)
+				_ = apiSendObj(out, req, http.StatusOK, p2)
 			} else {
-				apiSendObj(out, req, http.StatusOK, peers)
+				_ = apiSendObj(out, req, http.StatusOK, peers)
 			}
 		} else {
 			out.Header().Set("Allow", "GET, HEAD")
-			apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
+			_ = apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
 		}
 	})
 
@@ -287,14 +287,14 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 			var err error
 			queriedID, err = NewNetworkIDFromString(req.URL.Path[9:])
 			if err != nil {
-				apiSendObj(out, req, http.StatusNotFound, nil)
+				_ = apiSendObj(out, req, http.StatusNotFound, nil)
 				return
 			}
 		}
 
 		if req.Method == http.MethodPost || req.Method == http.MethodPut {
 			if queriedID == 0 {
-				apiSendObj(out, req, http.StatusBadRequest, nil)
+				_ = apiSendObj(out, req, http.StatusBadRequest, nil)
 			} else {
 				var nw APINetwork
 				if apiReadObj(out, req, &nw) == nil {
@@ -302,15 +302,15 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 					if n == nil {
 						n, err := node.Join(nw.ID, nw.Settings, nil)
 						if err != nil {
-							apiSendObj(out, req, http.StatusBadRequest, nil)
+							_ = apiSendObj(out, req, http.StatusBadRequest, nil)
 						} else {
-							apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
+							_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
 						}
 					} else {
 						if nw.Settings != nil {
 							n.SetLocalSettings(nw.Settings)
 						}
-						apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
+						_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
 					}
 				}
 			}
@@ -321,18 +321,18 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 				for _, nw := range networks {
 					nws = append(nws, apiNetworkFromNetwork(nw))
 				}
-				apiSendObj(out, req, http.StatusOK, nws)
+				_ = apiSendObj(out, req, http.StatusOK, nws)
 			} else {
 				for _, nw := range networks {
 					if nw.ID() == queriedID {
-						apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw))
+						_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw))
 						break
 					}
 				}
 			}
 		} else {
 			out.Header().Set("Allow", "GET, HEAD, PUT, POST")
-			apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
+			_ = apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
 		}
 	})
 
@@ -347,14 +347,14 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 			var err error
 			queriedID, err = NewAddressFromString(req.URL.Path[6:])
 			if err != nil {
-				apiSendObj(out, req, http.StatusNotFound, nil)
+				_ = apiSendObj(out, req, http.StatusNotFound, nil)
 				return
 			}
 		}
 
 		if req.Method == http.MethodPost || req.Method == http.MethodPut {
 			if queriedID == 0 {
-				apiSendObj(out, req, http.StatusBadRequest, nil)
+				_ = apiSendObj(out, req, http.StatusBadRequest, nil)
 			} else {
 				var r Root
 				if apiReadObj(out, req, &r) == nil {
@@ -362,10 +362,10 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 			}
 		} else if req.Method == http.MethodGet || req.Method == http.MethodHead {
 			roots := node.Roots()
-			apiSendObj(out, req, http.StatusOK, roots)
+			_ = apiSendObj(out, req, http.StatusOK, roots)
 		} else {
 			out.Header().Set("Allow", "GET, HEAD, PUT, POST")
-			apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
+			_ = apiSendObj(out, req, http.StatusMethodNotAllowed, nil)
 		}
 	})
 
@@ -382,8 +382,11 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
 	}
 	httpServer.SetKeepAlivesEnabled(true)
 	go func() {
-		httpServer.Serve(listener)
-		listener.Close()
+		err := httpServer.Serve(listener)
+		if err != nil {
+			node.log.Printf("ERROR: unable to start API HTTP server: %s (continuing anyway but CLI will not work!)", err.Error())
+		}
+		_ = listener.Close()
 	}()
 
 	return httpServer, nil

+ 11 - 11
go/pkg/zerotier/errors.go

@@ -20,15 +20,15 @@ func (e Err) Error() string { return (string)(e) }
 
 // Simple ZeroTier Errors
 const (
-	ErrInternal                  Err = "internal error"
-	ErrNodeInitFailed            Err = "unable to initialize core Node instance"
-	ErrInvalidMACAddress         Err = "invalid MAC address"
-	ErrInvalidZeroTierAddress    Err = "invalid ZeroTier address"
-	ErrInvalidNetworkID          Err = "invalid network ID"
-	ErrInvalidParameter          Err = "invalid parameter"
-	ErrTapInitFailed             Err = "unable to create native Tap instance"
-	ErrUncrecognizedIdentityType Err = "unrecognized identity type"
-	ErrInvalidKey                Err = "invalid key data"
-	ErrInvalidSignature          Err = "invalid signature"
-	ErrSecretKeyRequired         Err = "secret key required"
+	ErrInternal                 Err = "internal error"
+	ErrNodeInitFailed           Err = "unable to initialize core Node instance"
+	ErrInvalidMACAddress        Err = "invalid MAC address"
+	ErrInvalidZeroTierAddress   Err = "invalid ZeroTier address"
+	ErrInvalidNetworkID         Err = "invalid network ID"
+	ErrInvalidParameter         Err = "invalid parameter"
+	ErrTapInitFailed            Err = "unable to create native Tap instance"
+	ErrUnrecognizedIdentityType Err = "unrecognized identity type"
+	ErrInvalidKey               Err = "invalid key data"
+	ErrInvalidSignature         Err = "invalid signature"
+	ErrSecretKeyRequired        Err = "secret key required"
 )

+ 1 - 1
go/pkg/zerotier/identity.go

@@ -62,7 +62,7 @@ func NewIdentityFromString(s string) (*Identity, error) {
 	} else if ss[1] == "1" {
 		id.idtype = 1
 	} else {
-		return nil, ErrUncrecognizedIdentityType
+		return nil, ErrUnrecognizedIdentityType
 	}
 
 	switch id.idtype {

+ 1 - 1
go/pkg/zerotier/mac.go

@@ -36,7 +36,7 @@ func NewMACFromString(s string) (MAC, error) {
 		if c > 0xff {
 			return MAC(0), ErrInvalidMACAddress
 		}
-		m |= (c & 0xff)
+		m |= c & 0xff
 	}
 	return MAC(m), nil
 }

+ 4 - 4
go/pkg/zerotier/misc.go

@@ -53,7 +53,7 @@ func checkPort(port int) bool {
 	ua.Port = port
 	uc, err := net.ListenUDP("udp6", &ua)
 	if uc != nil {
-		uc.Close()
+		_ = uc.Close()
 	}
 	if err != nil {
 		return false
@@ -61,7 +61,7 @@ func checkPort(port int) bool {
 	ua.IP = net.IPv4zero
 	uc, err = net.ListenUDP("udp4", &ua)
 	if uc != nil {
-		uc.Close()
+		_ = uc.Close()
 	}
 	if err != nil {
 		return false
@@ -72,7 +72,7 @@ func checkPort(port int) bool {
 	ta.Port = port
 	tc, err := net.ListenTCP("tcp6", &ta)
 	if tc != nil {
-		tc.Close()
+		_ = tc.Close()
 	}
 	if err != nil {
 		return false
@@ -80,7 +80,7 @@ func checkPort(port int) bool {
 	ta.IP = net.IPv4zero
 	tc, err = net.ListenTCP("tcp4", &ta)
 	if tc != nil {
-		tc.Close()
+		_ = tc.Close()
 	}
 	if err != nil {
 		return false

+ 1 - 1
go/pkg/zerotier/multicastgroup.go

@@ -28,7 +28,7 @@ func (mg *MulticastGroup) String() string {
 
 // Less returns true if this MulticastGroup is less than another.
 func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
-	return (mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI))
+	return mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI)
 }
 
 // key returns an array usable as a key for a map[]

+ 2 - 2
go/pkg/zerotier/nativetap.go

@@ -233,11 +233,11 @@ func handleTapMulticastGroupChange(gn unsafe.Pointer, nwid, mac C.uint64_t, adi
 }
 
 //export goHandleTapAddedMulticastGroup
-func goHandleTapAddedMulticastGroup(gn, tapP unsafe.Pointer, nwid, mac C.uint64_t, adi C.uint32_t) {
+func goHandleTapAddedMulticastGroup(gn, _ unsafe.Pointer, nwid, mac C.uint64_t, adi C.uint32_t) {
 	handleTapMulticastGroupChange(gn, nwid, mac, adi, true)
 }
 
 //export goHandleTapRemovedMulticastGroup
-func goHandleTapRemovedMulticastGroup(gn, tapP unsafe.Pointer, nwid, mac C.uint64_t, adi C.uint32_t) {
+func goHandleTapRemovedMulticastGroup(gn, _ unsafe.Pointer, nwid, mac C.uint64_t, adi C.uint32_t) {
 	handleTapMulticastGroupChange(gn, nwid, mac, adi, false)
 }

+ 4 - 4
go/pkg/zerotier/network.go

@@ -312,7 +312,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
 				wantAssignedIPs[k] = true
 				if _, have := haveAssignedIPs[k]; !have {
 					n.node.log.Printf("%.16x adding managed IP %s", uint64(n.id), ip.String())
-					n.tap.AddIP(&ip)
+					_ = n.tap.AddIP(&ip)
 				}
 			}
 		}
@@ -320,7 +320,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
 	for k, ip := range haveAssignedIPs {
 		if _, want := wantAssignedIPs[k]; !want {
 			n.node.log.Printf("%.16x removing managed IP %s", uint64(n.id), ip.String())
-			n.tap.RemoveIP(ip)
+			_ = n.tap.RemoveIP(ip)
 		}
 	}
 
@@ -341,7 +341,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
 				wantManagedRoutes[k] = true
 				if _, have := haveManagedRoutes[k]; !have {
 					n.node.log.Printf("%.16x adding managed route %s", uint64(n.id), r.String())
-					n.tap.AddRoute(&r)
+					_ = n.tap.AddRoute(&r)
 				}
 			}
 		}
@@ -349,7 +349,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
 	for k, r := range haveManagedRoutes {
 		if _, want := wantManagedRoutes[k]; !want {
 			n.node.log.Printf("%.16x removing managed route %s", uint64(n.id), r.String())
-			n.tap.RemoveRoute(r)
+			_ = n.tap.RemoveRoute(r)
 		}
 	}
 

+ 75 - 62
go/pkg/zerotier/node.go

@@ -26,7 +26,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"log"
-	rand "math/rand"
+	"math/rand"
 	"net"
 	"net/http"
 	"os"
@@ -38,7 +38,7 @@ import (
 	"time"
 	"unsafe"
 
-	acl "github.com/hectane/go-acl"
+	"github.com/hectane/go-acl"
 )
 
 var nullLogger = log.New(ioutil.Discard, "", 0)
@@ -90,14 +90,14 @@ func sockaddrStorageToIPNet(ss *C.struct_sockaddr_storage) *net.IPNet {
 		sa4 := (*C.struct_sockaddr_in)(unsafe.Pointer(ss))
 		var ip4 [4]byte
 		copy(ip4[:], (*[4]byte)(unsafe.Pointer(&sa4.sin_addr))[:])
-		a.IP = net.IP(ip4[:])
+		a.IP = ip4[:]
 		a.Mask = net.CIDRMask(int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa4.sin_port)))[:])), 32)
 		return &a
 	case AFInet6:
 		sa6 := (*C.struct_sockaddr_in6)(unsafe.Pointer(ss))
 		var ip6 [16]byte
 		copy(ip6[:], (*[16]byte)(unsafe.Pointer(&sa6.sin6_addr))[:])
-		a.IP = net.IP(ip6[:])
+		a.IP = ip6[:]
 		a.Mask = net.CIDRMask(int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa6.sin6_port)))[:])), 128)
 		return &a
 	}
@@ -111,14 +111,14 @@ func sockaddrStorageToUDPAddr(ss *C.struct_sockaddr_storage) *net.UDPAddr {
 		sa4 := (*C.struct_sockaddr_in)(unsafe.Pointer(ss))
 		var ip4 [4]byte
 		copy(ip4[:], (*[4]byte)(unsafe.Pointer(&sa4.sin_addr))[:])
-		a.IP = net.IP(ip4[:])
+		a.IP = ip4[:]
 		a.Port = int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa4.sin_port)))[:]))
 		return &a
 	case AFInet6:
 		sa6 := (*C.struct_sockaddr_in6)(unsafe.Pointer(ss))
 		var ip6 [16]byte
 		copy(ip6[:], (*[16]byte)(unsafe.Pointer(&sa6.sin6_addr))[:])
-		a.IP = net.IP(ip6[:])
+		a.IP = ip6[:]
 		a.Port = int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa6.sin6_port)))[:]))
 		return &a
 	}
@@ -176,7 +176,7 @@ type Node struct {
 func NewNode(basePath string) (*Node, error) {
 	var err error
 
-	os.MkdirAll(basePath, 0755)
+	_ = os.MkdirAll(basePath, 0755)
 	if _, err := os.Stat(basePath); err != nil {
 		return nil, err
 	}
@@ -257,15 +257,15 @@ func NewNode(basePath string) (*Node, error) {
 		}
 
 		if portsChanged {
-			n.localConfig.Write(n.localConfigPath)
+			_ = n.localConfig.Write(n.localConfigPath)
 		}
 	} else if !checkPort(n.localConfig.Settings.PrimaryPort) {
 		return nil, errors.New("unable to bind to primary port")
 	}
 
-	cpath := C.CString(basePath)
-	n.gn = C.ZT_GoNode_new(cpath)
-	C.free(unsafe.Pointer(cpath))
+	cPath := C.CString(basePath)
+	n.gn = C.ZT_GoNode_new(cPath)
+	C.free(unsafe.Pointer(cPath))
 	if n.gn == nil {
 		n.log.Println("FATAL: node initialization failed")
 		return nil, ErrNodeInitFailed
@@ -274,10 +274,10 @@ func NewNode(basePath string) (*Node, error) {
 
 	var ns C.ZT_NodeStatus
 	C.ZT_Node_status(unsafe.Pointer(n.zn), &ns)
-	idstr := C.GoString(ns.secretIdentity)
-	n.id, err = NewIdentityFromString(idstr)
+	idString := C.GoString(ns.secretIdentity)
+	n.id, err = NewIdentityFromString(idString)
 	if err != nil {
-		n.log.Printf("FATAL: node's identity does not seem valid (%s)", idstr)
+		n.log.Printf("FATAL: node's identity does not seem valid (%s)", string(idString))
 		C.ZT_GoNode_delete(n.gn)
 		return nil, err
 	}
@@ -381,7 +381,7 @@ func NewNode(basePath string) (*Node, error) {
 
 				// Trim log if it's gone over its size limit
 				if n.localConfig.Settings.LogSizeMax > 0 && n.logW != nil {
-					n.logW.trim(n.localConfig.Settings.LogSizeMax*1024, 0.5, true)
+					_ = n.logW.trim(n.localConfig.Settings.LogSizeMax*1024, 0.5, true)
 				}
 
 				n.localConfigLock.RUnlock()
@@ -396,7 +396,7 @@ func NewNode(basePath string) (*Node, error) {
 // Close closes this Node and frees its underlying C++ Node structures
 func (n *Node) Close() {
 	if atomic.SwapUint32(&n.running, 0) != 0 {
-		n.apiServer.Close()
+		_ = n.apiServer.Close()
 		C.ZT_GoNode_delete(n.gn)
 		nodesByUserPtrLock.Lock()
 		delete(nodesByUserPtr, uintptr(unsafe.Pointer(n.gn)))
@@ -453,7 +453,7 @@ func (n *Node) SetLocalConfig(lc *LocalConfig) (restartRequired bool, err error)
 	}
 	if lc.Settings.LogSizeMax < 0 {
 		n.log = nullLogger
-		n.logW.Close()
+		_ = n.logW.Close()
 		n.logW = nil
 	} else if n.logW != nil {
 		n.logW, err = sizeLimitWriterOpen(path.Join(n.basePath, "service.log"))
@@ -492,7 +492,7 @@ func (n *Node) Join(nwid NetworkID, settings *NetworkLocalSettings, tap Tap) (*N
 		return nil, ErrTapInitFailed
 	}
 
-	nw, err := newNetwork(n, NetworkID(nwid), &nativeTap{tap: unsafe.Pointer(ntap), enabled: 1})
+	nw, err := newNetwork(n, nwid, &nativeTap{tap: unsafe.Pointer(ntap), enabled: 1})
 	if err != nil {
 		n.log.Printf("join network %.16x failed: network failed to initialize: %s", nwid, err.Error())
 		C.ZT_GoNode_leave(n.gn, C.uint64_t(nwid))
@@ -561,8 +561,8 @@ func (n *Node) Roots() []*Root {
 					Name:      C.GoString(root.name),
 					Identity:  id,
 					Addresses: addrs,
-					Preferred: (root.preferred != 0),
-					Online:    (root.online != 0),
+					Preferred: root.preferred != 0,
+					Online:    root.online != 0,
 				})
 			}
 		}
@@ -588,7 +588,7 @@ func (n *Node) SetRoot(name string, locator *Locator) error {
 	}
 	var lbp unsafe.Pointer
 	if len(lb) > 0 {
-		lbp = unsafe.Pointer(&lb[0])
+		lbp = &lb[0]
 	}
 	cn := C.CString(name)
 	defer C.free(unsafe.Pointer(cn))
@@ -732,12 +732,12 @@ func (n *Node) makeStateObjectPath(objType int, id [2]uint64) (string, bool) {
 		secret = true
 	case C.ZT_STATE_OBJECT_PEER:
 		fp = path.Join(n.basePath, "peers.d")
-		os.Mkdir(fp, 0700)
+		_ = os.Mkdir(fp, 0700)
 		fp = path.Join(fp, fmt.Sprintf("%.10x.peer", id[0]))
 		secret = true
 	case C.ZT_STATE_OBJECT_NETWORK_CONFIG:
 		fp = path.Join(n.basePath, "networks.d")
-		os.Mkdir(fp, 0755)
+		_ = os.Mkdir(fp, 0755)
 		fp = path.Join(fp, fmt.Sprintf("%.16x.conf", id[0]))
 	case C.ZT_STATE_OBJECT_ROOT_LIST:
 		fp = path.Join(n.basePath, "roots")
@@ -752,9 +752,9 @@ func (n *Node) stateObjectPut(objType int, id [2]uint64, data []byte) {
 		if secret {
 			fileMode = os.FileMode(0600)
 		}
-		ioutil.WriteFile(fp, data, fileMode)
+		_ = ioutil.WriteFile(fp, data, fileMode)
 		if secret {
-			acl.Chmod(fp, 0600) // this emulates Unix chmod on Windows and uses os.Chmod on Unix-type systems
+			_ = acl.Chmod(fp, 0600) // this emulates Unix chmod on Windows and uses os.Chmod on Unix-type systems
 		}
 	}
 }
@@ -762,7 +762,7 @@ func (n *Node) stateObjectPut(objType int, id [2]uint64, data []byte) {
 func (n *Node) stateObjectDelete(objType int, id [2]uint64) {
 	fp, _ := n.makeStateObjectPath(objType, id)
 	if len(fp) > 0 {
-		os.Remove(fp)
+		_ = os.Remove(fp)
 	}
 }
 
@@ -801,14 +801,22 @@ func goPathCheckFunc(gn unsafe.Pointer, ztAddress C.uint64_t, af C.int, ip unsaf
 	nodesByUserPtrLock.RLock()
 	node := nodesByUserPtr[uintptr(gn)]
 	nodesByUserPtrLock.RUnlock()
-	if node != nil && node.pathCheck(Address(ztAddress), int(af), nil, int(port)) {
+	var nip net.IP
+	if af == AFInet {
+		nip = ((*[4]byte)(ip))[:]
+	} else if af == AFInet6 {
+		nip = ((*[16]byte)(ip))[:]
+	} else {
+		return 0
+	}
+	if node != nil && len(nip) > 0 && node.pathCheck(Address(ztAddress), int(af), nip, int(port)) {
 		return 1
 	}
 	return 0
 }
 
 //export goPathLookupFunc
-func goPathLookupFunc(gn unsafe.Pointer, ztAddress C.uint64_t, desiredAddressFamily int, familyP, ipP, portP unsafe.Pointer) C.int {
+func goPathLookupFunc(gn unsafe.Pointer, ztAddress C.uint64_t, _ int, familyP, ipP, portP unsafe.Pointer) C.int {
 	nodesByUserPtrLock.RLock()
 	node := nodesByUserPtr[uintptr(gn)]
 	nodesByUserPtrLock.RUnlock()
@@ -903,7 +911,7 @@ func goDNSResolverFunc(gn unsafe.Pointer, dnsRecordTypes unsafe.Pointer, numDNSR
 }
 
 //export goVirtualNetworkConfigFunc
-func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.int, conf unsafe.Pointer) {
+func goVirtualNetworkConfigFunc(gn, _ unsafe.Pointer, nwid C.uint64_t, op C.int, conf unsafe.Pointer) {
 	go func() {
 		nodesByUserPtrLock.RLock()
 		node := nodesByUserPtr[uintptr(gn)]
@@ -911,47 +919,52 @@ func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.i
 		if node == nil {
 			return
 		}
+
 		node.networksLock.RLock()
 		network := node.networks[NetworkID(nwid)]
 		node.networksLock.RUnlock()
+
 		if network != nil {
-			ncc := (*C.ZT_VirtualNetworkConfig)(conf)
-			if network.networkConfigRevision() > uint64(ncc.netconfRevision) {
-				return
-			}
-			var nc NetworkConfig
-			nc.ID = NetworkID(ncc.nwid)
-			nc.MAC = MAC(ncc.mac)
-			nc.Name = C.GoString(&ncc.name[0])
-			nc.Status = int(ncc.status)
-			nc.Type = int(ncc._type)
-			nc.MTU = int(ncc.mtu)
-			nc.Bridge = (ncc.bridge != 0)
-			nc.BroadcastEnabled = (ncc.broadcastEnabled != 0)
-			nc.NetconfRevision = uint64(ncc.netconfRevision)
-			for i := 0; i < int(ncc.assignedAddressCount); i++ {
-				a := sockaddrStorageToIPNet(&ncc.assignedAddresses[i])
-				if a != nil {
-					nc.AssignedAddresses = append(nc.AssignedAddresses, *a)
+			switch op {
+			case C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP, C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP:
+				ncc := (*C.ZT_VirtualNetworkConfig)(conf)
+				if network.networkConfigRevision() > uint64(ncc.netconfRevision) {
+					return
 				}
-			}
-			for i := 0; i < int(ncc.routeCount); i++ {
-				tgt := sockaddrStorageToIPNet(&ncc.routes[i].target)
-				viaN := sockaddrStorageToIPNet(&ncc.routes[i].via)
-				var via net.IP
-				if viaN != nil {
-					via = viaN.IP
+				var nc NetworkConfig
+				nc.ID = NetworkID(ncc.nwid)
+				nc.MAC = MAC(ncc.mac)
+				nc.Name = C.GoString(&ncc.name[0])
+				nc.Status = int(ncc.status)
+				nc.Type = int(ncc._type)
+				nc.MTU = int(ncc.mtu)
+				nc.Bridge = ncc.bridge != 0
+				nc.BroadcastEnabled = ncc.broadcastEnabled != 0
+				nc.NetconfRevision = uint64(ncc.netconfRevision)
+				for i := 0; i < int(ncc.assignedAddressCount); i++ {
+					a := sockaddrStorageToIPNet(&ncc.assignedAddresses[i])
+					if a != nil {
+						nc.AssignedAddresses = append(nc.AssignedAddresses, *a)
+					}
 				}
-				if tgt != nil {
-					nc.Routes = append(nc.Routes, Route{
-						Target: *tgt,
-						Via:    via,
-						Flags:  uint16(ncc.routes[i].flags),
-						Metric: uint16(ncc.routes[i].metric),
-					})
+				for i := 0; i < int(ncc.routeCount); i++ {
+					tgt := sockaddrStorageToIPNet(&ncc.routes[i].target)
+					viaN := sockaddrStorageToIPNet(&ncc.routes[i].via)
+					var via net.IP
+					if viaN != nil {
+						via = viaN.IP
+					}
+					if tgt != nil {
+						nc.Routes = append(nc.Routes, Route{
+							Target: *tgt,
+							Via:    via,
+							Flags:  uint16(ncc.routes[i].flags),
+							Metric: uint16(ncc.routes[i].metric),
+						})
+					}
 				}
+				network.updateConfig(&nc, nil)
 			}
-			network.updateConfig(&nc, nil)
 		}
 	}()
 }

+ 1 - 1
go/pkg/zerotier/osdep-posix.go

@@ -26,7 +26,7 @@ import (
 
 func createNamedSocketListener(basePath, name string) (net.Listener, error) {
 	apiSockPath := path.Join(basePath, name)
-	os.Remove(apiSockPath)
+	_ = os.Remove(apiSockPath)
 	return net.Listen("unix", apiSockPath)
 }
 

+ 5 - 0
go/pkg/zerotier/osdep-windows.go

@@ -26,3 +26,8 @@ const windowsAPISocketPathPrefix = "\\\\.\\pipe\\zerotier_"
 func createNamedSocketListener(basePath, name string) (net.Listener, error) {
 	winio.ListenPipe(windowsAPISocketPathPrefix+name, nil)
 }
+
+func createNamedSocketHTTPClient(basePath, name string) (*http.Client, error) {
+	panic("needs implementation")
+	return nil, nil
+}

+ 4 - 3
go/pkg/zerotier/sizelimitwriter.go

@@ -14,6 +14,7 @@
 package zerotier
 
 import (
+	"io"
 	"os"
 	"sync"
 )
@@ -28,7 +29,7 @@ func sizeLimitWriterOpen(p string) (*sizeLimitWriter, error) {
 	if err != nil {
 		return nil, err
 	}
-	f.Seek(0, os.SEEK_END)
+	_, _ = f.Seek(0, io.SeekEnd)
 	return &sizeLimitWriter{f: f}, nil
 }
 
@@ -50,7 +51,7 @@ func (w *sizeLimitWriter) trim(maxSize int, trimFactor float64, trimAtCR bool) e
 	w.l.Lock()
 	defer w.l.Unlock()
 
-	flen, err := w.f.Seek(0, os.SEEK_END)
+	flen, err := w.f.Seek(0, io.SeekEnd)
 	if err != nil {
 		return err
 	}
@@ -100,7 +101,7 @@ func (w *sizeLimitWriter) trim(maxSize int, trimFactor float64, trimAtCR bool) e
 		if err != nil {
 			return err
 		}
-		_, err = w.f.Seek(0, os.SEEK_END)
+		_, err = w.f.Seek(0, io.SeekEnd)
 		return err
 	}