This commit is contained in:
Adam Ierymenko 2020-01-14 15:34:06 -08:00
parent b2f0b35608
commit b53b7f4950
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
6 changed files with 83 additions and 48 deletions

View file

@ -14,7 +14,7 @@ debug:
mkdir -p ${BUILDDIR} && cd ${BUILDDIR} && cmake .. -DCMAKE_BUILD_TYPE=Debug && $(MAKE) mkdir -p ${BUILDDIR} && cd ${BUILDDIR} && cmake .. -DCMAKE_BUILD_TYPE=Debug && $(MAKE)
clean: clean:
rm -rf ${BUILDDIR} rm -rf ${BUILDDIR} cmake-build-*
distclean: distclean:
rm -rf ${BUILDDIR} rm -rf ${BUILDDIR}

View file

@ -1,2 +0,0 @@
all:
go build -trimpath -ldflags -s -o ../build/zerotier cmd/zerotier/zerotier.go

View file

@ -21,9 +21,8 @@ import (
) )
func SelfTest() { func SelfTest() {
fmt.Print("Running ZeroTier core tests...\n\n") if !zerotier.SelfTest() {
if !zerotier.CSelfTest() { fmt.Println("FAILED: at least one ZeroTier self-test reported failure.")
fmt.Println("FAILED: at least one ZeroTier core test reported failure.")
os.Exit(1) os.Exit(1)
} }
os.Exit(0) os.Exit(0)

View file

@ -230,6 +230,7 @@ extern "C" int ZT_TestCrypto()
return -1; return -1;
} }
} }
{
Salsa20 s20(s20TV0Key,s20TV0Iv); Salsa20 s20(s20TV0Key,s20TV0Iv);
memset(buf1,0,sizeof(buf1)); memset(buf1,0,sizeof(buf1));
memset(buf2,0,sizeof(buf2)); memset(buf2,0,sizeof(buf2));
@ -247,6 +248,7 @@ extern "C" int ZT_TestCrypto()
return -1; return -1;
} }
std::cout << "PASS" ZT_EOL_S; std::cout << "PASS" ZT_EOL_S;
}
#ifdef ZT_SALSA20_SSE #ifdef ZT_SALSA20_SSE
std::cout << "[crypto] Salsa20 SSE: ENABLED" ZT_EOL_S; std::cout << "[crypto] Salsa20 SSE: ENABLED" ZT_EOL_S;
@ -493,6 +495,7 @@ extern "C" int ZT_TestCrypto()
std::cout << " ECC P-384 ECDH: " << (1000.0 / ((double)(end - start) / 1000.0)) << " agreements/second" ZT_EOL_S; std::cout << " ECC P-384 ECDH: " << (1000.0 / ((double)(end - start) / 1000.0)) << " agreements/second" ZT_EOL_S;
} }
std::cout.flush();
return 0; return 0;
} }
@ -598,6 +601,7 @@ extern "C" int ZT_TestIdentity()
} }
} }
std::cout.flush();
return 0; return 0;
} }
@ -743,5 +747,6 @@ extern "C" int ZT_TestOther()
std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" ZT_EOL_S; std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" ZT_EOL_S;
} }
std::cout.flush();
return 0; return 0;
} }

View file

@ -86,28 +86,14 @@ var (
nodesByUserPtrLock sync.RWMutex nodesByUserPtrLock sync.RWMutex
) )
// CSelfTest runs self-test functions from the core, sending results to stdout and returning true on success.
func CSelfTest() bool {
if C.ZT_TestOther() != 0 {
return false
}
fmt.Println()
if C.ZT_TestCrypto() != 0 {
return false
}
fmt.Println()
if C.ZT_TestIdentity() != 0 {
return false
}
return true
}
// Node is an instance of the ZeroTier core node and related C++ I/O code // Node is an instance of the ZeroTier core node and related C++ I/O code
type Node struct { type Node struct {
networks map[NetworkID]*Network networks map[NetworkID]*Network
networksByMAC map[MAC]*Network // locked by networksLock networksByMAC map[MAC]*Network // locked by networksLock
interfaceAddresses map[string]net.IP // physical external IPs on the machine interfaceAddresses map[string]net.IP // physical external IPs on the machine
basePath string basePath string
peersPath string
networksPath string
localConfigPath string localConfigPath string
localConfig LocalConfig localConfig LocalConfig
localConfigLock sync.RWMutex localConfigLock sync.RWMutex
@ -126,22 +112,30 @@ type Node struct {
} }
// NewNode creates and initializes a new instance of the ZeroTier node service // NewNode creates and initializes a new instance of the ZeroTier node service
func NewNode(basePath string) (*Node, error) { func NewNode(basePath string) (n *Node, err error) {
var err error n = new(Node)
_ = os.MkdirAll(basePath, 0755)
if _, err := os.Stat(basePath); err != nil {
return nil, err
}
n := new(Node)
n.networks = make(map[NetworkID]*Network) n.networks = make(map[NetworkID]*Network)
n.networksByMAC = make(map[MAC]*Network) n.networksByMAC = make(map[MAC]*Network)
n.interfaceAddresses = make(map[string]net.IP) n.interfaceAddresses = make(map[string]net.IP)
_ = os.MkdirAll(basePath, 0755)
if _, err = os.Stat(basePath); err != nil {
return
}
n.basePath = basePath n.basePath = basePath
n.peersPath = path.Join(basePath, "peers.d")
_ = os.MkdirAll(n.peersPath, 0700)
_ = acl.Chmod(n.peersPath, 0700)
if _, err = os.Stat(n.peersPath); err != nil {
return
}
n.networksPath = path.Join(basePath, "networks.d")
_ = os.MkdirAll(n.networksPath, 0755)
if _, err = os.Stat(n.networksPath); err != nil {
return
}
n.localConfigPath = path.Join(basePath, "local.conf") n.localConfigPath = path.Join(basePath, "local.conf")
err = n.localConfig.Read(n.localConfigPath, true) err = n.localConfig.Read(n.localConfigPath, true)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -0,0 +1,39 @@
/*
* Copyright (c)2019 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2023-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
package zerotier
//#include "../../native/GoGlue.h"
import "C"
import "fmt"
// SelfTest runs a series of tests on the ZeroTier core and the Go service code, returning true on success.
// Results are sent to stdout.
func SelfTest() bool {
fmt.Print("Running ZeroTier core tests...\n\n")
if C.ZT_TestOther() != 0 {
return false
}
fmt.Println()
if C.ZT_TestCrypto() != 0 {
return false
}
fmt.Println()
if C.ZT_TestIdentity() != 0 {
return false
}
return true
}