Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
e822811
reorganize rustybits into a single library with smeeclient behind the…
glimberg Aug 5, 2025
f9500ca
fix dependencies when temporal isn't needed
glimberg Aug 5, 2025
44d0e81
gcloud-pubsub only if ztcontroller is flagged
glimberg Aug 5, 2025
a552163
fix macos build
glimberg Aug 5, 2025
4b3b847
fix windows bui ld
glimberg Aug 5, 2025
837f15d
tokio is needed by both temporal & gcloud pubsub, so make just one in…
glimberg Aug 7, 2025
f079f8b
cleanup warnings
glimberg Aug 11, 2025
06b2ce9
WIP: pubsub wrapper in Rust
glimberg Aug 12, 2025
0e94891
plumb through callbacks
glimberg Aug 13, 2025
bf8c9d0
function naming cleanup.
glimberg Aug 13, 2025
ccb0fa7
updates & tests.
glimberg Aug 14, 2025
3a209e2
expose change_handler to C via FFI
glimberg Aug 14, 2025
a842ad8
remove ztcontroller from default feature list
glimberg Aug 14, 2025
d4ee95e
feature cleanup
glimberg Aug 14, 2025
e4147f7
fix build script
glimberg Aug 14, 2025
4fab227
fix calling into async functions from non-async via the FFI
glimberg Aug 14, 2025
4237830
revert default feature list once again
glimberg Aug 14, 2025
b90ad51
more calling async from non-async changes
glimberg Aug 15, 2025
650fc0c
Add C++ wrapper around pubsub listeners
glimberg Aug 15, 2025
ebe8fdb
rename classes
glimberg Aug 20, 2025
9522437
Refactor Redis & Posgres notification listeners into listener subclas…
glimberg Aug 21, 2025
2833d0e
make whether SSO is enabled a switchable config value
glimberg Aug 21, 2025
f8a4a5d
rework protobuf messages
glimberg Aug 25, 2025
7f3b150
Update central controller build to use CMake + conda
glimberg Aug 27, 2025
9bdd564
spacing
glimberg Aug 27, 2025
3187c2f
clang format change (not applied project-wide yet)
glimberg Aug 29, 2025
85f2335
add a StatusWriter class hierarchy for writing member status updates
glimberg Aug 29, 2025
d119547
wire up status writers
glimberg Sep 1, 2025
e347f89
add sleep at end of online notificaiton loop
glimberg Sep 1, 2025
17b48d7
Merge branch 'dev' into gl/ctl-pubsub
glimberg Sep 1, 2025
b114896
PubSub to gcloud-cpp library for simplicity's sake
glimberg Sep 1, 2025
db6e698
rework the pubsub listener again so the subscription is set up on its…
glimberg Sep 1, 2025
0f63783
remove rust-based pubsub
glimberg Sep 1, 2025
496e69e
add def for new style controllers
glimberg Sep 1, 2025
195d5b4
Merge branch 'adam/1.16' into gl/ctl-pubsub
glimberg Sep 1, 2025
4ddb1fb
Create the pubsub topic if it doesn't exist
glimberg Sep 2, 2025
a5bd262
Wiring through initialization of the CentralDB version of the controller
glimberg Sep 2, 2025
0753556
wire up configuration.
glimberg Sep 2, 2025
70f9fe0
update central controller readme with config block
glimberg Sep 2, 2025
2a647d4
remove otel warning
glimberg Sep 2, 2025
7c1bfc9
setup github action for building
glimberg Sep 3, 2025
0f13363
runs-on matrix
glimberg Sep 3, 2025
09f1ee7
skip caching until this all works
glimberg Sep 3, 2025
97681b5
trying to get this working
glimberg Sep 3, 2025
e1db40d
test
glimberg Sep 3, 2025
cab33df
no linux/arm64 build available for google-cloud-cpp 2.39 :/. Downgra…
glimberg Sep 3, 2025
22484c7
dependency juggling
glimberg Sep 3, 2025
3ad36c7
fix cmake options
glimberg Sep 3, 2025
f43bc3d
more conda
glimberg Sep 3, 2025
21e20f2
more conda
glimberg Sep 3, 2025
648f091
skip cmake action
glimberg Sep 3, 2025
3470ceb
cmake --build args
glimberg Sep 3, 2025
d3f1ec7
fix arm64 build flag
glimberg Sep 3, 2025
0f3a514
fix deps for selftest
glimberg Sep 3, 2025
d31b3a0
set ZT_AES_NEON for arm64
glimberg Sep 3, 2025
1dae4c4
cache conda environment
glimberg Sep 3, 2025
4395574
cache conda environment
glimberg Sep 3, 2025
b09956a
fix run arg
glimberg Sep 3, 2025
3ff4d67
bump
glimberg Sep 3, 2025
a841e96
put git branch ref into cache key name
glimberg Sep 3, 2025
3f3e684
only update conda env if cache was not hit
glimberg Sep 3, 2025
000f3d5
let's build a docker image
glimberg Sep 3, 2025
7fd112e
fix short hash
glimberg Sep 3, 2025
594d227
fix multi-arch manifest creation
glimberg Sep 3, 2025
4abf902
update ld.so.conf for paths to libraries
glimberg Sep 3, 2025
9d73c34
new modified startup script for central controller docker images with…
glimberg Sep 3, 2025
3ad352c
no trailing comma on bigtable block
glimberg Sep 3, 2025
6ceb8ea
text alignment
glimberg Sep 3, 2025
4f07599
add jemalloc
glimberg Sep 3, 2025
2416c42
change tag to match existing
glimberg Sep 4, 2025
4516e6a
need a conda init here first apparently
glimberg Sep 4, 2025
96aa893
stray backtick
glimberg Sep 4, 2025
158d245
also have to add postgres to the container for pg_isready
glimberg Sep 4, 2025
1da9e24
no absolute path for pg_isready
glimberg Sep 4, 2025
092fc26
ok back to full path
glimberg Sep 4, 2025
d216a37
run process in conda env directly from docker
glimberg Sep 4, 2025
c9c8e95
debug output of main script
glimberg Sep 4, 2025
b94fa2d
.
glimberg Sep 4, 2025
7e4e7ef
fix case for redis: null
glimberg Sep 4, 2025
ce84de6
and instead of or in postgres check
glimberg Sep 4, 2025
6866535
debug printf
glimberg Sep 4, 2025
f33e706
get a running controller in docker
glimberg Sep 4, 2025
73e3287
debugging runtime link issues on arm64
glimberg Sep 4, 2025
2264452
try to make this work on both x64 & arm64
glimberg Sep 4, 2025
7d5a60b
will this make arm64 containers work?
glimberg Sep 4, 2025
40f6508
add conda builder dockerfile
glimberg Sep 4, 2025
70d24fc
trying to build in a docker container
glimberg Sep 4, 2025
8bd96d3
build in containers
glimberg Sep 4, 2025
67526d4
move up docker auth
glimberg Sep 4, 2025
3616c40
move up the gcp auth step
glimberg Sep 4, 2025
dcd583f
cleanup controller github action
glimberg Sep 4, 2025
f208007
enable otel exporter
glimberg Sep 4, 2025
b16d937
fix otel exporting
glimberg Sep 4, 2025
20746b2
query fix
glimberg Sep 4, 2025
3b7958a
another query fix
glimberg Sep 4, 2025
e9565cf
another query fix
glimberg Sep 4, 2025
a18e370
another query fix
glimberg Sep 4, 2025
a061c86
fix
glimberg Sep 5, 2025
48ff61b
fix
glimberg Sep 5, 2025
282d7c7
another fix
glimberg Sep 5, 2025
ba6200f
add a ChangeSource enum to the change protobuf messages
glimberg Sep 5, 2025
74f0525
Add `frontend` column to networks & network_memberships tables so the…
glimberg Sep 5, 2025
024824c
wire up pubsub outgoing status changes from controller -> CV2
glimberg Sep 5, 2025
7ad264d
whoops. mesed up the migrate naming convention
glimberg Sep 5, 2025
3d72a43
misc bugfixes
glimberg Sep 6, 2025
69efa92
apply patch to libnatpmp repo so we can compile on macOS with CMake
glimberg Sep 6, 2025
36219c5
compiler on mac doesn't like this. not really needed though
glimberg Sep 6, 2025
a78ac17
fix compile & link on macOS
glimberg Sep 6, 2025
71d68e9
fix stack corruption in DB::get
glimberg Sep 8, 2025
ebf66b7
fix typo in cmake file
glimberg Sep 8, 2025
006ced2
more fixes
glimberg Sep 8, 2025
190d836
alloc meatadata with new so pubsub can delete it
glimberg Sep 8, 2025
f51bfdb
delete pubsub subscription on shutdown
glimberg Sep 8, 2025
88f08fa
append 8 random hex chars to the subscription id
glimberg Sep 8, 2025
934aa93
forgot a ;
glimberg Sep 8, 2025
1ba4ccd
pass version info to status writer
glimberg Sep 8, 2025
1d65c1e
back to bulk apply for status updates in BigTable
glimberg Sep 8, 2025
facca36
only update os, architecture and client version if they've changed (o…
glimberg Sep 8, 2025
ee87eb3
removing some log output
glimberg Sep 8, 2025
012443a
wire up pubsub notifications from controller to frontend
glimberg Sep 8, 2025
7aa451b
clean up deprecation warnings in pqxx
glimberg Sep 10, 2025
493cc4f
fix version string
glimberg Sep 10, 2025
1ce37e7
add `use_for_new_networks` column in controller table
glimberg Sep 11, 2025
ad1fc5f
add tables for the controller load log and sso nonces & expiry
glimberg Sep 13, 2025
cb2de5a
fix migration
glimberg Sep 13, 2025
6113bad
make pubsub topics configurable
glimberg Sep 18, 2025
d96d3b2
try making the controller attach to an existing pubsub subscription i…
glimberg Sep 22, 2025
6196e87
only create the subscription if pubsub emulator is being used.
glimberg Sep 22, 2025
069d7c1
set objtype on messages received via PubSub
glimberg Sep 25, 2025
e51e516
fix subscription creation
glimberg Sep 25, 2025
c6b7c26
query fix for new networks
glimberg Sep 25, 2025
315bf24
json field fix
glimberg Sep 25, 2025
97d20a1
more logging for errors on pubsub listener
glimberg Sep 30, 2025
02908e5
stray ` got in there
glimberg Sep 30, 2025
20a67ab
fix attempted null -> string conversion
glimberg Oct 1, 2025
b4f018b
debug output from parsing pubsub messages
glimberg Oct 1, 2025
f028213
debug output
glimberg Oct 1, 2025
dad1a1e
more logging
glimberg Oct 1, 2025
aecd7fd
more logging
glimberg Oct 1, 2025
1f557b5
more debug output
glimberg Oct 1, 2025
7faf705
make the default an empty array here
glimberg Oct 1, 2025
80f8213
fix tags/capabilities?
glimberg Oct 1, 2025
a8b5c89
think this is where things are crashing, but I'm not sure why yet. C…
glimberg Oct 1, 2025
fb75369
throwing stuff at the wall cuz I can't actually debug this right now
glimberg Oct 1, 2025
3bbf194
pubsub writer should work now
glimberg Oct 1, 2025
0d21250
one last json parsing fix
glimberg Oct 1, 2025
4861b7d
one last json parsing fix. but really this time
glimberg Oct 2, 2025
a75d06a
cleaning up some gross JSON code
glimberg Oct 2, 2025
18714c7
add explicit nack if there's an error processing a pubsub message
glimberg Oct 2, 2025
1ef7ea0
Fixing more JSON issues
glimberg Oct 2, 2025
6df7366
no need for these timeouts
glimberg Oct 2, 2025
fe221b9
debug output for IP addressing & fixing order of operations in a coup…
glimberg Oct 6, 2025
6b74bf2
fix assign mode json
glimberg Oct 6, 2025
b92fb93
Merge branch 'dev' into gl/ctl-pubsub
glimberg Oct 6, 2025
946d96f
dont NACK failed messages. That gets us into a loop of failing the s…
glimberg Oct 9, 2025
46a8cd7
robustify the handling of tags/capabilities/rules which are strings o…
glimberg Oct 9, 2025
4736767
more robustifying incoming messages
glimberg Oct 9, 2025
e3f65ff
compiler fix
glimberg Oct 9, 2025
19ccc98
more variations on checking json
glimberg Oct 9, 2025
bf0fe2c
these should be empty json arrays, not just "[]".
glimberg Oct 9, 2025
77aa8c7
missed one
glimberg Oct 9, 2025
76ba890
ensure change source is controller if otherwise unset
glimberg Oct 9, 2025
c21ff23
Added some more logging to the ctl around deauths
glimberg Oct 27, 2025
30c4484
Set ordering key on pubsub message publishing.
glimberg Oct 27, 2025
5c27068
Enable cross-service propagation of otel trace metadata
glimberg Oct 30, 2025
00dca6a
Merge branch 'dev' into gl/ctl-pubsub
glimberg Nov 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 46 additions & 47 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,71 @@ BreakBeforeBraces: Stroustrup
IndentWidth: 4
TabWidth: 4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignConsecutiveMacros: "true"
AlignConsecutiveAssignments: "false"
AlignConsecutiveDeclarations: "false"
AlignEscapedNewlines: Right
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'false'
AlignOperands: "true"
AlignTrailingComments: "true"
AllowAllArgumentsOnNextLine: "false"
AllowAllConstructorInitializersOnNextLine: "false"
AllowAllParametersOfDeclarationOnNextLine: "false"
AllowShortBlocksOnASingleLine: "true"
AllowShortCaseLabelsOnASingleLine: "false"
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AlwaysBreakAfterReturnType: None
BinPackArguments: 'false'
BinPackParameters: 'false'
BinPackArguments: "true"
BinPackParameters: OnePerLine
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: 'true'
BreakBeforeTernaryOperators: "true"
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
CompactNamespaces: 'false'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'false'
FixNamespaceComments: 'true'
CompactNamespaces: "false"
ConstructorInitializerAllOnOneLineOrOnePerLine: "true"
ConstructorInitializerIndentWidth: "4"
ContinuationIndentWidth: "4"
Cpp11BracedListStyle: "false"
FixNamespaceComments: "true"
IncludeBlocks: Regroup
IndentCaseLabels: 'true'
IndentCaseLabels: "true"
IndentPPDirectives: None
IndentWrappedFunctionNames: 'false'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
MaxEmptyLinesToKeep: '1'
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'
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: 'Always'
SpaceBeforeRangeBasedForLoopColon: "true"
SpaceInEmptyParentheses: "false"
SpacesBeforeTrailingComments: "3"
SpacesInAngles: "false"
SpacesInCStyleCastParentheses: "false"
SpacesInContainerLiterals: "true"
SpacesInParentheses: "false"
SpacesInSquareBrackets: "false"
UseTab: "Always"

---
Language: Cpp
Standard: Cpp03
ColumnLimit: '240'
ColumnLimit: "120"
---
Language: ObjC
ColumnLimit: '240'
ColumnLimit: "120"
---
Language: Java
ColumnLimit: '240'
ColumnLimit: "120"
---
Language: CSharp
ColumnLimit: '240'
...
ColumnLimit: "120"
82 changes: 82 additions & 0 deletions .github/workflows/central-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# on:
# workflow_dispatch:
on:
push:
workflow_dispatch:

jobs:
central_controller:
name: Central Controller Build
strategy:
matrix:
runner: [gha-runner-x64, gha-runner-arm64]
runs-on: ${{ matrix.runner }}
steps:
- name: checkout
uses: actions/checkout@v4

- name: GCP Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.DOCKER_REGISTRY_WRITER}}

- name: Set up GCloud CLI
uses: google-github-actions/setup-gcloud@v2

- name: Docker Auth
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet

- name: Get branch name and sanitize
id: branch
run: |
BRANCH_NAME="${GITHUB_REF##*/}"
SANITIZED_BRANCH="${BRANCH_NAME//\//-}"
echo "branch_name=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT

- name: Get short git commit SHA
id: sha
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV

- name: Build & Push Docker Image
run: |
docker build -t us-central1-docker.pkg.dev/zerotier-421eb9/docker-images/ztcentral-controller:${{ env.COMMIT_SHORT_SHA }}-${{ steps.branch.outputs.branch_name }}-${{ runner.arch }} -f ext/central-controller-docker/Dockerfile.new . --push

multi-arch-docker:
runs-on: gha-runner-x64
needs: central_controller
steps:
- name: Checkout
uses: actions/checkout@v4

- name: GCP Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.DOCKER_REGISTRY_WRITER}}

- name: Set up GCloud CLI
uses: google-github-actions/setup-gcloud@v2

- name: Docker Auth
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet

- name: Get branch name and sanitize
id: branch
run: |
BRANCH_NAME="${GITHUB_REF##*/}"
SANITIZED_BRANCH="${BRANCH_NAME//\//-}"
echo "branch_name=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT

- name: Get short git commit SHA
id: sha
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV

- name: Create and push multi-arch manifest
run: |
docker manifest create us-central1-docker.pkg.dev/zerotier-421eb9/docker-images/ztcentral-controller:${{ env.COMMIT_SHORT_SHA }}-${{ steps.branch.outputs.branch_name }} \
--amend us-central1-docker.pkg.dev/zerotier-421eb9/docker-images/ztcentral-controller:${{ env.COMMIT_SHORT_SHA }}-${{ steps.branch.outputs.branch_name }}-X64 \
--amend us-central1-docker.pkg.dev/zerotier-421eb9/docker-images/ztcentral-controller:${{ env.COMMIT_SHORT_SHA }}-${{ steps.branch.outputs.branch_name }}-ARM64
docker manifest push us-central1-docker.pkg.dev/zerotier-421eb9/docker-images/ztcentral-controller:${{ env.COMMIT_SHORT_SHA }}-${{ steps.branch.outputs.branch_name }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ __pycache__
*.pyc
*_source.tar.bz2
snap/.snapcraft
build/
167 changes: 161 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,167 @@
# 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)
option(ADDRESS_SANITIZER "Build with Address Sanitizer enabled (only for x86_64/arm64)" 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}")

target_compile_options(zerotiercore PRIVATE ${ZT_DEFS})
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
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack")

if(ADDRESS_SANITIZER)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
elseif(CPU_ARCHITECTURE STREQUAL "aarch64" OR CPU_ARCHITECTURE STREQUAL "arm64")
add_definitions(-DZT_ARCHITECTURE=4 -DZT_ARCH_ARM_HAS_NEON=1 -DZT_SSO_SUPPORTED=1 -DZT_AES_NEON=1)
add_compile_options(-march=armv8-a+crypto -mtune=generic -mstrict-align)

if(ADDRESS_SANITIZER)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
endif()

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 exporters_otlp_grpc exporters_otlp_http exporters_prometheus )
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_NONFREE_CONTROLLER=1 -DZT_CONTROLLER_USE_LIBPQ=1 -DZT1_CENTRAL_CONTROLLER=1 -DZT_OPENTELEMETRY_ENABLED=1)
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)



# 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(nonfree)

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
opentelemetry-cpp::trace
opentelemetry-cpp::proto_grpc
opentelemetry-cpp::otlp_grpc_client
opentelemetry-cpp::otlp_grpc_exporter
opentelemetry-cpp::otlp_grpc_log_record_exporter
opentelemetry-cpp::otlp_grpc_metrics_exporter
opentelemetry-cpp::otlp_http_exporter
opentelemetry-cpp::otlp_http_log_record_exporter
opentelemetry-cpp::otlp_http_metric_exporter
opentelemetry-cpp::prometheus_exporter
)
endif()

if (APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
find_library(SECURITY_LIBRARY Security)
find_library(SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
find_library(CARBON Carbon)
find_library(CORESERVICES_LIBRARY CoreServices)
list(APPEND LINKED_LIBRARIES ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY} ${CARBON_LIBRARY} ${SYSTEM_CONFIGURATION_LIBRARY} ${CORESERVICES_LIBRARY})
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
zerotier-osdep
Threads::Threads
nlohmann_json::nlohmann_json
prometheus-cpp-lite
Threads::Threads)
Loading
Loading