mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-08 20:30:10 +00:00
Bunch of small warnings and stylistic things...
This commit is contained in:
parent
f680924585
commit
e4799ff8c4
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
9
.idea/ZeroTierOne.iml
generated
Normal file
9
.idea/ZeroTierOne.iml
generated
Normal file
@ -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
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
11
.idea/dictionaries/api.xml
generated
Normal file
11
.idea/dictionaries/api.xml
generated
Normal file
@ -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
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
10
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -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
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -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
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -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
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -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
.idea/watcherTasks.xml
generated
Normal file
29
.idea/watcherTasks.xml
generated
Normal file
@ -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>
|
@ -25,7 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acl "github.com/hectane/go-acl"
|
"github.com/hectane/go-acl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APISocketName is the default socket name for accessing the API
|
// 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) {
|
func apiReadObj(out http.ResponseWriter, req *http.Request, dest interface{}) (err error) {
|
||||||
err = json.NewDecoder(req.Body).Decode(&dest)
|
err = json.NewDecoder(req.Body).Decode(&dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiSendObj(out, req, http.StatusBadRequest, nil)
|
_ = apiSendObj(out, req, http.StatusBadRequest, nil)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func apiCheckAuth(out http.ResponseWriter, req *http.Request, token string) bool
|
|||||||
if len(ah) > 0 && strings.TrimSpace(ah) == token {
|
if len(ah) > 0 && strings.TrimSpace(ah) == token {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
apiSendObj(out, req, http.StatusUnauthorized, nil)
|
_ = apiSendObj(out, req, http.StatusUnauthorized, nil)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,13 +182,13 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for i := 0; i < 20; i++ {
|
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)
|
err = ioutil.WriteFile(authTokenFile, atb[:], 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
acl.Chmod(authTokenFile, 0600)
|
_ = acl.Chmod(authTokenFile, 0600)
|
||||||
authToken = string(atb[:])
|
authToken = string(atb[:])
|
||||||
} else {
|
} else {
|
||||||
authToken = strings.TrimSpace(string(authTokenB))
|
authToken = strings.TrimSpace(string(authTokenB))
|
||||||
@ -202,7 +202,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
|
|||||||
}
|
}
|
||||||
apiSetStandardHeaders(out)
|
apiSetStandardHeaders(out)
|
||||||
if req.Method == http.MethodGet || req.Method == http.MethodHead {
|
if req.Method == http.MethodGet || req.Method == http.MethodHead {
|
||||||
apiSendObj(out, req, http.StatusOK, &APIStatus{
|
_ = apiSendObj(out, req, http.StatusOK, &APIStatus{
|
||||||
Address: node.Address(),
|
Address: node.Address(),
|
||||||
Clock: TimeMs(),
|
Clock: TimeMs(),
|
||||||
Config: node.LocalConfig(),
|
Config: node.LocalConfig(),
|
||||||
@ -218,7 +218,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
out.Header().Set("Allow", "GET, HEAD")
|
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 {
|
if req.Method == http.MethodPost || req.Method == http.MethodPut {
|
||||||
var c LocalConfig
|
var c LocalConfig
|
||||||
if apiReadObj(out, req, &c) == nil {
|
if apiReadObj(out, req, &c) == nil {
|
||||||
node.SetLocalConfig(&c)
|
_, _ = node.SetLocalConfig(&c)
|
||||||
apiSendObj(out, req, http.StatusOK, node.LocalConfig())
|
_ = apiSendObj(out, req, http.StatusOK, node.LocalConfig())
|
||||||
}
|
}
|
||||||
} else if req.Method == http.MethodGet || req.Method == http.MethodHead {
|
} 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 {
|
} else {
|
||||||
out.Header().Set("Allow", "GET, HEAD, PUT, POST")
|
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
|
var err error
|
||||||
queriedID, err = NewAddressFromString(req.URL.Path[6:])
|
queriedID, err = NewAddressFromString(req.URL.Path[6:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiSendObj(out, req, http.StatusNotFound, nil)
|
_ = apiSendObj(out, req, http.StatusNotFound, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,13 +266,13 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
|
|||||||
p2 = append(p2, p)
|
p2 = append(p2, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiSendObj(out, req, http.StatusOK, p2)
|
_ = apiSendObj(out, req, http.StatusOK, p2)
|
||||||
} else {
|
} else {
|
||||||
apiSendObj(out, req, http.StatusOK, peers)
|
_ = apiSendObj(out, req, http.StatusOK, peers)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.Header().Set("Allow", "GET, HEAD")
|
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
|
var err error
|
||||||
queriedID, err = NewNetworkIDFromString(req.URL.Path[9:])
|
queriedID, err = NewNetworkIDFromString(req.URL.Path[9:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiSendObj(out, req, http.StatusNotFound, nil)
|
_ = apiSendObj(out, req, http.StatusNotFound, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Method == http.MethodPost || req.Method == http.MethodPut {
|
if req.Method == http.MethodPost || req.Method == http.MethodPut {
|
||||||
if queriedID == 0 {
|
if queriedID == 0 {
|
||||||
apiSendObj(out, req, http.StatusBadRequest, nil)
|
_ = apiSendObj(out, req, http.StatusBadRequest, nil)
|
||||||
} else {
|
} else {
|
||||||
var nw APINetwork
|
var nw APINetwork
|
||||||
if apiReadObj(out, req, &nw) == nil {
|
if apiReadObj(out, req, &nw) == nil {
|
||||||
@ -302,15 +302,15 @@ func createAPIServer(basePath string, node *Node) (*http.Server, error) {
|
|||||||
if n == nil {
|
if n == nil {
|
||||||
n, err := node.Join(nw.ID, nw.Settings, nil)
|
n, err := node.Join(nw.ID, nw.Settings, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiSendObj(out, req, http.StatusBadRequest, nil)
|
_ = apiSendObj(out, req, http.StatusBadRequest, nil)
|
||||||
} else {
|
} else {
|
||||||
apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
|
_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if nw.Settings != nil {
|
if nw.Settings != nil {
|
||||||
n.SetLocalSettings(nw.Settings)
|
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 {
|
for _, nw := range networks {
|
||||||
nws = append(nws, apiNetworkFromNetwork(nw))
|
nws = append(nws, apiNetworkFromNetwork(nw))
|
||||||
}
|
}
|
||||||
apiSendObj(out, req, http.StatusOK, nws)
|
_ = apiSendObj(out, req, http.StatusOK, nws)
|
||||||
} else {
|
} else {
|
||||||
for _, nw := range networks {
|
for _, nw := range networks {
|
||||||
if nw.ID() == queriedID {
|
if nw.ID() == queriedID {
|
||||||
apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw))
|
_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.Header().Set("Allow", "GET, HEAD, PUT, POST")
|
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
|
var err error
|
||||||
queriedID, err = NewAddressFromString(req.URL.Path[6:])
|
queriedID, err = NewAddressFromString(req.URL.Path[6:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiSendObj(out, req, http.StatusNotFound, nil)
|
_ = apiSendObj(out, req, http.StatusNotFound, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Method == http.MethodPost || req.Method == http.MethodPut {
|
if req.Method == http.MethodPost || req.Method == http.MethodPut {
|
||||||
if queriedID == 0 {
|
if queriedID == 0 {
|
||||||
apiSendObj(out, req, http.StatusBadRequest, nil)
|
_ = apiSendObj(out, req, http.StatusBadRequest, nil)
|
||||||
} else {
|
} else {
|
||||||
var r Root
|
var r Root
|
||||||
if apiReadObj(out, req, &r) == nil {
|
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 {
|
} else if req.Method == http.MethodGet || req.Method == http.MethodHead {
|
||||||
roots := node.Roots()
|
roots := node.Roots()
|
||||||
apiSendObj(out, req, http.StatusOK, roots)
|
_ = apiSendObj(out, req, http.StatusOK, roots)
|
||||||
} else {
|
} else {
|
||||||
out.Header().Set("Allow", "GET, HEAD, PUT, POST")
|
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)
|
httpServer.SetKeepAlivesEnabled(true)
|
||||||
go func() {
|
go func() {
|
||||||
httpServer.Serve(listener)
|
err := httpServer.Serve(listener)
|
||||||
listener.Close()
|
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
|
return httpServer, nil
|
||||||
|
@ -27,7 +27,7 @@ const (
|
|||||||
ErrInvalidNetworkID Err = "invalid network ID"
|
ErrInvalidNetworkID Err = "invalid network ID"
|
||||||
ErrInvalidParameter Err = "invalid parameter"
|
ErrInvalidParameter Err = "invalid parameter"
|
||||||
ErrTapInitFailed Err = "unable to create native Tap instance"
|
ErrTapInitFailed Err = "unable to create native Tap instance"
|
||||||
ErrUncrecognizedIdentityType Err = "unrecognized identity type"
|
ErrUnrecognizedIdentityType Err = "unrecognized identity type"
|
||||||
ErrInvalidKey Err = "invalid key data"
|
ErrInvalidKey Err = "invalid key data"
|
||||||
ErrInvalidSignature Err = "invalid signature"
|
ErrInvalidSignature Err = "invalid signature"
|
||||||
ErrSecretKeyRequired Err = "secret key required"
|
ErrSecretKeyRequired Err = "secret key required"
|
||||||
|
@ -62,7 +62,7 @@ func NewIdentityFromString(s string) (*Identity, error) {
|
|||||||
} else if ss[1] == "1" {
|
} else if ss[1] == "1" {
|
||||||
id.idtype = 1
|
id.idtype = 1
|
||||||
} else {
|
} else {
|
||||||
return nil, ErrUncrecognizedIdentityType
|
return nil, ErrUnrecognizedIdentityType
|
||||||
}
|
}
|
||||||
|
|
||||||
switch id.idtype {
|
switch id.idtype {
|
||||||
|
@ -36,7 +36,7 @@ func NewMACFromString(s string) (MAC, error) {
|
|||||||
if c > 0xff {
|
if c > 0xff {
|
||||||
return MAC(0), ErrInvalidMACAddress
|
return MAC(0), ErrInvalidMACAddress
|
||||||
}
|
}
|
||||||
m |= (c & 0xff)
|
m |= c & 0xff
|
||||||
}
|
}
|
||||||
return MAC(m), nil
|
return MAC(m), nil
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func checkPort(port int) bool {
|
|||||||
ua.Port = port
|
ua.Port = port
|
||||||
uc, err := net.ListenUDP("udp6", &ua)
|
uc, err := net.ListenUDP("udp6", &ua)
|
||||||
if uc != nil {
|
if uc != nil {
|
||||||
uc.Close()
|
_ = uc.Close()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -61,7 +61,7 @@ func checkPort(port int) bool {
|
|||||||
ua.IP = net.IPv4zero
|
ua.IP = net.IPv4zero
|
||||||
uc, err = net.ListenUDP("udp4", &ua)
|
uc, err = net.ListenUDP("udp4", &ua)
|
||||||
if uc != nil {
|
if uc != nil {
|
||||||
uc.Close()
|
_ = uc.Close()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -72,7 +72,7 @@ func checkPort(port int) bool {
|
|||||||
ta.Port = port
|
ta.Port = port
|
||||||
tc, err := net.ListenTCP("tcp6", &ta)
|
tc, err := net.ListenTCP("tcp6", &ta)
|
||||||
if tc != nil {
|
if tc != nil {
|
||||||
tc.Close()
|
_ = tc.Close()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -80,7 +80,7 @@ func checkPort(port int) bool {
|
|||||||
ta.IP = net.IPv4zero
|
ta.IP = net.IPv4zero
|
||||||
tc, err = net.ListenTCP("tcp4", &ta)
|
tc, err = net.ListenTCP("tcp4", &ta)
|
||||||
if tc != nil {
|
if tc != nil {
|
||||||
tc.Close()
|
_ = tc.Close()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
@ -28,7 +28,7 @@ func (mg *MulticastGroup) String() string {
|
|||||||
|
|
||||||
// Less returns true if this MulticastGroup is less than another.
|
// Less returns true if this MulticastGroup is less than another.
|
||||||
func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
|
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[]
|
// key returns an array usable as a key for a map[]
|
||||||
|
@ -233,11 +233,11 @@ func handleTapMulticastGroupChange(gn unsafe.Pointer, nwid, mac C.uint64_t, adi
|
|||||||
}
|
}
|
||||||
|
|
||||||
//export goHandleTapAddedMulticastGroup
|
//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)
|
handleTapMulticastGroupChange(gn, nwid, mac, adi, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goHandleTapRemovedMulticastGroup
|
//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)
|
handleTapMulticastGroupChange(gn, nwid, mac, adi, false)
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
|||||||
wantAssignedIPs[k] = true
|
wantAssignedIPs[k] = true
|
||||||
if _, have := haveAssignedIPs[k]; !have {
|
if _, have := haveAssignedIPs[k]; !have {
|
||||||
n.node.log.Printf("%.16x adding managed IP %s", uint64(n.id), ip.String())
|
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 {
|
for k, ip := range haveAssignedIPs {
|
||||||
if _, want := wantAssignedIPs[k]; !want {
|
if _, want := wantAssignedIPs[k]; !want {
|
||||||
n.node.log.Printf("%.16x removing managed IP %s", uint64(n.id), ip.String())
|
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
|
wantManagedRoutes[k] = true
|
||||||
if _, have := haveManagedRoutes[k]; !have {
|
if _, have := haveManagedRoutes[k]; !have {
|
||||||
n.node.log.Printf("%.16x adding managed route %s", uint64(n.id), r.String())
|
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 {
|
for k, r := range haveManagedRoutes {
|
||||||
if _, want := wantManagedRoutes[k]; !want {
|
if _, want := wantManagedRoutes[k]; !want {
|
||||||
n.node.log.Printf("%.16x removing managed route %s", uint64(n.id), r.String())
|
n.node.log.Printf("%.16x removing managed route %s", uint64(n.id), r.String())
|
||||||
n.tap.RemoveRoute(r)
|
_ = n.tap.RemoveRoute(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
rand "math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -38,7 +38,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
acl "github.com/hectane/go-acl"
|
"github.com/hectane/go-acl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var nullLogger = log.New(ioutil.Discard, "", 0)
|
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))
|
sa4 := (*C.struct_sockaddr_in)(unsafe.Pointer(ss))
|
||||||
var ip4 [4]byte
|
var ip4 [4]byte
|
||||||
copy(ip4[:], (*[4]byte)(unsafe.Pointer(&sa4.sin_addr))[:])
|
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)
|
a.Mask = net.CIDRMask(int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa4.sin_port)))[:])), 32)
|
||||||
return &a
|
return &a
|
||||||
case AFInet6:
|
case AFInet6:
|
||||||
sa6 := (*C.struct_sockaddr_in6)(unsafe.Pointer(ss))
|
sa6 := (*C.struct_sockaddr_in6)(unsafe.Pointer(ss))
|
||||||
var ip6 [16]byte
|
var ip6 [16]byte
|
||||||
copy(ip6[:], (*[16]byte)(unsafe.Pointer(&sa6.sin6_addr))[:])
|
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)
|
a.Mask = net.CIDRMask(int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa6.sin6_port)))[:])), 128)
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
@ -111,14 +111,14 @@ func sockaddrStorageToUDPAddr(ss *C.struct_sockaddr_storage) *net.UDPAddr {
|
|||||||
sa4 := (*C.struct_sockaddr_in)(unsafe.Pointer(ss))
|
sa4 := (*C.struct_sockaddr_in)(unsafe.Pointer(ss))
|
||||||
var ip4 [4]byte
|
var ip4 [4]byte
|
||||||
copy(ip4[:], (*[4]byte)(unsafe.Pointer(&sa4.sin_addr))[:])
|
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)))[:]))
|
a.Port = int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa4.sin_port)))[:]))
|
||||||
return &a
|
return &a
|
||||||
case AFInet6:
|
case AFInet6:
|
||||||
sa6 := (*C.struct_sockaddr_in6)(unsafe.Pointer(ss))
|
sa6 := (*C.struct_sockaddr_in6)(unsafe.Pointer(ss))
|
||||||
var ip6 [16]byte
|
var ip6 [16]byte
|
||||||
copy(ip6[:], (*[16]byte)(unsafe.Pointer(&sa6.sin6_addr))[:])
|
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)))[:]))
|
a.Port = int(binary.BigEndian.Uint16(((*[2]byte)(unsafe.Pointer(&sa6.sin6_port)))[:]))
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ type Node struct {
|
|||||||
func NewNode(basePath string) (*Node, error) {
|
func NewNode(basePath string) (*Node, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
os.MkdirAll(basePath, 0755)
|
_ = os.MkdirAll(basePath, 0755)
|
||||||
if _, err := os.Stat(basePath); err != nil {
|
if _, err := os.Stat(basePath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -257,15 +257,15 @@ func NewNode(basePath string) (*Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if portsChanged {
|
if portsChanged {
|
||||||
n.localConfig.Write(n.localConfigPath)
|
_ = n.localConfig.Write(n.localConfigPath)
|
||||||
}
|
}
|
||||||
} else if !checkPort(n.localConfig.Settings.PrimaryPort) {
|
} else if !checkPort(n.localConfig.Settings.PrimaryPort) {
|
||||||
return nil, errors.New("unable to bind to primary port")
|
return nil, errors.New("unable to bind to primary port")
|
||||||
}
|
}
|
||||||
|
|
||||||
cpath := C.CString(basePath)
|
cPath := C.CString(basePath)
|
||||||
n.gn = C.ZT_GoNode_new(cpath)
|
n.gn = C.ZT_GoNode_new(cPath)
|
||||||
C.free(unsafe.Pointer(cpath))
|
C.free(unsafe.Pointer(cPath))
|
||||||
if n.gn == nil {
|
if n.gn == nil {
|
||||||
n.log.Println("FATAL: node initialization failed")
|
n.log.Println("FATAL: node initialization failed")
|
||||||
return nil, ErrNodeInitFailed
|
return nil, ErrNodeInitFailed
|
||||||
@ -274,10 +274,10 @@ func NewNode(basePath string) (*Node, error) {
|
|||||||
|
|
||||||
var ns C.ZT_NodeStatus
|
var ns C.ZT_NodeStatus
|
||||||
C.ZT_Node_status(unsafe.Pointer(n.zn), &ns)
|
C.ZT_Node_status(unsafe.Pointer(n.zn), &ns)
|
||||||
idstr := C.GoString(ns.secretIdentity)
|
idString := C.GoString(ns.secretIdentity)
|
||||||
n.id, err = NewIdentityFromString(idstr)
|
n.id, err = NewIdentityFromString(idString)
|
||||||
if err != nil {
|
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)
|
C.ZT_GoNode_delete(n.gn)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -381,7 +381,7 @@ func NewNode(basePath string) (*Node, error) {
|
|||||||
|
|
||||||
// Trim log if it's gone over its size limit
|
// Trim log if it's gone over its size limit
|
||||||
if n.localConfig.Settings.LogSizeMax > 0 && n.logW != nil {
|
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()
|
n.localConfigLock.RUnlock()
|
||||||
@ -396,7 +396,7 @@ func NewNode(basePath string) (*Node, error) {
|
|||||||
// Close closes this Node and frees its underlying C++ Node structures
|
// Close closes this Node and frees its underlying C++ Node structures
|
||||||
func (n *Node) Close() {
|
func (n *Node) Close() {
|
||||||
if atomic.SwapUint32(&n.running, 0) != 0 {
|
if atomic.SwapUint32(&n.running, 0) != 0 {
|
||||||
n.apiServer.Close()
|
_ = n.apiServer.Close()
|
||||||
C.ZT_GoNode_delete(n.gn)
|
C.ZT_GoNode_delete(n.gn)
|
||||||
nodesByUserPtrLock.Lock()
|
nodesByUserPtrLock.Lock()
|
||||||
delete(nodesByUserPtr, uintptr(unsafe.Pointer(n.gn)))
|
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 {
|
if lc.Settings.LogSizeMax < 0 {
|
||||||
n.log = nullLogger
|
n.log = nullLogger
|
||||||
n.logW.Close()
|
_ = n.logW.Close()
|
||||||
n.logW = nil
|
n.logW = nil
|
||||||
} else if n.logW != nil {
|
} else if n.logW != nil {
|
||||||
n.logW, err = sizeLimitWriterOpen(path.Join(n.basePath, "service.log"))
|
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
|
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 {
|
if err != nil {
|
||||||
n.log.Printf("join network %.16x failed: network failed to initialize: %s", nwid, err.Error())
|
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))
|
C.ZT_GoNode_leave(n.gn, C.uint64_t(nwid))
|
||||||
@ -561,8 +561,8 @@ func (n *Node) Roots() []*Root {
|
|||||||
Name: C.GoString(root.name),
|
Name: C.GoString(root.name),
|
||||||
Identity: id,
|
Identity: id,
|
||||||
Addresses: addrs,
|
Addresses: addrs,
|
||||||
Preferred: (root.preferred != 0),
|
Preferred: root.preferred != 0,
|
||||||
Online: (root.online != 0),
|
Online: root.online != 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -588,7 +588,7 @@ func (n *Node) SetRoot(name string, locator *Locator) error {
|
|||||||
}
|
}
|
||||||
var lbp unsafe.Pointer
|
var lbp unsafe.Pointer
|
||||||
if len(lb) > 0 {
|
if len(lb) > 0 {
|
||||||
lbp = unsafe.Pointer(&lb[0])
|
lbp = &lb[0]
|
||||||
}
|
}
|
||||||
cn := C.CString(name)
|
cn := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cn))
|
defer C.free(unsafe.Pointer(cn))
|
||||||
@ -732,12 +732,12 @@ func (n *Node) makeStateObjectPath(objType int, id [2]uint64) (string, bool) {
|
|||||||
secret = true
|
secret = true
|
||||||
case C.ZT_STATE_OBJECT_PEER:
|
case C.ZT_STATE_OBJECT_PEER:
|
||||||
fp = path.Join(n.basePath, "peers.d")
|
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]))
|
fp = path.Join(fp, fmt.Sprintf("%.10x.peer", id[0]))
|
||||||
secret = true
|
secret = true
|
||||||
case C.ZT_STATE_OBJECT_NETWORK_CONFIG:
|
case C.ZT_STATE_OBJECT_NETWORK_CONFIG:
|
||||||
fp = path.Join(n.basePath, "networks.d")
|
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]))
|
fp = path.Join(fp, fmt.Sprintf("%.16x.conf", id[0]))
|
||||||
case C.ZT_STATE_OBJECT_ROOT_LIST:
|
case C.ZT_STATE_OBJECT_ROOT_LIST:
|
||||||
fp = path.Join(n.basePath, "roots")
|
fp = path.Join(n.basePath, "roots")
|
||||||
@ -752,9 +752,9 @@ func (n *Node) stateObjectPut(objType int, id [2]uint64, data []byte) {
|
|||||||
if secret {
|
if secret {
|
||||||
fileMode = os.FileMode(0600)
|
fileMode = os.FileMode(0600)
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(fp, data, fileMode)
|
_ = ioutil.WriteFile(fp, data, fileMode)
|
||||||
if secret {
|
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) {
|
func (n *Node) stateObjectDelete(objType int, id [2]uint64) {
|
||||||
fp, _ := n.makeStateObjectPath(objType, id)
|
fp, _ := n.makeStateObjectPath(objType, id)
|
||||||
if len(fp) > 0 {
|
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()
|
nodesByUserPtrLock.RLock()
|
||||||
node := nodesByUserPtr[uintptr(gn)]
|
node := nodesByUserPtr[uintptr(gn)]
|
||||||
nodesByUserPtrLock.RUnlock()
|
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 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goPathLookupFunc
|
//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()
|
nodesByUserPtrLock.RLock()
|
||||||
node := nodesByUserPtr[uintptr(gn)]
|
node := nodesByUserPtr[uintptr(gn)]
|
||||||
nodesByUserPtrLock.RUnlock()
|
nodesByUserPtrLock.RUnlock()
|
||||||
@ -903,7 +911,7 @@ func goDNSResolverFunc(gn unsafe.Pointer, dnsRecordTypes unsafe.Pointer, numDNSR
|
|||||||
}
|
}
|
||||||
|
|
||||||
//export goVirtualNetworkConfigFunc
|
//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() {
|
go func() {
|
||||||
nodesByUserPtrLock.RLock()
|
nodesByUserPtrLock.RLock()
|
||||||
node := nodesByUserPtr[uintptr(gn)]
|
node := nodesByUserPtr[uintptr(gn)]
|
||||||
@ -911,10 +919,14 @@ func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.i
|
|||||||
if node == nil {
|
if node == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
node.networksLock.RLock()
|
node.networksLock.RLock()
|
||||||
network := node.networks[NetworkID(nwid)]
|
network := node.networks[NetworkID(nwid)]
|
||||||
node.networksLock.RUnlock()
|
node.networksLock.RUnlock()
|
||||||
|
|
||||||
if network != nil {
|
if network != nil {
|
||||||
|
switch op {
|
||||||
|
case C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP, C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP:
|
||||||
ncc := (*C.ZT_VirtualNetworkConfig)(conf)
|
ncc := (*C.ZT_VirtualNetworkConfig)(conf)
|
||||||
if network.networkConfigRevision() > uint64(ncc.netconfRevision) {
|
if network.networkConfigRevision() > uint64(ncc.netconfRevision) {
|
||||||
return
|
return
|
||||||
@ -926,8 +938,8 @@ func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.i
|
|||||||
nc.Status = int(ncc.status)
|
nc.Status = int(ncc.status)
|
||||||
nc.Type = int(ncc._type)
|
nc.Type = int(ncc._type)
|
||||||
nc.MTU = int(ncc.mtu)
|
nc.MTU = int(ncc.mtu)
|
||||||
nc.Bridge = (ncc.bridge != 0)
|
nc.Bridge = ncc.bridge != 0
|
||||||
nc.BroadcastEnabled = (ncc.broadcastEnabled != 0)
|
nc.BroadcastEnabled = ncc.broadcastEnabled != 0
|
||||||
nc.NetconfRevision = uint64(ncc.netconfRevision)
|
nc.NetconfRevision = uint64(ncc.netconfRevision)
|
||||||
for i := 0; i < int(ncc.assignedAddressCount); i++ {
|
for i := 0; i < int(ncc.assignedAddressCount); i++ {
|
||||||
a := sockaddrStorageToIPNet(&ncc.assignedAddresses[i])
|
a := sockaddrStorageToIPNet(&ncc.assignedAddresses[i])
|
||||||
@ -953,6 +965,7 @@ func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.i
|
|||||||
}
|
}
|
||||||
network.updateConfig(&nc, nil)
|
network.updateConfig(&nc, nil)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
|
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
|
||||||
apiSockPath := path.Join(basePath, name)
|
apiSockPath := path.Join(basePath, name)
|
||||||
os.Remove(apiSockPath)
|
_ = os.Remove(apiSockPath)
|
||||||
return net.Listen("unix", apiSockPath)
|
return net.Listen("unix", apiSockPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,3 +26,8 @@ const windowsAPISocketPathPrefix = "\\\\.\\pipe\\zerotier_"
|
|||||||
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
|
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
|
||||||
winio.ListenPipe(windowsAPISocketPathPrefix+name, nil)
|
winio.ListenPipe(windowsAPISocketPathPrefix+name, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createNamedSocketHTTPClient(basePath, name string) (*http.Client, error) {
|
||||||
|
panic("needs implementation")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
package zerotier
|
package zerotier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -28,7 +29,7 @@ func sizeLimitWriterOpen(p string) (*sizeLimitWriter, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.Seek(0, os.SEEK_END)
|
_, _ = f.Seek(0, io.SeekEnd)
|
||||||
return &sizeLimitWriter{f: f}, nil
|
return &sizeLimitWriter{f: f}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ func (w *sizeLimitWriter) trim(maxSize int, trimFactor float64, trimAtCR bool) e
|
|||||||
w.l.Lock()
|
w.l.Lock()
|
||||||
defer w.l.Unlock()
|
defer w.l.Unlock()
|
||||||
|
|
||||||
flen, err := w.f.Seek(0, os.SEEK_END)
|
flen, err := w.f.Seek(0, io.SeekEnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ func (w *sizeLimitWriter) trim(maxSize int, trimFactor float64, trimAtCR bool) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = w.f.Seek(0, os.SEEK_END)
|
_, err = w.f.Seek(0, io.SeekEnd)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user