diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..7411a0c6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,75 @@
+---
+BasedOnStyle: LLVM
+BreakBeforeBraces: Stroustrup
+IndentWidth: 4
+TabWidth: 4
+AlignAfterOpenBracket: AlwaysBreak
+AlignConsecutiveMacros: 'true'
+AlignConsecutiveAssignments: 'false'
+AlignConsecutiveDeclarations: 'false'
+AlignEscapedNewlines: Right
+AlignOperands: 'true'
+AlignTrailingComments: 'true'
+AllowAllArgumentsOnNextLine: 'false'
+AllowAllConstructorInitializersOnNextLine: 'false'
+AllowAllParametersOfDeclarationOnNextLine: 'false'
+AllowShortBlocksOnASingleLine: 'true'
+AllowShortCaseLabelsOnASingleLine: 'false'
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: Never
+AlwaysBreakAfterReturnType: None
+BinPackArguments: 'false'
+BinPackParameters: 'false'
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeTernaryOperators: 'true'
+BreakConstructorInitializers: BeforeComma
+BreakInheritanceList: BeforeComma
+CompactNamespaces: 'false'
+ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
+ConstructorInitializerIndentWidth: '4'
+ContinuationIndentWidth: '4'
+Cpp11BracedListStyle: 'false'
+FixNamespaceComments: 'true'
+IncludeBlocks: Regroup
+IndentCaseLabels: 'true'
+IndentPPDirectives: None
+IndentWrappedFunctionNames: 'false'
+KeepEmptyLinesAtTheStartOfBlocks: 'false'
+MaxEmptyLinesToKeep: '1'
+NamespaceIndentation: None
+PointerAlignment: Left
+ReflowComments: 'true'
+SortIncludes: 'true'
+SortUsingDeclarations: 'true'
+SpaceAfterCStyleCast: 'false'
+SpaceAfterLogicalNot: 'true'
+SpaceAfterTemplateKeyword: 'true'
+SpaceBeforeAssignmentOperators: 'true'
+SpaceBeforeCpp11BracedList: 'true'
+SpaceBeforeCtorInitializerColon: 'true'
+SpaceBeforeInheritanceColon: 'true'
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: 'true'
+SpaceInEmptyParentheses: 'false'
+SpacesBeforeTrailingComments: '3'
+SpacesInAngles: 'false'
+SpacesInCStyleCastParentheses: 'false'
+SpacesInContainerLiterals: 'true'
+SpacesInParentheses: 'false'
+SpacesInSquareBrackets: 'false'
+UseTab: 'Never'
+
+---
+Language: Cpp
+Standard: Cpp03
+ColumnLimit: '240'
+---
+Language: ObjC
+ColumnLimit: '240'
+---
+Language: Java
+ColumnLimit: '240'
+---
+Language: CSharp
+ColumnLimit: '240'
+...
diff --git a/.clangd b/.clangd
new file mode 100644
index 00000000..0605ccdb
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,6 @@
+CompileFlags:
+ Add:
+ - "-std=c++17"
+ - "-I../ext"
+ - "-I../ext/prometheus-cpp-lite-1.0/core/include"
+ - "-I../ext/prometheus-cpp-lite-1.0/simpleapi/include"
diff --git a/.gitignore b/.gitignore
old mode 100755
new mode 100644
index 44b5eb56..a1562793
--- a/.gitignore
+++ b/.gitignore
@@ -1,19 +1,56 @@
-# Main binaries created in *nix builds
-/zerotier-one
-/zerotier-idtool
-/zerotier-cli
-/zerotier-selftest
-/zerotier
-/nltest
-
-# OS-created garbage files from various platforms
+build/
+/version.h
.DS_Store
+.Trashes
+*.swp
+._*
+*~
+*~.nib
.Apple*
Thumbs.db
@eaDir
-._*
+DerivedData/
+*.pbxuser
+*.mode1v3
+*.mode2v3
+*.perspectivev3
+!default.pbxuser
+!default.mode1v3
+!default.mode2v3
+!default.perspectivev3
+*.xccheckout
+xcuserdata/
+.vscode
+__pycache__
+attic/world/*.c25519
+attic/world/mkworld
+*.log
+*.opensdf
+*.user
+*.cache
+*.obj
+*.tlog
+*.pid
+*.pkg
+*.o
+*.o-*
+*.core
+*.deb
+*.rpm
+*.autosave
+*.tmp
+.depend
+node_modules
+debian/files
+debian/zerotier-one
+debian/zerotier-one*.debhelper
+debian/*.log
+debian/zerotier-one.substvars
+root/identity.*
+root/config.*
+/ext/installfiles/windows/chocolatey/zerotier-one/*.nupkg
+/go/zerotier
-# Windows build droppings
/windows/ZeroTierOne.sdf
/windows/ZeroTierOne.v11.suo
/windows/x64
@@ -32,7 +69,7 @@ Thumbs.db
/ext/installfiles/windows/ZeroTier One-SetupFiles
/ext/installfiles/windows/Prerequisites
/ext/installfiles/windows/*-cache
-/ZeroTier One.msi
+/*.msi
/windows/.vs
*.vcxproj.backup
/windows/TapDriver6/Win7Debug
@@ -43,47 +80,6 @@ enc_temp_folder
/windows/copyutil/bin
/windows/copyutil/obj
-# *nix/Mac build droppings
-/build-*
-/ZeroTierOneInstaller-*
-/examples/docker/zerotier-one
-/examples/docker/test-*.env
-/world/mkworld
-/world/*.c25519
-zt1-src.tar.gz
-/MacEthernetTapAgent
-
-# Miscellaneous temporaries, build files, etc.
-*.log
-*.opensdf
-*.user
-*.cache
-*.obj
-*.tlog
-*.pid
-*.pkg
-*.o
-/*.a
-*.dylib
-*.so
-*.so.*
-*.o-*
-*.core
-*.deb
-*.rpm
-*.autosave
-*.tmp
-.depend
-node_modules
-zt1_update_*
-debian/files
-debian/zerotier-one
-debian/zerotier-one*.debhelper
-debian/*.log
-debian/zerotier-one.substvars
-root-watcher/config.json
-
-# Java/Android/JNI build droppings
java/obj/
java/libs/
java/bin/
@@ -95,28 +91,3 @@ java/build_win32/
windows/WinUI/obj/
windows/WinUI/bin/
windows/ZeroTierOne/Debug/
-/ext/installfiles/windows/chocolatey/zerotier-one/*.nupkg
-
-# Miscellaneous mac/Xcode droppings
-.DS_Store
-.Trashes
-*.swp
-*~.nib
-DerivedData/
-build/
-*.pbxuser
-*.mode1v3
-*.mode2v3
-*.perspectivev3
-!default.pbxuser
-!default.mode1v3
-!default.mode2v3
-!default.perspectivev3
-*.xccheckout
-xcuserdata/
-ext/librethinkdbxx/build
-.vscode
-__pycache__
-*~
-attic/world/*.c25519
-attic/world/mkworld
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..0e40fe8f
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+
+# Default ignored files
+/workspace.xml
\ No newline at end of file
diff --git a/.idea/ZeroTierOne.iml b/.idea/ZeroTierOne.iml
new file mode 100644
index 00000000..5e764c4f
--- /dev/null
+++ b/.idea/ZeroTierOne.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 00000000..a55e7a17
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/dictionaries/api.xml b/.idea/dictionaries/api.xml
new file mode 100644
index 00000000..53167764
--- /dev/null
+++ b/.idea/dictionaries/api.xml
@@ -0,0 +1,11 @@
+
+
+
+ apisocket
+ nwid
+ secrand
+ sockaddr
+ unmarshals
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 00000000..146ab09b
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..28a804d8
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..6b5db685
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..94a25f7f
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml
new file mode 100644
index 00000000..97ad6d2d
--- /dev/null
+++ b/.idea/watcherTasks.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AUTHORS.md b/AUTHORS.md
index 84bb8631..2d765fb6 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -36,12 +36,6 @@ ZeroTier includes the following third party code, either in ext/ or incorporated
* Home page: http://code.google.com/p/lz4/
* License grant: BSD 2-clause
- * http-parser by Joyent, Inc. (many authors)
-
- * Files: ext/http-parser/*
- * Home page: https://github.com/joyent/http-parser/
- * License grant: MIT/Expat
-
* C++11 json (nlohmann/json) by Niels Lohmann
* Files: ext/json/*
@@ -62,12 +56,6 @@ ZeroTier includes the following third party code, either in ext/ or incorporated
* License grant: public domain
* ZeroTier Modifications: slight cryptographically-irrelevant modifications for inclusion into ZeroTier core
- * MiniUPNPC and libnatpmp by Thomas Bernard
-
- * Files: ext/libnatpmp/* ext/miniupnpc/*
- * Home page: http://miniupnp.free.fr/
- * License grant: BSD attribution no-endorsement
-
* cpp-httplib by yhirose
* Files: ext/cpp-httplib/*
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fff7808e..e154a45c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,199 @@
-# CMake build script for libzerotiercore.a
+cmake_minimum_required (VERSION 3.10)
-cmake_minimum_required (VERSION 2.8)
-project (zerotiercore)
+if(${CMAKE_VERSION} VERSION_LESS 3.15)
+ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
+else()
+ cmake_policy(VERSION 3.15)
+endif()
-set (PROJ_DIR ${PROJECT_SOURCE_DIR})
-set (ZT_DEFS -std=c++11)
+if(WIN32)
+ # If building on Windows, set minimum target to Windows 7
+ set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
+endif(WIN32)
-file(GLOB core_src_glob ${PROJ_DIR}/node/*.cpp)
-add_library(zerotiercore STATIC ${core_src_glob})
+set(ZEROTIER_ONE_VERSION_MAJOR 2 CACHE INTERNAL "")
+set(ZEROTIER_ONE_VERSION_MINOR 0 CACHE INTERNAL "")
+set(ZEROTIER_ONE_VERSION_REVISION 0 CACHE INTERNAL "")
+set(ZEROTIER_ONE_VERSION_BUILD 0 CACHE INTERNAL "")
-target_compile_options(zerotiercore PRIVATE ${ZT_DEFS})
+set(default_build_type "Release")
+if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+ set(default_build_type "Debug")
+endif()
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
+ set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
+ STRING "Choose the type of build." FORCE)
+ # Set the possible values of build type for cmake-gui
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
+ "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
+endif()
+
+option(BUILD_CENTRAL_CONTROLLER "Build ZeroTier Central Controller" OFF)
+option(ZT_TRACE "Trace Messages" OFF)
+option(ZT_DEBUG_TRACE "Debug Trace Messages" OFF)
+
+if (BUILD_CENTRAL_CONTROLLER)
+ find_package(PostgreSQL REQUIRED)
+ set(ENABLE_SSL_SUPPORT OFF)
+ set(BUILD_SHARED_LIBS OFF)
+ set(BUILD_EXAMPLES OFF)
+ set(BUILD_TOOLS OFF)
+ set(BUILD_TESTS OFF)
+ set(BUILD_API_DOCS OFF)
+ add_subdirectory("ext/librabbitmq")
+endif(BUILD_CENTRAL_CONTROLLER)
+
+set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X Deployment Version")
+
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ add_definitions(-DZT_TRACE)
+endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
+
+project(zerotier
+ DESCRIPTION "ZeroTier Network Hypervisor"
+ LANGUAGES CXX C)
+
+if(WIN32)
+ add_definitions(-DNOMINMAX)
+else(WIN32)
+ if(APPLE)
+
+ message("Setting macOS Compiler Flags ${CMAKE_BUILD_TYPE}")
+ add_compile_options(
+ -Wall
+ -Wno-deprecated
+ -mmacosx-version-min=10.9
+ $<$:-g>
+ $<$:-O0>
+ $<$:-Ofast>
+ $<$:-fPIE>
+ $<$:-flto>
+ $<$:-Ofast>
+ $<$:-fPIE>
+ $<$:-g>
+ )
+ add_link_options(
+ -mmacosx-version-min=10.9
+ $<$:-flto>
+ )
+
+ elseif (
+ CMAKE_SYSTEM_NAME MATCHES "Linux" OR
+ CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR
+ CMAKE_SYSTEM_NAME MATCHES "OpenBSD" OR
+ CMAKE_SYSTEM_NAME MATCHES "NetBSD"
+ )
+
+ message("Setting Linux/BSD Compiler Flags (${CMAKE_BUILD_TYPE})")
+ add_compile_options(
+ -Wall
+ -Wno-deprecated
+ $<$:-g>
+ $<$:-O0>
+ $<$:-O3>
+ $<$:-fPIE>
+ $<$:-O3>
+ $<$:-fPIE>
+ $<$:-g>
+ )
+
+ endif(APPLE)
+endif(WIN32)
+
+if (
+ CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR
+ CMAKE_SYSTEM_PROCESSOR MATCHES "amd64" OR
+ CMAKE_SYSTEM_PROCESSOR MATCHES "i386" OR
+ CMAKE_SYSTEM_PROCESSOR MATCHES "i486" OR
+ CMAKE_SYSTEM_PROCESSOR MATCHES "i586" OR
+ CMAKE_SYSTEM_PROCESSOR MATCHES "i686"
+)
+ message("Adding SSE and AES-NI flags for processor ${CMAKE_SYSTEM_PROCESSOR}")
+ add_compile_options(
+ -maes
+ -mmmx
+ -mrdrnd
+ -mpclmul
+ -msse
+ -msse2
+ -msse3
+ -msse4.1
+ )
+endif()
+
+if(ZT_TRACE)
+ add_definitions(-DZT_TRACE)
+endif()
+if(ZT_DEBUG_TRACE)
+ add_definitions(-DZT_DEBUG_TRACE)
+endif()
+
+add_subdirectory(node)
+add_subdirectory(controller)
+add_subdirectory(osdep)
+add_subdirectory(go/native)
+
+#if(WIN32)
+# add_subdirectory("windows/WinUI")
+# add_subdirectory("windows/copyutil")
+# add_definitions(-DNOMINMAX)
+#endif(WIN32)
+
+set(
+ zt_osdep
+ zt_core
+ zt_controller
+ zt_go_native
+)
+
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/version.h
+)
+
+#set(src
+# one.cpp
+# "ext/http-parser/http_parser.c"
+#)
+#set(headers
+# "ext/http-parser/http_parser.h"
+#)
+
+if(WIN32)
+ set(libs ${libs} wsock32 ws2_32 rpcrt4 iphlpapi)
+else(WIN32)
+ set(libs ${libs} pthread)
+endif(WIN32)
+
+#if(WIN32)
+# set(libs ${libs} wsock32 ws2_32 rpcrt4 iphlpapi)
+# set(src
+# ${src}
+# "windows/ZeroTierOne/ServiceBase.cpp"
+# "windows/ZeroTierOne/ServiceInstaller.cpp"
+# "windows/ZeroTierOne/ZeroTierOneService.cpp"
+# "windows/ZeroTierOne/ZeroTierOne.rc"
+# )
+# set(headers
+# ${headers}
+# "windows/ZeroTierOne/ServiceBase.h"
+# "windows/ZeroTierOne/ServiceInstaller.h"
+# "windows/ZeroTierOne/ZeroTierOneService.h"
+# )
+#else(WIN32)
+# set(libs ${libs} pthread resolv)
+#endif(WIN32)
+
+#if(BUILD_CENTRAL_CONTROLLER)
+# set(libs ${libs} rabbitmq-static ${PostgreSQL_LIBRARIES})
+#endif(BUILD_CENTRAL_CONTROLLER)
+
+#add_executable(${PROJECT_NAME} ${src} ${headers})
+#target_link_libraries(${PROJECT_NAME} ${libs})
+#target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
+
+add_executable(zerotier-selftest selftest.cpp)
+target_link_libraries(zerotier-selftest ${libs} zt_core zt_osdep)
+target_compile_features(zerotier-selftest PUBLIC cxx_std_11)
diff --git a/Jenkinsfile b/Jenkinsfile
index 88989327..455115cb 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -14,7 +14,13 @@ parallel 'centos7': {
checkout scm
stage('Build Centos 7') {
- sh 'make -f make-linux.mk'
+ sh '''. /opt/rh/devtoolset-8/enable
+ rm -rf build/
+ mkdir build && cd build
+ cmake ..
+ make -j4
+ ./zerotier-selftest
+ '''
}
}
catch (err) {
diff --git a/Makefile b/Makefile
index 144225fc..9c82f78e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,28 +1,20 @@
# Common makefile -- loads make rules for each platform
-OSTYPE=$(shell uname -s)
+BUILDDIR := build
-ifeq ($(OSTYPE),Darwin)
- include make-mac.mk
-endif
+.PHONY: all
-ifeq ($(OSTYPE),Linux)
- include make-linux.mk
-endif
+all: setup
+ cd ${BUILDDIR} && $(MAKE) -j$(shell getconf _NPROCESSORS_ONLN)
-ifeq ($(OSTYPE),FreeBSD)
- CC=clang
- CXX=clang++
- ZT_BUILD_PLATFORM=7
- include make-bsd.mk
-endif
-ifeq ($(OSTYPE),OpenBSD)
- CC=egcc
- CXX=eg++
- ZT_BUILD_PLATFORM=9
- include make-bsd.mk
-endif
+setup:
+ mkdir -p ${BUILDDIR} && cd ${BUILDDIR} && cmake .. -DCMAKE_BUILD_TYPE=Release
-ifeq ($(OSTYPE),NetBSD)
- include make-netbsd.mk
-endif
+debug:
+ mkdir -p ${BUILDDIR} && cd ${BUILDDIR} && cmake .. -DCMAKE_BUILD_TYPE=Debug && $(MAKE)
+
+clean:
+ rm -rf ${BUILDDIR}
+
+distclean:
+ rm -rf ${BUILDDIR}
diff --git a/osdep/Binder.hpp b/attic/Binder.hpp
similarity index 98%
rename from osdep/Binder.hpp
rename to attic/Binder.hpp
index 660e6f0c..67debc80 100644
--- a/osdep/Binder.hpp
+++ b/attic/Binder.hpp
@@ -54,6 +54,12 @@
#include "Phy.hpp"
#include "OSUtils.hpp"
+#if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__))
+#define ZT_UDP_DESIRED_BUF_SIZE 1048576
+#else
+#define ZT_UDP_DESIRED_BUF_SIZE 131072
+#endif
+
// Period between refreshes of bindings
#define ZT_BINDER_REFRESH_PERIOD 30000
diff --git a/osdep/Http.cpp b/attic/Http.cpp
similarity index 100%
rename from osdep/Http.cpp
rename to attic/Http.cpp
diff --git a/osdep/Http.hpp b/attic/Http.hpp
similarity index 100%
rename from osdep/Http.hpp
rename to attic/Http.hpp
diff --git a/osdep/Phy.hpp b/attic/Phy.hpp
similarity index 99%
rename from osdep/Phy.hpp
rename to attic/Phy.hpp
index b65a520e..d4934edf 100644
--- a/osdep/Phy.hpp
+++ b/attic/Phy.hpp
@@ -48,6 +48,7 @@
#include
#include
#include
+#include
#include
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
diff --git a/attic/PortMapper-libnatpmp.c b/attic/PortMapper-libnatpmp.c
new file mode 100644
index 00000000..5da85cba
--- /dev/null
+++ b/attic/PortMapper-libnatpmp.c
@@ -0,0 +1,14 @@
+#define ENABLE_STRNATPMPERR
+#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
+#define _XOPEN_SOURCE 600
+
+#ifdef __APPLE__
+#ifndef _DARWIN_C_SOURCE
+#define _DARWIN_C_SOURCE
+#endif
+#endif
+
+#include "../ext/libnatpmp/getgateway.c"
+#include "../ext/libnatpmp/wingettimeofday.c"
+#include "../ext/libnatpmp/natpmp.c"
diff --git a/attic/PortMapper-miniupnpc.c b/attic/PortMapper-miniupnpc.c
new file mode 100644
index 00000000..8d28da10
--- /dev/null
+++ b/attic/PortMapper-miniupnpc.c
@@ -0,0 +1,41 @@
+#define MINIUPNP_STATICLIB
+#define MINIUPNPC_SET_SOCKET_TIMEOUT
+#define MINIUPNPC_GET_SRC_ADDR
+#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
+#define _XOPEN_SOURCE 600
+#define MINIUPNPC_VERSION_STRING "2.0"
+#define UPNP_VERSION_STRING "UPnP/1.1"
+
+#ifdef __LINUX__
+#define OS_STRING "Linux"
+#endif
+#ifdef __APPLE__
+#define OS_STRING "Darwin"
+#endif
+#ifdef __WINDOWS__
+#define OS_STRING "Windows"
+#endif
+#ifndef OS_STRING
+#define OS_STRING "ZeroTier"
+#endif
+
+#ifdef __APPLE__
+#ifndef _DARWIN_C_SOURCE
+#define _DARWIN_C_SOURCE
+#endif
+#endif
+
+#include "../ext/miniupnpc/connecthostport.c"
+#include "../ext/miniupnpc/igd_desc_parse.c"
+#include "../ext/miniupnpc/minisoap.c"
+#include "../ext/miniupnpc/miniupnpc.c"
+#include "../ext/miniupnpc/miniwget.c"
+#include "../ext/miniupnpc/minixml.c"
+#include "../ext/miniupnpc/portlistingparse.c"
+#include "../ext/miniupnpc/receivedata.c"
+#include "../ext/miniupnpc/upnpcommands.c"
+#include "../ext/miniupnpc/upnpdev.c"
+#include "../ext/miniupnpc/upnperrors.c"
+#include "../ext/miniupnpc/upnpreplyparse.c"
+#include "../ext/miniupnpc/minissdpc.c"
diff --git a/osdep/PortMapper.cpp b/attic/PortMapper.cpp
similarity index 83%
rename from osdep/PortMapper.cpp
rename to attic/PortMapper.cpp
index caad3ed4..d0ed87c3 100644
--- a/osdep/PortMapper.cpp
+++ b/attic/PortMapper.cpp
@@ -11,8 +11,6 @@
*/
/****/
-#ifdef ZT_USE_MINIUPNPC
-
// Uncomment to dump debug messages
//#define ZT_PORTMAPPER_TRACE 1
@@ -112,7 +110,7 @@ public:
mode = 1;
closenatpmp(&natpmp);
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: NAT-PMP: init failed, switching to UPnP mode" ZT_EOL_S);
+ PM_TRACE("PortMapper: NAT-PMP: init failed, switching to UPnP mode" ZT_EOL_S);
#endif
break;
}
@@ -135,7 +133,7 @@ public:
publicAddress = InetAddress((uint32_t)response.pnu.publicaddress.addr.s_addr,0);
} else {
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: NAT-PMP: request for external address failed, aborting..." ZT_EOL_S);
+ PM_TRACE("PortMapper: NAT-PMP: request for external address failed, aborting..." ZT_EOL_S);
#endif
closenatpmp(&natpmp);
break;
@@ -157,8 +155,8 @@ public:
if (r == 0) {
publicAddress.setPort(response.pnu.newportmapping.mappedpublicport);
#ifdef ZT_PORTMAPPER_TRACE
- char paddr[128];
- PM_TRACE("PortMapper: NAT-PMP: mapped %u to %s" ZT_EOL_S,(unsigned int)localPort,publicAddress.toString(paddr));
+ char paddr[128];
+ PM_TRACE("PortMapper: NAT-PMP: mapped %u to %s" ZT_EOL_S,(unsigned int)localPort,publicAddress.toString(paddr));
#endif
Mutex::Lock sl(surface_l);
surface.clear();
@@ -175,7 +173,7 @@ public:
if (!natPmpSuccess) {
mode = 1;
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: NAT-PMP: request failed, switching to UPnP mode" ZT_EOL_S);
+ PM_TRACE("PortMapper: NAT-PMP: request failed, switching to UPnP mode" ZT_EOL_S);
#endif
}
}
@@ -200,7 +198,7 @@ public:
{
UPNPDev *dev = devlist;
while (dev) {
- PM_TRACE("PortMapper: found UPnP device at URL '%s': %s" ZT_EOL_S,dev->descURL,dev->st);
+ PM_TRACE("PortMapper: found UPnP device at URL '%s': %s" ZT_EOL_S,dev->descURL,dev->st);
dev = dev->pNext;
}
}
@@ -214,11 +212,11 @@ public:
if ((UPNP_GetValidIGD(devlist,&urls,&data,lanaddr,sizeof(lanaddr)))&&(lanaddr[0])) {
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: my LAN IP address: %s" ZT_EOL_S,lanaddr);
+ PM_TRACE("PortMapper: UPnP: my LAN IP address: %s" ZT_EOL_S,lanaddr);
#endif
if ((UPNP_GetExternalIPAddress(urls.controlURL,data.first.servicetype,externalip) == UPNPCOMMAND_SUCCESS)&&(externalip[0])) {
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: my external IP address: %s" ZT_EOL_S,externalip);
+ PM_TRACE("PortMapper: UPnP: my external IP address: %s" ZT_EOL_S,externalip);
#endif
for(int tries=0;tries<60;++tries) {
@@ -244,7 +242,7 @@ public:
memset(haveLeaseDuration,0,sizeof(haveLeaseDuration));
if ((UPNP_GetSpecificPortMappingEntry(urls.controlURL,data.first.servicetype,outport,"UDP",(const char *)0,haveIntClient,haveIntPort,haveDesc,haveEnabled,haveLeaseDuration) == UPNPCOMMAND_SUCCESS)&&(uniqueName == haveDesc)) {
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: reusing previously reserved external port: %s" ZT_EOL_S,outport);
+ PM_TRACE("PortMapper: UPnP: reusing previously reserved external port: %s" ZT_EOL_S,outport);
#endif
Mutex::Lock sl(surface_l);
surface.clear();
@@ -259,7 +257,7 @@ public:
int mapResult = 0;
if ((mapResult = UPNP_AddPortMapping(urls.controlURL,data.first.servicetype,outport,inport,lanaddr,uniqueName.c_str(),"UDP",(const char *)0,"0")) == UPNPCOMMAND_SUCCESS) {
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: reserved external port: %s" ZT_EOL_S,outport);
+ PM_TRACE("PortMapper: UPnP: reserved external port: %s" ZT_EOL_S,outport);
#endif
Mutex::Lock sl(surface_l);
surface.clear();
@@ -269,7 +267,7 @@ public:
break;
} else {
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: UPNP_AddPortMapping(%s) failed: %d" ZT_EOL_S,outport,mapResult);
+ PM_TRACE("PortMapper: UPnP: UPNP_AddPortMapping(%s) failed: %d" ZT_EOL_S,outport,mapResult);
#endif
Thread::sleep(1000);
}
@@ -278,13 +276,13 @@ public:
} else {
mode = 0;
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: UPNP_GetExternalIPAddress failed, returning to NAT-PMP mode" ZT_EOL_S);
+ PM_TRACE("PortMapper: UPnP: UPNP_GetExternalIPAddress failed, returning to NAT-PMP mode" ZT_EOL_S);
#endif
}
} else {
mode = 0;
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: UPnP: UPNP_GetValidIGD failed, returning to NAT-PMP mode" ZT_EOL_S);
+ PM_TRACE("PortMapper: UPnP: UPNP_GetValidIGD failed, returning to NAT-PMP mode" ZT_EOL_S);
#endif
}
@@ -293,14 +291,14 @@ public:
} else {
mode = 0;
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("PortMapper: upnpDiscover failed, returning to NAT-PMP mode: %d" ZT_EOL_S,upnpError);
+ PM_TRACE("PortMapper: upnpDiscover failed, returning to NAT-PMP mode: %d" ZT_EOL_S,upnpError);
#endif
}
}
// ---------------------------------------------------------------------
#ifdef ZT_PORTMAPPER_TRACE
- PM_TRACE("UPNPClient: rescanning in %d ms" ZT_EOL_S,ZT_PORTMAPPER_REFRESH_DELAY);
+ PM_TRACE("UPNPClient: rescanning in %d ms" ZT_EOL_S,ZT_PORTMAPPER_REFRESH_DELAY);
#endif
Thread::sleep(ZT_PORTMAPPER_REFRESH_DELAY);
}
@@ -334,5 +332,3 @@ std::vector PortMapper::get() const
}
} // namespace ZeroTier
-
-#endif // ZT_USE_MINIUPNPC
diff --git a/osdep/PortMapper.hpp b/attic/PortMapper.hpp
similarity index 92%
rename from osdep/PortMapper.hpp
rename to attic/PortMapper.hpp
index be2c6468..54b04de1 100644
--- a/osdep/PortMapper.hpp
+++ b/attic/PortMapper.hpp
@@ -11,8 +11,6 @@
*/
/****/
-#ifdef ZT_USE_MINIUPNPC
-
#ifndef ZT_PORTMAPPER_HPP
#define ZT_PORTMAPPER_HPP
@@ -26,7 +24,7 @@
/**
* How frequently should we refresh our UPNP/NAT-PnP/whatever state?
*/
-#define ZT_PORTMAPPER_REFRESH_DELAY 300000
+#define ZT_PORTMAPPER_REFRESH_DELAY 120000
namespace ZeroTier {
@@ -62,5 +60,3 @@ private:
} // namespace ZeroTier
#endif
-
-#endif // ZT_USE_MINIUPNPC
diff --git a/attic/Root.hpp b/attic/Root.hpp
new file mode 100644
index 00000000..c526007d
--- /dev/null
+++ b/attic/Root.hpp
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ */
+/****/
+
+#ifndef ZT_ROOT_HPP
+#define ZT_ROOT_HPP
+
+#include "Constants.hpp"
+#include "Str.hpp"
+#include "ECC384.hpp"
+#include "Locator.hpp"
+#include "InetAddress.hpp"
+#include "Utils.hpp"
+#include "Identity.hpp"
+#include "Mutex.hpp"
+
+namespace ZeroTier {
+
+/**
+ * A root entry pointing to a node capable of global identity lookup and indirect transit
+ *
+ * Root entries point to DNS records that contain TXT entries that decode to Locator objects
+ * pointing to actual root nodes. A default root identity and static addresses can also be
+ * provided as fallback if DNS is not available.
+ *
+ * Note that root identities can change if DNS returns a different result, but that DNS entries
+ * are authenticated using their own signature scheme. This allows a root DNS name to serve
+ * up different roots based on factors like location or relative load of different roots.
+ *
+ * It's also possible to create a root with no DNS and no DNS validator public key. This root
+ * will be a static entry pointing to a single root identity and set of physical addresses.
+ */
+class Root
+{
+public:
+ ZT_ALWAYS_INLINE Root() : _dnsPublicKeySize(0) {}
+
+ /**
+ * Create a new root entry
+ *
+ * @param dn DNS name
+ * @param dnspk DNS public key for record validation
+ * @param dnspksize Size of DNS public key (currently always the size of a NIST P-384 point compressed public key)
+ * @param dflId Default identity if DNS is not available
+ * @param dflAddrs Default IP addresses if DNS is not available
+ */
+ template
+ ZT_ALWAYS_INLINE Root(S dn,const uint8_t *const dnspk,const unsigned int dnspksize,const Identity &dflId,const std::vector &dflAddrs) :
+ _defaultIdentity(dflId),
+ _defaultAddresses(dflAddrs),
+ _dnsName(dn),
+ _dnsPublicKeySize(dnspksize)
+ {
+ if (dnspksize != 0) {
+ if (dnspksize > sizeof(_dnsPublicKey))
+ throw ZT_EXCEPTION_INVALID_ARGUMENT;
+ memcpy(_dnsPublicKey,dnspk,dnspksize);
+ }
+ }
+
+ /**
+ * @return Current identity (either default or latest locator)
+ */
+ ZT_ALWAYS_INLINE const Identity id() const
+ {
+ if (_lastFetchedLocator.id())
+ return _lastFetchedLocator.id();
+ return _defaultIdentity;
+ }
+
+ /**
+ * @param id Identity to check
+ * @return True if identity equals this root's current identity
+ */
+ ZT_ALWAYS_INLINE bool is(const Identity &id) const
+ {
+ return ((_lastFetchedLocator.id()) ? (id == _lastFetchedLocator.id()) : (id == _defaultIdentity));
+ }
+
+ /**
+ * @return Current ZeroTier address (either default or latest locator)
+ */
+ ZT_ALWAYS_INLINE const Address address() const
+ {
+ if (_lastFetchedLocator.id())
+ return _lastFetchedLocator.id().address();
+ return _defaultIdentity.address();
+ }
+
+ /**
+ * @return DNS name for this root or empty string if static entry with no DNS
+ */
+ ZT_ALWAYS_INLINE const Str dnsName() const { return _dnsName; }
+
+ /**
+ * @return Latest locator or NIL locator object if none
+ */
+ ZT_ALWAYS_INLINE Locator locator() const { return _lastFetchedLocator; }
+
+ /**
+ * @return Timestamp of latest retrieved locator or 0 if none
+ */
+ ZT_ALWAYS_INLINE int64_t locatorTimestamp() const { return _lastFetchedLocator.timestamp(); }
+
+ /**
+ * Update locator, returning true if new locator is valid and newer than existing
+ */
+ ZT_ALWAYS_INLINE bool updateLocator(const Locator &loc)
+ {
+ if (!loc.verify())
+ return false;
+ if ((loc.phy().size() > 0)&&(loc.timestamp() > _lastFetchedLocator.timestamp())) {
+ _lastFetchedLocator = loc;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Update this root's locator from a series of TXT records
+ */
+ template
+ ZT_ALWAYS_INLINE bool updateLocatorFromTxt(I start,I end)
+ {
+ try {
+ if (_dnsPublicKeySize != ZT_ECC384_PUBLIC_KEY_SIZE)
+ return false;
+ Locator loc;
+ if (!loc.decodeTxtRecords(start,end,_dnsPublicKey)) // also does verify()
+ return false;
+ if ((loc.phy().size() > 0)&&(loc.timestamp() > _lastFetchedLocator.timestamp())) {
+ _lastFetchedLocator = loc;
+ return true;
+ }
+ return false;
+ } catch ( ... ) {}
+ return false;
+ }
+
+ /**
+ * Pick a random physical IP for this root with the given address family
+ *
+ * @param addressFamily AF_INET or AF_INET6
+ * @return Address or InetAddress::NIL if no addresses exist for the given family
+ */
+ ZT_ALWAYS_INLINE const InetAddress &pickPhysical(const int addressFamily) const
+ {
+ std::vector pickList;
+ const std::vector *const av = (_lastFetchedLocator) ? &(_lastFetchedLocator.phy()) : &_defaultAddresses;
+ for(std::vector::const_iterator i(av->begin());i!=av->end();++i) {
+ if (addressFamily == (int)i->ss_family) {
+ pickList.push_back(&(*i));
+ }
+ }
+ if (pickList.size() == 1)
+ return *pickList[0];
+ else if (pickList.size() > 1)
+ return *pickList[(unsigned long)Utils::random() % (unsigned long)pickList.size()];
+ return InetAddress::NIL;
+ }
+
+private:
+ Identity _defaultIdentity;
+ std::vector _defaultAddresses;
+ Str _dnsName;
+ Locator _lastFetchedLocator;
+ unsigned int _dnsPublicKeySize;
+ uint8_t _dnsPublicKey[ZT_ECC384_PUBLIC_KEY_SIZE];
+};
+
+} // namespace ZeroTier
+
+#endif
diff --git a/cycle_controllers.sh b/attic/cycle_controllers.sh
similarity index 100%
rename from cycle_controllers.sh
rename to attic/cycle_controllers.sh
diff --git a/ext/misc/linux-old-glibc-compat.c b/attic/linux-old-glibc-compat.c
similarity index 100%
rename from ext/misc/linux-old-glibc-compat.c
rename to attic/linux-old-glibc-compat.c
diff --git a/attic/listaddrinfo.go b/attic/listaddrinfo.go
new file mode 100644
index 00000000..3db54bf0
--- /dev/null
+++ b/attic/listaddrinfo.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "fmt"
+ "net"
+)
+
+func main() {
+ ifs, err := net.Interfaces()
+ if err != nil {
+ fmt.Printf("Error: %s\n", err.Error())
+ return
+ }
+ for _, i := range ifs {
+ fmt.Printf("name: %s\n", i.Name)
+ fmt.Printf("hwaddr: %s\n", i.HardwareAddr.String())
+ fmt.Printf("index: %d\n", i.Index)
+ fmt.Printf("addrs:\n")
+ addrs, _ := i.Addrs()
+ for _, a := range addrs {
+ fmt.Printf(" %s\n", a.String())
+ }
+ fmt.Printf("multicast:\n")
+ mc, _ := i.MulticastAddrs()
+ for _, m := range mc {
+ fmt.Printf(" %s\n", m.String())
+ }
+ fmt.Printf("\n")
+ }
+}
diff --git a/make-bsd.mk b/attic/make-bsd.mk
similarity index 100%
rename from make-bsd.mk
rename to attic/make-bsd.mk
diff --git a/make-linux.mk b/attic/make-linux.mk
similarity index 100%
rename from make-linux.mk
rename to attic/make-linux.mk
diff --git a/make-mac.mk b/attic/make-mac.mk
similarity index 94%
rename from make-mac.mk
rename to attic/make-mac.mk
index 1fe2d7a4..3eb8a277 100644
--- a/make-mac.mk
+++ b/attic/make-mac.mk
@@ -60,14 +60,14 @@ endif
# Debug mode -- dump trace output, build binary with -g
ifeq ($(ZT_DEBUG),1)
ZT_TRACE=1
- CFLAGS+=-Wall -g $(INCLUDES) $(DEFS)
+ CFLAGS+=-Wall -g -maes -mpclmul $(INCLUDES) $(DEFS)
STRIP=echo
# The following line enables optimization for the crypto code, since
# C25519 in particular is almost UNUSABLE in heavy testing without it.
-node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g $(INCLUDES) $(DEFS)
+node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o node/AES.o: CFLAGS = -Wall -O2 -g -maes -mpclmul $(INCLUDES) $(DEFS)
else
CFLAGS?=-Ofast -fstack-protector-strong
- CFLAGS+=$(ARCH_FLAGS) -Wall -flto -fPIE -mmacosx-version-min=10.7 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
+ CFLAGS+=$(ARCH_FLAGS) -Wall -flto -fPIE -maes -msse -msse2 -msse3 -mpclmul -mmacosx-version-min=10.9 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
STRIP=strip
endif
diff --git a/make-netbsd.mk b/attic/make-netbsd.mk
similarity index 100%
rename from make-netbsd.mk
rename to attic/make-netbsd.mk
diff --git a/objects.mk b/attic/objects.mk
similarity index 83%
rename from objects.mk
rename to attic/objects.mk
index 32f62588..2bc708d8 100644
--- a/objects.mk
+++ b/attic/objects.mk
@@ -1,8 +1,8 @@
CORE_OBJS=\
+ node/AES.o \
node/C25519.o \
- node/Capability.o \
- node/CertificateOfMembership.o \
- node/CertificateOfOwnership.o \
+ node/Credential.o \
+ node/ECC384.o \
node/Identity.o \
node/IncomingPacket.o \
node/InetAddress.o \
@@ -16,13 +16,10 @@ CORE_OBJS=\
node/Path.o \
node/Peer.o \
node/Poly1305.o \
- node/Revocation.o \
node/Salsa20.o \
node/SelfAwareness.o \
node/SHA512.o \
node/Switch.o \
- node/Tag.o \
- node/Topology.o \
node/Trace.o \
node/Utils.o
diff --git a/one.cpp b/attic/one.cpp
similarity index 88%
rename from one.cpp
rename to attic/one.cpp
index 06d56e7a..2a3be098 100644
--- a/one.cpp
+++ b/attic/one.cpp
@@ -66,7 +66,6 @@
#include "node/Utils.hpp"
#include "node/NetworkController.hpp"
#include "node/Buffer.hpp"
-#include "node/World.hpp"
#include "osdep/OSUtils.hpp"
#include "osdep/Http.hpp"
@@ -95,10 +94,9 @@ static OneService *volatile zt1Service = (OneService *)0;
static void cliPrintHelp(const char *pn,FILE *out)
{
fprintf(out,
- "%s version %d.%d.%d build %d (platform %d arch %d)" ZT_EOL_S,
+ "%s version %d.%d.%d build %d" ZT_EOL_S,
PROGRAM_NAME,
- ZEROTIER_ONE_VERSION_MAJOR, ZEROTIER_ONE_VERSION_MINOR, ZEROTIER_ONE_VERSION_REVISION, ZEROTIER_ONE_VERSION_BUILD,
- ZT_BUILD_PLATFORM, ZT_BUILD_ARCHITECTURE);
+ ZEROTIER_ONE_VERSION_MAJOR, ZEROTIER_ONE_VERSION_MINOR, ZEROTIER_ONE_VERSION_REVISION, ZEROTIER_ONE_VERSION_BUILD);
fprintf(out,
COPYRIGHT_NOTICE ZT_EOL_S
LICENSE_GRANT ZT_EOL_S);
@@ -119,9 +117,6 @@ static void cliPrintHelp(const char *pn,FILE *out)
fprintf(out," leave - Leave a network" ZT_EOL_S);
fprintf(out," set - Set a network setting" ZT_EOL_S);
fprintf(out," get - Get a network setting" ZT_EOL_S);
- fprintf(out," listmoons - List moons (federated root sets)" ZT_EOL_S);
- fprintf(out," orbit - Join a moon via any member root" ZT_EOL_S);
- fprintf(out," deorbit - Leave a moon" ZT_EOL_S);
fprintf(out,ZT_EOL_S"Available settings:" ZT_EOL_S);
fprintf(out," Settings to use with [get/set] may include property names from " ZT_EOL_S);
fprintf(out," the JSON output of \"zerotier-cli -j listnetworks\". Additionally, " ZT_EOL_S);
@@ -576,80 +571,6 @@ static int cli(int argc,char **argv)
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
return 1;
}
- } else if (command == "listmoons") {
- const unsigned int scode = Http::GET(1024 * 1024 * 16,60000,(const struct sockaddr *)&addr,"/moon",requestHeaders,responseHeaders,responseBody);
-
- if (scode == 0) {
- printf("Error connecting to the ZeroTier service: %s\n\nPlease check that the service is running and that TCP port 9993 can be contacted via 127.0.0.1." ZT_EOL_S, responseBody.c_str());
- return 1;
- }
-
- nlohmann::json j;
- try {
- j = OSUtils::jsonParse(responseBody);
- } catch (std::exception &exc) {
- printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
- return 1;
- } catch ( ... ) {
- printf("%u %s invalid JSON response (unknown exception)" ZT_EOL_S,scode,command.c_str());
- return 1;
- }
-
- if (scode == 200) {
- printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str());
- return 0;
- } else {
- printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
- return 1;
- }
- } else if (command == "orbit") {
- const uint64_t worldId = Utils::hexStrToU64(arg1.c_str());
- const uint64_t seed = Utils::hexStrToU64(arg2.c_str());
- if ((worldId)&&(seed)) {
- char jsons[1024];
- OSUtils::ztsnprintf(jsons,sizeof(jsons),"{\"seed\":\"%s\"}",arg2.c_str());
- char cl[128];
- OSUtils::ztsnprintf(cl,sizeof(cl),"%u",(unsigned int)strlen(jsons));
- requestHeaders["Content-Type"] = "application/json";
- requestHeaders["Content-Length"] = cl;
- unsigned int scode = Http::POST(
- 1024 * 1024 * 16,
- 60000,
- (const struct sockaddr *)&addr,
- (std::string("/moon/") + arg1).c_str(),
- requestHeaders,
- jsons,
- (unsigned long)strlen(jsons),
- responseHeaders,
- responseBody);
- if (scode == 200) {
- printf("200 orbit OK" ZT_EOL_S);
- return 0;
- } else {
- printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
- return 1;
- }
- }
- } else if (command == "deorbit") {
- unsigned int scode = Http::DEL(
- 1024 * 1024 * 16,
- 60000,
- (const struct sockaddr *)&addr,
- (std::string("/moon/") + arg1).c_str(),
- requestHeaders,
- responseHeaders,
- responseBody);
- if (scode == 200) {
- if (json) {
- printf("%s",cliFixJsonCRs(responseBody).c_str());
- } else {
- printf("200 deorbit OK" ZT_EOL_S);
- }
- return 0;
- } else {
- printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
- return 1;
- }
} else if (command == "set") {
if (arg1.length() != 16) {
fprintf(stderr,"invalid format: must be a 16-digit (network) ID\n");
@@ -812,8 +733,6 @@ static void idtoolPrintHelp(FILE *out,const char *pn)
fprintf(out," getpublic " ZT_EOL_S);
fprintf(out," sign " ZT_EOL_S);
fprintf(out," verify " ZT_EOL_S);
- fprintf(out," initmoon " ZT_EOL_S);
- fprintf(out," genmoon " ZT_EOL_S);
}
static Identity getIdFromArg(char *arg)
@@ -855,7 +774,7 @@ static int idtool(int argc,char **argv)
Identity id;
for(;;) {
- id.generate();
+ id.generate(Identity::C25519);
if ((id.address().toInt() >> (40 - vanityBits)) == vanity) {
if (vanityBits > 0) {
fprintf(stderr,"vanity address: found %.10llx !\n",(unsigned long long)id.address().toInt());
@@ -933,9 +852,10 @@ static int idtool(int argc,char **argv)
fprintf(stderr,"%s is not readable" ZT_EOL_S,argv[3]);
return 1;
}
- C25519::Signature signature = id.sign(inf.data(),(unsigned int)inf.length());
- char hexbuf[1024];
- printf("%s",Utils::hex(signature.data,ZT_C25519_SIGNATURE_LEN,hexbuf));
+ uint8_t signature[ZT_SIGNATURE_BUFFER_SIZE];
+ const unsigned int siglen = id.sign(inf.data(),(unsigned int)inf.length(),signature,sizeof(signature));
+ char hexbuf[256];
+ printf("%s",Utils::hex(signature,siglen,hexbuf));
} else if (!strcmp(argv[1],"verify")) {
if (argc < 5) {
idtoolPrintHelp(stdout,argv[0]);
@@ -973,94 +893,6 @@ static int idtool(int argc,char **argv)
return 1;
}
}
- } else if (!strcmp(argv[1],"initmoon")) {
- if (argc < 3) {
- idtoolPrintHelp(stdout,argv[0]);
- } else {
- const Identity id = getIdFromArg(argv[2]);
- if (!id) {
- fprintf(stderr,"%s is not a valid identity" ZT_EOL_S,argv[2]);
- return 1;
- }
-
- C25519::Pair kp(C25519::generate());
-
- char idtmp[4096];
- nlohmann::json mj;
- mj["objtype"] = "world";
- mj["worldType"] = "moon";
- mj["updatesMustBeSignedBy"] = mj["signingKey"] = Utils::hex(kp.pub.data,ZT_C25519_PUBLIC_KEY_LEN,idtmp);
- mj["signingKey_SECRET"] = Utils::hex(kp.priv.data,ZT_C25519_PRIVATE_KEY_LEN,idtmp);
- mj["id"] = id.address().toString(idtmp);
- nlohmann::json seedj;
- seedj["identity"] = id.toString(false,idtmp);
- seedj["stableEndpoints"] = nlohmann::json::array();
- (mj["roots"] = nlohmann::json::array()).push_back(seedj);
- std::string mjd(OSUtils::jsonDump(mj));
-
- printf("%s" ZT_EOL_S,mjd.c_str());
- }
- } else if (!strcmp(argv[1],"genmoon")) {
- if (argc < 3) {
- idtoolPrintHelp(stdout,argv[0]);
- } else {
- std::string buf;
- if (!OSUtils::readFile(argv[2],buf)) {
- fprintf(stderr,"cannot read %s" ZT_EOL_S,argv[2]);
- return 1;
- }
- nlohmann::json mj(OSUtils::jsonParse(buf));
-
- const uint64_t id = Utils::hexStrToU64(OSUtils::jsonString(mj["id"],"0").c_str());
- if (!id) {
- fprintf(stderr,"ID in %s is invalid" ZT_EOL_S,argv[2]);
- return 1;
- }
-
- World::Type t;
- if (mj["worldType"] == "moon") {
- t = World::TYPE_MOON;
- } else if (mj["worldType"] == "planet") {
- t = World::TYPE_PLANET;
- } else {
- fprintf(stderr,"invalid worldType" ZT_EOL_S);
- return 1;
- }
-
- C25519::Pair signingKey;
- C25519::Public updatesMustBeSignedBy;
- Utils::unhex(OSUtils::jsonString(mj["signingKey"],"").c_str(),signingKey.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
- Utils::unhex(OSUtils::jsonString(mj["signingKey_SECRET"],"").c_str(),signingKey.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
- Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],"").c_str(),updatesMustBeSignedBy.data,ZT_C25519_PUBLIC_KEY_LEN);
-
- std::vector roots;
- nlohmann::json &rootsj = mj["roots"];
- if (rootsj.is_array()) {
- for(unsigned long i=0;i<(unsigned long)rootsj.size();++i) {
- nlohmann::json &r = rootsj[i];
- if (r.is_object()) {
- roots.push_back(World::Root());
- roots.back().identity = Identity(OSUtils::jsonString(r["identity"],"").c_str());
- nlohmann::json &stableEndpointsj = r["stableEndpoints"];
- if (stableEndpointsj.is_array()) {
- for(unsigned long k=0;k<(unsigned long)stableEndpointsj.size();++k)
- roots.back().stableEndpoints.push_back(InetAddress(OSUtils::jsonString(stableEndpointsj[k],"").c_str()));
- std::sort(roots.back().stableEndpoints.begin(),roots.back().stableEndpoints.end());
- }
- }
- }
- }
- std::sort(roots.begin(),roots.end());
-
- const int64_t now = OSUtils::now();
- World w(World::make(t,id,now,updatesMustBeSignedBy,roots,signingKey));
- Buffer wbuf;
- w.serialize(wbuf);
- char fn[128];
- OSUtils::ztsnprintf(fn,sizeof(fn),"%.16llx.moon",w.id());
- OSUtils::writeFile(fn,wbuf.data(),wbuf.size());
- printf("wrote %s (signed world with timestamp %llu)" ZT_EOL_S,fn,(unsigned long long)now);
- }
} else {
idtoolPrintHelp(stdout,argv[0]);
return 1;
diff --git a/rule-compiler/README.md b/attic/rule-compiler/README.md
similarity index 100%
rename from rule-compiler/README.md
rename to attic/rule-compiler/README.md
diff --git a/rule-compiler/cli.js b/attic/rule-compiler/cli.js
similarity index 100%
rename from rule-compiler/cli.js
rename to attic/rule-compiler/cli.js
diff --git a/rule-compiler/examples/capabilities-and-tags.ztrules b/attic/rule-compiler/examples/capabilities-and-tags.ztrules
similarity index 100%
rename from rule-compiler/examples/capabilities-and-tags.ztrules
rename to attic/rule-compiler/examples/capabilities-and-tags.ztrules
diff --git a/rule-compiler/package.json b/attic/rule-compiler/package.json
similarity index 100%
rename from rule-compiler/package.json
rename to attic/rule-compiler/package.json
diff --git a/rule-compiler/rule-compiler.js b/attic/rule-compiler/rule-compiler.js
similarity index 100%
rename from rule-compiler/rule-compiler.js
rename to attic/rule-compiler/rule-compiler.js
diff --git a/attic/service/CMakeLists.txt b/attic/service/CMakeLists.txt
new file mode 100644
index 00000000..bebfb2cd
--- /dev/null
+++ b/attic/service/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 2.8)
+project(zt_service)
+
+if(WIN32)
+ add_definitions(-DNOMINMAX)
+endif(WIN32)
+
+set(src
+ OneService.cpp
+)
+
+set(headers
+ OneService.hpp
+)
+
+add_library(${PROJECT_NAME} STATIC ${src} ${headers})
+target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
diff --git a/service/OneService.cpp b/attic/service/OneService.cpp
similarity index 77%
rename from service/OneService.cpp
rename to attic/service/OneService.cpp
index 69b439ae..e84da792 100644
--- a/service/OneService.cpp
+++ b/attic/service/OneService.cpp
@@ -25,8 +25,7 @@
#include
#include
-#include "../version.h"
-#include "../include/ZeroTierOne.h"
+#include "../include/ZeroTierCore.h"
#include "../node/Constants.hpp"
#include "../node/Mutex.hpp"
@@ -35,7 +34,6 @@
#include "../node/InetAddress.hpp"
#include "../node/MAC.hpp"
#include "../node/Identity.hpp"
-#include "../node/World.hpp"
#include "../node/Salsa20.hpp"
#include "../node/Poly1305.hpp"
#include "../node/SHA512.hpp"
@@ -50,7 +48,6 @@
#include "../osdep/BlockingQueue.hpp"
#include "OneService.hpp"
-#include "SoftwareUpdater.hpp"
#ifdef __WINDOWS__
#include
@@ -75,12 +72,6 @@
#include "../ext/http-parser/http_parser.h"
#endif
-#if ZT_VAULT_SUPPORT
-extern "C" {
-#include
-}
-#endif
-
#include "../ext/json/json.hpp"
using json = nlohmann::json;
@@ -92,10 +83,6 @@ using json = nlohmann::json;
#include "../osdep/WindowsEthernetTap.hpp"
#endif
-#ifndef ZT_SOFTWARE_UPDATE_DEFAULT
-#define ZT_SOFTWARE_UPDATE_DEFAULT "disable"
-#endif
-
// Sanity limits for HTTP
#define ZT_MAX_HTTP_MESSAGE_SIZE (1024 * 1024 * 64)
#define ZT_MAX_HTTP_CONNECTIONS 65536
@@ -107,62 +94,16 @@ using json = nlohmann::json;
// How often to check for new multicast subscriptions on a tap device
#define ZT_TAP_CHECK_MULTICAST_INTERVAL 5000
-// TCP fallback relay (run by ZeroTier, Inc. -- this will eventually go away)
-#ifndef ZT_SDK
-#define ZT_TCP_FALLBACK_RELAY "204.80.128.1/443"
-#endif
-
-// Frequency at which we re-resolve the TCP fallback relay
-#define ZT_TCP_FALLBACK_RERESOLVE_DELAY 86400000
-
-// Attempt to engage TCP fallback after this many ms of no reply to packets sent to global-scope IPs
-#define ZT_TCP_FALLBACK_AFTER 60000
-
// How often to check for local interface addresses
#define ZT_LOCAL_INTERFACE_CHECK_INTERVAL 60000
-// Maximum write buffer size for outgoing TCP connections (sanity limit)
-#define ZT_TCP_MAX_WRITEQ_SIZE 33554432
-
-// TCP activity timeout
-#define ZT_TCP_ACTIVITY_TIMEOUT 60000
-
-#if ZT_VAULT_SUPPORT
-size_t curlResponseWrite(void *ptr, size_t size, size_t nmemb, std::string *data)
-{
- data->append((char*)ptr, size * nmemb);
- return size * nmemb;
-}
-#endif
+// How often local.conf is checked for changes
+#define ZT_LOCAL_CONF_FILE_CHECK_INTERVAL 10000
namespace ZeroTier {
namespace {
-static const InetAddress NULL_INET_ADDR;
-
-// Fake TLS hello for TCP tunnel outgoing connections (TUNNELED mode)
-static const char ZT_TCP_TUNNEL_HELLO[9] = { 0x17,0x03,0x03,0x00,0x04,(char)ZEROTIER_ONE_VERSION_MAJOR,(char)ZEROTIER_ONE_VERSION_MINOR,(char)((ZEROTIER_ONE_VERSION_REVISION >> 8) & 0xff),(char)(ZEROTIER_ONE_VERSION_REVISION & 0xff) };
-
-static std::string _trimString(const std::string &s)
-{
- unsigned long end = (unsigned long)s.length();
- while (end) {
- char c = s[end - 1];
- if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
- --end;
- else break;
- }
- unsigned long start = 0;
- while (start < end) {
- char c = s[start];
- if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
- ++start;
- else break;
- }
- return s.substr(start,end - start);
-}
-
static void _networkToJson(nlohmann::json &nj,const ZT_VirtualNetworkConfig *nc,const std::string &portDeviceName,const OneService::NetworkSettings &localSettings)
{
char tmp[256];
@@ -300,28 +241,6 @@ static void _peerAggregateLinkToJson(nlohmann::json &pj,const ZT_Peer *peer)
pj["paths"] = pa;
}
-static void _moonToJson(nlohmann::json &mj,const World &world)
-{
- char tmp[4096];
- OSUtils::ztsnprintf(tmp,sizeof(tmp),"%.16llx",world.id());
- mj["id"] = tmp;
- mj["timestamp"] = world.timestamp();
- mj["signature"] = Utils::hex(world.signature().data,ZT_C25519_SIGNATURE_LEN,tmp);
- mj["updatesMustBeSignedBy"] = Utils::hex(world.updatesMustBeSignedBy().data,ZT_C25519_PUBLIC_KEY_LEN,tmp);
- nlohmann::json ra = nlohmann::json::array();
- for(std::vector::const_iterator r(world.roots().begin());r!=world.roots().end();++r) {
- nlohmann::json rj;
- rj["identity"] = r->identity.toString(false,tmp);
- nlohmann::json eps = nlohmann::json::array();
- for(std::vector::const_iterator a(r->stableEndpoints.begin());a!=r->stableEndpoints.end();++a)
- eps.push_back(a->toString(tmp));
- rj["stableEndpoints"] = eps;
- ra.push_back(rj);
- }
- mj["roots"] = ra;
- mj["waiting"] = false;
-}
-
class OneServiceImpl;
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,void *tptr,uint64_t nwid,void **nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf);
@@ -378,8 +297,6 @@ struct TcpConnection
enum {
TCP_UNCATEGORIZED_INCOMING, // uncategorized incoming connection
TCP_HTTP_INCOMING,
- TCP_HTTP_OUTGOING,
- TCP_TUNNEL_OUTGOING // TUNNELED mode proxy outbound connection
} type;
OneServiceImpl *parent;
@@ -401,15 +318,6 @@ struct TcpConnection
Mutex writeq_m;
};
-struct OneServiceIncomingPacket
-{
- uint64_t now;
- int64_t sock;
- struct sockaddr_storage from;
- unsigned int size;
- uint8_t data[ZT_MAX_MTU];
-};
-
class OneServiceImpl : public OneService
{
public:
@@ -424,17 +332,14 @@ public:
EmbeddedNetworkController *_controller;
Phy _phy;
Node *_node;
- SoftwareUpdater *_updater;
PhySocket *_localControlSocket4;
PhySocket *_localControlSocket6;
bool _updateAutoApply;
- bool _allowTcpFallbackRelay;
bool _allowSecondaryPort;
unsigned int _multipathMode;
unsigned int _primaryPort;
unsigned int _secondaryPort;
unsigned int _tertiaryPort;
- volatile unsigned int _udpPortPickerCounter;
// Local configuration and memo-ized information from it
json _localConfig;
@@ -448,7 +353,7 @@ public:
std::vector< std::string > _interfacePrefixBlacklist;
Mutex _localConfig_m;
- std::vector explicitBind;
+ std::vector _explicitBind;
/*
* To attempt to handle NAT/gateway craziness we use three local UDP ports:
@@ -466,9 +371,6 @@ public:
// Time we last received a packet from a global address
uint64_t _lastDirectReceiveFromGlobal;
-#ifdef ZT_TCP_FALLBACK_RELAY
- uint64_t _lastSendToGlobalV4;
-#endif
// Last potential sleep/wake event
uint64_t _lastRestart;
@@ -500,7 +402,6 @@ public:
// Active TCP/IP connections
std::vector< TcpConnection * > _tcpConnections;
Mutex _tcpConnections_m;
- TcpConnection *_tcpFallbackTunnel;
// Termination status information
ReasonForTermination _termReason;
@@ -509,17 +410,7 @@ public:
// uPnP/NAT-PMP port mapper if enabled
bool _portMappingEnabled; // local.conf settings
-#ifdef ZT_USE_MINIUPNPC
PortMapper *_portMapper;
-#endif
-
- // HashiCorp Vault Settings
-#if ZT_VAULT_SUPPORT
- bool _vaultEnabled;
- std::string _vaultURL;
- std::string _vaultToken;
- std::string _vaultPath; // defaults to cubbyhole/zerotier/identity.secret for per-access key storage
-#endif
// Set to false to force service to stop
volatile bool _run;
@@ -537,40 +428,22 @@ public:
,_controller((EmbeddedNetworkController *)0)
,_phy(this,false,true)
,_node((Node *)0)
- ,_updater((SoftwareUpdater *)0)
,_localControlSocket4((PhySocket *)0)
,_localControlSocket6((PhySocket *)0)
,_updateAutoApply(false)
,_primaryPort(port)
- ,_udpPortPickerCounter(0)
,_lastDirectReceiveFromGlobal(0)
-#ifdef ZT_TCP_FALLBACK_RELAY
- ,_lastSendToGlobalV4(0)
-#endif
,_lastRestart(0)
,_nextBackgroundTaskDeadline(0)
- ,_tcpFallbackTunnel((TcpConnection *)0)
,_termReason(ONE_STILL_RUNNING)
,_portMappingEnabled(true)
-#ifdef ZT_USE_MINIUPNPC
,_portMapper((PortMapper *)0)
-#endif
-#ifdef ZT_VAULT_SUPPORT
- ,_vaultEnabled(false)
- ,_vaultURL()
- ,_vaultToken()
- ,_vaultPath("cubbyhole/zerotier")
-#endif
,_run(true)
,_mqc(NULL)
{
_ports[0] = 0;
_ports[1] = 0;
_ports[2] = 0;
-
-#if ZT_VAULT_SUPPORT
- curl_global_init(CURL_GLOBAL_DEFAULT);
-#endif
}
virtual ~OneServiceImpl()
@@ -579,13 +452,7 @@ public:
_phy.close(_localControlSocket4);
_phy.close(_localControlSocket6);
-#if ZT_VAULT_SUPPORT
- curl_global_cleanup();
-#endif
-
-#ifdef ZT_USE_MINIUPNPC
delete _portMapper;
-#endif
delete _controller;
delete _mqc;
}
@@ -610,12 +477,11 @@ public:
OSUtils::lockDownFile(authTokenPath.c_str(),false);
}
}
- _authToken = _trimString(_authToken);
+ _authToken = OSUtils::trimString(_authToken);
}
{
struct ZT_Node_Callbacks cb;
- cb.version = 0;
cb.stateGetFunction = SnodeStateGetFunction;
cb.statePutFunction = SnodeStatePutFunction;
cb.wirePacketSendFunction = SnodeWirePacketSendFunction;
@@ -691,7 +557,6 @@ public:
}
}
-#ifdef ZT_USE_MINIUPNPC
if (_portMappingEnabled) {
// If we're running uPnP/NAT-PMP, bind a *third* port for that. We can't
// use the other two ports for that because some NATs do really funky
@@ -715,14 +580,13 @@ public:
}
}
}
-#endif
// Delete legacy iddb.d if present (cleanup)
OSUtils::rmDashRf((_homePath + ZT_PATH_SEPARATOR_S "iddb.d").c_str());
// Network controller is now enabled by default for desktop and server
_controller = new EmbeddedNetworkController(_node,_homePath.c_str(),_controllerDbPath.c_str(),_ports[0], _mqc);
- _node->setNetconfMaster((void *)_controller);
+ _node->setController((void *)_controller);
// Join existing networks in networks.d
{
@@ -734,23 +598,12 @@ public:
}
}
- // Orbit existing moons in moons.d
- {
- std::vector moonsDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S "moons.d").c_str()));
- for(std::vector::iterator f(moonsDotD.begin());f!=moonsDotD.end();++f) {
- std::size_t dot = f->find_last_of('.');
- if ((dot == 16)&&(f->substr(16) == ".moon"))
- _node->orbit((void *)0,Utils::hexStrToU64(f->substr(0,dot).c_str()),0);
- }
- }
-
// Main I/O loop
_nextBackgroundTaskDeadline = 0;
int64_t clockShouldBe = OSUtils::now();
_lastRestart = clockShouldBe;
int64_t lastTapMulticastGroupCheck = 0;
int64_t lastBindRefresh = 0;
- int64_t lastUpdateCheck = clockShouldBe;
int64_t lastMultipathModeUpdate = 0;
int64_t lastCleanedPeersDb = 0;
int64_t lastLocalInterfaceAddressCheck = (clockShouldBe - ZT_LOCAL_INTERFACE_CHECK_INTERVAL) + 15000; // do this in 15s to give portmapper time to configure and other things time to settle
@@ -776,13 +629,6 @@ public:
restarted = true;
}
- // Check for updates (if enabled)
- if ((_updater)&&((now - lastUpdateCheck) > 10000)) {
- lastUpdateCheck = now;
- if (_updater->check(now) && _updateAutoApply)
- _updater->apply();
- }
-
// Reload local.conf if anything changed recently
if ((now - lastLocalConfFileCheck) >= ZT_LOCAL_CONF_FILE_CHECK_INTERVAL) {
lastLocalConfFileCheck = now;
@@ -805,7 +651,7 @@ public:
if (_ports[i])
p[pc++] = _ports[i];
}
- _binder.refresh(_phy,p,pc,explicitBind,*this);
+ _binder.refresh(_phy,p,pc,_explicitBind,*this);
{
Mutex::Lock _l(_nets_m);
for(std::map::iterator n(_nets.begin());n!=_nets.end();++n) {
@@ -827,10 +673,6 @@ public:
dl = _nextBackgroundTaskDeadline;
}
- // Close TCP fallback tunnel if we have direct UDP
- if ((_tcpFallbackTunnel)&&((now - _lastDirectReceiveFromGlobal) < (ZT_TCP_FALLBACK_AFTER / 2)))
- _phy.close(_tcpFallbackTunnel->sock);
-
// Sync multicast group memberships
if ((now - lastTapMulticastGroupCheck) >= ZT_TAP_CHECK_MULTICAST_INTERVAL) {
lastTapMulticastGroupCheck = now;
@@ -859,13 +701,11 @@ public:
_node->clearLocalInterfaceAddresses();
-#ifdef ZT_USE_MINIUPNPC
if (_portMapper) {
std::vector mappedAddresses(_portMapper->get());
for(std::vector::const_iterator ext(mappedAddresses.begin());ext!=mappedAddresses.end();++ext)
_node->addLocalInterfaceAddress(reinterpret_cast(&(*ext)));
}
-#endif
std::vector boundAddrs(_binder.allBoundLocalInterfaceAddresses());
for(std::vector::const_iterator i(boundAddrs.begin());i!=boundAddrs.end();++i)
@@ -903,8 +743,6 @@ public:
_nets.clear();
}
- delete _updater;
- _updater = (SoftwareUpdater *)0;
delete _node;
_node = (Node *)0;
@@ -1003,7 +841,7 @@ public:
if (ips.length() > 0) {
InetAddress ip(ips.c_str());
if ((ip.ss_family == AF_INET)||(ip.ss_family == AF_INET6))
- explicitBind.push_back(ip);
+ _explicitBind.push_back(ip);
}
}
}
@@ -1199,7 +1037,6 @@ public:
res["address"] = tmp;
res["publicIdentity"] = status.publicIdentity;
res["online"] = (bool)(status.online != 0);
- res["tcpFallbackActive"] = (_tcpFallbackTunnel != (TcpConnection *)0);
res["versionMajor"] = ZEROTIER_ONE_VERSION_MAJOR;
res["versionMinor"] = ZEROTIER_ONE_VERSION_MINOR;
res["versionRev"] = ZEROTIER_ONE_VERSION_REVISION;
@@ -1214,7 +1051,6 @@ public:
}
json &settings = res["config"]["settings"];
settings["primaryPort"] = OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff;
- settings["allowTcpFallbackRelay"] = OSUtils::jsonBool(settings["allowTcpFallbackRelay"],_allowTcpFallbackRelay);
if (_multipathMode) {
json &multipathConfig = res["multipath"];
@@ -1232,46 +1068,9 @@ public:
}
}
-#ifdef ZT_USE_MINIUPNPC
settings["portMappingEnabled"] = OSUtils::jsonBool(settings["portMappingEnabled"],true);
-#else
- settings["portMappingEnabled"] = false; // not supported in build
-#endif
-#ifndef ZT_SDK
- settings["softwareUpdate"] = OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT);
- settings["softwareUpdateChannel"] = OSUtils::jsonString(settings["softwareUpdateChannel"],ZT_SOFTWARE_UPDATE_DEFAULT_CHANNEL);
-#endif
- const World planet(_node->planet());
- res["planetWorldId"] = planet.id();
- res["planetWorldTimestamp"] = planet.timestamp();
scode = 200;
- } else if (ps[0] == "moon") {
- std::vector moons(_node->moons());
- if (ps.size() == 1) {
- // Return [array] of all moons
-
- res = json::array();
- for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) {
- json mj;
- _moonToJson(mj,*m);
- res.push_back(mj);
- }
-
- scode = 200;
- } else {
- // Return a single moon by ID
-
- const uint64_t id = Utils::hexStrToU64(ps[1].c_str());
- for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) {
- if (m->id() == id) {
- _moonToJson(res,*m);
- scode = 200;
- break;
- }
- }
-
- }
} else if (ps[0] == "network") {
ZT_VirtualNetworkList *nws = _node->networks();
if (nws) {
@@ -1344,44 +1143,7 @@ public:
} else if ((httpMethod == HTTP_POST)||(httpMethod == HTTP_PUT)) {
if (isAuth) {
- if (ps[0] == "moon") {
- if (ps.size() == 2) {
-
- uint64_t seed = 0;
- try {
- json j(OSUtils::jsonParse(body));
- if (j.is_object()) {
- seed = Utils::hexStrToU64(OSUtils::jsonString(j["seed"],"0").c_str());
- }
- } catch (std::exception &exc) {
- } catch ( ... ) {
- }
-
- std::vector moons(_node->moons());
- const uint64_t id = Utils::hexStrToU64(ps[1].c_str());
- for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) {
- if (m->id() == id) {
- _moonToJson(res,*m);
- scode = 200;
- break;
- }
- }
-
- if ((scode != 200)&&(seed != 0)) {
- char tmp[64];
- OSUtils::ztsnprintf(tmp,sizeof(tmp),"%.16llx",id);
- res["id"] = tmp;
- res["roots"] = json::array();
- res["timestamp"] = 0;
- res["signature"] = json();
- res["updatesMustBeSignedBy"] = json();
- res["waiting"] = true;
- _node->orbit((void *)0,id,seed);
- scode = 200;
- }
-
- } else scode = 404;
- } else if (ps[0] == "network") {
+ if (ps[0] == "network") {
if (ps.size() == 2) {
uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str());
@@ -1428,13 +1190,7 @@ public:
} else if (httpMethod == HTTP_DELETE) {
if (isAuth) {
- if (ps[0] == "moon") {
- if (ps.size() == 2) {
- _node->deorbit((void *)0,Utils::hexStrToU64(ps[1].c_str()));
- res["result"] = true;
- scode = 200;
- } // else 404
- } else if (ps[0] == "network") {
+ if (ps[0] == "network") {
ZT_VirtualNetworkList *nws = _node->networks();
if (nws) {
if (ps.size() == 2) {
@@ -1559,7 +1315,6 @@ public:
json &settings = lc["settings"];
_primaryPort = (unsigned int)OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff;
- _allowTcpFallbackRelay = OSUtils::jsonBool(settings["allowTcpFallbackRelay"],true);
_allowSecondaryPort = OSUtils::jsonBool(settings["allowSecondaryPort"],true);
_secondaryPort = (unsigned int)OSUtils::jsonInt(settings["secondaryPort"],0);
_tertiaryPort = (unsigned int)OSUtils::jsonInt(settings["tertiaryPort"],0);
@@ -1567,28 +1322,8 @@ public:
fprintf(stderr,"WARNING: using manually-specified ports. This can cause NAT issues." ZT_EOL_S);
}
_multipathMode = (unsigned int)OSUtils::jsonInt(settings["multipathMode"],0);
- if (_multipathMode != 0 && _allowTcpFallbackRelay) {
- fprintf(stderr,"WARNING: multipathMode cannot be used with allowTcpFallbackRelay. Disabling allowTcpFallbackRelay" ZT_EOL_S);
- _allowTcpFallbackRelay = false;
- }
_portMappingEnabled = OSUtils::jsonBool(settings["portMappingEnabled"],true);
-#ifndef ZT_SDK
- const std::string up(OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT));
- const bool udist = OSUtils::jsonBool(settings["softwareUpdateDist"],false);
- if (((up == "apply")||(up == "download"))||(udist)) {
- if (!_updater)
- _updater = new SoftwareUpdater(*_node,_homePath);
- _updateAutoApply = (up == "apply");
- _updater->setUpdateDistribution(udist);
- _updater->setChannel(OSUtils::jsonString(settings["softwareUpdateChannel"],ZT_SOFTWARE_UPDATE_DEFAULT_CHANNEL));
- } else {
- delete _updater;
- _updater = (SoftwareUpdater *)0;
- _updateAutoApply = false;
- }
-#endif
-
json &ignoreIfs = settings["interfacePrefixBlacklist"];
if (ignoreIfs.is_array()) {
for(unsigned long i=0;i(&(n.config.routes[i].target));
const InetAddress *const via = reinterpret_cast(&(n.config.routes[i].via));
- const InetAddress *src = NULL;
- for (unsigned int j=0; j(&(n.config.assignedAddresses[j]));
- if (target->isV4() && tmp->isV4()) {
- src = reinterpret_cast(&(n.config.assignedAddresses[j]));
- break;
- } else if (target->isV6() && tmp->isV6()) {
- src = reinterpret_cast(&(n.config.assignedAddresses[j]));
- break;
- }
- }
- if (!src)
- src = &NULL_INET_ADDR;
-
if ( (!checkIfManagedIsAllowed(n,*target)) || ((via->ss_family == target->ss_family)&&(matchIpOnly(myIps,*via))) )
continue;
@@ -1807,7 +1487,7 @@ public:
continue;
// Add and apply new routes
- n.managedRoutes.push_back(SharedPtr(new ManagedRoute(*target,*via,*src,tapdev)));
+ n.managedRoutes.push_back(SharedPtr(new ManagedRoute(*target,*via,tapdev)));
if (!n.managedRoutes.back()->sync())
n.managedRoutes.pop_back();
#endif
@@ -1837,26 +1517,7 @@ public:
inline void phyOnTcpConnect(PhySocket *sock,void **uptr,bool success)
{
- if (!success) {
- phyOnTcpClose(sock,uptr);
- return;
- }
-
- TcpConnection *const tc = reinterpret_cast(*uptr);
- if (!tc) { // sanity check
- _phy.close(sock,true);
- return;
- }
- tc->sock = sock;
-
- if (tc->type == TcpConnection::TCP_TUNNEL_OUTGOING) {
- if (_tcpFallbackTunnel)
- _phy.close(_tcpFallbackTunnel->sock);
- _tcpFallbackTunnel = tc;
- _phy.streamSend(sock,ZT_TCP_TUNNEL_HELLO,sizeof(ZT_TCP_TUNNEL_HELLO));
- } else {
- _phy.close(sock,true);
- }
+ _phy.close(sock,true);
}
inline void phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from)
@@ -1895,9 +1556,6 @@ public:
{
TcpConnection *tc = (TcpConnection *)*uptr;
if (tc) {
- if (tc == _tcpFallbackTunnel) {
- _tcpFallbackTunnel = (TcpConnection *)0;
- }
{
Mutex::Lock _l(_tcpConnections_m);
_tcpConnections.erase(std::remove(_tcpConnections.begin(),_tcpConnections.end(),tc),_tcpConnections.end());
@@ -1954,86 +1612,11 @@ public:
return;
case TcpConnection::TCP_HTTP_INCOMING:
- case TcpConnection::TCP_HTTP_OUTGOING:
http_parser_execute(&(tc->parser),&HTTP_PARSER_SETTINGS,(const char *)data,len);
if ((tc->parser.upgrade)||(tc->parser.http_errno != HPE_OK))
_phy.close(sock);
return;
- case TcpConnection::TCP_TUNNEL_OUTGOING:
- tc->readq.append((const char *)data,len);
- while (tc->readq.length() >= 5) {
- const char *data = tc->readq.data();
- const unsigned long mlen = ( ((((unsigned long)data[3]) & 0xff) << 8) | (((unsigned long)data[4]) & 0xff) );
- if (tc->readq.length() >= (mlen + 5)) {
- InetAddress from;
-
- unsigned long plen = mlen; // payload length, modified if there's an IP header
- data += 5; // skip forward past pseudo-TLS junk and mlen
- if (plen == 4) {
- // Hello message, which isn't sent by proxy and would be ignored by client
- } else if (plen) {
- // Messages should contain IPv4 or IPv6 source IP address data
- switch(data[0]) {
- case 4: // IPv4
- if (plen >= 7) {
- from.set((const void *)(data + 1),4,((((unsigned int)data[5]) & 0xff) << 8) | (((unsigned int)data[6]) & 0xff));
- data += 7; // type + 4 byte IP + 2 byte port
- plen -= 7;
- } else {
- _phy.close(sock);
- return;
- }
- break;
- case 6: // IPv6
- if (plen >= 19) {
- from.set((const void *)(data + 1),16,((((unsigned int)data[17]) & 0xff) << 8) | (((unsigned int)data[18]) & 0xff));
- data += 19; // type + 16 byte IP + 2 byte port
- plen -= 19;
- } else {
- _phy.close(sock);
- return;
- }
- break;
- case 0: // none/omitted
- ++data;
- --plen;
- break;
- default: // invalid address type
- _phy.close(sock);
- return;
- }
-
- if (from) {
- InetAddress fakeTcpLocalInterfaceAddress((uint32_t)0xffffffff,0xffff);
- const ZT_ResultCode rc = _node->processWirePacket(
- (void *)0,
- OSUtils::now(),
- -1,
- reinterpret_cast(&from),
- data,
- plen,
- &_nextBackgroundTaskDeadline);
- if (ZT_ResultCode_isFatal(rc)) {
- char tmp[256];
- OSUtils::ztsnprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket: %d",(int)rc);
- Mutex::Lock _l(_termReason_m);
- _termReason = ONE_UNRECOVERABLE_ERROR;
- _fatalErrorMessage = tmp;
- this->terminate();
- _phy.close(sock);
- return;
- }
- }
- }
-
- if (tc->readq.length() > (mlen + 5))
- tc->readq.erase(tc->readq.begin(),tc->readq.begin() + (mlen + 5));
- else tc->readq.clear();
- } else break;
- }
- return;
-
}
} catch (std::exception &exc) {
_phy.close(sock);
@@ -2204,12 +1787,6 @@ public:
inline void nodeEventCallback(enum ZT_Event event,const void *metaData)
{
switch(event) {
- case ZT_EVENT_FATAL_ERROR_IDENTITY_COLLISION: {
- Mutex::Lock _l(_termReason_m);
- _termReason = ONE_IDENTITY_COLLISION;
- _fatalErrorMessage = "identity/address collision";
- this->terminate();
- } break;
case ZT_EVENT_TRACE: {
if (metaData) {
@@ -2218,106 +1795,18 @@ public:
}
} break;
- case ZT_EVENT_USER_MESSAGE: {
- const ZT_UserMessage *um = reinterpret_cast(metaData);
- if ((um->typeId == ZT_SOFTWARE_UPDATE_USER_MESSAGE_TYPE)&&(_updater)) {
- _updater->handleSoftwareUpdateUserMessage(um->origin,um->data,um->length);
- }
- } break;
-
case ZT_EVENT_REMOTE_TRACE: {
- const ZT_RemoteTrace *rt = reinterpret_cast(metaData);
- if ((rt)&&(rt->len > 0)&&(rt->len <= ZT_MAX_REMOTE_TRACE_SIZE)&&(rt->data))
- _controller->handleRemoteTrace(*rt);
+ // TODO
}
default:
break;
+
}
}
-#if ZT_VAULT_SUPPORT
- inline bool nodeVaultPutIdentity(enum ZT_StateObjectType type, const void *data, int len)
- {
- bool retval = false;
- if (type != ZT_STATE_OBJECT_IDENTITY_PUBLIC && type != ZT_STATE_OBJECT_IDENTITY_SECRET) {
- return retval;
- }
-
- CURL *curl = curl_easy_init();
- if (curl) {
- char token[512] = { 0 };
- snprintf(token, sizeof(token), "X-Vault-Token: %s", _vaultToken.c_str());
-
- struct curl_slist *chunk = NULL;
- chunk = curl_slist_append(chunk, token);
-
-
- char content_type[512] = { 0 };
- snprintf(content_type, sizeof(content_type), "Content-Type: application/json");
-
- chunk = curl_slist_append(chunk, content_type);
-
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
-
- char url[2048] = { 0 };
- snprintf(url, sizeof(url), "%s/v1/%s", _vaultURL.c_str(), _vaultPath.c_str());
-
- curl_easy_setopt(curl, CURLOPT_URL, url);
-
- json d = json::object();
- if (type == ZT_STATE_OBJECT_IDENTITY_PUBLIC) {
- std::string key((const char*)data, len);
- d["public"] = key;
- }
- else if (type == ZT_STATE_OBJECT_IDENTITY_SECRET) {
- std::string key((const char*)data, len);
- d["secret"] = key;
- }
-
- if (!d.empty()) {
- std::string post = d.dump();
-
- if (!post.empty()) {
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post.length());
-
-#ifndef NDEBUG
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-#endif
-
- CURLcode res = curl_easy_perform(curl);
- if (res == CURLE_OK) {
- long response_code = 0;
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
- if (response_code == 200 || response_code == 204) {
- retval = true;
- }
- }
- }
- }
-
- curl_easy_cleanup(curl);
- curl = NULL;
- curl_slist_free_all(chunk);
- chunk = NULL;
- }
-
- return retval;
- }
-#endif
-
inline void nodeStatePutFunction(enum ZT_StateObjectType type,const uint64_t id[2],const void *data,int len)
{
-#if ZT_VAULT_SUPPORT
- if (_vaultEnabled && (type == ZT_STATE_OBJECT_IDENTITY_SECRET || type == ZT_STATE_OBJECT_IDENTITY_PUBLIC)) {
- if (nodeVaultPutIdentity(type, data, len)) {
- // value successfully written to Vault
- return;
- }
- // else fallback to disk
- }
-#endif
char p[1024];
FILE *f;
bool secure = false;
@@ -2332,13 +1821,6 @@ public:
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.secret",_homePath.c_str());
secure = true;
break;
- case ZT_STATE_OBJECT_PLANET:
- OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "planet",_homePath.c_str());
- break;
- case ZT_STATE_OBJECT_MOON:
- OSUtils::ztsnprintf(dirname,sizeof(dirname),"%s" ZT_PATH_SEPARATOR_S "moons.d",_homePath.c_str());
- OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "%.16llx.moon",dirname,(unsigned long long)id[0]);
- break;
case ZT_STATE_OBJECT_NETWORK_CONFIG:
OSUtils::ztsnprintf(dirname,sizeof(dirname),"%s" ZT_PATH_SEPARATOR_S "networks.d",_homePath.c_str());
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "%.16llx.conf",dirname,(unsigned long long)id[0]);
@@ -2348,6 +1830,9 @@ public:
OSUtils::ztsnprintf(dirname,sizeof(dirname),"%s" ZT_PATH_SEPARATOR_S "peers.d",_homePath.c_str());
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "%.10llx.peer",dirname,(unsigned long long)id[0]);
break;
+ case ZT_STATE_OBJECT_ROOT_LIST:
+ OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "roots",_homePath.c_str());
+ break;
default:
return;
}
@@ -2389,93 +1874,8 @@ public:
}
}
-#if ZT_VAULT_SUPPORT
- inline int nodeVaultGetIdentity(enum ZT_StateObjectType type, void *data, unsigned int maxlen)
- {
- if (type != ZT_STATE_OBJECT_IDENTITY_SECRET && type != ZT_STATE_OBJECT_IDENTITY_PUBLIC) {
- return -1;
- }
-
- int ret = -1;
- CURL *curl = curl_easy_init();
- if (curl) {
- char token[512] = { 0 };
- snprintf(token, sizeof(token), "X-Vault-Token: %s", _vaultToken.c_str());
-
- struct curl_slist *chunk = NULL;
- chunk = curl_slist_append(chunk, token);
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
-
- char url[2048] = { 0 };
- snprintf(url, sizeof(url), "%s/v1/%s", _vaultURL.c_str(), _vaultPath.c_str());
-
- curl_easy_setopt(curl, CURLOPT_URL, url);
-
- std::string response;
- std::string res_headers;
-
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curlResponseWrite);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
- curl_easy_setopt(curl, CURLOPT_HEADERDATA, &res_headers);
-
-#ifndef NDEBUG
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-#endif
-
- CURLcode res = curl_easy_perform(curl);
-
- if (res == CURLE_OK) {
- long response_code = 0;
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
- if (response_code == 200) {
- try {
- json payload = json::parse(response);
- if (!payload["data"].is_null()) {
- json &d = payload["data"];
- if (type == ZT_STATE_OBJECT_IDENTITY_SECRET) {
- std::string secret = OSUtils::jsonString(d["secret"],"");
-
- if (!secret.empty()) {
- ret = (int)secret.length();
- memcpy(data, secret.c_str(), ret);
- }
- }
- else if (type == ZT_STATE_OBJECT_IDENTITY_PUBLIC) {
- std::string pub = OSUtils::jsonString(d["public"],"");
-
- if (!pub.empty()) {
- ret = (int)pub.length();
- memcpy(data, pub.c_str(), ret);
- }
- }
- }
- }
- catch (...) {
- ret = -1;
- }
- }
- }
-
- curl_easy_cleanup(curl);
- curl = NULL;
- curl_slist_free_all(chunk);
- chunk = NULL;
- }
- return ret;
- }
-#endif
-
inline int nodeStateGetFunction(enum ZT_StateObjectType type,const uint64_t id[2],void *data,unsigned int maxlen)
{
-#if ZT_VAULT_SUPPORT
- if (_vaultEnabled && (type == ZT_STATE_OBJECT_IDENTITY_SECRET || type == ZT_STATE_OBJECT_IDENTITY_PUBLIC) ) {
- int retval = nodeVaultGetIdentity(type, data, maxlen);
- if (retval >= 0)
- return retval;
-
- // else continue file based lookup
- }
-#endif
char p[4096];
switch(type) {
case ZT_STATE_OBJECT_IDENTITY_PUBLIC:
@@ -2484,12 +1884,6 @@ public:
case ZT_STATE_OBJECT_IDENTITY_SECRET:
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.secret",_homePath.c_str());
break;
- case ZT_STATE_OBJECT_PLANET:
- OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "planet",_homePath.c_str());
- break;
- case ZT_STATE_OBJECT_MOON:
- OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "moons.d" ZT_PATH_SEPARATOR_S "%.16llx.moon",_homePath.c_str(),(unsigned long long)id[0]);
- break;
case ZT_STATE_OBJECT_NETWORK_CONFIG:
OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.conf",_homePath.c_str(),(unsigned long long)id[0]);
break;
@@ -2503,17 +1897,6 @@ public:
if (f) {
int n = (int)fread(data,1,maxlen,f);
fclose(f);
-#if ZT_VAULT_SUPPORT
- if (_vaultEnabled && (type == ZT_STATE_OBJECT_IDENTITY_SECRET || type == ZT_STATE_OBJECT_IDENTITY_PUBLIC)) {
- // If we've gotten here while Vault is enabled, Vault does not know the key and it's been
- // read from disk instead.
- //
- // We should put the value in Vault and remove the local file.
- if (nodeVaultPutIdentity(type, data, n)) {
- unlink(p);
- }
- }
-#endif
if (n >= 0)
return n;
}
@@ -2522,68 +1905,6 @@ public:
inline int nodeWirePacketSendFunction(const int64_t localSocket,const struct sockaddr_storage *addr,const void *data,unsigned int len,unsigned int ttl)
{
-#ifdef ZT_TCP_FALLBACK_RELAY
- if(_allowTcpFallbackRelay) {
- if (addr->ss_family == AF_INET) {
- // TCP fallback tunnel support, currently IPv4 only
- if ((len >= 16)&&(reinterpret_cast(addr)->ipScope() == InetAddress::IP_SCOPE_GLOBAL)) {
- // Engage TCP tunnel fallback if we haven't received anything valid from a global
- // IP address in ZT_TCP_FALLBACK_AFTER milliseconds. If we do start getting
- // valid direct traffic we'll stop using it and close the socket after a while.
- const int64_t now = OSUtils::now();
- if (((now - _lastDirectReceiveFromGlobal) > ZT_TCP_FALLBACK_AFTER)&&((now - _lastRestart) > ZT_TCP_FALLBACK_AFTER)) {
- if (_tcpFallbackTunnel) {
- bool flushNow = false;
- {
- Mutex::Lock _l(_tcpFallbackTunnel->writeq_m);
- if (_tcpFallbackTunnel->writeq.size() < (1024 * 64)) {
- if (_tcpFallbackTunnel->writeq.length() == 0) {
- _phy.setNotifyWritable(_tcpFallbackTunnel->sock,true);
- flushNow = true;
- }
- const unsigned long mlen = len + 7;
- _tcpFallbackTunnel->writeq.push_back((char)0x17);
- _tcpFallbackTunnel->writeq.push_back((char)0x03);
- _tcpFallbackTunnel->writeq.push_back((char)0x03); // fake TLS 1.2 header
- _tcpFallbackTunnel->writeq.push_back((char)((mlen >> 8) & 0xff));
- _tcpFallbackTunnel->writeq.push_back((char)(mlen & 0xff));
- _tcpFallbackTunnel->writeq.push_back((char)4); // IPv4
- _tcpFallbackTunnel->writeq.append(reinterpret_cast(reinterpret_cast(&(reinterpret_cast(addr)->sin_addr.s_addr))),4);
- _tcpFallbackTunnel->writeq.append(reinterpret_cast(reinterpret_cast(&(reinterpret_cast(addr)->sin_port))),2);
- _tcpFallbackTunnel->writeq.append((const char *)data,len);
- }
- }
- if (flushNow) {
- void *tmpptr = (void *)_tcpFallbackTunnel;
- phyOnTcpWritable(_tcpFallbackTunnel->sock,&tmpptr);
- }
- } else if (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER)&&((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2))) {
- const InetAddress addr(ZT_TCP_FALLBACK_RELAY);
- TcpConnection *tc = new TcpConnection();
- {
- Mutex::Lock _l(_tcpConnections_m);
- _tcpConnections.push_back(tc);
- }
- tc->type = TcpConnection::TCP_TUNNEL_OUTGOING;
- tc->remoteAddr = addr;
- tc->lastReceive = OSUtils::now();
- tc->parent = this;
- tc->sock = (PhySocket *)0; // set in connect handler
- tc->messageSize = 0;
- bool connected = false;
- _phy.tcpConnect(reinterpret_cast(&addr),connected,(void *)tc,true);
- }
- }
- _lastSendToGlobalV4 = now;
- }
- }
- }
-#endif // ZT_TCP_FALLBACK_RELAY
-
- // Even when relaying we still send via UDP. This way if UDP starts
- // working we can instantly "fail forward" to it and stop using TCP
- // proxy fallback, which is slow.
-
if ((localSocket != -1)&&(localSocket != 0)&&(_binder.isUdpSocketValid((PhySocket *)((uintptr_t)localSocket)))) {
if ((ttl)&&(addr->ss_family == AF_INET)) _phy.setIp4UdpTtl((PhySocket *)((uintptr_t)localSocket),ttl);
const bool r = _phy.udpSend((PhySocket *)((uintptr_t)localSocket),(const struct sockaddr *)addr,data,len);
@@ -2658,7 +1979,7 @@ public:
{
const Hashtable< uint64_t,std::vector > *lh = (const Hashtable< uint64_t,std::vector > *)0;
if (family < 0)
- lh = (_node->prng() & 1) ? &_v4Hints : &_v6Hints;
+ lh = (Utils::random() & 1) ? &_v4Hints : &_v6Hints;
else if (family == AF_INET)
lh = &_v4Hints;
else if (family == AF_INET6)
@@ -2666,7 +1987,7 @@ public:
else return 0;
const std::vector *l = lh->get(ztaddr);
if ((l)&&(l->size() > 0)) {
- memcpy(result,&((*l)[(unsigned long)_node->prng() % l->size()]),sizeof(struct sockaddr_storage));
+ memcpy(result,&((*l)[(unsigned long)Utils::random() % l->size()]),sizeof(struct sockaddr_storage));
return 1;
} else return 0;
}
diff --git a/service/OneService.hpp b/attic/service/OneService.hpp
similarity index 100%
rename from service/OneService.hpp
rename to attic/service/OneService.hpp
diff --git a/service/README.md b/attic/service/README.md
similarity index 100%
rename from service/README.md
rename to attic/service/README.md
diff --git a/update_controllers.sh b/attic/update_controllers.sh
similarity index 100%
rename from update_controllers.sh
rename to attic/update_controllers.sh
diff --git a/windows-clean.bat b/attic/windows-clean.bat
similarity index 100%
rename from windows-clean.bat
rename to attic/windows-clean.bat
diff --git a/attic/world/README.md b/attic/world/README.md
deleted file mode 100644
index dda4920a..00000000
--- a/attic/world/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-World Definitions and Generator Code
-======
-
-This little bit of code is used to generate world updates. Ordinary users probably will never need this unless they want to test or experiment.
-
-See mkworld.cpp for documentation. To build from this directory use 'source ./build.sh'.
-
diff --git a/attic/world/build.sh b/attic/world/build.sh
deleted file mode 100755
index d8800cd4..00000000
--- a/attic/world/build.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-c++ -std=c++11 -I../.. -I.. -g -o mkworld ../../node/C25519.cpp ../../node/Salsa20.cpp ../../node/SHA512.cpp ../../node/Identity.cpp ../../node/Utils.cpp ../../node/InetAddress.cpp ../../osdep/OSUtils.cpp mkworld.cpp -lm
diff --git a/attic/world/mkworld.cpp b/attic/world/mkworld.cpp
deleted file mode 100644
index 6b9bbe8d..00000000
--- a/attic/world/mkworld.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * ZeroTier One - Network Virtualization Everywhere
- * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/*
- * This utility makes the World from the configuration specified below.
- * It probably won't be much use to anyone outside ZeroTier, Inc. except
- * for testing and experimentation purposes.
- *
- * If you want to make your own World you must edit this file.
- *
- * When run, it expects two files in the current directory:
- *
- * previous.c25519 - key pair to sign this world (key from previous world)
- * current.c25519 - key pair whose public key should be embedded in this world
- *
- * If these files do not exist, they are both created with the same key pair
- * and a self-signed initial World is born.
- */
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace ZeroTier;
-
-int main(int argc,char **argv)
-{
- std::string previous,current;
- if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
- C25519::Pair np(C25519::generate());
- previous = std::string();
- previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
- previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
- current = previous;
- OSUtils::writeFile("previous.c25519",previous);
- OSUtils::writeFile("current.c25519",current);
- fprintf(stderr,"INFO: created initial world keys: previous.c25519 and current.c25519 (both initially the same)" ZT_EOL_S);
- }
-
- if ((previous.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))||(current.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))) {
- fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S);
- return 1;
- }
- C25519::Pair previousKP;
- memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
- memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
- C25519::Pair currentKP;
- memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
- memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
-
- // =========================================================================
- // EDIT BELOW HERE
-
- std::vector roots;
-
- const uint64_t id = ZT_WORLD_ID_EARTH;
- const uint64_t ts = 1567191349589ULL; // August 30th, 2019
-
- // Los Angeles
- roots.push_back(World::Root());
- roots.back().identity = Identity("3a46f1bf30:0:76e66fab33e28549a62ee2064d1843273c2c300ba45c3f20bef02dbad225723bb59a9bb4b13535730961aeecf5a163ace477cceb0727025b99ac14a5166a09a3");
- roots.back().stableEndpoints.push_back(InetAddress("185.180.13.82/9993"));
- roots.back().stableEndpoints.push_back(InetAddress("2a02:6ea0:c815::/9993"));
-
- // Miami
- roots.push_back(World::Root());
- roots.back().identity = Identity("de8950a8b2:0:1b3ada8251b91b6b6fa6535b8c7e2460918f4f729abdec97d3c7f3796868fb02f0de0b0ee554b2d59fc3524743eebfcf5315e790ed6d92db5bd10c28c09b40ef");
- roots.back().stableEndpoints.push_back(InetAddress("207.246.73.245/443"));
- roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:9002:5cb:ec4:7aff:fe8f:69d9/443"));
-
- // Tokyo
- roots.push_back(World::Root());
- roots.back().identity = Identity("34e0a5e174:0:93efb50934788f856d5cfb9ca5be88e85b40965586b75befac900df77352c145a1ba7007569d37c77bfe52c0999f3bdc67a47a4a6000b720a883ce47aa2fb7f8");
- roots.back().stableEndpoints.push_back(InetAddress("147.75.92.2/443"));
- roots.back().stableEndpoints.push_back(InetAddress("2604:1380:3000:7100::1/443"));
-
- // Amsterdam
- roots.push_back(World::Root());
- roots.back().identity = Identity("992fcf1db7:0:206ed59350b31916f749a1f85dffb3a8787dcbf83b8c6e9448d4e3ea0e3369301be716c3609344a9d1533850fb4460c50af43322bcfc8e13d3301a1f1003ceb6");
- roots.back().stableEndpoints.push_back(InetAddress("195.181.173.159/443"));
- roots.back().stableEndpoints.push_back(InetAddress("2a02:6ea0:c024::/443"));
-
- // Alice
- //roots.push_back(World::Root());
- //roots.back().identity = Identity("9d219039f3:0:01f0922a98e3b34ebcbff333269dc265d7a020aab69d72be4d4acc9c8c9294785771256cd1d942a90d1bd1d2dca3ea84ef7d85afe6611fb43ff0b74126d90a6e");
- //roots.back().stableEndpoints.push_back(InetAddress("188.166.94.177/9993")); // Amsterdam
- //roots.back().stableEndpoints.push_back(InetAddress("2a03:b0c0:2:d0::7d:1/9993")); // Amsterdam
- //roots.back().stableEndpoints.push_back(InetAddress("154.66.197.33/9993")); // Johannesburg
- //roots.back().stableEndpoints.push_back(InetAddress("2c0f:f850:154:197::33/9993")); // Johannesburg
- //roots.back().stableEndpoints.push_back(InetAddress("159.203.97.171/9993")); // New York
- //roots.back().stableEndpoints.push_back(InetAddress("2604:a880:800:a1::54:6001/9993")); // New York
- //roots.back().stableEndpoints.push_back(InetAddress("131.255.6.16/9993")); // Buenos Aires
- //roots.back().stableEndpoints.push_back(InetAddress("2803:eb80:0:e::2/9993")); // Buenos Aires
- //roots.back().stableEndpoints.push_back(InetAddress("107.170.197.14/9993")); // San Francisco
- //roots.back().stableEndpoints.push_back(InetAddress("2604:a880:1:20::200:e001/9993")); // San Francisco
- //roots.back().stableEndpoints.push_back(InetAddress("128.199.197.217/9993")); // Singapore
- //roots.back().stableEndpoints.push_back(InetAddress("2400:6180:0:d0::b7:4001/9993")); // Singapore
-
- // Bob
- //roots.push_back(World::Root());
- //roots.back().identity = Identity("8841408a2e:0:bb1d31f2c323e264e9e64172c1a74f77899555ed10751cd56e86405cde118d02dffe555d462ccf6a85b5631c12350c8d5dc409ba10b9025d0f445cf449d92b1c");
- //roots.back().stableEndpoints.push_back(InetAddress("45.32.198.130/9993")); // Dallas
- //roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:6400:81c3:5400:00ff:fe18:1d61/9993")); // Dallas
- //roots.back().stableEndpoints.push_back(InetAddress("46.101.160.249/9993")); // Frankfurt
- //roots.back().stableEndpoints.push_back(InetAddress("2a03:b0c0:3:d0::6a:3001/9993")); // Frankfurt
- //roots.back().stableEndpoints.push_back(InetAddress("107.191.46.210/9993")); // Paris
- //roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:6800:83a4::64/9993")); // Paris
- //roots.back().stableEndpoints.push_back(InetAddress("45.32.246.179/9993")); // Sydney
- //roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:5800:8bf8:5400:ff:fe15:b39a/9993")); // Sydney
- //roots.back().stableEndpoints.push_back(InetAddress("45.32.248.87/9993")); // Tokyo
- //roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:7000:9bc9:5400:00ff:fe15:c4f5/9993")); // Tokyo
- //roots.back().stableEndpoints.push_back(InetAddress("159.203.2.154/9993")); // Toronto
- //roots.back().stableEndpoints.push_back(InetAddress("2604:a880:cad:d0::26:7001/9993")); // Toronto
-
- // END WORLD DEFINITION
- // =========================================================================
-
- fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu" ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts);
-
- World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
-
- Buffer outtmp;
- nw.serialize(outtmp,false);
- World testw;
- testw.deserialize(outtmp,0);
- if (testw != nw) {
- fprintf(stderr,"FATAL: serialization test failed!" ZT_EOL_S);
- return 1;
- }
-
- OSUtils::writeFile("world.bin",std::string((const char *)outtmp.data(),outtmp.size()));
- fprintf(stderr,"INFO: world.bin written with %u bytes of binary world data." ZT_EOL_S,outtmp.size());
-
- fprintf(stdout,ZT_EOL_S);
- fprintf(stdout,"#define ZT_DEFAULT_WORLD_LENGTH %u" ZT_EOL_S,outtmp.size());
- fprintf(stdout,"static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {");
- for(unsigned int i=0;i 0)
- fprintf(stdout,",");
- fprintf(stdout,"0x%.2x",(unsigned int)d[i]);
- }
- fprintf(stdout,"};" ZT_EOL_S);
-
- return 0;
-}
diff --git a/attic/world/world.bin b/attic/world/world.bin
deleted file mode 100644
index 88049ccd..00000000
Binary files a/attic/world/world.bin and /dev/null differ
diff --git a/attic/world/world.c b/attic/world/world.c
deleted file mode 100644
index ecf30e6f..00000000
--- a/attic/world/world.c
+++ /dev/null
@@ -1,3 +0,0 @@
-
-#define ZT_DEFAULT_WORLD_LENGTH 732
-static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {0x01,0x00,0x00,0x00,0x00,0x08,0xea,0xc9,0x0a,0x00,0x00,0x01,0x6b,0xd4,0x16,0x08,0xc1,0xb8,0xb3,0x88,0xa4,0x69,0x22,0x14,0x91,0xaa,0x9a,0xcd,0x66,0xcc,0x76,0x4c,0xde,0xfd,0x56,0x03,0x9f,0x10,0x67,0xae,0x15,0xe6,0x9c,0x6f,0xb4,0x2d,0x7b,0x55,0x33,0x0e,0x3f,0xda,0xac,0x52,0x9c,0x07,0x92,0xfd,0x73,0x40,0xa6,0xaa,0x21,0xab,0xa8,0xa4,0x89,0xfd,0xae,0xa4,0x4a,0x39,0xbf,0x2d,0x00,0x65,0x9a,0xc9,0xc8,0x18,0xeb,0x16,0x93,0xf4,0xe5,0xbd,0x20,0xda,0x10,0xad,0xc7,0x05,0xf4,0x99,0xfe,0x04,0x08,0x9b,0xe0,0x9e,0x77,0x1d,0x9f,0x47,0x16,0xaa,0x92,0x4f,0x10,0x16,0x3d,0xc7,0xec,0xd3,0x90,0x9e,0xd1,0x74,0xfc,0xb3,0xb5,0x07,0x9c,0x4d,0x95,0xc5,0x17,0x8b,0x3d,0x0b,0x60,0x76,0xe8,0x51,0xbb,0xb6,0x3d,0x74,0xb5,0x21,0x83,0x7b,0x95,0x1d,0x02,0x9b,0xcd,0xaf,0x5c,0x3e,0x96,0xdf,0x37,0x2c,0x56,0x6d,0xfa,0x75,0x0f,0xda,0x55,0x85,0x13,0xf4,0x76,0x1a,0x66,0x4d,0x3b,0x8d,0xcf,0x12,0xc9,0x34,0xb9,0x0d,0x61,0x03,0x3a,0x46,0xf1,0xbf,0x30,0x00,0x76,0xe6,0x6f,0xab,0x33,0xe2,0x85,0x49,0xa6,0x2e,0xe2,0x06,0x4d,0x18,0x43,0x27,0x3c,0x2c,0x30,0x0b,0xa4,0x5c,0x3f,0x20,0xbe,0xf0,0x2d,0xba,0xd2,0x25,0x72,0x3b,0xb5,0x9a,0x9b,0xb4,0xb1,0x35,0x35,0x73,0x09,0x61,0xae,0xec,0xf5,0xa1,0x63,0xac,0xe4,0x77,0xcc,0xeb,0x07,0x27,0x02,0x5b,0x99,0xac,0x14,0xa5,0x16,0x6a,0x09,0xa3,0x00,0x02,0x04,0xb9,0xb4,0x0d,0x52,0x27,0x09,0x06,0x2a,0x02,0x6e,0xa0,0xc8,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x27,0x09,0x9d,0x21,0x90,0x39,0xf3,0x00,0x01,0xf0,0x92,0x2a,0x98,0xe3,0xb3,0x4e,0xbc,0xbf,0xf3,0x33,0x26,0x9d,0xc2,0x65,0xd7,0xa0,0x20,0xaa,0xb6,0x9d,0x72,0xbe,0x4d,0x4a,0xcc,0x9c,0x8c,0x92,0x94,0x78,0x57,0x71,0x25,0x6c,0xd1,0xd9,0x42,0xa9,0x0d,0x1b,0xd1,0xd2,0xdc,0xa3,0xea,0x84,0xef,0x7d,0x85,0xaf,0xe6,0x61,0x1f,0xb4,0x3f,0xf0,0xb7,0x41,0x26,0xd9,0x0a,0x6e,0x00,0x0c,0x04,0xbc,0xa6,0x5e,0xb1,0x27,0x09,0x06,0x2a,0x03,0xb0,0xc0,0x00,0x02,0x00,0xd0,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x01,0x27,0x09,0x04,0x9a,0x42,0xc5,0x21,0x27,0x09,0x06,0x2c,0x0f,0xf8,0x50,0x01,0x54,0x01,0x97,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x27,0x09,0x04,0x9f,0xcb,0x61,0xab,0x27,0x09,0x06,0x26,0x04,0xa8,0x80,0x08,0x00,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,0x54,0x60,0x01,0x27,0x09,0x04,0x83,0xff,0x06,0x10,0x27,0x09,0x06,0x28,0x03,0xeb,0x80,0x00,0x00,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x27,0x09,0x04,0x6b,0xaa,0xc5,0x0e,0x27,0x09,0x06,0x26,0x04,0xa8,0x80,0x00,0x01,0x00,0x20,0x00,0x00,0x00,0x00,0x02,0x00,0xe0,0x01,0x27,0x09,0x04,0x80,0xc7,0xc5,0xd9,0x27,0x09,0x06,0x24,0x00,0x61,0x80,0x00,0x00,0x00,0xd0,0x00,0x00,0x00,0x00,0x00,0xb7,0x40,0x01,0x27,0x09,0x88,0x41,0x40,0x8a,0x2e,0x00,0xbb,0x1d,0x31,0xf2,0xc3,0x23,0xe2,0x64,0xe9,0xe6,0x41,0x72,0xc1,0xa7,0x4f,0x77,0x89,0x95,0x55,0xed,0x10,0x75,0x1c,0xd5,0x6e,0x86,0x40,0x5c,0xde,0x11,0x8d,0x02,0xdf,0xfe,0x55,0x5d,0x46,0x2c,0xcf,0x6a,0x85,0xb5,0x63,0x1c,0x12,0x35,0x0c,0x8d,0x5d,0xc4,0x09,0xba,0x10,0xb9,0x02,0x5d,0x0f,0x44,0x5c,0xf4,0x49,0xd9,0x2b,0x1c,0x00,0x0c,0x04,0x2d,0x20,0xc6,0x82,0x27,0x09,0x06,0x20,0x01,0x19,0xf0,0x64,0x00,0x81,0xc3,0x54,0x00,0x00,0xff,0xfe,0x18,0x1d,0x61,0x27,0x09,0x04,0x2e,0x65,0xa0,0xf9,0x27,0x09,0x06,0x2a,0x03,0xb0,0xc0,0x00,0x03,0x00,0xd0,0x00,0x00,0x00,0x00,0x00,0x6a,0x30,0x01,0x27,0x09,0x04,0x6b,0xbf,0x2e,0xd2,0x27,0x09,0x06,0x20,0x01,0x19,0xf0,0x68,0x00,0x83,0xa4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x27,0x09,0x04,0x2d,0x20,0xf6,0xb3,0x27,0x09,0x06,0x20,0x01,0x19,0xf0,0x58,0x00,0x8b,0xf8,0x54,0x00,0x00,0xff,0xfe,0x15,0xb3,0x9a,0x27,0x09,0x04,0x2d,0x20,0xf8,0x57,0x27,0x09,0x06,0x20,0x01,0x19,0xf0,0x70,0x00,0x9b,0xc9,0x54,0x00,0x00,0xff,0xfe,0x15,0xc4,0xf5,0x27,0x09,0x04,0x9f,0xcb,0x02,0x9a,0x27,0x09,0x06,0x26,0x04,0xa8,0x80,0x0c,0xad,0x00,0xd0,0x00,0x00,0x00,0x00,0x00,0x26,0x70,0x01,0x27,0x09};
diff --git a/controller/CMakeLists.txt b/controller/CMakeLists.txt
new file mode 100644
index 00000000..c886b54b
--- /dev/null
+++ b/controller/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8)
+project(zt_controller)
+
+if(WIN32)
+ add_definitions(-DNOMINMAX)
+endif(WIN32)
+
+set(ctl_src
+ DB.cpp
+ DBMirrorSet.cpp
+ EmbeddedNetworkController.cpp
+ FileDB.cpp
+ LFDB.cpp
+ RabbitMQ.cpp
+)
+
+set(ctl_hdr
+ DB.hpp
+ DBMirrorSet.hpp
+ EmbeddedNetworkController.hpp
+ FileDB.hpp
+ LFDB.hpp
+ RabbitMQ.hpp
+)
+
+if(BUILD_CENTRAL_CONTROLLER)
+ add_definitions(-DZT_CONTROLLER_USE_LIBPQ)
+ include_directories("../ext/librabbitmq/librabbitmq" ${PostgreSQL_INCLUDE_DIRS})
+
+ set(ctl_src ${ctl_src} PostgreSQL.cpp)
+ set(ctl_hdr ${ctl_hdr} PostgreSQL.hpp)
+endif(BUILD_CENTRAL_CONTROLLER)
+
+add_library(${PROJECT_NAME} STATIC ${ctl_src} ${ctl_hdr})
+target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
+
diff --git a/controller/DBMirrorSet.cpp b/controller/DBMirrorSet.cpp
index b2c7c71b..c467e171 100644
--- a/controller/DBMirrorSet.cpp
+++ b/controller/DBMirrorSet.cpp
@@ -36,7 +36,7 @@ DBMirrorSet::DBMirrorSet(DB::ChangeListener *listener) :
}
for(auto db=dbs.begin();db!=dbs.end();++db) {
- (*db)->each([this,&dbs,&db](uint64_t networkId,const nlohmann::json &network,uint64_t memberId,const nlohmann::json &member) {
+ (*db)->each([&dbs,&db](uint64_t networkId,const nlohmann::json &network,uint64_t memberId,const nlohmann::json &member) {
try {
if (network.is_object()) {
if (memberId == 0) {
diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp
index e0e2a3ea..0b6c4405 100644
--- a/controller/EmbeddedNetworkController.cpp
+++ b/controller/EmbeddedNetworkController.cpp
@@ -29,8 +29,14 @@
#include
#include
+#include "../node/Constants.hpp"
+#include "../node/Node.hpp"
+#include "../node/CertificateOfMembership.hpp"
+#include "../node/NetworkConfig.hpp"
+#include "../node/Dictionary.hpp"
+#include "../node/MAC.hpp"
+
#include "../include/ZeroTierOne.h"
-#include "../version.h"
#include "EmbeddedNetworkController.hpp"
#include "LFDB.hpp"
@@ -39,12 +45,6 @@
#include "PostgreSQL.hpp"
#endif
-#include "../node/Node.hpp"
-#include "../node/CertificateOfMembership.hpp"
-#include "../node/NetworkConfig.hpp"
-#include "../node/Dictionary.hpp"
-#include "../node/MAC.hpp"
-
using json = nlohmann::json;
// API version reported via JSON control plane
@@ -548,8 +548,6 @@ void EmbeddedNetworkController::request(
unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
const std::vector &path,
- const std::map &urlArgs,
- const std::map &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType)
@@ -645,8 +643,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
const std::vector &path,
- const std::map &urlArgs,
- const std::map &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType)
@@ -1055,8 +1051,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
const std::vector &path,
- const std::map &urlArgs,
- const std::map &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType)
@@ -1113,56 +1107,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
return 404;
}
-void EmbeddedNetworkController::handleRemoteTrace(const ZT_RemoteTrace &rt)
-{
- static volatile unsigned long idCounter = 0;
- char id[128],tmp[128];
- std::string k,v;
-
- try {
- // Convert Dictionary into JSON object
- json d;
- char *saveptr = (char *)0;
- for(char *l=Utils::stok(rt.data,"\n",&saveptr);(l);l=Utils::stok((char *)0,"\n",&saveptr)) {
- char *eq = strchr(l,'=');
- if (eq > l) {
- k.assign(l,(unsigned long)(eq - l));
- v.clear();
- ++eq;
- while (*eq) {
- if (*eq == '\\') {
- ++eq;
- if (*eq) {
- switch(*eq) {
- case 'r': v.push_back('\r'); break;
- case 'n': v.push_back('\n'); break;
- case '0': v.push_back((char)0); break;
- case 'e': v.push_back('='); break;
- default: v.push_back(*eq); break;
- }
- ++eq;
- }
- } else {
- v.push_back(*(eq++));
- }
- }
- if ((k.length() > 0)&&(v.length() > 0))
- d[k] = v;
- }
- }
-
- const int64_t now = OSUtils::now();
- OSUtils::ztsnprintf(id,sizeof(id),"%.10llx-%.16llx-%.10llx-%.4x",_signingId.address().toInt(),now,rt.origin,(unsigned int)(idCounter++ & 0xffff));
- d["id"] = id;
- d["objtype"] = "trace";
- d["ts"] = now;
- d["nodeId"] = Utils::hex10(rt.origin,tmp);
- _db.save(d,true);
- } catch ( ... ) {
- // drop invalid trace messages if an error occurs
- }
-}
-
void EmbeddedNetworkController::onNetworkUpdate(const void *db,uint64_t networkId,const nlohmann::json &network)
{
// Send an update to all members of the network that are online
@@ -1188,7 +1132,7 @@ void EmbeddedNetworkController::onNetworkMemberUpdate(const void *db,uint64_t ne
void EmbeddedNetworkController::onNetworkMemberDeauthorize(const void *db,uint64_t networkId,uint64_t memberId)
{
const int64_t now = OSUtils::now();
- Revocation rev((uint32_t)_node->prng(),networkId,0,now,ZT_REVOCATION_FLAG_FAST_PROPAGATE,Address(memberId),Revocation::CREDENTIAL_TYPE_COM);
+ Revocation rev((uint32_t)Utils::random(),networkId,0,now,ZT_REVOCATION_FLAG_FAST_PROPAGATE,Address(memberId),Revocation::CREDENTIAL_TYPE_COM);
rev.sign(_signingId);
{
std::lock_guard l(_memberStatus_l);
@@ -1704,7 +1648,7 @@ void EmbeddedNetworkController::_request(
DB::cleanMember(member);
_db.save(member,true);
- _sender->ncSendConfig(nwid,requestPacketId,identity.address(),*(nc.get()),metaData.getUI(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_VERSION,0) < 6);
+ _sender->ncSendConfig(nwid,requestPacketId,identity.address(),*(nc.get()),false);
}
void EmbeddedNetworkController::_startThreads()
diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp
index 1db4cf42..82946940 100644
--- a/controller/EmbeddedNetworkController.hpp
+++ b/controller/EmbeddedNetworkController.hpp
@@ -51,6 +51,7 @@ class EmbeddedNetworkController : public NetworkController,public DB::ChangeList
public:
/**
* @param node Parent node
+ * @param ztPath ZeroTier base path
* @param dbPath Database path (file path or database credentials)
*/
EmbeddedNetworkController(Node *node,const char *ztPath,const char *dbPath, int listenPort, MQConfig *mqc = NULL);
@@ -67,28 +68,20 @@ public:
unsigned int handleControlPlaneHttpGET(
const std::vector &path,
- const std::map &urlArgs,
- const std::map &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType);
unsigned int handleControlPlaneHttpPOST(
const std::vector &path,
- const std::map &urlArgs,
- const std::map &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType);
unsigned int handleControlPlaneHttpDELETE(
const std::vector &path,
- const std::map &urlArgs,
- const std::map &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType);
- void handleRemoteTrace(const ZT_RemoteTrace &rt);
-
virtual void onNetworkUpdate(const void *db,uint64_t networkId,const nlohmann::json &network);
virtual void onNetworkMemberUpdate(const void *db,uint64_t networkId,uint64_t memberId,const nlohmann::json &member);
virtual void onNetworkMemberDeauthorize(const void *db,uint64_t networkId,uint64_t memberId);
diff --git a/controller/FileDB.cpp b/controller/FileDB.cpp
index b4eaf58c..0b360d88 100644
--- a/controller/FileDB.cpp
+++ b/controller/FileDB.cpp
@@ -20,13 +20,11 @@ FileDB::FileDB(const char *path) :
DB(),
_path(path),
_networksPath(_path + ZT_PATH_SEPARATOR_S + "network"),
- _tracePath(_path + ZT_PATH_SEPARATOR_S + "trace"),
_running(true)
{
OSUtils::mkdir(_path.c_str());
OSUtils::lockDownFile(_path.c_str(),true);
OSUtils::mkdir(_networksPath.c_str());
- OSUtils::mkdir(_tracePath.c_str());
std::vector networks(OSUtils::listDirectory(_networksPath.c_str(),false));
std::string buf;
diff --git a/controller/FileDB.hpp b/controller/FileDB.hpp
index fcd7af0f..82e634e6 100644
--- a/controller/FileDB.hpp
+++ b/controller/FileDB.hpp
@@ -35,7 +35,6 @@ public:
protected:
std::string _path;
std::string _networksPath;
- std::string _tracePath;
std::thread _onlineUpdateThread;
std::map< uint64_t,std::map > > _online;
std::mutex _online_l;
diff --git a/ext/arm32-neon-salsa2012-asm/README.md b/ext/arm32-neon-salsa2012-asm/README.md
deleted file mode 100644
index 54fc6f5f..00000000
--- a/ext/arm32-neon-salsa2012-asm/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-ARM NEON (32-bit) ASM implementation of Salsa20/12
-======
-
-This is from [supercop](http://bench.cr.yp.to/supercop.html) and was originally written by Daniel J. Bernstein. Code is in the public domain like the rest of Salsa20. It's much faster than the naive implementation.
-
-It's included automatically in 32-bit Linux ARM builds. It likely will not work on 64-bit ARM, so it'll need to be ported at least. That will unfortunately keep it out of mobile versions for now since those are all going 64-bit.
diff --git a/ext/arm32-neon-salsa2012-asm/salsa2012.h b/ext/arm32-neon-salsa2012-asm/salsa2012.h
deleted file mode 100644
index 262c9b9b..00000000
--- a/ext/arm32-neon-salsa2012-asm/salsa2012.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef ZT_SALSA2012_ARM32NEON_ASM
-#define ZT_SALSA2012_ARM32NEON_ASM
-
-#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
-#include
-#include
-#define zt_arm_has_neon() ((getauxval(AT_HWCAP) & HWCAP_NEON) != 0)
-#elif defined(__ARM_NEON__) || defined(__ARM_NEON)
-#define zt_arm_has_neon() (true)
-#else
-#define zt_arm_has_neon() (false)
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// ciphertext buffer, message/NULL, length, nonce (8 bytes), key (32 bytes)
-extern int zt_salsa2012_armneon3_xor(unsigned char *c,const unsigned char *m,unsigned long long len,const unsigned char *n,const unsigned char *k);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ext/arm32-neon-salsa2012-asm/salsa2012.s b/ext/arm32-neon-salsa2012-asm/salsa2012.s
deleted file mode 100644
index 9e5989cd..00000000
--- a/ext/arm32-neon-salsa2012-asm/salsa2012.s
+++ /dev/null
@@ -1,2231 +0,0 @@
-
-# qhasm: int32 input_0
-
-# qhasm: int32 input_1
-
-# qhasm: int32 input_2
-
-# qhasm: int32 input_3
-
-# qhasm: stack32 input_4
-
-# qhasm: stack32 input_5
-
-# qhasm: stack32 input_6
-
-# qhasm: stack32 input_7
-
-# qhasm: int32 caller_r4
-
-# qhasm: int32 caller_r5
-
-# qhasm: int32 caller_r6
-
-# qhasm: int32 caller_r7
-
-# qhasm: int32 caller_r8
-
-# qhasm: int32 caller_r9
-
-# qhasm: int32 caller_r10
-
-# qhasm: int32 caller_r11
-
-# qhasm: int32 caller_r14
-
-# qhasm: reg128 caller_q4
-
-# qhasm: reg128 caller_q5
-
-# qhasm: reg128 caller_q6
-
-# qhasm: reg128 caller_q7
-
-# qhasm: startcode
-.fpu neon
-.text
-
-# qhasm: constant sigma:
-.align 2
-sigma:
-
-# qhasm: const32 1634760805
-.word 1634760805
-
-# qhasm: const32 857760878
-.word 857760878
-
-# qhasm: const32 2036477234
-.word 2036477234
-
-# qhasm: const32 1797285236
-.word 1797285236
-
-# qhasm: int128 abab
-
-# qhasm: int128 diag0
-
-# qhasm: int128 diag1
-
-# qhasm: int128 diag2
-
-# qhasm: int128 diag3
-
-# qhasm: int128 a0
-
-# qhasm: int128 a1
-
-# qhasm: int128 a2
-
-# qhasm: int128 a3
-
-# qhasm: int128 b0
-
-# qhasm: int128 b1
-
-# qhasm: int128 b2
-
-# qhasm: int128 b3
-
-# qhasm: int128 next_diag0
-
-# qhasm: int128 next_diag1
-
-# qhasm: int128 next_diag2
-
-# qhasm: int128 next_diag3
-
-# qhasm: int128 next_a0
-
-# qhasm: int128 next_a1
-
-# qhasm: int128 next_a2
-
-# qhasm: int128 next_a3
-
-# qhasm: int128 next_b0
-
-# qhasm: int128 next_b1
-
-# qhasm: int128 next_b2
-
-# qhasm: int128 next_b3
-
-# qhasm: int128 x0x5x10x15
-
-# qhasm: int128 x12x1x6x11
-
-# qhasm: int128 x8x13x2x7
-
-# qhasm: int128 x4x9x14x3
-
-# qhasm: int128 x0x1x10x11
-
-# qhasm: int128 x12x13x6x7
-
-# qhasm: int128 x8x9x2x3
-
-# qhasm: int128 x4x5x14x15
-
-# qhasm: int128 x0x1x2x3
-
-# qhasm: int128 x4x5x6x7
-
-# qhasm: int128 x8x9x10x11
-
-# qhasm: int128 x12x13x14x15
-
-# qhasm: int128 m0m1m2m3
-
-# qhasm: int128 m4m5m6m7
-
-# qhasm: int128 m8m9m10m11
-
-# qhasm: int128 m12m13m14m15
-
-# qhasm: int128 start0
-
-# qhasm: int128 start1
-
-# qhasm: int128 start2
-
-# qhasm: int128 start3
-
-# qhasm: stack128 stack_start3
-
-# qhasm: stack128 next_start2
-
-# qhasm: stack128 next_start3
-
-# qhasm: int128 k0k1k2k3
-
-# qhasm: int128 k4k5k6k7
-
-# qhasm: int128 k1n1k7k2
-
-# qhasm: int128 n2n3n3n2
-
-# qhasm: int128 k2k3k6k7
-
-# qhasm: int128 nextblock
-
-# qhasm: stack128 stack_q4
-
-# qhasm: stack128 stack_q5
-
-# qhasm: stack128 stack_q6
-
-# qhasm: stack128 stack_q7
-
-# qhasm: stack32 stack_r4
-
-# qhasm: stack128 k2k3k6k7_stack
-
-# qhasm: stack128 k1n1k7k2_stack
-
-# qhasm: stack512 tmp
-
-# qhasm: stack32 savec
-
-# qhasm: int32 i
-
-# qhasm: int32 ci
-
-# qhasm: int32 mi
-
-# qhasm: enter zt_salsa2012_armneon3_xor
-.align 2
-.global _zt_salsa2012_armneon3_xor
-.global zt_salsa2012_armneon3_xor
-.type _zt_salsa2012_armneon3_xor STT_FUNC
-.type zt_salsa2012_armneon3_xor STT_FUNC
-_zt_salsa2012_armneon3_xor:
-zt_salsa2012_armneon3_xor:
-sub sp,sp,#256
-
-# qhasm: new stack_q4
-
-# qhasm: new stack_q5
-
-# qhasm: new stack_q6
-
-# qhasm: new stack_q7
-
-# qhasm: stack_q4 bot = caller_q4 bot
-# asm 1: vstr stack_r4=stack32#2
-# asm 2: str stack_r4=[sp,#68]
-str r4,[sp,#68]
-
-# qhasm: int32 c
-
-# qhasm: c = input_0
-# asm 1: mov >c=int32#1,c=r0,m=int32#2,m=r1,mlenlow=int32#3,mlenlow=r2,mlenhigh=int32#4,mlenhigh=r3,n=int32#5,n=r4,k=int32#13,k=r12,k0k1k2k3=reg128#1%bot->k0k1k2k3=reg128#1%top},[k0k1k2k3=d0->k0k1k2k3=d1},[k4k5k6k7=reg128#2%bot->k4k5k6k7=reg128#2%top},[k4k5k6k7=d2->k4k5k6k7=d3},[i=int32#13,=sigma
-# asm 2: ldr >i=r12,=sigma
-ldr r12,=sigma
-
-# qhasm: start0 = mem128[i]
-# asm 1: vld1.8 {>start0=reg128#3%bot->start0=reg128#3%top},[start0=d4->start0=d5},[start1=reg128#4,#0
-# asm 2: vmov.i64 >start1=q3,#0
-vmov.i64 q3,#0
-
-# qhasm: start1 bot = mem64[n]
-# asm 1: vld1.8 {k2k3k6k7=reg128#6,k2k3k6k7=q5,n2n3n3n2=reg128#1,#0
-# asm 2: vmov.i64 >n2n3n3n2=q0,#0
-vmov.i64 q0,#0
-
-# qhasm: unsigned mlenlow - 128
-# asm 1: cmp diag0=reg128#8,diag0=q7,diag1=reg128#9,diag1=q8,start2=reg128#10,start2=q9,nextblock=reg128#11,#0xff
-# asm 2: vmov.i64 >nextblock=q10,#0xff
-vmov.i64 q10,#0xff
-
-# qhasm: 4x nextblock unsigned>>= 7
-# asm 1: vshr.u32 >nextblock=reg128#11,nextblock=q10,n2n3n3n2=reg128#1,n2n3n3n2=q0,n2n3n3n2=reg128#1,n2n3n3n2=q0,next_diag0=reg128#2,next_diag0=q1,next_diag1=reg128#5,next_diag1=q4,i=int32#5,=12
-# asm 2: ldr >i=r4,=12
-ldr r4,=12
-
-# qhasm: mainloop2:
-._mainloop2:
-
-# qhasm: 4x a0 = diag1 + diag0
-# asm 1: vadd.i32 >a0=reg128#11,a0=q10,next_a0=reg128#14,next_a0=q13,b0=reg128#15,b0=q14,next_b0=reg128#16,next_b0=q15,> 25
-# asm 1: vsri.i32 > 25
-# asm 1: vsri.i32 diag3=reg128#7,diag3=q6,next_diag3=reg128#11,next_diag3=q10,a1=reg128#13,a1=q12,next_a1=reg128#14,next_a1=q13,b1=reg128#15,b1=q14,next_b1=reg128#16,next_b1=q15,> 23
-# asm 1: vsri.i32 > 23
-# asm 1: vsri.i32 diag2=reg128#6,diag2=q5,next_diag2=reg128#12,next_diag2=q11,a2=reg128#13,a2=q12,diag3=reg128#7,diag3=q6,next_a2=reg128#14,next_a2=q13,b2=reg128#15,b2=q14,next_diag3=reg128#11,next_diag3=q10,next_b2=reg128#16,next_b2=q15,> 19
-# asm 1: vsri.i32 > 19
-# asm 1: vsri.i32 diag1=reg128#9,diag1=q8,next_diag1=reg128#5,next_diag1=q4,a3=reg128#13,a3=q12,next_a3=reg128#14,next_a3=q13,b3=reg128#15,b3=q14,next_b3=reg128#16,next_b3=q15,> 14
-# asm 1: vsri.i32 diag1=reg128#9,diag1=q8,> 14
-# asm 1: vsri.i32 diag0=reg128#8,diag0=q7,next_diag1=reg128#5,next_diag1=q4,next_diag0=reg128#2,next_diag0=q1,a0=reg128#13,a0=q12,next_a0=reg128#14,next_a0=q13,b0=reg128#15,b0=q14,next_b0=reg128#16,next_b0=q15,> 25
-# asm 1: vsri.i32 > 25
-# asm 1: vsri.i32 diag1=reg128#9,diag1=q8,next_diag1=reg128#5,next_diag1=q4,a1=reg128#13,a1=q12,next_a1=reg128#14,next_a1=q13,b1=reg128#15,