Update central controller build to use CMake + conda

Muuuuch easier to use external dependencies now

Also tried out conan and vcpkg.   Ran into dependency issues when solving for packages to install with conan.

vcpkg is just obtuse as all hell to install and not easy to integrate
This commit is contained in:
Grant Limberg 2025-08-27 16:23:02 -07:00
parent f8a4a5d6af
commit 7f3b15011e
27 changed files with 615 additions and 3015 deletions

1
.gitignore vendored
View file

@ -141,3 +141,4 @@ snap/.snapcraft
tcp-proxy/tcp-proxy
rustybits/target
ext/installfiles/windows/*.back*.aip
build/

View file

@ -1,12 +1,133 @@
# CMake build script for libzerotiercore.a
cmake_minimum_required (VERSION 2.8)
project (zerotiercore)
cmake_minimum_required (VERSION 3.13)
project (zerotier-one LANGUAGES CXX C)
option(ZT1_CENTRAL_CONTROLLER "Build with ZeroTier Central Controller support" OFF)
set (PROJ_DIR ${PROJECT_SOURCE_DIR})
set (ZT_DEFS -std=c++11)
file(GLOB core_src_glob ${PROJ_DIR}/node/*.cpp)
add_library(zerotiercore STATIC ${core_src_glob})
execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE CPU_ARCHITECTURE)
set(CPU_ARCHITECTURE ${CPU_ARCHITECTURE} CACHE STRING "Target CPU architecture (detected automatically)")
message(STATUS "Detected CPU architecture: ${CPU_ARCHITECTURE}")
if(CPU_ARCHITECTURE STREQUAL "x86_64")
add_definitions(
-DZT_ARCHITECTURE=2
-DZT_USE_X64_ASM_SALSA=1
-DZT_USE_X64_ASM_ED25519=1
-DZT_SSO_SUPPORTED=1
-DZT_USE_X64_ASM_SALSA2012=1
-DZT_USE_FAST_X64_ED25519=1
)
elseif(CPU_ARCHITECTURE STREQUAL "aarch64")
add_definitions(-DZT_ARCHITECTURE=4 -DZT_U-DZT_ARCH_ARM_HAS_NEON=1 -DZT_SSO_SUPPORTED=1)
add_compile_options(-march=armv8-a+crypto -mtune=generic -mstrict-align)
endif()
target_compile_options(zerotiercore PRIVATE ${ZT_DEFS})
include(FetchContent)
include(ExternalProject)
add_definitions(-DCMAKE_BUILD)
find_package(OpenSSL REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(inja REQUIRED)
set(CMAKE_THREDAD_PREFER_PTHREAD TRUE CACHE INTERNAL "Use pthreads" FORCE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE CACHE INTERNAL "Use pthreads" FORCE)
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
if(ZT1_CENTRAL_CONTROLLER)
find_package(PostgreSQL REQUIRED)
find_package(opentelemetry-cpp REQUIRED COMPONENTS api sdk)
find_package(google_cloud_cpp_bigtable REQUIRED)
find_package(google_cloud_cpp_pubsub REQUIRED)
else()
find_package(opentelemetry-cpp REQUIRED COMPONENTS api)
endif()
if(ZT1_CENTRAL_CONTROLLER)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to" FORCE)
set(CMAKE_CXX_STANDARD_REQUIRED True CACHE BOOL "C++ standard required" FORCE)
set(CMAKE_CXX_EXTENSIONS ON CACHE BOOL "Enable compiler-specific extensions" FORCE)
add_definitions(-DZT_CONTROLLER_USE_LIBPQ)
set(CONTROLLER_RUST_FEATURES ztcontroller)
set(RUST_BUILD_COMMAND cargo build --release -F ${CONTROLLER_RUST_FEATURES})
else()
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED True CACHE BOOL "C++ standard required")
set(CMAKE_CXX_EXTENSIONS ON CACHE BOOL "Enable compiler-specific extensions")
set(RUST_BUILD_COMMAND "cargo build --release")
endif()
# build rustybits
ExternalProject_Add(
rustybits_build
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
# PREFIX ${PROJ_DIR}/rustybits
BUILD_COMMAND cd ${PROJ_DIR}/rustybits && ${RUST_BUILD_COMMAND}
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${PROJ_DIR}/rustybits/target/release/librustybits.a ${PROJ_DIR}/rustybits/target/rustybits.h
)
set(RUSTYBITS_LIB ${PROJ_DIR}/rustybits/target/release/librustybits.a)
set(RUSTYBITS_INCLUDE_DIR ${PROJ_DIR}/rustybits/target)
add_library(rustybits STATIC IMPORTED GLOBAL)
set_property(TARGET rustybits PROPERTY IMPORTED_LOCATION ${RUSTYBITS_LIB})
add_dependencies(rustybits rustybits_build)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack")
# Get & build dependencies not in conda
include (cmake/cpp-httplib.cmake)
include (cmake/redis-plus-plus.cmake)
include (cmake/miniupnpc.cmake)
add_subdirectory(ext)
add_subdirectory(node)
add_subdirectory(osdep)
add_subdirectory(service)
add_subdirectory(controller)
set(LINKED_LIBRARIES
prometheus-cpp-lite
zerotier-service
zerotier-osdep
zerotier-core
zerotier-controller
Threads::Threads
nlohmann_json::nlohmann_json
opentelemetry-cpp::api
rustybits
OpenSSL::Crypto
OpenSSL::SSL
Threads::Threads
)
if(ZT1_CENTRAL_CONTROLLER)
list(APPEND LINKED_LIBRARIES
opentelemetry-cpp::sdk)
endif()
add_executable(zerotier-one
one.cpp
ext/http-parser/http_parser.c)
target_link_libraries(zerotier-one
${LINKED_LIBRARIES}
)
add_executable(zerotier-selftest
selftest.cpp
)
target_link_libraries(zerotier-selftest
zerotier-core
Threads::Threads
nlohmann_json::nlohmann_json
prometheus-cpp-lite
Threads::Threads)

18
build_central_controller.sh Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
cmake -DCMAKE_BUILD_TYPE=Release -DZT1_CENTRAL_CONTROLLER=1 -DCMAKE_INSTALL_PREFIX=$PWD -S . -B build/ -DCMAKE_INSTALL_PREFIX=$(shell pwd)/build-out
cmake --build build/ --target all -j4 --verbose
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
ARCH="amd64"
elif [ "$ARCH" = "aarch64" ]; then
ARCH="arm64"
fi
if [ -z "$TARGET_DOCKER_REPO" ]; then
TARGET_DOCKER_REPO="us-central1-docker.pkg.dev/zerotier-421eb9/docker-images"
fi
docker build -platform linux/$ARCH -t $TARGET_DOCKER_REPO/ztcentral-controller:$(git rev-parse --short HEAD)-$ARCH -f ext/central-controller/docker/Dockerfile.central-controller . --load --push

21
cmake/cpp-httplib.cmake Normal file
View file

@ -0,0 +1,21 @@
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
cpp-httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG v0.25.0
GIT_SHALLOW ON
)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(HTTPLIB_COMPILE OFF CACHE INTERNAL "")
set(HTTPLIB_USE_ZLIB_IF_AVAILABLE ON CACHE INTERNAL "Use zlib if available")
set(HTTPLIB_USE_BROTLI_IF_AVAILABLE ON CACHE INTERNAL "Use brotli if available")
set(HTTPLIB_USE_OPENSSL_IF_AVAILABLE ON CACHE INTERNAL "Use OpenSSL if available")
set(HTTPLIB_USE_ZSTD_IF_AVAILABLE ON CACHE INTERNAL "Use zstd if available")
FetchContent_MakeAvailable(cpp-httplib)
if (NOT TARGET httplib::httplib)
message(FATAL_ERROR "A required cpp-httplib target (cpp-httplib) was not imported")
endif()

30
cmake/miniupnpc.cmake Normal file
View file

@ -0,0 +1,30 @@
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
miniupnpc
URL https://github.com/miniupnp/miniupnp/releases/download/miniupnpc_2_3_3/miniupnpc-2.3.3.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
set(UPNPC_BUILD_TESTS FALSE CACHE INTERNAL "Build tests" FORCE)
set(UPNPC_BUILD_SHARED FALSE CACHE INTERNAL "Build shared library" FORCE)
set(UPNPC_BUILD_STATIC TRUE CACHE INTERNAL "Build static library" FORCE)
set(UPNPC_BUILD_SAMPLE FALSE CACHE INTERNAL "Build sample" FORCE)
FetchContent_MakeAvailable(miniupnpc)
if (NOT TARGET miniupnpc::miniupnpc)
message(FATAL_ERROR "A required miniupnpc target (miniupnpc::miniupnpc) was not imported")
endif()
add_definitions(-DZT_USE_MINIUPNPC)
FetchContent_Declare(
libnatpmp
GIT_REPOSITORY https://github.com/miniupnp/libnatpmp.git
GIT_TAG master
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(libnatpmp)
if (NOT TARGET natpmp)
message(FATAL_ERROR "A required libnatpmp target (natpmp) was not imported")
endif()

View file

@ -0,0 +1,19 @@
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
redis-plus-plus
GIT_REPOSITORY https://github.com/sewenew/redis-plus-plus.git
GIT_TAG 1.3.15
GIT_SHALLOW ON
)
set(REDIS_PLUS_PLUS_BUILD_STATIC ON CACHE INTERNAL "Build static library" FORCE)
set(REDIS_PLUS_PLUS_BUILD_SHARED ON CACHE INTERNAL "Build shared library" FORCE)
set(REDIS_PLUS_PLUS_BUILD_TEST OFF CACHE INTERNAL "Build tests" FORCE)
set(REDIS_PLUS_PLUS_BUILD_STATIC_WITH_PIC ON CACHE INTERNAL "Build static library with PIC" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build shared libraries" FORCE)
FetchContent_MakeAvailable(redis-plus-plus)
if(NOT TARGET redis++::redis++_static)
message(FATAL_ERROR "A required redis-plus-plus target (redis++::redis++) was not imported")
endif()
message(STATUS "redis-plus-plus imported")

75
controller/CMakeLists.txt Normal file
View file

@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 3.13)
project(zerotier-controller)
set(SRC_FILES
DB.cpp
DB.hpp
DBMirrorSet.cpp
DBMirrorSet.hpp
EmbeddedNetworkController.cpp
EmbeddedNetworkController.hpp
FileDB.cpp
FileDB.hpp
LFDB.cpp
LFDB.hpp
CtlUtil.cpp
CtlUtil.hpp
)
set(INCLUDE_DIRS
"${httplib_SOURCE_DIR}"
${RUSTYBITS_INCLUDE_DIR}
)
set(LINK_LIBS
zerotier-osdep
nlohmann_json::nlohmann_json
opentelemetry-cpp::api
rustybits
Threads::Threads
prometheus-cpp-lite
Threads::Threads
)
if (ZT1_CENTRAL_CONTROLLER)
find_package(PostgreSQL REQUIRED)
list(APPEND SRC_FILES
CV1.cpp
CV1.hpp
CV2.cpp
CV2.hpp
CentralDB.cpp
CentralDB.hpp
NotificationListener.hpp
PostgreSQL.cpp
PostgreSQL.hpp
PubSubListener.cpp
PubSubListener.hpp
Redis.hpp
RedisListener.cpp
RedisListener.hpp)
list(APPEND INCLUDE_DIRS
${PostgreSQL_INCLUDE_DIRS}
"${redis++_BUILD_DIR}/src"
${pqxx_INCLUDE_DIRS}
)
list(APPEND LINK_LIBS
redis++::redis++_static
pqxx
${PostgreSQL_LIBRARIES}
)
endif()
add_library(zerotier-controller STATIC ${SRC_FILES})
target_include_directories(zerotier-controller PRIVATE ${INCLUDE_DIRS})
add_dependencies(zerotier-controller redis++::redis++)
target_link_libraries(zerotier-controller
${LINK_LIBS}
)

View file

@ -26,7 +26,7 @@
#include <memory>
#include <pqxx/pqxx>
#include <redis++/redis++.h>
#include <sw/redis++/redis++.h>
namespace rustybits {
struct SmeeClient;

View file

@ -26,7 +26,7 @@
#include <memory>
#include <pqxx/pqxx>
#include <redis++/redis++.h>
#include <sw/redis++/redis++.h>
namespace ZeroTier {

View file

@ -13,7 +13,7 @@
#include <memory>
#include <pqxx/pqxx>
#include <redis++/redis++.h>
#include <sw/redis++/redis++.h>
namespace rustybits {
struct SmeeClient;

View file

@ -26,7 +26,11 @@
#include "DBMirrorSet.hpp"
#include <atomic>
#ifdef CMAKE_BUILD
#include <httplib.h>
#else
#include <cpp-httplib/httplib.h>
#endif
#include <list>
#include <map>
#include <nlohmann/json.hpp>

View file

@ -13,7 +13,11 @@
#include "LFDB.hpp"
#ifdef CMAKE_BUILD
#include "httplib.h"
#else
#include "../ext/cpp-httplib/httplib.h"
#endif
#include "../osdep/OSUtils.hpp"
#include <chrono>

View file

@ -0,0 +1,56 @@
# Central Controller Builds
NOTE: for ZeroTier, Inc Internal use only. We do not support these builds for external use, nor do we guarantee this will work for anyone but us.
## Prerequisites
`cmake` is used for builds and `conda` is used to manage external dependencies.
First, install `conda`:
```bash
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o /tmp/miniconda.sh
bash /tmp/miniconda.sh -b -u -p $HOME/miniconda3
```
Initialize conda:
```bash
source ~/miniconda3/bin/activate
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
conda config --set channel_priority strict
```
Install external dependencies:
```bash
conda install -y -c conda-forge \
conda-forge::cmake \
conda-forge::git \
conda-forge::cxx-compiler \
conda-forge::c-compiler \
conda-forge::make \
conda-forge::pkg-config \
conda-forge::libpqxx=7.7.3 \
conda-forge::libopentelemetry-cpp=1.21.0 \
conda-forge::libopentelemetry-cpp-headers=1.21.0 \
conda-forge::google-cloud-cpp=2.39.0 \
conda-forge::libgoogle-cloud=2.39.0 \
conda-forge::rust=1.89.0 \
conda-forge::inja=3.3.0 \
conda-forge::libhiredis=1.3.0 \
conda-forge::nlohmann_json=3.12.0
```
## Build the Central Controller Binary
```bash
cmake -DCMAKE_BUILD_TYPE=Release -DZT1_CENTRAL_CONTROLLER=1 -DCMAKE_INSTALL_PREFIX=$PWD/out -S . -B build/ -DCMAKE_INSTALL_PREFIX=$(shell pwd)/build-out
cmake --build build/ --target all -j8 --verbose
```
## Packaging via Docker
TODO: write me

View file

@ -8,8 +8,8 @@
#include "Redis.hpp"
#include <memory>
#include <redis++/redis++.h>
#include <string>
#include <sw/redis++/redis++.h>
#include <thread>
namespace ZeroTier {

12
ext/CMakeLists.txt Normal file
View file

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.13)
project(ext)
file(GLOB_RECURSE PROM_CORE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/prometheus-cpp-lite-1.0/core/include/*.h )
set(PROMETHEUS_CPP_LITE_HEADERS ${PROM_CORE_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/prometheus-cpp-lite-1.0/simpleapi/include)
add_library(prometheus-cpp-lite INTERFACE)
target_sources(prometheus-cpp-lite INTERFACE ${PROMETHEUS_CPP_LITE_HEADERS})
target_include_directories(prometheus-cpp-lite INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/prometheus-cpp-lite-1.0/simpleapi/include ${CMAKE_CURRENT_SOURCE_DIR}/prometheus-cpp-lite-1.0/core/include)
add_custom_target(prometheus-cpp-lite-ide SOURCES ${PROMETHEUS_CPP_LITE_HEADERS})
set(prometheus-cpp-lite_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/prometheus-cpp-lite-1.0/simpleapi/include ${CMAKE_CURRENT_SOURCE_DIR}/prometheus-cpp-lite-1.0/core/include PARENT_SCOPE)

View file

@ -0,0 +1,23 @@
FROM continuumio/miniconda3:25.3.1-1
LABEL maintainer="ZeroTier Inc."
RUN conda config --set channel_priority strict && \
conda install -y -c conda-forge \
conda-forge::cmake=3.25.1 \
conda-forge::git \
conda-forge::cxx-compiler \
conda-forge::c-compiler \
conda-forge::make \
conda-forge::pkg-config \
conda-forge::libpqxx=7.7.3 \
conda-forge::libopentelemetry-cpp=1.21.0 \
conda-forge::libopentelemetry-cpp-headers=1.21.0 \
conda-forge::google-cloud-cpp=2.39.0 \
conda-forge::libgoogle-cloud=2.39.0 \
conda-forge::rust=1.89.0 \
conda-forge::inja=3.3.0 \
conda-forge::libhiredis=1.3.0 \
conda-forge::nlohmann_json=3.12.0
# ADD . /src

View file

@ -5,7 +5,7 @@
# Distributed under the MIT License.
# (See accompanying file LICENSE or copy at https://mit-license.org/)
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(http-client-lite)
## Set output binary

View file

@ -1,5 +1,5 @@
project(prometheus-cpp-lite-core)
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.13)
file(GLOB_RECURSE PROMETHEUS_CPP_LITE_HEADERS *.h)

View file

@ -1,5 +1,5 @@
project(prometheus-cpp-simpleapi)
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.13)
add_library (${PROJECT_NAME} STATIC "./src/simpleapi.cpp" )
target_sources (${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/prometheus/simpleapi.h")

View file

@ -344,7 +344,7 @@ ifeq ($(ZT_CONTROLLER),1)
override CXXFLAGS+=-Wall -Wno-deprecated -std=c++17 -pthread $(INCLUDES) -DNDEBUG $(DEFS)
override LDLIBS+=-Lext/libpqxx-7.7.3/install/ubuntu22.04/$(EXT_ARCH)/lib -lpqxx -lpq ext/hiredis-1.0.2/lib/ubuntu22.04/$(EXT_ARCH)/libhiredis.a ext/redis-plus-plus-1.3.3/install/ubuntu22.04/$(EXT_ARCH)/lib/libredis++.a -lssl -lcrypto
override DEFS+=-DZT_CONTROLLER_USE_LIBPQ -DZT_NO_PEER_METRICS -DZT_OPENTELEMETRY_ENABLED
override INCLUDES+=-I/usr/include/postgresql -Iext/libpqxx-7.7.3/install/ubuntu22.04/$(EXT_ARCH)/include -Iext/hiredis-1.0.2/include/ -Iext/redis-plus-plus-1.3.3/install/ubuntu22.04/$(EXT_ARCH)/include/sw/
override INCLUDES+=-I/usr/include/postgresql -Iext/libpqxx-7.7.3/install/ubuntu22.04/$(EXT_ARCH)/include -Iext/hiredis-1.0.2/include/ -Iext/redis-plus-plus-1.3.3/install/ubuntu22.04/$(EXT_ARCH)/include
override ZT_CARGO_FLAGS+=-F ztcontroller
ifeq ($(ZT_DEBUG),1)
override LDLIBS+=rustybits/target/debug/librustybits.a

94
node/CMakeLists.txt Normal file
View file

@ -0,0 +1,94 @@
cmake_minimum_required(VERSION 3.13)
project(zerotier-core LANGUAGES CXX ASM)
file (GLOB core_src_glob ${PROJ_DIR}/node/*.cpp)
file (GLOB core_hdr_glob ${PROJ_DIR}/node/*.hpp)
if(${CPU_ARCHITECTURE} STREQUAL "x86_64")
set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp -z noexecstack")
set(ASM_SALSA_DIR ${CMAKE_SOURCE_DIR}/ext/x64-salsa2012-asm)
set(ASM_ED25519_DIR ${CMAKE_SOURCE_DIR}/ext/ed25519-amd64-asm)
list(APPEND core_src_glob
${ASM_SALSA_DIR}/salsa2012.s
#${ASM_ED25519_DIR}/batch.c
${ASM_ED25519_DIR}/choose_t.s
${ASM_ED25519_DIR}/consts.s
${ASM_ED25519_DIR}/fe25519_add.s
${ASM_ED25519_DIR}/fe25519_freeze.s
${ASM_ED25519_DIR}/fe25519_getparity.c
${ASM_ED25519_DIR}/fe25519_invert.c
${ASM_ED25519_DIR}/fe25519_iseq.c
${ASM_ED25519_DIR}/fe25519_iszero.c
${ASM_ED25519_DIR}/fe25519_mul.s
${ASM_ED25519_DIR}/fe25519_neg.c
${ASM_ED25519_DIR}/fe25519_pack.c
${ASM_ED25519_DIR}/fe25519_pow2523.c
${ASM_ED25519_DIR}/fe25519_setint.c
${ASM_ED25519_DIR}/fe25519_square.s
${ASM_ED25519_DIR}/fe25519_sub.s
${ASM_ED25519_DIR}/fe25519_unpack.c
${ASM_ED25519_DIR}/ge25519_add_p1p1.s
${ASM_ED25519_DIR}/ge25519_add.c
${ASM_ED25519_DIR}/ge25519_base.c
${ASM_ED25519_DIR}/ge25519_dbl_p1p1.s
${ASM_ED25519_DIR}/ge25519_double_scalarmult.c
${ASM_ED25519_DIR}/ge25519_double.c
${ASM_ED25519_DIR}/ge25519_isneutral.c
${ASM_ED25519_DIR}/ge25519_multi_scalarmult.c
${ASM_ED25519_DIR}/ge25519_nielsadd_p1p1.s
${ASM_ED25519_DIR}/ge25519_nielsadd2.s
${ASM_ED25519_DIR}/ge25519_p1p1_to_p2.s
${ASM_ED25519_DIR}/ge25519_p1p1_to_p3.s
${ASM_ED25519_DIR}/ge25519_pack.c
${ASM_ED25519_DIR}/ge25519_pnielsadd_p1p1.s
${ASM_ED25519_DIR}/ge25519_scalarmult_base.c
${ASM_ED25519_DIR}/ge25519_unpackneg.c
${ASM_ED25519_DIR}/heap_rootreplaced_1limb.s
${ASM_ED25519_DIR}/heap_rootreplaced_2limbs.s
${ASM_ED25519_DIR}/heap_rootreplaced_3limbs.s
${ASM_ED25519_DIR}/heap_rootreplaced.s
${ASM_ED25519_DIR}/hram.c
${ASM_ED25519_DIR}/index_heap.c
#${ASM_ED25519_DIR}/keypair.c
#${ASM_ED25519_DIR}/open.c
${ASM_ED25519_DIR}/sc25519_add.s
${ASM_ED25519_DIR}/sc25519_barrett.s
${ASM_ED25519_DIR}/sc25519_from_shortsc.c
${ASM_ED25519_DIR}/sc25519_from32bytes.c
${ASM_ED25519_DIR}/sc25519_from64bytes.c
${ASM_ED25519_DIR}/sc25519_iszero.c
${ASM_ED25519_DIR}/sc25519_lt.s
${ASM_ED25519_DIR}/sc25519_mul_shortsc.c
${ASM_ED25519_DIR}/sc25519_mul.c
${ASM_ED25519_DIR}/sc25519_slide.c
${ASM_ED25519_DIR}/sc25519_sub_nored.s
${ASM_ED25519_DIR}/sc25519_to32bytes.c
${ASM_ED25519_DIR}/sc25519_window4.c
${ASM_ED25519_DIR}/sign.c
${ASM_ED25519_DIR}/ull4_mul.s
)
list(APPEND core_hdr_glob
${ASM_SALSA_DIR}/salsa2012.h
${ASM_ED25519_DIR}/fe25519.h
${ASM_ED25519_DIR}/ge25519.h
${ASM_ED25519_DIR}/hram.h
${ASM_ED25519_DIR}/index_heap.h
${ASM_ED25519_DIR}/sc25519.h)
set_property(SOURCE ${ASM_ED25519_DIR}/fe25519_freeze.s PROPERTY COMPILE_FLAGS "-z noexecstack")
elseif(${CPU_ARCHITECTURE} STREQUAL "aarch64")
endif()
add_library(zerotier-core STATIC ${core_src_glob} ${core_hdr_glob})
target_include_directories(zerotier-core
PRIVATE
${prometheus-cpp-lite_INCLUDE}
)
target_link_libraries(zerotier-core
PRIVATE
nlohmann_json::nlohmann_json
Threads::Threads
prometheus-cpp-lite
Threads::Threads)

59
osdep/CMakeLists.txt Normal file
View file

@ -0,0 +1,59 @@
cmake_minimum_required(VERSION 3.13)
project(osdep LANGUAGES CXX ASM)
set(SRC_FILES
Arp.cpp
Arp.hpp
Binder.hpp
BlockingQueue.hpp
EthernetTap.cpp
EthernetTap.hpp
Http.cpp
Http.hpp
ManagedRoute.cpp
ManagedRoute.hpp
NeighborDiscovery.cpp
NeighborDiscovery.hpp
OSUtils.cpp
OSUtils.hpp
Phy.hpp
PortMapper.cpp
PortMapper.hpp
Thread.hpp
)
option(EXT_OSDEP "Build with external osdep feature" OFF)
if(EXT_OSDEP)
add_definitions(-DZT_EXTOSDEP)
list(APPEND SRC_FILES
ExtOsdep.cpp
ExtOsdep.hpp)
endif()
if(LINUX)
list(APPEND SRC_FILES
LinuxEthernetTap.cpp
LinuxEthernetTap.hpp
LinuxNetLink.cpp
LinuxNetLink.hpp)
endif()
if(MACOS)
list(APPEND SRC_FILES
MacOSEthernetTap.cpp
MacOSEthernetTap.hpp
MacKextEthernetTap.cpp
MacKextEthernetTap.hpp)
endif()
add_library(zerotier-osdep STATIC ${SRC_FILES})
target_link_libraries(zerotier-osdep
PRIVATE
nlohmann_json::nlohmann_json
Threads::Threads
prometheus-cpp-lite
Threads::Threads
miniupnpc::miniupnpc
natpmp
)

View file

@ -23,6 +23,8 @@
#define ZT_TAP_BUF_SIZE 16384
#ifdef ZT_EXTOSDEP
namespace ZeroTier {
static int eodFd = -1;
@ -626,3 +628,5 @@ void ExtOsdepTap::setMtu(unsigned int mtu)
}
} // namespace ZeroTier
#endif // ZT_EXTOSDEP

View file

@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["staticlib", "rlib"]
[features]
default = ["zeroidc"]
default = ["zeroidc", "ztcontroller"]
zeroidc = []
ztcontroller = [
"dep:serde",

File diff suppressed because it is too large Load diff

50
service/CMakeLists.txt Normal file
View file

@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.13)
project(service)
file(GLOB service_src_glob ${PROJ_DIR}/service/*.cpp)
file(GLOB service_hdr_glob ${PROJ_DIR}/service/*.hpp)
add_library(zerotier-service STATIC ${service_src_glob} ${service_hdr_glob})
set(INCLUDE_DIRS
"${httplib_SOURCE_DIR}"
${RUSTYBITS_INCLUDE_DIR}
)
find_package(OpenSSL REQUIRED)
set(LINK_LIBS
zerotier-osdep
zerotier-core
prometheus-cpp-lite
nlohmann_json::nlohmann_json
Threads::Threads
opentelemetry-cpp::api
Threads::Threads
OpenSSL::Crypto
OpenSSL::SSL
rustybits
)
if(ZT1_CENTRAL_CONTROLLER)
add_definitions(-DZT_CONTROLLER_USE_LIBPQ)
list(APPEND INCLUDE_DIRS
${PostgreSQL_INCLUDE_DIRS}
"${redis++_BUILD_DIR}/src"
${pqxx_INCLUDE_DIRS}
)
list(APPEND LINK_LIBS
pqxx
opentelemetry-cpp::sdk
)
endif()
target_include_directories(zerotier-service
PRIVATE
${INCLUDE_DIRS}
)
target_link_libraries(zerotier-service
${LINK_LIBS}
)

View file

@ -57,7 +57,11 @@
#include "OneService.hpp"
#include "SoftwareUpdater.hpp"
#ifdef CMAKE_BUILD
#include <httplib.h>
#else
#include <cpp-httplib/httplib.h>
#endif
#ifdef ZT_OPENTELEMETRY_ENABLED
#include "opentelemetry/exporters/memory/in_memory_data.h"
@ -139,8 +143,10 @@ extern "C" {
using json = nlohmann::json;
#include "../controller/EmbeddedNetworkController.hpp"
#ifdef ZT_CONTROLLER_USE_LIBPQ
#include "../controller/PostgreSQL.hpp"
#include "../controller/Redis.hpp"
#endif
#include "../osdep/EthernetTap.hpp"
#ifdef __WINDOWS__
#include "../osdep/WindowsEthernetTap.hpp"
@ -2851,13 +2857,14 @@ class OneServiceImpl : public OneService {
std::string linkSelectMethodStr;
if (customPolicy.contains("linkSelectMethod")) {
linkSelectMethodStr = OSUtils::jsonString(customPolicy["linkSelectMethod"], "always");
} else {
}
else {
linkSelectMethodStr = OSUtils::jsonString(customPolicy["activeReselect"], "always");
if (customPolicy.contains("activeReselect")) {
fprintf(stderr, "warning: 'activeReselect' is deprecated, please use 'linkSelectMethod' instead in policy '%s'\n", customPolicyStr.c_str());
}
}
if (linkSelectMethodStr == "always") {
newTemplateBond->setLinkSelectMethod(ZT_BOND_RESELECTION_POLICY_ALWAYS);
}