mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-21 14:36:55 +02:00
.
This commit is contained in:
parent
b2f0b35608
commit
b53b7f4950
6 changed files with 83 additions and 48 deletions
2
Makefile
2
Makefile
|
@ -14,7 +14,7 @@ debug:
|
|||
mkdir -p ${BUILDDIR} && cd ${BUILDDIR} && cmake .. -DCMAKE_BUILD_TYPE=Debug && $(MAKE)
|
||||
|
||||
clean:
|
||||
rm -rf ${BUILDDIR}
|
||||
rm -rf ${BUILDDIR} cmake-build-*
|
||||
|
||||
distclean:
|
||||
rm -rf ${BUILDDIR}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
all:
|
||||
go build -trimpath -ldflags -s -o ../build/zerotier cmd/zerotier/zerotier.go
|
|
@ -21,9 +21,8 @@ import (
|
|||
)
|
||||
|
||||
func SelfTest() {
|
||||
fmt.Print("Running ZeroTier core tests...\n\n")
|
||||
if !zerotier.CSelfTest() {
|
||||
fmt.Println("FAILED: at least one ZeroTier core test reported failure.")
|
||||
if !zerotier.SelfTest() {
|
||||
fmt.Println("FAILED: at least one ZeroTier self-test reported failure.")
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0)
|
||||
|
|
|
@ -230,23 +230,25 @@ extern "C" int ZT_TestCrypto()
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
Salsa20 s20(s20TV0Key,s20TV0Iv);
|
||||
memset(buf1,0,sizeof(buf1));
|
||||
memset(buf2,0,sizeof(buf2));
|
||||
s20.crypt20(buf1,buf2,64);
|
||||
if (memcmp(buf2,s20TV0Ks,64)) {
|
||||
std::cout << "FAIL (test vector 0)" ZT_EOL_S;
|
||||
return -1;
|
||||
{
|
||||
Salsa20 s20(s20TV0Key,s20TV0Iv);
|
||||
memset(buf1,0,sizeof(buf1));
|
||||
memset(buf2,0,sizeof(buf2));
|
||||
s20.crypt20(buf1,buf2,64);
|
||||
if (memcmp(buf2,s20TV0Ks,64)) {
|
||||
std::cout << "FAIL (test vector 0)" ZT_EOL_S;
|
||||
return -1;
|
||||
}
|
||||
s20.init(s2012TV0Key,s2012TV0Iv);
|
||||
memset(buf1,0,sizeof(buf1));
|
||||
memset(buf2,0,sizeof(buf2));
|
||||
s20.crypt12(buf1,buf2,64);
|
||||
if (memcmp(buf2,s2012TV0Ks,64)) {
|
||||
std::cout << "FAIL (test vector 1)" ZT_EOL_S;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "PASS" ZT_EOL_S;
|
||||
}
|
||||
s20.init(s2012TV0Key,s2012TV0Iv);
|
||||
memset(buf1,0,sizeof(buf1));
|
||||
memset(buf2,0,sizeof(buf2));
|
||||
s20.crypt12(buf1,buf2,64);
|
||||
if (memcmp(buf2,s2012TV0Ks,64)) {
|
||||
std::cout << "FAIL (test vector 1)" ZT_EOL_S;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "PASS" ZT_EOL_S;
|
||||
|
||||
#ifdef ZT_SALSA20_SSE
|
||||
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.flush();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -598,6 +601,7 @@ extern "C" int ZT_TestIdentity()
|
|||
}
|
||||
}
|
||||
|
||||
std::cout.flush();
|
||||
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.flush();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -86,28 +86,14 @@ var (
|
|||
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
|
||||
type Node struct {
|
||||
networks map[NetworkID]*Network
|
||||
networksByMAC map[MAC]*Network // locked by networksLock
|
||||
interfaceAddresses map[string]net.IP // physical external IPs on the machine
|
||||
basePath string
|
||||
peersPath string
|
||||
networksPath string
|
||||
localConfigPath string
|
||||
localConfig LocalConfig
|
||||
localConfigLock sync.RWMutex
|
||||
|
@ -126,22 +112,30 @@ type Node struct {
|
|||
}
|
||||
|
||||
// NewNode creates and initializes a new instance of the ZeroTier node service
|
||||
func NewNode(basePath string) (*Node, error) {
|
||||
var err error
|
||||
|
||||
_ = os.MkdirAll(basePath, 0755)
|
||||
if _, err := os.Stat(basePath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n := new(Node)
|
||||
|
||||
func NewNode(basePath string) (n *Node, err error) {
|
||||
n = new(Node)
|
||||
n.networks = make(map[NetworkID]*Network)
|
||||
n.networksByMAC = make(map[MAC]*Network)
|
||||
n.interfaceAddresses = make(map[string]net.IP)
|
||||
|
||||
_ = os.MkdirAll(basePath, 0755)
|
||||
if _, err = os.Stat(basePath); err != nil {
|
||||
return
|
||||
}
|
||||
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")
|
||||
|
||||
err = n.localConfig.Read(n.localConfigPath, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
39
go/pkg/zerotier/selftest.go
Normal file
39
go/pkg/zerotier/selftest.go
Normal 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
|
||||
}
|
Loading…
Add table
Reference in a new issue