From a6f6886a8c8c07249f9e5d0cae431848727fe845 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 1 Jun 2022 14:40:54 -0700 Subject: [PATCH 01/55] Exclude temporary IPv6 checks for SDK builds (#147 and #184) --- ext/ZeroTierOne | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ZeroTierOne b/ext/ZeroTierOne index 7e46c83..a47c3cb 160000 --- a/ext/ZeroTierOne +++ b/ext/ZeroTierOne @@ -1 +1 @@ -Subproject commit 7e46c8359231b4aa55c5d739462c4e5682d35755 +Subproject commit a47c3cb16f1c16bc9be555fd7f6bcd34e843f001 From 361c6ffa50d475c465d57b27391e35c854550109 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 1 Jun 2022 15:26:55 -0700 Subject: [PATCH 02/55] Add mention of JDK to build matrix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2968623..590c9fb 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Peer-to-peer and cross-platform encrypted connections built right into your app | C# | `Install-Package ZeroTier.Sockets` | |[C#](./examples/csharp) | | Python | `pip install libzt`| |[Python](./examples/python) | | Rust | See: [crates.io/crates/libzt](https://crates.io/crates/libzt) | version|[Rust](./examples/rust) | -| Java | `./build.sh host-jar` | |[Java](./examples/java) | +| Java | Install JDK, then: `./build.sh host-jar` | |[Java](./examples/java) | | Linux | `brew install zerotier/tap/libzt` | version| [C/C++](./examples/c) | | macOS | `brew install zerotier/tap/libzt`| version| [C/C++](./examples/c) | | iOS / iPadOS | `./build.sh iphoneos-framework` | | [Objective-C](./attic/objective-c), [Swift](./attic/swift) | From 0bcae7b8e6d85ccfd1ecdcda25de4740a62ce792 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 1 Jun 2022 15:41:07 -0700 Subject: [PATCH 03/55] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 590c9fb..740e8d7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Peer-to-peer and cross-platform encrypted connections built right into your app Examples | Documentation | -Community | Report a Bug From cc58bceb843ac8f356fbea734cfa00b7c8959c2a Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 1 Jun 2022 15:47:57 -0700 Subject: [PATCH 04/55] Tweak build.sh --- .version | 1 - build.sh | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 .version diff --git a/.version b/.version deleted file mode 100644 index bfa363e..0000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -1.8.4 diff --git a/build.sh b/build.sh index dfd3bea..a488446 100755 --- a/build.sh +++ b/build.sh @@ -494,7 +494,7 @@ host-jar() { check_submodules ARTIFACT="jar" - PKG_VERSION=$(cat .version) + PKG_VERSION=$(git describe --tags --abbrev=0) # Default to release BUILD_TYPE=${1:-release} if [[ $1 = *"docs"* ]]; then @@ -745,13 +745,12 @@ clean() find . -type d -name "__pycache__" -exec rm -rf {} + # Python pkg - cd pkg/pypi && ./build.sh clean + # cd pkg/pypi && ./build.sh clean } tag_release() { git tag -a $1 -m $2 - "$(git describe --tags --abbrev=0)" >> .version git push origin --tags } From 7ad5b78ceeeec101dfbb56eea7366be53c69d499 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:05:44 +0000 Subject: [PATCH 05/55] Bump regex from 1.5.4 to 1.5.6 in /pkg/crate/libzt Bumps [regex](https://github.com/rust-lang/regex) from 1.5.4 to 1.5.6. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.5.4...1.5.6) --- updated-dependencies: - dependency-name: regex dependency-type: indirect ... Signed-off-by: dependabot[bot] --- pkg/crate/libzt/Cargo.lock | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/crate/libzt/Cargo.lock b/pkg/crate/libzt/Cargo.lock index 854a290..d7bcabd 100644 --- a/pkg/crate/libzt/Cargo.lock +++ b/pkg/crate/libzt/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.18" @@ -236,9 +238,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.4" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" dependencies = [ "aho-corasick", "memchr", @@ -247,9 +249,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "rustc-hash" From 038166f9f2a428daa32ad53d8f67758cb073f1d3 Mon Sep 17 00:00:00 2001 From: tejas238 Date: Wed, 23 Nov 2022 21:32:55 +0530 Subject: [PATCH 06/55] upgrade gradle versions and include .cxx bindings --- CMakeLists.txt | 2 ++ pkg/android/app/build.gradle | 6 +++--- pkg/android/build.gradle | 2 +- pkg/android/gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a95b8c..1924937 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,8 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Android") set(BUILD_HOST_SELFTEST FALSE) set(BUILD_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) + set(LANG_WRAPPER_FILE ${LIBZT_SRC_DIR}/bindings/java/*.cxx) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZTS_ENABLE_JAVA=1") endif() if(BUILD_MACOS_FRAMEWORK) diff --git a/pkg/android/app/build.gradle b/pkg/android/app/build.gradle index ca41335..f806add 100644 --- a/pkg/android/app/build.gradle +++ b/pkg/android/app/build.gradle @@ -1,10 +1,10 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 28 + compileSdkVersion 31 defaultConfig { - minSdkVersion 14 - targetSdkVersion 23 + minSdkVersion 21 + targetSdkVersion 31 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/pkg/android/build.gradle b/pkg/android/build.gradle index 43c0708..fcafdd4 100644 --- a/pkg/android/build.gradle +++ b/pkg/android/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:7.2.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/pkg/android/gradle/wrapper/gradle-wrapper.properties b/pkg/android/gradle/wrapper/gradle-wrapper.properties index 9fe8d05..567ad65 100644 --- a/pkg/android/gradle/wrapper/gradle-wrapper.properties +++ b/pkg/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip From 9d66844523849e02aeeba5b470578f86d1b12353 Mon Sep 17 00:00:00 2001 From: janvanbouwel Date: Tue, 21 Feb 2023 18:16:11 +0100 Subject: [PATCH 07/55] Fix ZTS_MAX_PEER_NETWORK_PATHS to equal ZTO submodule --- include/ZeroTierSockets.h | 2 +- pkg/crate/libzt/src/include/ZeroTierSockets.h | 2 +- src/bindings/java/ZeroTierNative.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index 98058e9..f57cd24 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -338,7 +338,7 @@ typedef enum { /** * Maximum number of direct network paths to a given peer */ -#define ZTS_MAX_PEER_NETWORK_PATHS 16 +#define ZTS_MAX_PEER_NETWORK_PATHS 64 /** * Maximum number of multicast groups a device / network interface can be diff --git a/pkg/crate/libzt/src/include/ZeroTierSockets.h b/pkg/crate/libzt/src/include/ZeroTierSockets.h index fe01d43..7d306e6 100644 --- a/pkg/crate/libzt/src/include/ZeroTierSockets.h +++ b/pkg/crate/libzt/src/include/ZeroTierSockets.h @@ -338,7 +338,7 @@ typedef enum { /** * Maximum number of direct network paths to a given peer */ -#define ZTS_MAX_PEER_NETWORK_PATHS 16 +#define ZTS_MAX_PEER_NETWORK_PATHS 64 /** * Maximum number of multicast groups a device / network interface can be diff --git a/src/bindings/java/ZeroTierNative.java b/src/bindings/java/ZeroTierNative.java index 0300e1d..9205315 100644 --- a/src/bindings/java/ZeroTierNative.java +++ b/src/bindings/java/ZeroTierNative.java @@ -407,7 +407,7 @@ public class ZeroTierNative { /** * Maximum number of direct network paths to a given peer */ - public static int ZTS_MAX_PEER_NETWORK_PATHS = 16; + public static int ZTS_MAX_PEER_NETWORK_PATHS = 64; /** * Maximum number of multicast groups a device / network interface can be From 71c2f97056b61a1d030d40d4e33e49a80a7f0ae6 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Tue, 21 Feb 2023 13:45:27 -0800 Subject: [PATCH 08/55] Fix broken include path for JSON library --- pkg/pypi/build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/pypi/build.py b/pkg/pypi/build.py index 3ab8c57..557a648 100644 --- a/pkg/pypi/build.py +++ b/pkg/pypi/build.py @@ -26,6 +26,7 @@ INCLUDE_DIRS = [ os.path.join(ROOT_DIR, "ext/lwip-contrib/ports/unix/port/include"), os.path.join(ROOT_DIR, "ext/ZeroTierOne/include"), os.path.join(ROOT_DIR, "ext/ZeroTierOne"), + os.path.join(ROOT_DIR, "ext/ZeroTierOne/ext"), os.path.join(ROOT_DIR, "ext/ZeroTierOne/node"), os.path.join(ROOT_DIR, "ext/ZeroTierOne/service"), os.path.join(ROOT_DIR, "ext/ZeroTierOne/osdep"), From 48adf41cc1ca35e82d81f510a1910e82e222e264 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 06:40:06 -0500 Subject: [PATCH 09/55] Move java files to com/zerotier/sockets subfolder This adheres to standard Java style and fixes: Package name 'com.zerotier.sockets' does not correspond to the file path '' in Android Studio --- build.sh | 36 +++++++++---------- .../sockets}/ZeroTierDatagramSocket.java | 0 .../sockets}/ZeroTierEventListener.java | 0 .../sockets}/ZeroTierFileDescriptorSet.java | 0 .../sockets}/ZeroTierInputStream.java | 0 .../zerotier/sockets}/ZeroTierNative.java | 0 .../zerotier/sockets}/ZeroTierNode.java | 0 .../sockets}/ZeroTierOutputStream.java | 0 .../sockets}/ZeroTierPeerDetails.java | 0 .../sockets}/ZeroTierServerSocket.java | 0 .../zerotier/sockets}/ZeroTierSocket.java | 0 .../sockets}/ZeroTierSocketAddress.java | 0 12 files changed, 18 insertions(+), 18 deletions(-) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierDatagramSocket.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierEventListener.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierFileDescriptorSet.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierInputStream.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierNative.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierNode.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierOutputStream.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierPeerDetails.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierServerSocket.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierSocket.java (100%) rename src/bindings/java/{ => com/zerotier/sockets}/ZeroTierSocketAddress.java (100%) diff --git a/build.sh b/build.sh index a488446..a486d12 100755 --- a/build.sh +++ b/build.sh @@ -499,7 +499,7 @@ host-jar() BUILD_TYPE=${1:-release} if [[ $1 = *"docs"* ]]; then # Generate documentation - javadoc src/bindings/java/*.java -d docs/java + javadoc src/bindings/java/com/zerotier/sockets/*.java -d docs/java exit 0 fi VARIANT="-DZTS_ENABLE_JAVA=True" @@ -512,7 +512,7 @@ host-jar() JAVA_JAR_DIR=$CACHE_DIR/pkg/jar JAVA_JAR_SOURCE_TREE_DIR=$JAVA_JAR_DIR/com/zerotier/sockets/ mkdir -p $JAVA_JAR_SOURCE_TREE_DIR - cp -f src/bindings/java/*.java $JAVA_JAR_SOURCE_TREE_DIR + cp -f src/bindings/java/com/zerotier/sockets/*.java $JAVA_JAR_SOURCE_TREE_DIR # Build $CMAKE $VARIANT -H. -B$CACHE_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE --build $CACHE_DIR $BUILD_CONCURRENCY @@ -601,7 +601,7 @@ android-aar() export PATH=$ANDROID_HOME/cmdline-tools/tools/bin:$PATH # Copy source files into project mkdir -p ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/sockets - cp -f src/bindings/java/*.java ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/sockets + cp -f src/bindings/java/com/zerotier/sockets/*.java ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/sockets # Build UPPERCASE_BUILD_TYPE="$(tr '[:lower:]' '[:upper:]' <<< ${BUILD_TYPE:0:1})${BUILD_TYPE:1}" CMAKE_FLAGS="-D${CMAKE_SWITCH}=1 -D${CMAKE_SWITCH}=ON" @@ -652,21 +652,21 @@ format-code() if [[ ! $(which $CLANG_FORMAT) = "" ]]; then # Eventually: find . -path ./ext -prune -false -o -type f \( -iname \*.c -o -iname \*.h -o -iname \*.cpp -o -iname \*.hpp \) -exec clang-format -i {} \; - $CLANG_FORMAT -i --verbose include/*.h \ - src/*.c \ - src/*.cpp \ - src/*.hpp \ - examples/c/*.c \ - examples/csharp/*.cs \ - examples/java/*.java \ - test/*.c \ - test/*.cs \ - src/bindings/csharp/*.cs \ - src/bindings/csharp/*.cxx \ - src/bindings/java/*.java \ - src/bindings/java/*.cxx \ - examples/csharp/*.cs \ - src/bindings/python/PythonSockets.cxx \ + $CLANG_FORMAT -i --verbose include/*.h \ + src/*.c \ + src/*.cpp \ + src/*.hpp \ + examples/c/*.c \ + examples/csharp/*.cs \ + examples/java/*.java \ + test/*.c \ + test/*.cs \ + src/bindings/csharp/*.cs \ + src/bindings/csharp/*.cxx \ + src/bindings/java/com/zerotier/sockets/*.java \ + src/bindings/java/*.cxx \ + examples/csharp/*.cs \ + src/bindings/python/PythonSockets.cxx \ src/bindings/python/PythonSocket.h return 0 else diff --git a/src/bindings/java/ZeroTierDatagramSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierDatagramSocket.java similarity index 100% rename from src/bindings/java/ZeroTierDatagramSocket.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierDatagramSocket.java diff --git a/src/bindings/java/ZeroTierEventListener.java b/src/bindings/java/com/zerotier/sockets/ZeroTierEventListener.java similarity index 100% rename from src/bindings/java/ZeroTierEventListener.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierEventListener.java diff --git a/src/bindings/java/ZeroTierFileDescriptorSet.java b/src/bindings/java/com/zerotier/sockets/ZeroTierFileDescriptorSet.java similarity index 100% rename from src/bindings/java/ZeroTierFileDescriptorSet.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierFileDescriptorSet.java diff --git a/src/bindings/java/ZeroTierInputStream.java b/src/bindings/java/com/zerotier/sockets/ZeroTierInputStream.java similarity index 100% rename from src/bindings/java/ZeroTierInputStream.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierInputStream.java diff --git a/src/bindings/java/ZeroTierNative.java b/src/bindings/java/com/zerotier/sockets/ZeroTierNative.java similarity index 100% rename from src/bindings/java/ZeroTierNative.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierNative.java diff --git a/src/bindings/java/ZeroTierNode.java b/src/bindings/java/com/zerotier/sockets/ZeroTierNode.java similarity index 100% rename from src/bindings/java/ZeroTierNode.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierNode.java diff --git a/src/bindings/java/ZeroTierOutputStream.java b/src/bindings/java/com/zerotier/sockets/ZeroTierOutputStream.java similarity index 100% rename from src/bindings/java/ZeroTierOutputStream.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierOutputStream.java diff --git a/src/bindings/java/ZeroTierPeerDetails.java b/src/bindings/java/com/zerotier/sockets/ZeroTierPeerDetails.java similarity index 100% rename from src/bindings/java/ZeroTierPeerDetails.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierPeerDetails.java diff --git a/src/bindings/java/ZeroTierServerSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierServerSocket.java similarity index 100% rename from src/bindings/java/ZeroTierServerSocket.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierServerSocket.java diff --git a/src/bindings/java/ZeroTierSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java similarity index 100% rename from src/bindings/java/ZeroTierSocket.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java diff --git a/src/bindings/java/ZeroTierSocketAddress.java b/src/bindings/java/com/zerotier/sockets/ZeroTierSocketAddress.java similarity index 100% rename from src/bindings/java/ZeroTierSocketAddress.java rename to src/bindings/java/com/zerotier/sockets/ZeroTierSocketAddress.java From 8952a6bf95d7ee45ba9d14a771bca749754a8ae7 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 06:55:17 -0500 Subject: [PATCH 10/55] Fix typos ZTS_CENRTAL_MAX_URL_LEN -> ZTS_CENTRAL_MAX_URL_LEN --- include/ZeroTierSockets.h | 2 +- src/Central.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index f57cd24..0374bac 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -1023,7 +1023,7 @@ typedef struct { #ifndef ZTS_DISABLE_CENTRAL_API #define ZTS_CENTRAL_DEFAULT_URL "https://my.zerotier.com" -#define ZTS_CENRTAL_MAX_URL_LEN 128 +#define ZTS_CENTRAL_MAX_URL_LEN 128 #define ZTS_CENTRAL_TOKEN_LEN 32 #define ZTS_CENTRAL_RESP_BUF_DEFAULT_SZ (128 * 1024) diff --git a/src/Central.cpp b/src/Central.cpp index 247d0b2..e6ea8b0 100644 --- a/src/Central.cpp +++ b/src/Central.cpp @@ -25,7 +25,7 @@ #define REQ_LEN 64 -char api_url[ZTS_CENRTAL_MAX_URL_LEN]; +char api_url[ZTS_CENTRAL_MAX_URL_LEN]; char api_token[ZTS_CENTRAL_TOKEN_LEN + 1]; char* _resp_buf; @@ -97,12 +97,12 @@ int zts_central_init(const char* url_str, const char* token_str, char* resp_buf, // Initialize all curl internal submodules curl_global_init(CURL_GLOBAL_ALL); - int url_len = strnlen(url_str, ZTS_CENRTAL_MAX_URL_LEN); - if (url_len < 3 || url_len > ZTS_CENRTAL_MAX_URL_LEN) { + int url_len = strnlen(url_str, ZTS_CENTRAL_MAX_URL_LEN); + if (url_len < 3 || url_len > ZTS_CENTRAL_MAX_URL_LEN) { return ZTS_ERR_ARG; } else { - memset(api_url, 0, ZTS_CENRTAL_MAX_URL_LEN); + memset(api_url, 0, ZTS_CENTRAL_MAX_URL_LEN); strncpy(api_url, url_str, url_len); } int token_len = strnlen(token_str, ZTS_CENTRAL_TOKEN_LEN); @@ -146,19 +146,19 @@ int central_req( return ZTS_ERR_SERVICE; } zts_central_clear_resp_buf(); - int central_strlen = strnlen(central_str, ZTS_CENRTAL_MAX_URL_LEN); - int api_route_strlen = strnlen(api_route_str, ZTS_CENRTAL_MAX_URL_LEN); + int central_strlen = strnlen(central_str, ZTS_CENTRAL_MAX_URL_LEN); + int api_route_strlen = strnlen(api_route_str, ZTS_CENTRAL_MAX_URL_LEN); int token_strlen = strnlen(token_str, ZTS_CENTRAL_TOKEN_LEN); int url_len = central_strlen + api_route_strlen; if (token_strlen > ZTS_CENTRAL_TOKEN_LEN) { return ZTS_ERR_ARG; } - if (url_len > ZTS_CENRTAL_MAX_URL_LEN) { + if (url_len > ZTS_CENTRAL_MAX_URL_LEN) { return ZTS_ERR_ARG; } - char req_url[ZTS_CENRTAL_MAX_URL_LEN] = { 0 }; - strncpy(req_url, central_str, ZTS_CENRTAL_MAX_URL_LEN); - strncat(req_url, api_route_str, ZTS_CENRTAL_MAX_URL_LEN); + char req_url[ZTS_CENTRAL_MAX_URL_LEN] = { 0 }; + strncpy(req_url, central_str, ZTS_CENTRAL_MAX_URL_LEN); + strncat(req_url, api_route_str, ZTS_CENTRAL_MAX_URL_LEN); CURL* curl; CURLcode res; From d00f72ae925be96da977df358251907a72b1da80 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 06:56:31 -0500 Subject: [PATCH 11/55] Fix typo accetpedFd -> acceptedFd --- .../java/com/zerotier/sockets/ZeroTierSocket.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java index ffedb3b..66e7946 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java @@ -232,12 +232,12 @@ public class ZeroTierSocket { if (_zfd < 0) { throw new IOException("Invalid socket (fd < 0)"); } - int accetpedFd = -1; + int acceptedFd = -1; ZeroTierSocketAddress addr = new ZeroTierSocketAddress(); - if ((accetpedFd = ZeroTierNative.zts_bsd_accept(_zfd, addr)) < 0) { - throw new IOException("Error while accepting connection (" + accetpedFd + ")"); + if ((acceptedFd = ZeroTierNative.zts_bsd_accept(_zfd, addr)) < 0) { + throw new IOException("Error while accepting connection (" + acceptedFd + ")"); } - return new ZeroTierSocket(_family, _type, _protocol, accetpedFd); + return new ZeroTierSocket(_family, _type, _protocol, acceptedFd); } /** From 51af6aacd944f52e952d0fefcee2cb196ffc7ae3 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 07:04:52 -0500 Subject: [PATCH 12/55] Fix typo TCP_SLOW_INTERVALs -> TCP_SLOW_INTERVAL --- src/lwipopts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lwipopts.h b/src/lwipopts.h index 20e7437..5ddb269 100644 --- a/src/lwipopts.h +++ b/src/lwipopts.h @@ -149,7 +149,7 @@ happening sooner than they should. #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL #endif /* TCP_FAST_INTERVAL */ -#ifndef TCP_SLOW_INTERVALs +#ifndef TCP_SLOW_INTERVAL /* the coarse grained timeout in milliseconds */ #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) #endif /* TCP_SLOW_INTERVAL */ From 8bd9a18a386141bbaa69249a2c28b2bb50705cf9 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 06:52:14 -0500 Subject: [PATCH 13/55] remove stray U+200b characters --- .../sockets/ZeroTierDatagramSocket.java | 10 +++---- .../zerotier/sockets/ZeroTierInputStream.java | 26 +++++++++---------- .../com/zerotier/sockets/ZeroTierSocket.java | 10 +++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierDatagramSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierDatagramSocket.java index a37608d..34d4470 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierDatagramSocket.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierDatagramSocket.java @@ -165,7 +165,7 @@ public class ZeroTierDatagramSocket { 0, packet.getLength()); if ((bytesRead <= 0) | (bytesRead == -104) /* EINTR, from SO_RCVTIMEO */) { - throw new IOException("read​(DatagramPacket), errno=" + bytesRead); + throw new IOException("read(DatagramPacket), errno=" + bytesRead); } } @@ -277,16 +277,16 @@ public class ZeroTierDatagramSocket { * Return whether this ZeroTierSocket is bound to a local address * @return true or false */ - public boolean isBound​() + public boolean isBound() { - return _socket.isBound​(); + return _socket.isBound(); } /** * Return whether this ZeroTierSocket has been closed * @return true or false */ - public boolean isClosed​() + public boolean isClosed() { return _socket.isClosed(); } @@ -295,7 +295,7 @@ public class ZeroTierDatagramSocket { * Return whether this ZeroTierSocket is connected to a remote address * @return true or false */ - public boolean isConnected​() + public boolean isConnected() { return _socket.isConnected(); } diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierInputStream.java b/src/bindings/java/com/zerotier/sockets/ZeroTierInputStream.java index 8d23d88..e5d2d4f 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierInputStream.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierInputStream.java @@ -30,7 +30,7 @@ public class ZeroTierInputStream extends InputStream { * Close the ZeroTierInputStream * @exception IOException when an I/O error occurs */ - public void close​() throws IOException + public void close() throws IOException { /* Note: this operation currently only stops RX on a socket that is shared between both I/OStreams. This means that closing this stream will only shutdown @@ -47,7 +47,7 @@ public class ZeroTierInputStream extends InputStream { * @return Number of bytes transferred * @exception IOException when an I/O error occurs */ - public long transferTo​(OutputStream destStream) throws IOException + public long transferTo(OutputStream destStream) throws IOException { Objects.requireNonNull(destStream, "destStream must not be null"); int bytesTransferred = 0, bytesRead; @@ -64,7 +64,7 @@ public class ZeroTierInputStream extends InputStream { * @return Single byte read * @exception IOException when an I/O error occurs */ - public int read​() throws IOException + public int read() throws IOException { byte[] buf = new byte[1]; // Unlike a native read(), if nothing is read we should return -1 @@ -73,7 +73,7 @@ public class ZeroTierInputStream extends InputStream { return -1; } if (retval < 0) { - throw new IOException("read​(), errno=" + retval); + throw new IOException("read(), errno=" + retval); } return buf[0]; } @@ -84,7 +84,7 @@ public class ZeroTierInputStream extends InputStream { * @return Number of bytes read * @exception IOException when an I/O error occurs */ - public int read​(byte[] destBuffer) throws IOException + public int read(byte[] destBuffer) throws IOException { Objects.requireNonNull(destBuffer, "input byte array must not be null"); // Unlike a native read(), if nothing is read we should return -1 @@ -93,7 +93,7 @@ public class ZeroTierInputStream extends InputStream { return -1; } if (retval < 0) { - throw new IOException("read​(destBuffer), errno=" + retval); + throw new IOException("read(destBuffer), errno=" + retval); } return retval; } @@ -106,7 +106,7 @@ public class ZeroTierInputStream extends InputStream { * @return Number of bytes read. * @exception IOException when an I/O error occurs */ - public int read​(byte[] destBuffer, int offset, int numBytes) throws IOException + public int read(byte[] destBuffer, int offset, int numBytes) throws IOException { Objects.requireNonNull(destBuffer, "input byte array must not be null"); if (offset < 0) { @@ -127,7 +127,7 @@ public class ZeroTierInputStream extends InputStream { return -1; } if (retval < 0) { - throw new IOException("read​(destBuffer, offset, numBytes), errno=" + retval); + throw new IOException("read(destBuffer, offset, numBytes), errno=" + retval); } return retval; } @@ -137,7 +137,7 @@ public class ZeroTierInputStream extends InputStream { * @return Array of bytes * @exception IOException when an I/O error occurs */ - public byte[] readAllBytes​() throws IOException + public byte[] readAllBytes() throws IOException { int pendingDataSize = ZeroTierNative.zts_get_pending_data_size(zfd); byte[] buf = new byte[pendingDataSize]; @@ -146,7 +146,7 @@ public class ZeroTierInputStream extends InputStream { // No action needed } if (retval < 0) { - throw new IOException("readAllBytes​(), errno=" + retval); + throw new IOException("readAllBytes(), errno=" + retval); } return buf; } @@ -159,7 +159,7 @@ public class ZeroTierInputStream extends InputStream { * @return Nothing. * @exception IOException when an I/O error occurs */ - public int readNBytes​(byte[] destBuffer, int offset, int numBytes) throws IOException + public int readNBytes(byte[] destBuffer, int offset, int numBytes) throws IOException { Objects.requireNonNull(destBuffer, "input byte array must not be null"); if (offset < 0) { @@ -179,7 +179,7 @@ public class ZeroTierInputStream extends InputStream { // No action needed } if (retval < 0) { - throw new IOException("readNBytes​(destBuffer, offset, numBytes), errno=" + retval); + throw new IOException("readNBytes(destBuffer, offset, numBytes), errno=" + retval); } return retval; } @@ -190,7 +190,7 @@ public class ZeroTierInputStream extends InputStream { * @return Nothing. * @exception IOException when an I/O error occurs */ - public long skip​(long numBytes) throws IOException + public long skip(long numBytes) throws IOException { if (numBytes <= 0) { return 0; diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java index 66e7946..7b0fea3 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierSocket.java @@ -421,7 +421,7 @@ public class ZeroTierSocket { * Return whether this ZeroTierSocket is bound to a local address * @return true or false */ - public boolean isBound​() + public boolean isBound() { return _isBound; } @@ -430,7 +430,7 @@ public class ZeroTierSocket { * Return whether this ZeroTierSocket has been closed * @return true or false */ - public boolean isClosed​() + public boolean isClosed() { return _isClosed; } @@ -439,7 +439,7 @@ public class ZeroTierSocket { * Return whether this ZeroTierSocket is connected to a remote address * @return true or false */ - public boolean isConnected​() + public boolean isConnected() { return _isConnected; } @@ -526,7 +526,7 @@ public class ZeroTierSocket { * Return whether the input-aspect of the ZeroTierSocket has been disabled. * @return true or false */ - public boolean inputStreamHasBeenShutdown​() + public boolean inputStreamHasBeenShutdown() { return _inputHasBeenShutdown; } @@ -535,7 +535,7 @@ public class ZeroTierSocket { * Return whether the output-aspect of the ZeroTierSocket has been disabled. * @return true or false */ - public boolean outputStreamHasBeenShutdown​() + public boolean outputStreamHasBeenShutdown() { return _outputHasBeenShutdown; } From 18c009d55d2be5007b39ec267a54b8b2a957809b Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 17:03:43 -0500 Subject: [PATCH 14/55] fix: Incorrect type for parameter 'thisObj', which should have type 'jclass'. --- src/bindings/java/JavaSockets.cxx | 170 +++++++++++++++--------------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index d3de89b..588f8b5 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -53,7 +53,7 @@ void fdset2ztfdset(JNIEnv* env, int nfds, zts_fd_set* src_fd_set, jobject dest_z * Called from Java, saves a static reference to the VM so it can be used * later to call a user-specified callback method from C. */ -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1init(JNIEnv* env, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1init(JNIEnv* env, jclass clazz) { jint rs = env->GetJavaVM(&jvm); return rs != JNI_OK ? ZTS_ERR_GENERAL : ZTS_ERR_OK; @@ -61,7 +61,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1init(JNIEnv JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1socket( JNIEnv* env, - jobject thisObj, + jclass clazz, jint family, jint type, jint protocol) @@ -71,7 +71,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1socket } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1listen(JNIEnv* env, jobject thisObj, jint fd, int backlog) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1listen(JNIEnv* env, jclass clazz, jint fd, int backlog) { int retval = zts_bsd_listen(fd, backlog); return retval > -1 ? retval : -(zts_errno); @@ -79,7 +79,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1listen(JNIEnv* env, jobject t JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1accept( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jobject addr, jint port) @@ -92,7 +92,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1accept } JNIEXPORT jboolean JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1getsockname(JNIEnv* env, jobject thisObj, jint fd, jobject addr) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1getsockname(JNIEnv* env, jclass clazz, jint fd, jobject addr) { struct zts_sockaddr_storage ss; zts_socklen_t addrlen = sizeof(struct zts_sockaddr_storage); @@ -102,7 +102,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1getsockname(JNIEnv* env, jobj } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1getpeername(JNIEnv* env, jobject thisObj, jint fd, jobject addr) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1getpeername(JNIEnv* env, jclass clazz, jint fd, jobject addr) { struct zts_sockaddr_storage ss; int retval = @@ -111,14 +111,14 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1getpeername(JNIEnv* env, jobj return retval > -1 ? retval : -(zts_errno); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1close(JNIEnv* env, jobject thisObj, jint fd) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1close(JNIEnv* env, jclass clazz, jint fd) { return zts_bsd_close(fd); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1select( JNIEnv* env, - jobject thisObj, + jclass clazz, jint nfds, jobject readfds, jobject writefds, @@ -159,7 +159,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1select } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1fcntl(JNIEnv* env, jobject thisObj, jint fd, jint cmd, jint flags) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1fcntl(JNIEnv* env, jclass clazz, jint fd, jint cmd, jint flags) { int retval = zts_bsd_fcntl(fd, cmd, flags); return retval > -1 ? retval : -(zts_errno); @@ -194,7 +194,7 @@ JNIEXPORT int JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1ioctl( JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1send( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, int flags) @@ -207,7 +207,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1send( JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1sendto( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, jint flags, @@ -225,7 +225,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1sendto JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1recv( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, jint flags) @@ -238,7 +238,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1recv( JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1recvfrom( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, jint flags, @@ -254,7 +254,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1recvfr } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read(JNIEnv* env, jobject thisObj, jint fd, jbyteArray buf) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read(JNIEnv* env, jclass clazz, jint fd, jbyteArray buf) { void* data = env->GetPrimitiveArrayCritical(buf, NULL); int retval = zts_bsd_read(fd, data, env->GetArrayLength(buf)); @@ -270,7 +270,7 @@ ssize_t zts_bsd_read_offset(int fd, void* buf, size_t offset, size_t len) JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read_1offset( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, jint offset, @@ -284,7 +284,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read_1 JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read_1length( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, jint len) @@ -296,7 +296,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read_1 } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write__IB(JNIEnv* env, jobject thisObj, jint fd, jbyteArray buf) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write__IB(JNIEnv* env, jclass clazz, jint fd, jbyteArray buf) { void* data = env->GetPrimitiveArrayCritical(buf, NULL); int retval = zts_bsd_write(fd, data, env->GetArrayLength(buf)); @@ -306,7 +306,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write__IB(JNIEnv* env, jobjec JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write_1offset( JNIEnv* env, - jobject thisObj, + jclass clazz, jint fd, jbyteArray buf, jint offset, @@ -319,14 +319,14 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write_ } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write_1byte(JNIEnv* env, jobject thisObj, jint fd, jbyte buf) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write_1byte(JNIEnv* env, jclass clazz, jint fd, jbyte buf) { int retval = zts_bsd_write(fd, &buf, 1); return retval > -1 ? retval : -(zts_errno); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1shutdown(JNIEnv* env, jobject thisObj, int fd, int how) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1shutdown(JNIEnv* env, jclass clazz, int fd, int how) { return zts_bsd_shutdown(fd, how); } @@ -448,19 +448,19 @@ void zta2ss(JNIEnv* env, struct zts_sockaddr_storage* ss, jobject addr) } } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1port(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1port(JNIEnv* jenv, jclass clazz) { return zts_node_get_port(); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1stop(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1stop(JNIEnv* jenv, jclass clazz) { int res = zts_node_stop(); java_detach_from_thread(); return res; } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1free(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1free(JNIEnv* jenv, jclass clazz) { int res = zts_node_free(); java_detach_from_thread(); @@ -468,13 +468,13 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1free( } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1join(JNIEnv* env, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1join(JNIEnv* env, jclass clazz, jlong net_id) { return zts_net_join((uint64_t)net_id); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1leave(JNIEnv* env, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1leave(JNIEnv* env, jclass clazz, jlong net_id) { return zts_net_leave((uint64_t)net_id); } @@ -492,7 +492,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1id_1pair_1is_1valid(JNIEnv* jenv, } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1from_1storage(JNIEnv* jenv, jobject thisObj, jstring path) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1from_1storage(JNIEnv* jenv, jclass clazz, jstring path) { if (! path) { return ZTS_ERR_ARG; @@ -507,7 +507,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1from_1storage(JNIEnv* jenv, } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1set_1event_1handler(JNIEnv* env, jobject thisObj, jobject callback) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1set_1event_1handler(JNIEnv* env, jclass clazz, jobject callback) { jclass eventListenerClass = env->GetObjectClass(callback); if (eventListenerClass == NULL) { @@ -523,7 +523,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1set_1event_1handler(JNIEnv* } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1set_1port(JNIEnv* jenv, jobject thisObj, short port) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1set_1port(JNIEnv* jenv, jclass clazz, short port) { return zts_init_set_port(port); } @@ -536,7 +536,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1from_1memory(JNIEnv* jenv, j JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1blacklist_1if( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jstring prefix, jint len) { @@ -559,32 +559,32 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1set_roots(JNIEnv* jenv, jobj } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1net_1cache(JNIEnv* jenv, jobject thisObj, jint allowed) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1net_1cache(JNIEnv* jenv, jclass clazz, jint allowed) { return zts_init_allow_net_cache(allowed); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1peer_1cache(JNIEnv* jenv, jobject thisObj, jint allowed) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1peer_1cache(JNIEnv* jenv, jclass clazz, jint allowed) { return zts_init_allow_peer_cache(allowed); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1roots_1cache(JNIEnv* jenv, jobject thisObj, jint allowed) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1roots_1cache(JNIEnv* jenv, jclass clazz, jint allowed) { return zts_init_allow_roots_cache(allowed); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1id_1cache(JNIEnv* jenv, jobject thisObj, jint allowed) +Java_com_zerotier_sockets_ZeroTierNative_zts_1init_1allow_1id_1cache(JNIEnv* jenv, jclass clazz, jint allowed) { return zts_init_allow_id_cache(allowed); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1is_1assigned( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong net_id, jint family) { @@ -602,7 +602,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get( } JNIEXPORT jstring JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str(JNIEnv* jenv, jobject thisObj, long net_id, jint family) +Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str(JNIEnv* jenv, jclass clazz, long net_id, jint family) { char ip_str[ZTS_IP_MAX_STR_LEN] = { 0 }; zts_addr_get_str(net_id, family, ip_str, ZTS_IP_MAX_STR_LEN); @@ -641,7 +641,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compu JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_1rfc4193_1str( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong net_id, jlong node_id, jstring dst, @@ -652,7 +652,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compu JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_16plane_1str( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong net_id, jlong node_id, jstring dst, @@ -663,7 +663,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compu JNIEXPORT uint64_t JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1compute_1adhoc_1id( JNIEnv* jenv, - jobject thisObj, + jclass clazz, short start_port, short end_port) { @@ -671,19 +671,19 @@ JNIEXPORT uint64_t JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1co } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1transport_1is_1ready(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1transport_1is_1ready(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_transport_is_ready(net_id); } JNIEXPORT uint64_t JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_get_mac(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_get_mac(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_mac(net_id); } JNIEXPORT jstring JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mac_1str(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mac_1str(JNIEnv* jenv, jclass clazz, jlong net_id) { char mac_str[ZTS_MAC_ADDRSTRLEN] = { 0 }; zts_net_get_mac_str(net_id, mac_str, ZTS_MAC_ADDRSTRLEN); @@ -692,20 +692,20 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mac_1str(JNIEnv* jenv, j } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1broadcast(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1broadcast(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_broadcast(net_id); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mtu(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mtu(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_mtu(net_id); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1name( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong net_id, jstring dst, jint len) @@ -714,37 +714,37 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1n } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1status(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1status(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_status(net_id); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1type(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1type(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_type(net_id); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1route_1is_1assigned( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong net_id, jint family) { return zts_route_is_assigned(net_id, family); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1start(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1start(JNIEnv* jenv, jclass clazz) { return zts_node_start(); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1is_1online(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1is_1online(JNIEnv* jenv, jclass clazz) { return zts_node_is_online(); } -JNIEXPORT uint64_t JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1id(JNIEnv* jenv, jobject thisObj) +JNIEXPORT uint64_t JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1id(JNIEnv* jenv, jclass clazz) { return zts_node_get_id(); } @@ -760,7 +760,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1 JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1moon_1orbit( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong moon_roots_id, jlong moon_seed) { @@ -768,14 +768,14 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1moon_1orbit } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1moon_1deorbit(JNIEnv* jenv, jobject thisObj, jlong moon_roots_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1moon_1deorbit(JNIEnv* jenv, jclass clazz, jlong moon_roots_id) { return zts_moon_deorbit(moon_roots_id); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1connect( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jint fd, jstring ipstr, jint port, @@ -794,7 +794,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1connect( } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bind(JNIEnv* jenv, jobject thisObj, jint fd, jstring ipstr, jint port) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bind(JNIEnv* jenv, jclass clazz, jint fd, jstring ipstr, jint port) { if (! ipstr) { return ZTS_ERR_ARG; @@ -827,20 +827,20 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1udp_1client(JNIEnv* jenv, jobject } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1no_1delay(JNIEnv* jenv, jobject thisObj, jint fd, jint enabled) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1no_1delay(JNIEnv* jenv, jclass clazz, jint fd, jint enabled) { return zts_set_no_delay(fd, enabled); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1no_1delay(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1no_1delay(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_no_delay(fd); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1linger( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jint fd, jint enabled, jint value) @@ -849,38 +849,38 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1linger } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1linger_1enabled(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1linger_1enabled(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_linger_enabled(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1linger_1value(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1linger_1value(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_linger_value(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1pending_1data_1size(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1pending_1data_1size(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_pending_data_size(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1reuse_1addr(JNIEnv* jenv, jobject thisObj, jint fd, jint enabled) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1reuse_1addr(JNIEnv* jenv, jclass clazz, jint fd, jint enabled) { return zts_set_reuse_addr(fd, enabled); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1reuse_1addr(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1reuse_1addr(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_reuse_addr(fd); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1recv_1timeout( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jint fd, jint seconds, jint microseconds) @@ -889,14 +889,14 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1recv_1 } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1recv_1timeout(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1recv_1timeout(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_recv_timeout(fd); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1send_1timeout( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jint fd, jint seconds, jint microseconds) @@ -905,66 +905,66 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1send_1 } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1send_1timeout(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1send_1timeout(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_send_timeout(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1send_1buf_1size(JNIEnv* jenv, jobject thisObj, jint fd, jint size) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1send_1buf_1size(JNIEnv* jenv, jclass clazz, jint fd, jint size) { return zts_set_send_buf_size(fd, size); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1send_1buf_1size(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1send_1buf_1size(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_send_buf_size(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1recv_1buf_1size(JNIEnv* jenv, jobject thisObj, jint fd, jint size) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1recv_1buf_1size(JNIEnv* jenv, jclass clazz, jint fd, jint size) { return zts_set_recv_buf_size(fd, size); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1recv_1buf_1size(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1recv_1buf_1size(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_recv_buf_size(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1ttl(JNIEnv* jenv, jobject thisObj, jint fd, jint ttl) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1ttl(JNIEnv* jenv, jclass clazz, jint fd, jint ttl) { return zts_set_ttl(fd, ttl); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1ttl(JNIEnv* jenv, jobject thisObj, jint fd) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1ttl(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_ttl(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1blocking(JNIEnv* jenv, jobject thisObj, jint fd, jint enabled) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1blocking(JNIEnv* jenv, jclass clazz, jint fd, jint enabled) { return zts_set_blocking(fd, enabled); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1blocking(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1blocking(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_blocking(fd); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1keepalive(JNIEnv* jenv, jobject thisObj, jint fd, jint enabled) +Java_com_zerotier_sockets_ZeroTierNative_zts_1set_1keepalive(JNIEnv* jenv, jclass clazz, jint fd, jint enabled) { return zts_set_keepalive(fd, enabled); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1keepalive(JNIEnv* jenv, jobject thisObj, jint fd) +Java_com_zerotier_sockets_ZeroTierNative_zts_1get_1keepalive(JNIEnv* jenv, jclass clazz, jint fd) { return zts_get_keepalive(fd); } @@ -989,25 +989,25 @@ JNIEXPORT ip_addr* JNICALL dns_1get_1server(JNIEnv* jenv, jobject thisObj, uint8 return NULL; } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1lock_1obtain(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1lock_1obtain(JNIEnv* jenv, jclass clazz) { return zts_core_lock_obtain(); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1lock_1release(JNIEnv* jenv, jobject thisObj) +JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1lock_1release(JNIEnv* jenv, jclass clazz) { return zts_core_lock_release(); } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1addr_1count(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1addr_1count(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_core_query_addr_count(net_id); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1addr( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong net_id, jint idx, jstring addr, @@ -1017,7 +1017,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1route_1count(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1route_1count(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_core_query_route_count(net_id); } @@ -1037,14 +1037,14 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1path_1count(JNIEnv* jenv, jobject thisObj, jlong peer_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1path_1count(JNIEnv* jenv, jclass clazz, jlong peer_id) { return zts_core_query_path_count(peer_id); } JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1path( JNIEnv* jenv, - jobject thisObj, + jclass clazz, jlong peer_id, jint idx, jstring dst, @@ -1054,7 +1054,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1mc_1count(JNIEnv* jenv, jobject thisObj, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1core_1query_1mc_1count(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_core_query_mc_count(net_id); } @@ -1087,7 +1087,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1util_1roots } JNIEXPORT void JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1util_1delay(JNIEnv* jenv, jobject thisObj, jlong milliseconds) +Java_com_zerotier_sockets_ZeroTierNative_zts_1util_1delay(JNIEnv* jenv, jclass clazz, jlong milliseconds) { zts_util_delay(milliseconds); } From 472b4d37f7cb2e8e8d79f319c30190a7b324fc91 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 17:30:32 -0500 Subject: [PATCH 15/55] fix bad parameter --- src/bindings/java/JavaSockets.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index d3de89b..349198d 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -81,8 +81,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1accept JNIEnv* env, jobject thisObj, jint fd, - jobject addr, - jint port) + jobject addr) { struct zts_sockaddr_storage ss; zts_socklen_t addrlen = sizeof(struct zts_sockaddr_storage); From e47e37d12e06dd6ededc6356064e1784d1fbff43 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 9 Dec 2022 17:32:06 -0500 Subject: [PATCH 16/55] fix stray GetFieldID --- src/bindings/java/JavaSockets.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index d3de89b..4f59af6 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -434,9 +434,8 @@ void zta2ss(JNIEnv* env, struct zts_sockaddr_storage* ss, jobject addr) } if (family == ZTS_AF_INET6) { struct zts_sockaddr_in6* in6 = (struct zts_sockaddr_in6*)ss; - jfieldID fid = env->GetFieldID(c, "_port", "I"); + fid = env->GetFieldID(c, "_port", "I"); in6->sin6_port = lwip_htons(env->GetIntField(addr, fid)); - fid = env->GetFieldID(c, "_family", "I"); in6->sin6_family = ZTS_AF_INET6; fid = env->GetFieldID(c, "_ip6", "[B"); jobject ipData = env->GetObjectField(addr, fid); From f65686869a5b93d5e2a700b53bf61a5772cf20e1 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Sun, 11 Dec 2022 08:35:12 -0500 Subject: [PATCH 17/55] update various settings for Android and Gradle --- pkg/android/app/build.gradle | 25 ++++++++++++++++---- pkg/android/app/src/main/AndroidManifest.xml | 3 +-- pkg/android/build.gradle | 6 ++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/android/app/build.gradle b/pkg/android/app/build.gradle index f806add..0c78c42 100644 --- a/pkg/android/app/build.gradle +++ b/pkg/android/app/build.gradle @@ -1,16 +1,18 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 31 + compileSdkVersion 33 defaultConfig { minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 33 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "" + version '3.22.1' + arguments "-DZTS_ENABLE_JAVA=ON" } } ndk { @@ -28,15 +30,28 @@ android { externalNativeBuild { cmake { path "../../../CMakeLists.txt" + version '3.22.1' + } + } + + ndkVersion '25.1.8937393' + + namespace 'com.example.zerotier' + + sourceSets { + main { + java { + srcDir 'src/main/java' + srcDir '../../../src/bindings/java' + } } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' - implementation 'com.android.support.constraint:constraint-layout:1.1.2' - testImplementation 'junit:junit:4.12' + implementation 'com.android.support.constraint:constraint-layout:2.0.4' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } \ No newline at end of file diff --git a/pkg/android/app/src/main/AndroidManifest.xml b/pkg/android/app/src/main/AndroidManifest.xml index 5385407..0465e5b 100644 --- a/pkg/android/app/src/main/AndroidManifest.xml +++ b/pkg/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/pkg/android/build.gradle b/pkg/android/build.gradle index fcafdd4..186f8f4 100644 --- a/pkg/android/build.gradle +++ b/pkg/android/build.gradle @@ -4,10 +4,10 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.1' + classpath 'com.android.tools.build:gradle:7.3.1' // NOTE: Do not place your application dependencies here; they belong @@ -18,7 +18,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } From 8a90a7bacab7ac92bf60a0e52b74b9f9c3f44bd1 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 26 May 2023 11:03:23 -0400 Subject: [PATCH 18/55] Fix warning about function never used The practice of appending "__" with type signature allows for references overloaded methods. But there is only a single zts_bsd_write method, so just remove. --- src/bindings/java/JavaSockets.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index 40e4ce4..56dda6b 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -295,7 +295,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1read_1 } JNIEXPORT jint JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write__IB(JNIEnv* env, jclass clazz, jint fd, jbyteArray buf) +Java_com_zerotier_sockets_ZeroTierNative_zts_1bsd_1write(JNIEnv* env, jclass clazz, jint fd, jbyteArray buf) { void* data = env->GetPrimitiveArrayCritical(buf, NULL); int retval = zts_bsd_write(fd, data, env->GetArrayLength(buf)); From 87e344bdb7277b481fcee370d323bf14bee26807 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Thu, 1 Jun 2023 11:16:03 -0400 Subject: [PATCH 19/55] add new prometheus headers that are now used by ZeroTierOne --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1924937..201cf6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,8 @@ include_directories(${ZTO_SRC_DIR}/osdep) # ZeroTier (ext) #include_directories(${ZTO_SRC_DIR}/ext/miniupnpc) include_directories(${ZTO_SRC_DIR}/ext/libnatpmp) +include_directories(${ZTO_SRC_DIR}/ext/prometheus-cpp-lite-1.0/core/include) +include_directories(${ZTO_SRC_DIR}/ext/prometheus-cpp-lite-1.0/simpleapi/include) # libzt include_directories(${PROJ_DIR}/src) include_directories(${PROJ_DIR}/include) From 0d81706227610bed58be8268bed95cded3d02a14 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 2 Jun 2023 16:30:14 -0400 Subject: [PATCH 20/55] Fix a few issues with Android build * do not remove miniupnpc/VERSION (unsure what previous problem was) * do not need to export PATH * do not copy source files, allow gradle to build from source * leave outputs from gradle (copy to PKG_OUTPUT_DIR instead of move) --- build.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/build.sh b/build.sh index a486d12..bd8b7b8 100755 --- a/build.sh +++ b/build.sh @@ -596,18 +596,12 @@ android-aar() PKG_OUTPUT_DIR=$BUILD_OUTPUT_DIR/$TARGET_PLATFORM-$TARGET_MACHINE_TYPE-$ARTIFACT-$BUILD_TYPE mkdir -p $CACHE_DIR mkdir -p $PKG_OUTPUT_DIR - # Unsure why, but Gradle's build script chokes on this non-source file now - rm -rf ext/ZeroTierOne/ext/miniupnpc/VERSION - export PATH=$ANDROID_HOME/cmdline-tools/tools/bin:$PATH - # Copy source files into project - mkdir -p ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/sockets - cp -f src/bindings/java/com/zerotier/sockets/*.java ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/sockets # Build UPPERCASE_BUILD_TYPE="$(tr '[:lower:]' '[:upper:]' <<< ${BUILD_TYPE:0:1})${BUILD_TYPE:1}" CMAKE_FLAGS="-D${CMAKE_SWITCH}=1 -D${CMAKE_SWITCH}=ON" cd $ANDROID_PKG_PROJ_DIR ./gradlew $GRADLE_ARGS assemble$UPPERCASE_BUILD_TYPE # assembleRelease / assembleDebug - mv $ANDROID_PKG_PROJ_DIR/app/build/outputs/aar/*.aar \ + cp $ANDROID_PKG_PROJ_DIR/app/build/outputs/aar/*.aar \ $PKG_OUTPUT_DIR/libzt-$BUILD_TYPE.aar cd - echo -e "\n - Build cache : $CACHE_DIR\n - Build output : $BUILD_OUTPUT_DIR\n" From 356dcd05f664da88b42dab60d56acbac9c5e982f Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Sun, 4 Jun 2023 15:07:32 -0700 Subject: [PATCH 21/55] Update Java example --- examples/java/Example.java | 4 +-- examples/java/Makefile | 9 ------- examples/java/README.md | 51 +++++++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 15 deletions(-) delete mode 100644 examples/java/Makefile diff --git a/examples/java/Example.java b/examples/java/Example.java index 344c3dd..736496e 100644 --- a/examples/java/Example.java +++ b/examples/java/Example.java @@ -5,7 +5,7 @@ import java.math.BigInteger; import java.net.DatagramPacket; import java.net.InetAddress; -public class selftest { +public class Example { public static void main(String[] args) { if (args.length < 4 || args.length > 5) { @@ -110,7 +110,7 @@ public class selftest { /** * (OPTIONAL) event handler */ -class MyZeroTierEventListener implements ZeroTierEventListener { +class MyZeroTierEventListener implements com.zerotier.sockets.ZeroTierEventListener { public void onZeroTierEvent(long id, int eventCode) { if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_UP) { diff --git a/examples/java/Makefile b/examples/java/Makefile deleted file mode 100644 index 4424d0a..0000000 --- a/examples/java/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -all: - jar xf *.jar libzt.dylib - javac -cp *.jar Example.java - -clean: - rm -rf *.class - -superclean: clean - rm -rf *.dylib *.so *.jar diff --git a/examples/java/README.md b/examples/java/README.md index 870f020..40db2d8 100644 --- a/examples/java/README.md +++ b/examples/java/README.md @@ -1,11 +1,54 @@ # Java example -Build or download the `libzt-${VERSION}.jar`, and copy it to this directory. +## Build the JAR + +From the top-level `libzt` directory: ``` -make -java -cp ".:libzt-${VERSION}.jar" Example server id_path 0123456789abcdef 9997 -java -cp ".:libzt-${VERSION}.jar" Example client id_path 0123456789abcdef ip.ip.ip.ip 9997 +./build.sh host-jar +``` + +Should result in something like: + +``` +dist +└── linux-x64-jar-release + └── pkg + └── libzt-1.8.10.jar +``` + +Copy the JAR to the working directory: + +*NOTE: If you've built multiple variants of the JAR such as debug/release or mac/linux you will need to specify their exact path in the following command. If not, you can use the wildcard form:* + + +``` +cp -f dist/*/pkg/*.jar examples/java/libzt.jar +``` + +Navigate to the `examples/java` directory and extract the `libzt.so|dylib|dll` dynamic library from the JAR into the working directory: + +``` +jar xf *.jar libzt.dylib libzt.so libzt.dll +``` + +## Build the example app + +``` +javac -cp *.jar Example.java +``` + +## Run the example app + +``` +java -Djava.library.path=. -cp ".:libzt.jar" Example server id_path 0123456789abcdef 9997 +java -Djava.library.path=. -cp ".:libzt.jar" Example client id_path 0123456789abcdef ip.ip.ip.ip 9997 +``` + +## Clean + +``` +rm -rf *.dylib *.so *.jar *.dll *.class ``` ## Links From 787dd6efc1a36b8bb55acce1e9a43ade5762029b Mon Sep 17 00:00:00 2001 From: Lennon Day-Reynolds Date: Mon, 5 Jun 2023 19:14:12 -0700 Subject: [PATCH 22/55] new rust demo + cleanup of build --- build.sh | 2 + pkg/crate/libzt/Cargo.lock | 493 +++++++++++++++++- pkg/crate/libzt/Cargo.toml | 14 +- pkg/crate/libzt/build.rs | 9 +- pkg/crate/libzt/examples/forwarding.rs | 170 ++++++ .../{src => }/examples/libzt-test-app.rs | 0 6 files changed, 662 insertions(+), 26 deletions(-) create mode 100644 pkg/crate/libzt/examples/forwarding.rs rename pkg/crate/libzt/{src => }/examples/libzt-test-app.rs (100%) diff --git a/build.sh b/build.sh index dfd3bea..71b68ee 100755 --- a/build.sh +++ b/build.sh @@ -350,6 +350,8 @@ host() mkdir -p $BIN_OUTPUT_DIR $CMAKE $VARIANT -H. -B$CACHE_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE --build $CACHE_DIR $BUILD_CONCURRENCY + rm -f $BUILD_OUTPUT_DIR/native + ln -s $TARGET_BUILD_DIR $BUILD_OUTPUT_DIR/native cp -f $CACHE_DIR/lib/libzt.* $LIB_OUTPUT_DIR cp -f $CACHE_DIR/bin/* $BIN_OUTPUT_DIR echo -e "\n - Build cache : $CACHE_DIR\n - Build output : $BUILD_OUTPUT_DIR\n" diff --git a/pkg/crate/libzt/Cargo.lock b/pkg/crate/libzt/Cargo.lock index 854a290..66606b9 100644 --- a/pkg/crate/libzt/Cargo.lock +++ b/pkg/crate/libzt/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.18" @@ -18,17 +20,78 @@ dependencies = [ "winapi", ] +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "anstyle-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" + [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.18", "libc", "winapi", ] +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bindgen" version = "0.58.1" @@ -38,8 +101,8 @@ dependencies = [ "bitflags", "cexpr", "clang-sys", - "clap", - "env_logger", + "clap 2.33.3", + "env_logger 0.8.3", "lazy_static", "lazycell", "log", @@ -99,12 +162,63 @@ dependencies = [ "ansi_term", "atty", "bitflags", - "strsim", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "401a4694d2bf92537b6867d94de48c4842089645fdcdf6c71865b175d836e9c2" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap-num" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488557e97528174edaa2ee268b23a809e0c598213a4bbcb4f34575a46fda147e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "clap_builder" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", + "strsim 0.10.0", +] + +[[package]] +name = "clap_derive" +version = "4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + [[package]] name = "cmake" version = "0.1.45" @@ -114,6 +228,33 @@ dependencies = [ "cc", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys", +] + [[package]] name = "env_logger" version = "0.8.3" @@ -127,12 +268,63 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.18" @@ -142,12 +334,41 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -162,9 +383,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "fc86cde3ff845662b8f4ef6cb50ea0e20c524eb3d29ae048287e06a1b3fa6a81" [[package]] name = "libloading" @@ -180,19 +401,39 @@ dependencies = [ name = "libzt" version = "0.1.2" dependencies = [ + "anyhow", "bindgen", + "clap 4.3.2", + "clap-num", "cmake", + "dirs", + "env_logger 0.10.0", "libc", + "log", + "parking_lot", +] + +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" [[package]] name = "memchr" @@ -210,6 +451,50 @@ dependencies = [ "version_check", ] +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets", +] + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -218,22 +503,51 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall 0.2.16", + "thiserror", +] + [[package]] name = "regex" version = "1.5.4" @@ -257,18 +571,61 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.37.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f79bef90eb6d984c72722595b5b1348ab39275a5e5123faca6863bf07d75a4e0" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "shlex" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -287,6 +644,32 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + [[package]] name = "unicode-width" version = "0.1.8" @@ -294,10 +677,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "vec_map" @@ -311,6 +694,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "which" version = "3.1.1" @@ -350,3 +739,69 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/pkg/crate/libzt/Cargo.toml b/pkg/crate/libzt/Cargo.toml index b1e8207..b9e9a89 100644 --- a/pkg/crate/libzt/Cargo.toml +++ b/pkg/crate/libzt/Cargo.toml @@ -13,6 +13,15 @@ keywords = ["zerotier", "p2p", "vpn", "socket", "network"] categories = ["network-programming", "cryptography"] [dependencies] +log = "0.4.18" +dirs = "5.0.1" + +[dev-dependencies] +anyhow = "1.0" +clap = { version = "4.3.0", features = ["derive"] } +clap-num = "1.0" +env_logger = "0.10" +parking_lot = { version = "0.12", features = ["send_guard"] } [build-dependencies] bindgen = "0.58" @@ -22,8 +31,3 @@ cmake = "0.1" [lib] name = "libzt" path = "src/lib.rs" - -[[example]] -name = "libzt-test-app" -path = "src/examples/libzt-test-app.rs" - diff --git a/pkg/crate/libzt/build.rs b/pkg/crate/libzt/build.rs index aabcc1b..7521feb 100644 --- a/pkg/crate/libzt/build.rs +++ b/pkg/crate/libzt/build.rs @@ -1,10 +1,15 @@ extern crate bindgen; use std::env; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; fn main() { - println!("cargo:rustc-link-lib=zt"); + let dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let lib_dir = Path::new(&dir).join("../../../dist/native/lib").canonicalize().unwrap(); + + println!("cargo:rustc-link-search=native={}", lib_dir.to_string_lossy()); + println!("cargo:rustc-link-lib=static=zt"); + println!("cargo:rustc-link-lib=dylib=c++"); let bindings = bindgen::Builder::default() .header("src/include/ZeroTierSockets.h") diff --git a/pkg/crate/libzt/examples/forwarding.rs b/pkg/crate/libzt/examples/forwarding.rs new file mode 100644 index 0000000..aa8eaed --- /dev/null +++ b/pkg/crate/libzt/examples/forwarding.rs @@ -0,0 +1,170 @@ +use std::{ + error::Error, + fmt, fs, + io::{self, Read, Write}, + net::{self, Shutdown}, + sync::Arc, + thread, + time::Duration, +}; + +use anyhow::Result; +use clap::Parser; +use parking_lot::FairMutex; + +use libzt::{node::ZeroTierNode, tcp as zt_tcp}; + +const BUF_SIZE: usize = 1024; +const SOCKET_IO_TIMEOUT: Duration = Duration::new(1, 0); +const DEFAULT_LISTEN_PORT: u16 = 9080; + +#[derive(Debug)] +enum ForwardingError { + BindFailed(String), + ConnectFailed(String), +} + +impl Error for ForwardingError {} + +#[derive(Parser, Debug)] +struct Args { + #[arg(short, long, value_parser=clap_num::maybe_hex::)] + network_id: u64, + #[arg(short, long)] + connect: String, + #[arg(short, long, default_value_t = DEFAULT_LISTEN_PORT)] + port: u16, +} + +fn setup_node(network_id: u64) -> Result { + log::info!("joining network: {:#x}", network_id); + + let mut storage_path = dirs::data_local_dir().unwrap(); + storage_path.push("libzt"); + storage_path.push("forwarding"); + + fs::create_dir_all(&storage_path)?; + + log::debug!( + "initializing from state dir: {}", + storage_path.to_string_lossy() + ); + + let node = ZeroTierNode {}; + + node.init_set_port(0); + node.init_from_storage(&storage_path.join("libzt-examples").to_string_lossy()); + node.start(); + + log::debug!("waiting for node to come online..."); + while !node.is_online() { + node.delay(250); + } + + log::info!("node id: {:#x}", node.id()); + + node.net_join(network_id); + + log::debug!("waiting for transport..."); + while !node.net_transport_is_ready(network_id) { + node.delay(250); + } + + let addr = node.addr_get(network_id).unwrap(); + log::info!("got ZT addr: {}", addr.to_string()); + + Ok(node) +} + +impl fmt::Display for ForwardingError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +fn main() -> Result<()> { + env_logger::init(); + + let Args { + connect: remote_addr, + network_id, + port: local_port, + } = Args::parse(); + + let _node = setup_node(network_id)?; + + let local_addr = format!("localhost:{}", local_port); + let listener = net::TcpListener::bind(&local_addr) + .map_err(|_| ForwardingError::BindFailed(local_addr.clone()))?; + + log::info!("listener bound to {}", local_addr); + + for conn in listener.incoming() { + log::debug!("incoming: {:?}", conn); + + if let Ok(client) = conn { + client.set_read_timeout(Some(SOCKET_IO_TIMEOUT))?; + client.set_write_timeout(Some(SOCKET_IO_TIMEOUT))?; + + let client = Arc::new(FairMutex::new(client)); + + log::info!("connecting to remote: {}", remote_addr); + + let remote = zt_tcp::TcpStream::connect(&remote_addr) + .map_err(|_| ForwardingError::ConnectFailed(remote_addr.clone()))?; + + remote.set_read_timeout(Some(SOCKET_IO_TIMEOUT))?; + remote.set_write_timeout(Some(SOCKET_IO_TIMEOUT))?; + + let remote = Arc::new(FairMutex::new(remote)); + + log::info!("connected"); + + thread::spawn(move || { + let mut buf = [0u8; BUF_SIZE]; + + loop { + let mut client = client.lock(); + let mut remote = remote.lock(); + + match client.read(&mut buf) { + Ok(n) if n > 0 => { + log::debug!("got {} bytes from client", n); + remote.write(&buf).unwrap(); + remote.flush().unwrap(); + } + Err(e) if e.kind() == io::ErrorKind::WouldBlock => { + thread::sleep(Duration::new(0, 5000)); + } + other => { + log::debug!("closing client connection: {:?}", other); + let _ = client.shutdown(Shutdown::Read); + let _ = remote.shutdown(Shutdown::Write); + break; + } + } + + buf.fill(0); + + match remote.read(&mut buf) { + Ok(n) if n > 0 => { + log::debug!("got {} bytes from remote", n); + client.write(&buf).unwrap(); + client.flush().unwrap(); + } + other => { + log::debug!("closing remote connection: {:?}", other); + let _ = remote.shutdown(Shutdown::Read); + let _ = client.shutdown(Shutdown::Write); + break; + } + } + + buf.fill(0); + } + }); + } + } + + Ok(()) +} diff --git a/pkg/crate/libzt/src/examples/libzt-test-app.rs b/pkg/crate/libzt/examples/libzt-test-app.rs similarity index 100% rename from pkg/crate/libzt/src/examples/libzt-test-app.rs rename to pkg/crate/libzt/examples/libzt-test-app.rs From 91b190da73983dc4bdd9a2ebaf16ee8d6dfa40c2 Mon Sep 17 00:00:00 2001 From: Lennon Day-Reynolds Date: Mon, 5 Jun 2023 21:58:54 -0700 Subject: [PATCH 23/55] should work for non-oneshot (request/response) protocols a little better now --- pkg/crate/libzt/examples/forwarding.rs | 44 ++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/pkg/crate/libzt/examples/forwarding.rs b/pkg/crate/libzt/examples/forwarding.rs index aa8eaed..217486a 100644 --- a/pkg/crate/libzt/examples/forwarding.rs +++ b/pkg/crate/libzt/examples/forwarding.rs @@ -22,6 +22,7 @@ const DEFAULT_LISTEN_PORT: u16 = 9080; enum ForwardingError { BindFailed(String), ConnectFailed(String), + CopyFailed(String), } impl Error for ForwardingError {} @@ -120,18 +121,31 @@ fn main() -> Result<()> { log::info!("connected"); + let client_ = client.clone(); + let remote_ = remote.clone(); + thread::spawn(move || { let mut buf = [0u8; BUF_SIZE]; + let mut running = true; - loop { + while running { let mut client = client.lock(); let mut remote = remote.lock(); match client.read(&mut buf) { Ok(n) if n > 0 => { - log::debug!("got {} bytes from client", n); - remote.write(&buf).unwrap(); - remote.flush().unwrap(); + log::debug!("got {} bytes from remote", n); + running = remote + .write(&buf) + .map(|_| { + remote.flush().unwrap(); + true + }) + .unwrap_or_else(|e| { + let msg = format!("failed to write to remote: {:?}", e); + log::error!("{}", msg); + false + }); } Err(e) if e.kind() == io::ErrorKind::WouldBlock => { thread::sleep(Duration::new(0, 5000)); @@ -145,12 +159,30 @@ fn main() -> Result<()> { } buf.fill(0); + } + }); + thread::spawn(move || { + let mut buf = [0u8; BUF_SIZE]; + let mut running = true; + + while running { + let mut client = client_.lock(); + let mut remote = remote_.lock(); match remote.read(&mut buf) { Ok(n) if n > 0 => { log::debug!("got {} bytes from remote", n); - client.write(&buf).unwrap(); - client.flush().unwrap(); + running = client + .write(&buf) + .map(|_| { + client.flush().unwrap(); + true + }) + .unwrap_or_else(|e| { + let msg = format!("failed to write to remote: {:?}", e); + log::error!("{}", msg); + false + }); } other => { log::debug!("closing remote connection: {:?}", other); From eabceab937cc40c7e741bf61d7991b085d4f6724 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Tue, 6 Jun 2023 09:57:26 -0700 Subject: [PATCH 24/55] Update ZTO submodule to 1.10.6-dev --- ext/ZeroTierOne | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ZeroTierOne b/ext/ZeroTierOne index a47c3cb..adfbbc3 160000 --- a/ext/ZeroTierOne +++ b/ext/ZeroTierOne @@ -1 +1 @@ -Subproject commit a47c3cb16f1c16bc9be555fd7f6bcd34e843f001 +Subproject commit adfbbc3fb00becc578afc0645c60b1de3d84bb4c From 916a2ce2f412c65df9d280a007cb1d07714557a5 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Tue, 6 Jun 2023 09:57:59 -0700 Subject: [PATCH 25/55] Update iOS SDK version to 16.4 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 201cf6c..1331e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,7 +225,7 @@ if(BUILD_IOS_FRAMEWORK) "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer") if(IOS_ARM64) set(CMAKE_OSX_ARCHITECTURES arm64) - set(SDKVER "11.4") + set(SDKVER "16.4") endif() if(IOS_ARMV7) # armv7 armv7s From fad04bf3c71b4b65a9a14263fe34bef3c361602b Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 30 Jun 2023 12:04:26 -0400 Subject: [PATCH 26/55] Update examples: Remove empty MainActivity.java Android example fix CMake variable BUILD_EXAMPLES -> BUILD_HOST_EXAMPLES fix some names in example usage messages: pingable-node -> callbackapi client -> nonblockingclient server -> nonblockingserver pingable-node -> statistics --- CMakeLists.txt | 12 ++++++------ examples/c/callbackapi.c | 2 +- examples/c/nonblockingclient.c | 2 +- examples/c/nonblockingserver.c | 2 +- examples/c/statistics.c | 2 +- .../main/java/com/example/zerotier/MainActivity.java | 1 - 6 files changed, 10 insertions(+), 11 deletions(-) delete mode 100644 pkg/android/app/src/main/java/com/example/zerotier/MainActivity.java diff --git a/CMakeLists.txt b/CMakeLists.txt index 1331e1b..dab7608 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,7 @@ if (ZTS_ENABLE_PINVOKE) # Features set(BUILD_STATIC_LIB FALSE) set(BUILD_SHARED_LIB TRUE) - set(BUILD_EXAMPLES FALSE) + set(BUILD_HOST_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) set(BUILD_HOST_SELFTEST FALSE) # Sources and libraries @@ -131,7 +131,7 @@ if (ZTS_ENABLE_RUST) # Features set(BUILD_STATIC_LIB TRUE) set(BUILD_SHARED_LIB FALSE) - set(BUILD_EXAMPLES FALSE) + set(BUILD_HOST_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) set(BUILD_HOST_SELFTEST FALSE) endif() @@ -144,7 +144,7 @@ if (ZTS_ENABLE_PYTHON) # Targets set(BUILD_STATIC_LIB FALSE) set(BUILD_SHARED_LIB TRUE) - set(BUILD_EXAMPLES FALSE) + set(BUILD_HOST_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) set(BUILD_HOST_SELFTEST FALSE) # Sources and libraries @@ -192,7 +192,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Android") set(BUILD_STATIC_LIB FALSE) set(BUILD_SHARED_LIB TRUE) set(BUILD_HOST_SELFTEST FALSE) - set(BUILD_EXAMPLES FALSE) + set(BUILD_HOST_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) set(LANG_WRAPPER_FILE ${LIBZT_SRC_DIR}/bindings/java/*.cxx) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZTS_ENABLE_JAVA=1") @@ -202,7 +202,7 @@ if(BUILD_MACOS_FRAMEWORK) set(BUILD_STATIC_LIB TRUE) set(BUILD_SHARED_LIB TRUE) set(BUILD_HOST_SELFTEST FALSE) - set(BUILD_EXAMPLES FALSE) + set(BUILD_HOST_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOMIT_JSON_SUPPORT=1") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DOMIT_JSON_SUPPORT=1") @@ -217,7 +217,7 @@ if(BUILD_IOS_FRAMEWORK) set(BUILD_STATIC_LIB TRUE) set(BUILD_SHARED_LIB TRUE) set(BUILD_HOST_SELFTEST FALSE) - set(BUILD_EXAMPLES FALSE) + set(BUILD_HOST_EXAMPLES FALSE) set(ALLOW_INSTALL_TARGET FALSE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOMIT_JSON_SUPPORT=1") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DOMIT_JSON_SUPPORT=1") diff --git a/examples/c/callbackapi.c b/examples/c/callbackapi.c index 02d92ec..8bb1722 100644 --- a/examples/c/callbackapi.c +++ b/examples/c/callbackapi.c @@ -52,7 +52,7 @@ int main(int argc, char** argv) { if (argc != 2) { printf("\nUsage:\n"); - printf("pingable-node \n"); + printf("callbackapi \n"); exit(0); } long long int net_id = strtoull(argv[1], NULL, 16); // At least 64 bits diff --git a/examples/c/nonblockingclient.c b/examples/c/nonblockingclient.c index 4d7f4d5..78f77e1 100644 --- a/examples/c/nonblockingclient.c +++ b/examples/c/nonblockingclient.c @@ -14,7 +14,7 @@ int main(int argc, char** argv) { if (argc != 5) { printf("\nlibzt example client\n"); - printf("client \n"); + printf("nonblockingclient \n"); exit(0); } char* storage_path = argv[1]; diff --git a/examples/c/nonblockingserver.c b/examples/c/nonblockingserver.c index 81a33b9..228bcb2 100644 --- a/examples/c/nonblockingserver.c +++ b/examples/c/nonblockingserver.c @@ -14,7 +14,7 @@ int main(int argc, char** argv) { if (argc != 5) { printf("\nlibzt example server\n"); - printf("server \n"); + printf("nonblockingserver \n"); exit(0); } char* storage_path = argv[1]; diff --git a/examples/c/statistics.c b/examples/c/statistics.c index 6fa59d2..4f14306 100644 --- a/examples/c/statistics.c +++ b/examples/c/statistics.c @@ -14,7 +14,7 @@ int main(int argc, char** argv) { if (argc != 2) { printf("\nUsage:\n"); - printf("pingable-node \n"); + printf("statistics \n"); exit(0); } long long int net_id = strtoull(argv[1], NULL, 16); // At least 64 bits diff --git a/pkg/android/app/src/main/java/com/example/zerotier/MainActivity.java b/pkg/android/app/src/main/java/com/example/zerotier/MainActivity.java deleted file mode 100644 index 8b13789..0000000 --- a/pkg/android/app/src/main/java/com/example/zerotier/MainActivity.java +++ /dev/null @@ -1 +0,0 @@ - From e60239329c7679edd87e5e764f486ea2c1922d0b Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 17 Jul 2023 16:53:09 -0700 Subject: [PATCH 27/55] Bump ZTO submodule commit to include iOS fix --- ext/ZeroTierOne | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ZeroTierOne b/ext/ZeroTierOne index adfbbc3..97492ee 160000 --- a/ext/ZeroTierOne +++ b/ext/ZeroTierOne @@ -1 +1 @@ -Subproject commit adfbbc3fb00becc578afc0645c60b1de3d84bb4c +Subproject commit 97492eec7c3a107c423698572571bfd895d01aa4 From 27805f8ff28f57d31021c41b0ef047cb0c4f798c Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Tue, 18 Jul 2023 13:04:40 -0700 Subject: [PATCH 28/55] Add low-bandwidth mode --- src/Controls.cpp | 6 ++++++ src/NodeService.cpp | 10 ++++++++++ src/NodeService.hpp | 3 +++ 3 files changed, 19 insertions(+) diff --git a/src/Controls.cpp b/src/Controls.cpp index 536868f..6bc3456 100644 --- a/src/Controls.cpp +++ b/src/Controls.cpp @@ -133,6 +133,12 @@ int zts_init_set_roots(const void* roots_data, unsigned int len) return zts_service->setRoots(roots_data, len); } +int zts_init_set_low_bandwidth_mode(bool enabled) +{ + ACQUIRE_SERVICE_OFFLINE(); + return zts_service->setLowBandwidthMode(enabled); +} + int zts_init_set_port(unsigned short port) { ACQUIRE_SERVICE_OFFLINE(); diff --git a/src/NodeService.cpp b/src/NodeService.cpp index 15b18ad..71e1dca 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -1829,6 +1829,16 @@ int NodeService::setRoots(const void* rootsData, unsigned int len) return ZTS_ERR_OK; } +int_fast32_t NodeService::setLowBandwidthMode(bool enabled) +{ + Mutex::Lock _lr(_run_m); + if (_run) { + return ZTS_ERR_SERVICE; + } + _node->setLowBandwidthMode(enabled); + return ZTS_ERR_OK; +} + int NodeService::addInterfacePrefixToBlacklist(const char* prefix, unsigned int len) { if (! prefix || len == 0 || len > 15) { diff --git a/src/NodeService.hpp b/src/NodeService.hpp index d9a9925..edd241c 100644 --- a/src/NodeService.hpp +++ b/src/NodeService.hpp @@ -398,6 +398,9 @@ class NodeService { /** Set the roots definition */ int setRoots(const void* data, unsigned int len); + /** Enable or disable low-bandwidth mode (sends less ambient traffic, network updates happen less frequently) */ + int setLowBandwidthMode(bool enabled); + /** Add Interface prefix to blacklist (prevents ZeroTier from using that interface) */ int addInterfacePrefixToBlacklist(const char* prefix, unsigned int len); From 9f363342d9ef4af8e362fe0820f00083a320c6f2 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Tue, 18 Jul 2023 13:06:19 -0700 Subject: [PATCH 29/55] Fix typo in return type --- src/NodeService.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NodeService.cpp b/src/NodeService.cpp index 71e1dca..b290c33 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -1829,7 +1829,7 @@ int NodeService::setRoots(const void* rootsData, unsigned int len) return ZTS_ERR_OK; } -int_fast32_t NodeService::setLowBandwidthMode(bool enabled) +int NodeService::setLowBandwidthMode(bool enabled) { Mutex::Lock _lr(_run_m); if (_run) { From 8d6d515beeb8bfb67d85c931f4f92002a2261a46 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Tue, 18 Jul 2023 15:14:05 -0400 Subject: [PATCH 30/55] fix links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 740e8d7..3211453 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Peer-to-peer and cross-platform encrypted connections built right into your app latest libzt version -Last Commit +Last Commit Build Status (master branch) @@ -92,7 +92,7 @@ Important directories: We provide ways for your app or enterprise to function independently from any of our services if desired. -While we do operate a global network of redundant root servers, network controllers and an admin API/UI called [Central](https://my.zerotier.com), some use-cases require full control over the infrastructure and we try to make it as easy as possible to set up your own controllers and root servers: See [here](https://github.com/zerotier/ZeroTierOne/tree/master/controller) to learn more about how to set up your own network controller, and [here](https://www.zerotier.com/manual/#4_4) to learn more about setting up your own roots. +While we do operate a global network of redundant root servers, network controllers and an admin API/UI called [Central](https://my.zerotier.com), some use-cases require full control over the infrastructure and we try to make it as easy as possible to set up your own controllers and root servers: See [here](https://github.com/zerotier/ZeroTierOne/tree/main/controller) to learn more about how to set up your own network controller, and [here](https://docs.zerotier.com/zerotier/moons) to learn more about setting up your own roots. # Help From 8066b0e81f3711fe421621c76e2a4810ebb3f1ff Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 19 Jul 2023 10:19:09 -0400 Subject: [PATCH 31/55] fix typos --- src/Events.hpp | 2 +- .../java/com/zerotier/sockets/ZeroTierEventListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Events.hpp b/src/Events.hpp index da911fc..f0ceb26 100644 --- a/src/Events.hpp +++ b/src/Events.hpp @@ -28,7 +28,7 @@ /* Macro substitutions to standardize state checking of service, node, callbacks, and TCP/IP * stack. These are used only for control functions that are called at a low frequency. All higher - * frequency socket calls use a unguarded state flags */ + * frequency socket calls use unguarded state flags */ // Lock service and check that it is running #define ACQUIRE_SERVICE(x) \ diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierEventListener.java b/src/bindings/java/com/zerotier/sockets/ZeroTierEventListener.java index 0154b7e..8eef532 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierEventListener.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierEventListener.java @@ -18,7 +18,7 @@ package com.zerotier.sockets; */ public interface ZeroTierEventListener { /* - * Called when an even occurs within ZeroTier + * Called when an event occurs within ZeroTier */ public void onZeroTierEvent(long id, int eventCode); } From 6ce18af3e6af8b5820201f78d7a16e6b7b4f0c21 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 19 Jul 2023 15:19:40 -0400 Subject: [PATCH 32/55] fix unused warnings libzt/src/bindings/java/JavaSockets.cxx:40:10: warning: unused variable 'rs' [-Wunused-variable] libzt/src/Events.cpp:185:14: warning: unused variable 'rs' [-Wunused-variable] libzt/src/Events.cpp:189:18: warning: unused variable 'arg' [-Wunused-variable] libzt/src/NodeService.cpp:1064:17: warning: variable 'err' set but not used [-Wunused-but-set-variable] --- src/Events.cpp | 5 ++--- src/NodeService.cpp | 9 ++++----- src/bindings/java/JavaSockets.cxx | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Events.cpp b/src/Events.cpp index 2076038..dd62f3e 100644 --- a/src/Events.cpp +++ b/src/Events.cpp @@ -182,11 +182,10 @@ void Events::sendToUser(zts_event_msg_t* msg) if (javaCbMethodId) { JNIEnv* env; #if defined(__ANDROID__) - jint rs = jvm->AttachCurrentThread(&env, NULL); + jvm->AttachCurrentThread(&env, NULL); #else - jint rs = jvm->AttachCurrentThread((void**)&env, NULL); + jvm->AttachCurrentThread((void**)&env, NULL); #endif - uint64_t arg = 0; uint64_t id = 0; if (ZTS_NODE_EVENT(msg->event_code)) { id = msg->node ? msg->node->node_id : 0; diff --git a/src/NodeService.cpp b/src/NodeService.cpp index b290c33..89838b4 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -1061,25 +1061,24 @@ int NodeService::getRouteAtIdx( return ZTS_ERR_ARG; } // target - const char* err = NULL; struct sockaddr* sa = (struct sockaddr*)&(netState.config.routes[idx].target); if (sa->sa_family == AF_INET) { struct sockaddr_in* in4 = (struct sockaddr_in*)sa; - err = inet_ntop(AF_INET, &(in4->sin_addr), target, ZTS_INET6_ADDRSTRLEN); + inet_ntop(AF_INET, &(in4->sin_addr), target, ZTS_INET6_ADDRSTRLEN); } if (sa->sa_family == AF_INET6) { struct sockaddr_in6* in6 = (struct sockaddr_in6*)sa; - err = inet_ntop(AF_INET6, &(in6->sin6_addr), target, ZTS_INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, &(in6->sin6_addr), target, ZTS_INET6_ADDRSTRLEN); } // via struct sockaddr* sa_via = (struct sockaddr*)&(netState.config.routes[idx].via); if (sa_via->sa_family == AF_INET) { struct sockaddr_in* in4 = (struct sockaddr_in*)sa_via; - err = inet_ntop(AF_INET, &(in4->sin_addr), via, ZTS_INET6_ADDRSTRLEN); + inet_ntop(AF_INET, &(in4->sin_addr), via, ZTS_INET6_ADDRSTRLEN); } if (sa_via->sa_family == AF_INET6) { struct sockaddr_in6* in6 = (struct sockaddr_in6*)sa_via; - err = inet_ntop(AF_INET6, &(in6->sin6_addr), via, ZTS_INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, &(in6->sin6_addr), via, ZTS_INET6_ADDRSTRLEN); } if (strlen(via) == 0) { strncpy(via, "0.0.0.0", 7); diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index 56dda6b..330203d 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -37,7 +37,7 @@ extern JavaVM* jvm; void java_detach_from_thread() { - jint rs = jvm->DetachCurrentThread(); + jvm->DetachCurrentThread(); } #ifdef __cplusplus From 88681c02c41565cd5aad6ec60c8a9f7e36e0984d Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 19 Jul 2023 15:23:17 -0400 Subject: [PATCH 33/55] fix: Cannot resolve corresponding JNI function Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mac. --- src/bindings/java/JavaSockets.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index 56dda6b..35f3d02 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -675,7 +675,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1transport_1is_1ready(JNIEnv* } JNIEXPORT uint64_t JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1net_get_mac(JNIEnv* jenv, jclass clazz, jlong net_id) +Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mac(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_mac(net_id); } From fd000261d6f9208a85aac36131aecf485813dce8 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 19 Jul 2023 15:00:48 -0400 Subject: [PATCH 34/55] fix 'No such file or directory' error Using a wildcard in cp was breaking the command when more than 1 file is present ``` brenton@Brentons-MacBook-Air libzt % ./build.sh android-aar "release" << build release aar >> brenton@Brentons-MacBook-Air libzt % brenton@Brentons-MacBook-Air libzt % ./build.sh android-aar "debug" << build debug aar >> ... BUILD SUCCESSFUL in 48s 33 actionable tasks: 28 executed, 5 up-to-date cp: target '/Users/brenton/development/github/libzt/dist/android-any-android-debug/libzt-debug.aar': No such file or directory /Users/brenton/development/github/libzt - Build cache : /Users/brenton/development/github/libzt/cache/android-any-android-debug - Build output : /Users/brenton/development/github/libzt/dist 0 /Users/brenton/development/github/libzt/dist/android-any-android-debug brenton@Brentons-MacBook-Air libzt % ``` --- build.sh | 2 +- pkg/android/app/build.gradle | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 31fb4ea..774411b 100755 --- a/build.sh +++ b/build.sh @@ -603,7 +603,7 @@ android-aar() CMAKE_FLAGS="-D${CMAKE_SWITCH}=1 -D${CMAKE_SWITCH}=ON" cd $ANDROID_PKG_PROJ_DIR ./gradlew $GRADLE_ARGS assemble$UPPERCASE_BUILD_TYPE # assembleRelease / assembleDebug - cp $ANDROID_PKG_PROJ_DIR/app/build/outputs/aar/*.aar \ + cp $ANDROID_PKG_PROJ_DIR/app/build/outputs/aar/libzt-$BUILD_TYPE.aar \ $PKG_OUTPUT_DIR/libzt-$BUILD_TYPE.aar cd - echo -e "\n - Build cache : $CACHE_DIR\n - Build output : $BUILD_OUTPUT_DIR\n" diff --git a/pkg/android/app/build.gradle b/pkg/android/app/build.gradle index 0c78c42..06c81eb 100644 --- a/pkg/android/app/build.gradle +++ b/pkg/android/app/build.gradle @@ -46,6 +46,12 @@ android { } } } + + android.libraryVariants.all { variant -> + variant.outputs.all { file -> + file.outputFileName = "libzt-${variant.buildType.name}.aar" + } + } } dependencies { From a0ffaec02c9a95f1d487f5f5950d92cacf45ab14 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 19 Jul 2023 12:23:30 -0400 Subject: [PATCH 35/55] fix return type warnings Not any of these functions are used in ZeroTierNative.java libzt/src/bindings/java/JavaSockets.cxx:600:1: warning: non-void function does not return a value [-Wreturn-type] libzt/src/bindings/java/JavaSockets.cxx:620:1: warning: non-void function does not return a value [-Wreturn-type] libzt/src/bindings/java/JavaSockets.cxx:629:1: warning: non-void function does not return a value [-Wreturn-type] libzt/src/bindings/java/JavaSockets.cxx:638:1: warning: non-void function does not return a value [-Wreturn-type] --- src/bindings/java/JavaSockets.cxx | 70 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index 56dda6b..f5f11d7 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -589,15 +589,15 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1is_1a return zts_addr_is_assigned(net_id, family); } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get( - JNIEnv* jenv, - jobject thisObj, - long net_id, - jint family, - struct sockaddr_storage* addr) -{ - // Use Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str instead -} +//JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get( +// JNIEnv* jenv, +// jobject thisObj, +// long net_id, +// jint family, +// struct sockaddr_storage* addr) +//{ +// // Use Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str instead +//} JNIEXPORT jstring JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str(JNIEnv* jenv, jclass clazz, long net_id, jint family) @@ -608,34 +608,34 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str(JNIEnv* jenv, jclas return result; } -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1all( - JNIEnv* jenv, - jobject thisObj, - long net_id, - struct sockaddr_storage* addr, - jint* count) -{ - /* This feature will be implemented once the lower-level - limitation of one addr per family per network is removed. */ -} +//JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1all( +// JNIEnv* jenv, +// jobject thisObj, +// long net_id, +// struct sockaddr_storage* addr, +// jint* count) +//{ +// /* This feature will be implemented once the lower-level +// limitation of one addr per family per network is removed. */ +//} -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_16plane( - JNIEnv* jenv, - jobject thisObj, - jlong net_id, - jlong node_id, - struct sockaddr_storage* addr) -{ -} +//JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_16plane( +// JNIEnv* jenv, +// jobject thisObj, +// jlong net_id, +// jlong node_id, +// struct sockaddr_storage* addr) +//{ +//} -JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_1rfc4193( - JNIEnv* jenv, - jobject thisObj, - jlong net_id, - jlong node_id, - struct sockaddr_storage* addr) -{ -} +//JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_1rfc4193( +// JNIEnv* jenv, +// jobject thisObj, +// jlong net_id, +// jlong node_id, +// struct sockaddr_storage* addr) +//{ +//} JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compute_1rfc4193_1str( JNIEnv* jenv, From 5874e442eb0b4fbd1b5ca44b51e39e5258832048 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 24 Jul 2023 18:56:40 -0700 Subject: [PATCH 36/55] Port over TCP relay functionality from ZeroTier One --- include/ZeroTierSockets.h | 18 +++ src/Controls.cpp | 21 +++ src/NodeService.cpp | 310 ++++++++++++++++++++++++++++++++++++-- src/NodeService.hpp | 88 ++++++++--- 4 files changed, 404 insertions(+), 33 deletions(-) diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index 0374bac..eb3c6c1 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -1274,6 +1274,24 @@ int zts_init_set_event_handler(jobject obj_ref, jmethodID id); ZTS_API int ZTCALL zts_init_set_event_handler(void (*callback)(void*)); #endif +/** + * @brief Set TCP relay for ZeroTier to use instead of P2P UDP + * + * @param tcp_relay_addr IP address of TCP relay + * @param tcp_relay_port Port of TCP relay + */ +ZTS_API int ZTCALL zts_init_set_tcp_relay(const char* tcp_relay_addr, unsigned short tcp_relay_port); + +/** + * @brief Allow TCP relay for ZeroTier to use instead of P2P UDP + */ +ZTS_API int ZTCALL zts_init_allow_tcp_relay(int enabled); + +/** + * @brief Force TCP relay for ZeroTier to use instead of P2P UDP + */ +ZTS_API int ZTCALL zts_init_force_tcp_relay(int enabled); + /** * @brief Blacklist an interface prefix (or name). This prevents ZeroTier from * sending traffic over matching interfaces. This is an initialization function that can diff --git a/src/Controls.cpp b/src/Controls.cpp index 6bc3456..331e888 100644 --- a/src/Controls.cpp +++ b/src/Controls.cpp @@ -121,6 +121,27 @@ int zts_init_set_event_handler(PythonDirectorCallbackClass* callback) return ZTS_ERR_OK; } +int zts_init_set_tcp_relay(const char* tcp_relay_addr, unsigned short tcp_relay_port) +{ + ACQUIRE_SERVICE_OFFLINE(); + zts_service->setTcpRelayAddress(tcp_relay_addr, tcp_relay_port); + return ZTS_ERR_OK; +} + +int zts_init_allow_tcp_relay(bool enabled) +{ + ACQUIRE_SERVICE_OFFLINE(); + zts_service->allowTcpRelay(enabled); + return ZTS_ERR_OK; +} + +int zts_init_force_tcp_relay(bool enabled) +{ + ACQUIRE_SERVICE_OFFLINE(); + zts_service->forceTcpRelay(enabled); + return ZTS_ERR_OK; +} + int zts_init_blacklist_if(const char* prefix, unsigned int len) { ACQUIRE_SERVICE_OFFLINE(); diff --git a/src/NodeService.cpp b/src/NodeService.cpp index 89838b4..f43c81d 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -17,6 +17,8 @@ * ZeroTier Node Service */ +#include + #include "NodeService.hpp" #include "../version.h" @@ -28,14 +30,16 @@ #include "VirtualTap.hpp" #if defined(__WINDOWS__) -#include -#include -#include #include #include +#include +#include +#include #define stat _stat #endif +#define ZT_TCP_FALLBACK_RELAY "204.80.128.1/443" + namespace ZeroTier { static int SnodeVirtualNetworkConfigFunction( @@ -173,7 +177,12 @@ NodeService::NodeService() , _randomPortRangeEnd(0) , _udpPortPickerCounter(0) , _lastDirectReceiveFromGlobal(0) + , _fallbackRelayAddress(ZT_TCP_FALLBACK_RELAY) + , _allowTcpRelay(true) + , _forceTcpRelay(false) + , _lastSendToGlobalV4(0) , _lastRestart(0) + , _tcpFallbackTunnel((TcpConnection*)0) , _nextBackgroundTaskDeadline(0) , _run(false) , _termReason(ONE_STILL_RUNNING) @@ -286,7 +295,8 @@ NodeService::ReasonForTermination NodeService::run() if (_allowSecondaryPort) { if (_secondaryPort) { _ports[1] = _secondaryPort; - } else { + } + else { _ports[1] = _getRandomPort(minPort, maxPort); } } @@ -301,9 +311,10 @@ NodeService::ReasonForTermination NodeService::run() if (_ports[1]) { if (_tertiaryPort) { _ports[2] = _tertiaryPort; - } else { + } + else { _ports[2] = minPort + (_ports[0] % 40000); - for(int i=0;;++i) { + for (int i = 0;; ++i) { if (i > 1000) { _ports[2] = 0; break; @@ -398,7 +409,10 @@ NodeService::ReasonForTermination NodeService::run() p[pc++] = _ports[i]; } } - _binder.refresh(_phy, p, pc, explicitBind, *this); + if (! _forceTcpRelay) { + // Only bother binding UDP ports if we aren't forcing TCP-relay mode + _binder.refresh(_phy, p, pc, explicitBind, *this); + } } // Generate callback messages for user application @@ -411,6 +425,12 @@ NodeService::ReasonForTermination NodeService::run() dl = _nextBackgroundTaskDeadline; } + // Close TCP fallback tunnel if we have direct UDP + if (! _forceTcpRelay && (_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; @@ -616,6 +636,9 @@ void NodeService::phyOnDatagram( void* data, unsigned long len) { + if (_forceTcpRelay) { + return; + } ZTS_UNUSED_ARG(uptr); ZTS_UNUSED_ARG(localAddr); if ((len >= 16) && (reinterpret_cast(from)->ipScope() == InetAddress::IP_SCOPE_GLOBAL)) @@ -639,6 +662,185 @@ void NodeService::phyOnDatagram( } } +void NodeService::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); + } +} + +void NodeService::phyOnTcpClose(PhySocket* sock, void** uptr) +{ + 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()); + } + delete tc; + } +} + +void NodeService::phyOnTcpData(PhySocket* sock, void** uptr, void* data, unsigned long len) +{ + try { + if (! len) { + return; // sanity check, should never happen + } + TcpConnection* tc = reinterpret_cast(*uptr); + tc->lastReceive = OSUtils::now(); + switch (tc->type) { + 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 (...) { + _phy.close(sock); + } +} + +void NodeService::phyOnTcpWritable(PhySocket* sock, void** uptr) +{ + TcpConnection* tc = reinterpret_cast(*uptr); + bool closeit = false; + { + Mutex::Lock _l(tc->writeq_m); + if (tc->writeq.length() > 0) { + long sent = (long)_phy.streamSend(sock, tc->writeq.data(), (unsigned long)tc->writeq.length(), true); + if (sent > 0) { + if ((unsigned long)sent >= (unsigned long)tc->writeq.length()) { + tc->writeq.clear(); + _phy.setNotifyWritable(sock, false); + } + else { + tc->writeq.erase(tc->writeq.begin(), tc->writeq.begin() + sent); + } + } + } + else { + _phy.setNotifyWritable(sock, false); + } + } + if (closeit) { + _phy.close(sock); + } +} + int NodeService::nodeVirtualNetworkConfigFunction( uint64_t net_id, void** nuptr, @@ -1225,7 +1427,7 @@ uint64_t NodeService::getNodeId() int NodeService::setIdentity(const char* keypair, unsigned int len) { if (keypair == NULL || len < ZT_IDENTITY_STRING_BUFFER_LENGTH) { - return ZTS_ERR_ARG; + // return ZTS_ERR_ARG; } // Double check user-provided keypair Identity id; @@ -1454,6 +1656,79 @@ int NodeService::nodeWirePacketSendFunction( unsigned int len, unsigned int ttl) { + if (_allowTcpRelay) { + 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 (_forceTcpRelay + || (((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 ( + _forceTcpRelay + || (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER) + && ((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2)))) { + const InetAddress addr(_fallbackRelayAddress); + 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 + bool connected = false; + _phy.tcpConnect(reinterpret_cast(&addr), connected, (void*)tc, true); + } + } + _lastSendToGlobalV4 = now; + } + } + } + + if (_forceTcpRelay) { + // Shortcut here so that we don't emit any UDP packets + return 0; + } + // 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. @@ -1682,9 +1957,9 @@ int NodeService::shouldBindInterface(const char* ifname, const InetAddress& ifad unsigned int NodeService::_getRandomPort(unsigned int minPort, unsigned int maxPort) { unsigned int randp = 0; - Utils::getSecureRandom(&randp,sizeof(randp)); + Utils::getSecureRandom(&randp, sizeof(randp)); randp = (randp % (maxPort - minPort + 1)) + minPort; - for(int i=0;;++i) { + for (int i = 0;; ++i) { if (i > 1000) { return 0; } @@ -1812,6 +2087,21 @@ void NodeService::enableEvents() _events->enable(); } +void NodeService::setTcpRelayAddress(const char* tcpRelayAddr, unsigned short tcpRelayPort) +{ + _fallbackRelayAddress = InetAddress(std::string(std::string(tcpRelayAddr) + std::string("/") + std::to_string(tcpRelayPort)).c_str()); +} + +void NodeService::allowTcpRelay(bool enabled) +{ + _allowTcpRelay = true; +} + +void NodeService::forceTcpRelay(bool enabled) +{ + _forceTcpRelay = true; +} + int NodeService::setRoots(const void* rootsData, unsigned int len) { if (! rootsData || len <= 0 || len > ZTS_STORE_DATA_LEN) { diff --git a/src/NodeService.hpp b/src/NodeService.hpp index edd241c..c600bbc 100644 --- a/src/NodeService.hpp +++ b/src/NodeService.hpp @@ -28,6 +28,7 @@ #include "Phy.hpp" #include "PortMapper.hpp" #include "ZeroTierSockets.h" +#include "version.h" #include #include @@ -43,17 +44,53 @@ // How often to check for local interface addresses #define ZT_LOCAL_INTERFACE_CHECK_INTERVAL 60000 +// Attempt to engage TCP fallback after this many ms of no reply to packets sent to global-scope IPs +#define ZT_TCP_FALLBACK_AFTER 30000 + +// 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) }; + #ifdef __WINDOWS__ #include #endif namespace ZeroTier { +class NodeService; struct InetAddress; class VirtualTap; class MAC; class Events; +/** + * A TCP connection and related state and buffers + */ +struct TcpConnection { + enum { + TCP_UNCATEGORIZED_INCOMING, // uncategorized incoming connection + TCP_HTTP_INCOMING, + TCP_HTTP_OUTGOING, + TCP_TUNNEL_OUTGOING // TUNNELED mode proxy outbound connection + } type; + + NodeService* parent; + PhySocket* sock; + InetAddress remoteAddr; + uint64_t lastReceive; + + std::string readq; + std::string writeq; + Mutex writeq_m; +}; + /** * ZeroTier node service */ @@ -161,6 +198,16 @@ class NodeService { // Time we last received a packet from a global address uint64_t _lastDirectReceiveFromGlobal; + InetAddress _fallbackRelayAddress; + bool _allowTcpRelay; + bool _forceTcpRelay; + uint64_t _lastSendToGlobalV4; + + // Active TCP/IP connections + std::vector _tcpConnections; + Mutex _tcpConnections_m; + TcpConnection* _tcpFallbackTunnel; + // Last potential sleep/wake event uint64_t _lastRestart; @@ -255,6 +302,8 @@ class NodeService { void* data, unsigned long len); + void phyOnTcpConnect(PhySocket* sock, void** uptr, bool success); + int nodeVirtualNetworkConfigFunction( uint64_t net_id, void** nuptr, @@ -393,6 +442,15 @@ class NodeService { /** Set the event system instance used to convey messages to the user */ int setUserEventSystem(Events* events); + /** Set the address and port for the tcp relay that ZeroTier should use */ + void setTcpRelayAddress(const char* tcpRelayAddr, unsigned short tcpRelayPort); + + /** Allow ZeroTier to use the TCP relay */ + void allowTcpRelay(bool enabled); + + /** Force ZeroTier to only use the the TCP relay */ + void forceTcpRelay(bool enabled); + void enableEvents(); /** Set the roots definition */ @@ -446,12 +504,6 @@ class NodeService { /** Return whether an address of the given family has been assigned by the network */ int addrIsAssigned(uint64_t net_id, unsigned int family); - void phyOnTcpConnect(PhySocket* sock, void** uptr, bool success) - { - ZTS_UNUSED_ARG(sock); - ZTS_UNUSED_ARG(uptr); - ZTS_UNUSED_ARG(success); - } void phyOnTcpAccept(PhySocket* sockL, PhySocket* sockN, void** uptrL, void** uptrN, const struct sockaddr* from) { ZTS_UNUSED_ARG(sockL); @@ -460,23 +512,13 @@ class NodeService { ZTS_UNUSED_ARG(uptrN); ZTS_UNUSED_ARG(from); } - void phyOnTcpClose(PhySocket* sock, void** uptr) - { - ZTS_UNUSED_ARG(sock); - ZTS_UNUSED_ARG(uptr); - } - void phyOnTcpData(PhySocket* sock, void** uptr, void* data, unsigned long len) - { - ZTS_UNUSED_ARG(sock); - ZTS_UNUSED_ARG(uptr); - ZTS_UNUSED_ARG(data); - ZTS_UNUSED_ARG(len); - } - void phyOnTcpWritable(PhySocket* sock, void** uptr) - { - ZTS_UNUSED_ARG(sock); - ZTS_UNUSED_ARG(uptr); - } + + void phyOnTcpClose(PhySocket* sock, void** uptr); + + void phyOnTcpData(PhySocket* sock, void** uptr, void* data, unsigned long len); + + void phyOnTcpWritable(PhySocket* sock, void** uptr); + void phyOnFileDescriptorActivity(PhySocket* sock, void** uptr, bool readable, bool writable) { ZTS_UNUSED_ARG(sock); From 10548d9b055ab49634df4d78b086b033e2b37fd9 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 26 Jul 2023 12:41:18 -0700 Subject: [PATCH 37/55] Fix mismatched types in tcp relay api --- src/Controls.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controls.cpp b/src/Controls.cpp index 331e888..2fd3bc7 100644 --- a/src/Controls.cpp +++ b/src/Controls.cpp @@ -128,14 +128,14 @@ int zts_init_set_tcp_relay(const char* tcp_relay_addr, unsigned short tcp_relay_ return ZTS_ERR_OK; } -int zts_init_allow_tcp_relay(bool enabled) +int zts_init_allow_tcp_relay(int enabled) { ACQUIRE_SERVICE_OFFLINE(); zts_service->allowTcpRelay(enabled); return ZTS_ERR_OK; } -int zts_init_force_tcp_relay(bool enabled) +int zts_init_force_tcp_relay(int enabled) { ACQUIRE_SERVICE_OFFLINE(); zts_service->forceTcpRelay(enabled); From 2d83bc25f36d791f976b739d5e57881036e13f4e Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 26 Jul 2023 12:42:43 -0700 Subject: [PATCH 38/55] Fix tcp relay api logic error --- src/NodeService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NodeService.cpp b/src/NodeService.cpp index f43c81d..a552ed6 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -2094,12 +2094,12 @@ void NodeService::setTcpRelayAddress(const char* tcpRelayAddr, unsigned short tc void NodeService::allowTcpRelay(bool enabled) { - _allowTcpRelay = true; + _allowTcpRelay = enabled; } void NodeService::forceTcpRelay(bool enabled) { - _forceTcpRelay = true; + _forceTcpRelay = enabled; } int NodeService::setRoots(const void* rootsData, unsigned int len) From b85a6a45975f8ad3be77ae27a9325b66376c1d78 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 2 Aug 2023 11:29:22 -0400 Subject: [PATCH 39/55] Fix typos and bump ZTO submodule commit to include Fix typos (https://github.com/zerotier/ZeroTierOne/pull/2075) --- ext/ZeroTierOne | 2 +- src/NodeService.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/ZeroTierOne b/ext/ZeroTierOne index 97492ee..e361272 160000 --- a/ext/ZeroTierOne +++ b/ext/ZeroTierOne @@ -1 +1 @@ -Subproject commit 97492eec7c3a107c423698572571bfd895d01aa4 +Subproject commit e36127283cc58ac184a9d4497852a5ed8b9c515b diff --git a/src/NodeService.cpp b/src/NodeService.cpp index a552ed6..5f1c31d 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -1703,7 +1703,7 @@ int NodeService::nodeWirePacketSendFunction( else if ( _forceTcpRelay || (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER) - && ((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2)))) { + && ((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INTERVAL / 2)))) { const InetAddress addr(_fallbackRelayAddress); TcpConnection* tc = new TcpConnection(); { From 6fe2d49ef17f42bda82cd71acb2f3296d43a4a1e Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 2 Aug 2023 12:08:07 -0400 Subject: [PATCH 40/55] Fix: field '_lastRestart' will be initialized after field '_tcpFallbackTunnel' [-Wreorder-ctor] --- src/NodeService.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NodeService.cpp b/src/NodeService.cpp index 5f1c31d..d0b52e5 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -181,8 +181,8 @@ NodeService::NodeService() , _allowTcpRelay(true) , _forceTcpRelay(false) , _lastSendToGlobalV4(0) - , _lastRestart(0) , _tcpFallbackTunnel((TcpConnection*)0) + , _lastRestart(0) , _nextBackgroundTaskDeadline(0) , _run(false) , _termReason(ONE_STILL_RUNNING) From aede837fea21116ac74586c924713781d01e6077 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 2 Aug 2023 12:11:47 -0400 Subject: [PATCH 41/55] Fix: warning: enumeration value 'TCP_HTTP_OUTGOING' not handled in switch [-Wswitch] --- src/NodeService.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/NodeService.cpp b/src/NodeService.cpp index 5f1c31d..501b5b8 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -713,6 +713,10 @@ void NodeService::phyOnTcpData(PhySocket* sock, void** uptr, void* data, unsigne TcpConnection* tc = reinterpret_cast(*uptr); tc->lastReceive = OSUtils::now(); switch (tc->type) { + case TcpConnection::TCP_UNCATEGORIZED_INCOMING: + case TcpConnection::TCP_HTTP_INCOMING: + case TcpConnection::TCP_HTTP_OUTGOING: + break; case TcpConnection::TCP_TUNNEL_OUTGOING: tc->readq.append((const char*)data, len); while (tc->readq.length() >= 5) { From b4c7fd1a0f0e7a2a58f5d8c9c64d9b3463d9bb94 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 2 Aug 2023 12:53:24 -0400 Subject: [PATCH 42/55] Fix: Cannot resolve symbol 'localPort' Remove second bind() with unused backlog arg and identical impl as first bind() --- .../com/zerotier/sockets/ZeroTierServerSocket.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierServerSocket.java b/src/bindings/java/com/zerotier/sockets/ZeroTierServerSocket.java index ac1e25f..1a3cc57 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierServerSocket.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierServerSocket.java @@ -76,7 +76,6 @@ public class ZeroTierServerSocket { /** * Bind to a local address * @param localAddr Local address to which this socket should bind - * @param localPort Local port to which this socket should bind * * @exception IOException when an I/O error occurs */ @@ -86,19 +85,6 @@ public class ZeroTierServerSocket { _socket.bind(inetAddr.getHostName(), inetAddr.getPort()); } - /** - * Bind to a local address - * @param localAddr Local address to which this socket should bind - * @param localPort Local port to which this socket should bind - * - * @exception IOException when an I/O error occurs - */ - public void bind(SocketAddress localAddr, int backlog) throws IOException - { - InetSocketAddress inetAddr = (InetSocketAddress)localAddr; - _socket.bind(inetAddr.getHostName(), inetAddr.getPort()); - } - /** * Close the ZeroTierSocket. * From 8aa689034eb9bc1589806d7f60fe968469f04897 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Wed, 2 Aug 2023 12:24:58 -0400 Subject: [PATCH 43/55] Fix: Incorrect type for parameter 'net_id', which should have type 'jlong'. Incorrect return type uint64_t, which should have been jlong. Incorrect return type uint64_t, which should have been jlong. Incorrect return type uint64_t, which should have been jlong. --- src/bindings/java/JavaSockets.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/java/JavaSockets.cxx b/src/bindings/java/JavaSockets.cxx index 05105df..e37f702 100644 --- a/src/bindings/java/JavaSockets.cxx +++ b/src/bindings/java/JavaSockets.cxx @@ -600,7 +600,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1is_1a //} JNIEXPORT jstring JNICALL -Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str(JNIEnv* jenv, jclass clazz, long net_id, jint family) +Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1get_1str(JNIEnv* jenv, jclass clazz, jlong net_id, jint family) { char ip_str[ZTS_IP_MAX_STR_LEN] = { 0 }; zts_addr_get_str(net_id, family, ip_str, ZTS_IP_MAX_STR_LEN); @@ -659,7 +659,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1addr_1compu return ZTS_ERR_OK; } -JNIEXPORT uint64_t JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1compute_1adhoc_1id( +JNIEXPORT jlong JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1compute_1adhoc_1id( JNIEnv* jenv, jclass clazz, short start_port, @@ -674,7 +674,7 @@ Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1transport_1is_1ready(JNIEnv* return zts_net_transport_is_ready(net_id); } -JNIEXPORT uint64_t JNICALL +JNIEXPORT jlong JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1net_1get_1mac(JNIEnv* jenv, jclass clazz, jlong net_id) { return zts_net_get_mac(net_id); @@ -742,7 +742,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1is_1o return zts_node_is_online(); } -JNIEXPORT uint64_t JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1id(JNIEnv* jenv, jclass clazz) +JNIEXPORT jlong JNICALL Java_com_zerotier_sockets_ZeroTierNative_zts_1node_1get_1id(JNIEnv* jenv, jclass clazz) { return zts_node_get_id(); } From dd0d606422b19f89029a3664bf6bc723efceef21 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Thu, 3 Aug 2023 15:47:50 -0700 Subject: [PATCH 44/55] Add missing zts_init_set_low_bandwidth_mode --- include/ZeroTierSockets.h | 17 +++++++++++++++++ src/Controls.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index eb3c6c1..8c74b9f 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -1315,6 +1315,23 @@ ZTS_API int ZTCALL zts_init_blacklist_if(const char* prefix, unsigned int len); */ ZTS_API int ZTCALL zts_init_set_roots(const void* roots_data, unsigned int len); +/** + * @brief Enable or disable low-bandwidth mode. This is an initialization function that can + * only be called before `zts_node_start()`. + * + * Low-bandwidth mode reduces the ambient traffic that ZeroTier sends + * at the expense of responsiveness to network changes. It does not reduce your + * established connection speeds. It is an adjustment to multiple internal + * timers that results in fewer keepalive probes and network configuration + * requests being sent. This is a good option if your underlying physical network + * doesn't change much. + * + * @param enabled Whether low-bandwidth mode is enabled or not (default: false) + * @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node + * experiences a problem. + */ +ZTS_API int ZTCALL zts_init_set_low_bandwidth_mode(int enabled); + /** * @brief Set the port to which the node should bind. This is an initialization function that can * only be called before `zts_node_start()`. diff --git a/src/Controls.cpp b/src/Controls.cpp index 2fd3bc7..8aa0a72 100644 --- a/src/Controls.cpp +++ b/src/Controls.cpp @@ -154,7 +154,7 @@ int zts_init_set_roots(const void* roots_data, unsigned int len) return zts_service->setRoots(roots_data, len); } -int zts_init_set_low_bandwidth_mode(bool enabled) +int zts_init_set_low_bandwidth_mode(int enabled) { ACQUIRE_SERVICE_OFFLINE(); return zts_service->setLowBandwidthMode(enabled); From dd45f9fb45c491b65e93743ae48788845ff2fc5e Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 4 Aug 2023 10:27:50 -0400 Subject: [PATCH 45/55] Fix https://github.com/zerotier/libzt/issues/242 When processing events, AttachCurrentThread is called, but matching DetachCurrentThread was not being called This prevented main thread from exiting --- src/Events.cpp | 2 ++ test/ExitTest.java | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 test/ExitTest.java diff --git a/src/Events.cpp b/src/Events.cpp index dd62f3e..57cdc20 100644 --- a/src/Events.cpp +++ b/src/Events.cpp @@ -197,6 +197,8 @@ void Events::sendToUser(zts_event_msg_t* msg) id = msg->peer ? msg->peer->peer_id : 0; } env->CallVoidMethod(javaCbObjRef, javaCbMethodId, id, msg->event_code); + + jvm->DetachCurrentThread(); } #endif // ZTS_ENABLE_JAVA #ifdef ZTS_ENABLE_PINVOKE diff --git a/test/ExitTest.java b/test/ExitTest.java new file mode 100644 index 0000000..be5b28e --- /dev/null +++ b/test/ExitTest.java @@ -0,0 +1,77 @@ +import com.zerotier.sockets.*; + +// +// Test for: +// Java process does not exit after finishing libzt work +// https://github.com/zerotier/libzt/issues/242 +// +// Run and ensure that process exits +// +public class ExitTest { + + public static void main(String[] args) throws InterruptedException { + + long networkId = Long.parseUnsignedLong("ebe7fbd445e76ac6", 16); + String storagePath = "exittest_storage"; + + ZeroTierNode node = new ZeroTierNode(); + node.initFromStorage(storagePath); + node.initSetEventHandler(new ZeroTierEventListener() { + @Override + public void onZeroTierEvent(long l, int eventCode) { + if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_UP) { + System.err.println("ZTS_EVENT_NODE_UP"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_ONLINE) { + System.err.println("ZTS_EVENT_NODE_ONLINE"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_OFFLINE) { + System.err.println("ZTS_EVENT_NODE_OFFLINE"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_DOWN) { + System.err.println("ZTS_EVENT_NODE_DOWN"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_READY_IP4) { + System.err.println("ZTS_EVENT_NETWORK_READY_IP4"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_READY_IP6) { + System.err.println("ZTS_EVENT_NETWORK_READY_IP6"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_DOWN) { + System.err.println("ZTS_EVENT_NETWORK_DOWN"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_OK) { + System.err.println("ZTS_EVENT_NETWORK_OK"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_ACCESS_DENIED) { + System.err.println("ZTS_EVENT_NETWORK_ACCESS_DENIED"); + } + if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_NOT_FOUND) { + System.err.println("ZTS_EVENT_NETWORK_NOT_FOUND"); + } + } + }); + + System.err.println("start"); + node.start(); + + System.err.println("delay until online"); + while (!node.isOnline()) { + ZeroTierNative.zts_util_delay(50); + } + System.err.println("done delaying"); + + System.out.println("join"); + node.join(networkId); + + System.out.println("delaying until transport ready"); + while (! node.isNetworkTransportReady(networkId)) { + ZeroTierNative.zts_util_delay(50); + } + + System.err.println("stop"); + node.stop(); + + System.err.println("exiting"); + } +} From b1d088f39cf2e7730ea1b5433be1b76893f2725b Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 18 Aug 2023 08:31:08 -0400 Subject: [PATCH 46/55] fix examples warnings warning: incompatible pointer types passing 'int *' to parameter of type 'unsigned short *' [-Wincompatible-pointer-types] --- examples/c/nonblockingserver.c | 2 +- examples/c/server.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/c/nonblockingserver.c b/examples/c/nonblockingserver.c index 228bcb2..8b5c312 100644 --- a/examples/c/nonblockingserver.c +++ b/examples/c/nonblockingserver.c @@ -95,7 +95,7 @@ int main(int argc, char** argv) // zts_bsd_accept(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen) char remote_ipstr[ZTS_INET6_ADDRSTRLEN] = { 0 }; - unsigned int port = 0; + unsigned short port = 0; printf("Accepting on listening socket...\n"); if ((accfd = zts_accept(fd, remote_ipstr, ZTS_INET6_ADDRSTRLEN, &port)) < 0) { printf("Error (fd=%d, ret=%d, zts_errno=%d). Exiting.\n", fd, err, zts_errno); diff --git a/examples/c/server.c b/examples/c/server.c index b3c606c..e43a00f 100644 --- a/examples/c/server.c +++ b/examples/c/server.c @@ -75,7 +75,7 @@ int main(int argc, char** argv) // Can also use traditional: zts_bsd_socket(), zts_bsd_bind(), zts_bsd_listen(), zts_bsd_accept(), etc. char remote_addr[ZTS_INET6_ADDRSTRLEN] = { 0 }; - int remote_port = 0; + unsigned short remote_port = 0; int len = ZTS_INET6_ADDRSTRLEN; if ((accfd = zts_tcp_server(local_addr, local_port, remote_addr, len, &remote_port)) < 0) { printf("Error (fd=%d, zts_errno=%d). Exiting.\n", accfd, zts_errno); From 84800534e7a4cc70abce75f34295ddc48c771fc6 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 18 Aug 2023 08:43:09 -0400 Subject: [PATCH 47/55] fix formatting --- src/Events.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Events.cpp b/src/Events.cpp index 57cdc20..30c6845 100644 --- a/src/Events.cpp +++ b/src/Events.cpp @@ -35,14 +35,14 @@ void PythonDirectorCallbackClass::on_zerotier_event(zts_event_msg_t* msg) } #endif -#define ZTS_NODE_EVENT(code) code >= ZTS_EVENT_NODE_UP&& code <= ZTS_EVENT_NODE_FATAL_ERROR -#define ZTS_NETWORK_EVENT(code) code >= ZTS_EVENT_NETWORK_NOT_FOUND&& code <= ZTS_EVENT_NETWORK_UPDATE -#define ZTS_STACK_EVENT(code) code >= ZTS_EVENT_STACK_UP&& code <= ZTS_EVENT_STACK_DOWN -#define ZTS_NETIF_EVENT(code) code >= ZTS_EVENT_NETIF_UP&& code <= ZTS_EVENT_NETIF_LINK_DOWN -#define ZTS_PEER_EVENT(code) code >= ZTS_EVENT_PEER_DIRECT&& code <= ZTS_EVENT_PEER_PATH_DEAD -#define ZTS_ROUTE_EVENT(code) code >= ZTS_EVENT_ROUTE_ADDED&& code <= ZTS_EVENT_ROUTE_REMOVED -#define ZTS_ADDR_EVENT(code) code >= ZTS_EVENT_ADDR_ADDED_IP4&& code <= ZTS_EVENT_ADDR_REMOVED_IP6 -#define ZTS_STORE_EVENT(code) code >= ZTS_EVENT_STORE_IDENTITY_SECRET&& code <= ZTS_EVENT_STORE_NETWORK +#define ZTS_NODE_EVENT(code) code >= ZTS_EVENT_NODE_UP && code <= ZTS_EVENT_NODE_FATAL_ERROR +#define ZTS_NETWORK_EVENT(code) code >= ZTS_EVENT_NETWORK_NOT_FOUND && code <= ZTS_EVENT_NETWORK_UPDATE +#define ZTS_STACK_EVENT(code) code >= ZTS_EVENT_STACK_UP && code <= ZTS_EVENT_STACK_DOWN +#define ZTS_NETIF_EVENT(code) code >= ZTS_EVENT_NETIF_UP && code <= ZTS_EVENT_NETIF_LINK_DOWN +#define ZTS_PEER_EVENT(code) code >= ZTS_EVENT_PEER_DIRECT && code <= ZTS_EVENT_PEER_PATH_DEAD +#define ZTS_ROUTE_EVENT(code) code >= ZTS_EVENT_ROUTE_ADDED && code <= ZTS_EVENT_ROUTE_REMOVED +#define ZTS_ADDR_EVENT(code) code >= ZTS_EVENT_ADDR_ADDED_IP4 && code <= ZTS_EVENT_ADDR_REMOVED_IP6 +#define ZTS_STORE_EVENT(code) code >= ZTS_EVENT_STORE_IDENTITY_SECRET && code <= ZTS_EVENT_STORE_NETWORK namespace ZeroTier { From 18a2c38f426c60391cf9d9741feb10befaa41bd4 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 18 Aug 2023 08:46:21 -0400 Subject: [PATCH 48/55] Fix warning: [cast] redundant cast to int --- build.sh | 2 +- src/bindings/java/com/zerotier/sockets/ZeroTierNative.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 774411b..bbe2049 100755 --- a/build.sh +++ b/build.sh @@ -522,7 +522,7 @@ host-jar() cp -f $CACHE_DIR/lib/libzt.* $JAVA_JAR_DIR cd $JAVA_JAR_DIR export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 - javac -Xlint:deprecation com/zerotier/sockets/*.java + javac -Xlint:all com/zerotier/sockets/*.java jar cf libzt-$PKG_VERSION.jar $SHARED_LIB_NAME com/zerotier/sockets/*.class rm -rf com $SHARED_LIB_NAME diff --git a/src/bindings/java/com/zerotier/sockets/ZeroTierNative.java b/src/bindings/java/com/zerotier/sockets/ZeroTierNative.java index 9205315..aa79711 100644 --- a/src/bindings/java/com/zerotier/sockets/ZeroTierNative.java +++ b/src/bindings/java/com/zerotier/sockets/ZeroTierNative.java @@ -228,7 +228,7 @@ public class ZeroTierNative { public static int ZTS_SO_DONTROUTE = 0x00000010; // NOT YET SUPPORTED public static int ZTS_SO_USELOOPBACK = 0x00000040; // NOT YET SUPPORTED public static int ZTS_SO_LINGER = 0x00000080; - public static int ZTS_SO_DONTLINGER = ((int)(~ZTS_SO_LINGER)); + public static int ZTS_SO_DONTLINGER = (~ZTS_SO_LINGER); public static int ZTS_SO_OOBINLINE = 0x00000100; // NOT YET SUPPORTED public static int ZTS_SO_REUSEPORT = 0x00000200; // NOT YET SUPPORTED public static int ZTS_SO_SNDBUF = 0x00001001; // NOT YET SUPPORTED From 9ca6873c48641853b68a3f6df974f40655359455 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 18 Aug 2023 08:42:01 -0400 Subject: [PATCH 49/55] add ZTS_IN6ADDR_ANY_INIT and zts_in6addr_any These mimic IN6ADDR_ANY_INIT and in6addr_any For setting sin6_addr in zts_sockaddr_in6: ``` struct zts_sockaddr_in6 addr6; addr6.sin6_addr = zts_in6addr_any; ``` --- include/ZeroTierSockets.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index 8c74b9f..ba9732a 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -437,6 +437,12 @@ typedef void (*CppCallback)(void* msg); /** 255.255.255.255 */ #define ZTS_INADDR_BROADCAST ZTS_IPADDR_BROADCAST + +#define ZTS_IN6ADDR_ANY_INIT {{{0,0,0,0}}} + + + + // Socket protocol types #define ZTS_SOCK_STREAM 0x0001 #define ZTS_SOCK_DGRAM 0x0002 @@ -503,6 +509,8 @@ struct zts_in6_addr { //#define s6_addr un.u8_addr }; +const struct zts_in6_addr zts_in6addr_any = ZTS_IN6ADDR_ANY_INIT; + /** * Address structure to specify an IPv4 endpoint */ From 29b20879f73d974e7489f6e122e8f703e4f26626 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 18 Aug 2023 12:04:33 -0400 Subject: [PATCH 50/55] Remove debug optimization -O3 This was running many optimization passes and preventing debugging --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dab7608..6f554e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,7 +281,6 @@ endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "debug") set(BUILD_DEBUG ON) set(CMAKE_VERBOSE_MAKEFILE ON) - set(DEBUG_OPTIMIZATION "-O3") endif() if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "release") set(BUILD_RELEASE ON) @@ -400,7 +399,6 @@ else() set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} \ - ${DEBUG_OPTIMIZATION} \ -DLWIP_DEBUG=1 -DLIBZT_DEBUG=1") set(CMAKE_C_FLAGS_RELEASE @@ -413,7 +411,6 @@ else() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \ - ${DEBUG_OPTIMIZATION} \ -DLWIP_DEBUG=1 -DLIBZT_DEBUG=1") set(CMAKE_CXX_FLAGS_RELEASE From 189576719b7886d2bd66eb7969ab4e60d1bcb540 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Fri, 18 Aug 2023 11:00:05 -0400 Subject: [PATCH 51/55] Fix fatal error: jni_md.h: No such file or directory And clean up finding JNI in general Tested on Mac, Linux, and Android --- CMakeLists.txt | 57 +++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dab7608..aeb96d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,8 +82,6 @@ endif() # ------------------------------------------------------------------------------ # | INCLUDE DIRECTORIES | # ------------------------------------------------------------------------------ -# Temporary measure to test GitHub workflow on Ubuntu -include_directories(/usr/lib/jvm/java-11-openjdk-amd64/include/linux/) # ZeroTier include_directories(${ZTO_SRC_DIR}) include_directories(${ZTO_SRC_DIR}/include) @@ -471,37 +469,40 @@ endif() if(ZTS_ENABLE_JAVA OR (BUILD_ANDROID AND NOT ZTS_NDK_ONLY)) message(STATUS "Looking for JNI") + message(STATUS "Ignore seeing \"Found JNI: NotNeeded\" below; check that JNI_INCLUDE_DIRS is valid") - if(BUILD_WIN) - # We are only interested in finding jni.h: we do not care about extended JVM - # functionality or the AWT library. set(JAVA_AWT_LIBRARY NotNeeded) - # set(JAVA_JVM_LIBRARY NotNeeded) set(JAVA_INCLUDE_PATH2 NotNeeded) - # set(JAVA_AWT_INCLUDE_PATH NotNeeded) - set(JAVA_INCLUDE_PATH "C:\\Program Files\\Java\\jdk-10.0.2\\include") - endif() - + # + # "trick" CMake into thinking that we have already found these + # https://stackoverflow.com/a/51764145 + # + # These may be missing, but we do not need them + # + # There is no official way of telling CMake: "skip looking for AWT, etc." + # set(JAVA_AWT_LIBRARY NotNeeded) set(JAVA_JVM_LIBRARY NotNeeded) - set(JAVA_INCLUDE_PATH2 NotNeeded) set(JAVA_AWT_INCLUDE_PATH NotNeeded) - find_package(JNI REQUIRED) + + # + # Do NOT make REQUIRED + # Until there is an official way of telling CMake to skip AWT, etc., + # then JNI will be considered as "not found" + # + find_package(JNI) - if(JNI_FOUND) - message(STATUS "JNI_INCLUDE_DIR=${JNI_INCLUDE_DIRS}") - message(STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}") - list(GET JNI_INCLUDE_DIRS 0 JNI_INCLUDE_DIR) - message(STATUS "jni path=${JNI_INCLUDE_DIR}") - include_directories("${JNI_INCLUDE_DIR}") - # include_directories ("${JNI_INCLUDE_DIRS}") - if(BUILD_WIN) - include_directories("${JNI_INCLUDE_DIR}\\win32") - endif() - if(BUILD_MACOS) - include_directories("${JNI_INCLUDE_DIR}/darwin") - endif() - if(BUILD_LINUX) - include_directories("${JNI_INCLUDE_DIR}/linux") - endif() + list(FILTER JNI_INCLUDE_DIRS EXCLUDE REGEX NotNeeded) + list(FILTER JNI_LIBRARIES EXCLUDE REGEX NotNeeded) + + # + # Do NOT check JNI_FOUND here, check JNI_INCLUDE_DIRS instead + # because of setting the above variables to NotNeeded, + # the variable JNI_FOUND is now set to NotNeeded, which is annoying + # + # We only care about JNI_INCLUDE_DIRS + # + if(JNI_INCLUDE_DIRS) + message(STATUS "JNI_INCLUDE_DIRS: ${JNI_INCLUDE_DIRS}") + include_directories("${JNI_INCLUDE_DIRS}") else() message(STATUS "JNI not found") endif() From f5ffc062e9ffe4bdbad5cdf4ff789d5eb270ced2 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Mon, 21 Aug 2023 12:20:23 -0400 Subject: [PATCH 52/55] rename --- src/NodeService.cpp | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/NodeService.cpp b/src/NodeService.cpp index b25bb80..2704e75 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -980,9 +980,9 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u case ZTS_EVENT_NETWORK_ACCESS_DENIED: case ZTS_EVENT_NETWORK_DOWN: { NetworkState* ns = (NetworkState*)obj; - zts_net_info_t* nd = new zts_net_info_t(); - nd->net_id = ns->config.nwid; - objptr = (void*)nd; + zts_net_info_t* nt = new zts_net_info_t(); + nt->net_id = ns->config.nwid; + objptr = (void*)nt; break; } case ZTS_EVENT_NETWORK_UPDATE: @@ -990,33 +990,33 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u case ZTS_EVENT_NETWORK_READY_IP6: case ZTS_EVENT_NETWORK_OK: { NetworkState* ns = (NetworkState*)obj; - zts_net_info_t* nd = new zts_net_info_t(); - nd->net_id = ns->config.nwid; - nd->mac = ns->config.mac; - strncpy(nd->name, ns->config.name, sizeof(ns->config.name)); - nd->status = (zts_network_status_t)ns->config.status; - nd->type = (zts_net_info_type_t)ns->config.type; - nd->mtu = ns->config.mtu; - nd->dhcp = ns->config.dhcp; - nd->bridge = ns->config.bridge; - nd->broadcast_enabled = ns->config.broadcastEnabled; - nd->port_error = ns->config.portError; - nd->netconf_rev = ns->config.netconfRevision; + zts_net_info_t* nt = new zts_net_info_t(); + nt->net_id = ns->config.nwid; + nt->mac = ns->config.mac; + strncpy(nt->name, ns->config.name, sizeof(ns->config.name)); + nt->status = (zts_network_status_t)ns->config.status; + nt->type = (zts_net_info_type_t)ns->config.type; + nt->mtu = ns->config.mtu; + nt->dhcp = ns->config.dhcp; + nt->bridge = ns->config.bridge; + nt->broadcast_enabled = ns->config.broadcastEnabled; + nt->port_error = ns->config.portError; + nt->netconf_rev = ns->config.netconfRevision; // Copy and convert address structures - nd->assigned_addr_count = ns->config.assignedAddressCount; + nt->assigned_addr_count = ns->config.assignedAddressCount; for (unsigned int i = 0; i < ns->config.assignedAddressCount; i++) { - native_ss_to_zts_ss(&(nd->assigned_addrs[i]), &(ns->config.assignedAddresses[i])); + native_ss_to_zts_ss(&(nt->assigned_addrs[i]), &(ns->config.assignedAddresses[i])); } - nd->route_count = ns->config.routeCount; + nt->route_count = ns->config.routeCount; for (unsigned int i = 0; i < ns->config.routeCount; i++) { - native_ss_to_zts_ss(&(nd->routes[i].target), &(ns->config.routes[i].target)); - native_ss_to_zts_ss(&(nd->routes[i].via), &(ns->config.routes[i].via)); - nd->routes[i].flags = ns->config.routes[i].flags; - nd->routes[i].metric = ns->config.routes[i].metric; + native_ss_to_zts_ss(&(nt->routes[i].target), &(ns->config.routes[i].target)); + native_ss_to_zts_ss(&(nt->routes[i].via), &(ns->config.routes[i].via)); + nt->routes[i].flags = ns->config.routes[i].flags; + nt->routes[i].metric = ns->config.routes[i].metric; } - nd->multicast_sub_count = ns->config.multicastSubscriptionCount; - memcpy(nd->multicast_subs, &(ns->config.multicastSubscriptions), sizeof(ns->config.multicastSubscriptions)); - objptr = (void*)nd; + nt->multicast_sub_count = ns->config.multicastSubscriptionCount; + memcpy(nt->multicast_subs, &(ns->config.multicastSubscriptions), sizeof(ns->config.multicastSubscriptions)); + objptr = (void*)nt; break; } case ZTS_EVENT_ADDR_ADDED_IP4: @@ -1051,13 +1051,13 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u case ZTS_EVENT_PEER_UNREACHABLE: case ZTS_EVENT_PEER_PATH_DISCOVERED: case ZTS_EVENT_PEER_PATH_DEAD: { - zts_peer_info_t* pd = new zts_peer_info_t(); + zts_peer_info_t* pr = new zts_peer_info_t(); ZT_Peer* peer = (ZT_Peer*)obj; - memcpy(pd, peer, sizeof(zts_peer_info_t)); + memcpy(pr, peer, sizeof(zts_peer_info_t)); for (unsigned int j = 0; j < peer->pathCount; j++) { - native_ss_to_zts_ss(&(pd->paths[j].address), &(peer->paths[j].address)); + native_ss_to_zts_ss(&(pr->paths[j].address), &(peer->paths[j].address)); } - objptr = (void*)pd; + objptr = (void*)pr; break; } default: From ee5047b59af26d8c2e37f597cc2f3665dbf80b3a Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Mon, 21 Aug 2023 11:50:05 -0400 Subject: [PATCH 53/55] Fix https://github.com/zerotier/libzt/issues/244: Memory leak if libzt events aren't consumed by user app If arg is not enqueued by Events, then treat as if ownership has NOT been transferred and caller of Events->enqueue is responsible for freeing --- src/Events.cpp | 26 ++++++++++------- src/Events.hpp | 6 +++- src/NodeService.cpp | 71 +++++++++++++++++++++++++++++++++++++++++---- src/VirtualTap.cpp | 4 +++ 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/src/Events.cpp b/src/Events.cpp index 30c6845..f549782 100644 --- a/src/Events.cpp +++ b/src/Events.cpp @@ -93,11 +93,18 @@ void Events::run() } } -void Events::enqueue(unsigned int event_code, const void* arg, int len) +bool Events::enqueue(unsigned int event_code, const void* arg, int len) { if (! _enabled) { - return; + return false; } + if (_callbackMsgQueue.size_approx() > 1024) { + /* Rate-limit number of events. This value should only grow if the + user application isn't returning from the event handler in a timely manner. + For most applications it should hover around 1 to 2 */ + return false; + } + zts_event_msg_t* msg = new zts_event_msg_t(); msg->event_code = event_code; @@ -132,15 +139,12 @@ void Events::enqueue(unsigned int event_code, const void* arg, int len) msg->cache = (void*)arg; msg->len = len; } - if (msg && _callbackMsgQueue.size_approx() > 1024) { - /* Rate-limit number of events. This value should only grow if the - user application isn't returning from the event handler in a timely manner. - For most applications it should hover around 1 to 2 */ - destroy(msg); - } - else { - _callbackMsgQueue.enqueue(msg); - } + + // + // ownership of arg is now transferred + // + _callbackMsgQueue.enqueue(msg); + return true; } void Events::destroy(zts_event_msg_t* msg) diff --git a/src/Events.hpp b/src/Events.hpp index f0ceb26..9064d69 100644 --- a/src/Events.hpp +++ b/src/Events.hpp @@ -115,8 +115,12 @@ class Events { /** * Enqueue an event to be sent to the user application + * + * Returns true if arg was enqueued. + * If enqueued, then ownership of arg has been transferred. + * If NOT enqueued, then ownership of arg has NOT been transferred. */ - void enqueue(unsigned int event_code, const void* arg, int len = 0); + bool enqueue(unsigned int event_code, const void* arg, int len = 0); /** * Send callback message to user application diff --git a/src/NodeService.cpp b/src/NodeService.cpp index 2704e75..501bc13 100644 --- a/src/NodeService.cpp +++ b/src/NodeService.cpp @@ -957,13 +957,17 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u void* objptr = NULL; + zts_node_info_t* nd; + zts_net_info_t* nt; + zts_peer_info_t* pr; + switch (zt_event_code) { case ZTS_EVENT_NODE_UP: case ZTS_EVENT_NODE_ONLINE: case ZTS_EVENT_NODE_OFFLINE: case ZTS_EVENT_NODE_DOWN: case ZTS_EVENT_NODE_FATAL_ERROR: { - zts_node_info_t* nd = new zts_node_info_t; + nd = new zts_node_info_t; nd->node_id = _nodeId; nd->ver_major = ZEROTIER_ONE_VERSION_MAJOR; nd->ver_minor = ZEROTIER_ONE_VERSION_MINOR; @@ -980,7 +984,7 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u case ZTS_EVENT_NETWORK_ACCESS_DENIED: case ZTS_EVENT_NETWORK_DOWN: { NetworkState* ns = (NetworkState*)obj; - zts_net_info_t* nt = new zts_net_info_t(); + nt = new zts_net_info_t(); nt->net_id = ns->config.nwid; objptr = (void*)nt; break; @@ -990,7 +994,7 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u case ZTS_EVENT_NETWORK_READY_IP6: case ZTS_EVENT_NETWORK_OK: { NetworkState* ns = (NetworkState*)obj; - zts_net_info_t* nt = new zts_net_info_t(); + nt = new zts_net_info_t(); nt->net_id = ns->config.nwid; nt->mac = ns->config.mac; strncpy(nt->name, ns->config.name, sizeof(ns->config.name)); @@ -1051,7 +1055,7 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u case ZTS_EVENT_PEER_UNREACHABLE: case ZTS_EVENT_PEER_PATH_DISCOVERED: case ZTS_EVENT_PEER_PATH_DEAD: { - zts_peer_info_t* pr = new zts_peer_info_t(); + pr = new zts_peer_info_t(); ZT_Peer* peer = (ZT_Peer*)obj; memcpy(pr, peer, sizeof(zts_peer_info_t)); for (unsigned int j = 0; j < peer->pathCount; j++) { @@ -1067,7 +1071,64 @@ void NodeService::sendEventToUser(unsigned int zt_event_code, const void* obj, u // Send event if (objptr) { - _events->enqueue(zt_event_code, objptr, len); + if (!_events->enqueue(zt_event_code, objptr, len)) { + // + // ownership of objptr was NOT transferred, so delete any news from above + // + switch (zt_event_code) { + case ZTS_EVENT_NODE_UP: + case ZTS_EVENT_NODE_ONLINE: + case ZTS_EVENT_NODE_OFFLINE: + case ZTS_EVENT_NODE_DOWN: + case ZTS_EVENT_NODE_FATAL_ERROR: { + delete nd; + break; + } + case ZTS_EVENT_NETWORK_NOT_FOUND: + case ZTS_EVENT_NETWORK_CLIENT_TOO_OLD: + case ZTS_EVENT_NETWORK_REQ_CONFIG: + case ZTS_EVENT_NETWORK_ACCESS_DENIED: + case ZTS_EVENT_NETWORK_DOWN: { + delete nt; + break; + } + case ZTS_EVENT_NETWORK_UPDATE: + case ZTS_EVENT_NETWORK_READY_IP4: + case ZTS_EVENT_NETWORK_READY_IP6: + case ZTS_EVENT_NETWORK_OK: { + delete nt; + break; + } + case ZTS_EVENT_ADDR_ADDED_IP4: + break; + case ZTS_EVENT_ADDR_ADDED_IP6: + break; + case ZTS_EVENT_ADDR_REMOVED_IP4: + break; + case ZTS_EVENT_ADDR_REMOVED_IP6: + break; + case ZTS_EVENT_STORE_IDENTITY_PUBLIC: + break; + case ZTS_EVENT_STORE_IDENTITY_SECRET: + break; + case ZTS_EVENT_STORE_PLANET: + break; + case ZTS_EVENT_STORE_PEER: + break; + case ZTS_EVENT_STORE_NETWORK: + break; + case ZTS_EVENT_PEER_DIRECT: + case ZTS_EVENT_PEER_RELAY: + case ZTS_EVENT_PEER_UNREACHABLE: + case ZTS_EVENT_PEER_PATH_DISCOVERED: + case ZTS_EVENT_PEER_PATH_DEAD: { + delete pr; + break; + } + default: + break; + } + } } } diff --git a/src/VirtualTap.cpp b/src/VirtualTap.cpp index a13dcbd..605ae4d 100644 --- a/src/VirtualTap.cpp +++ b/src/VirtualTap.cpp @@ -312,6 +312,10 @@ static void zts_main_lwip_driver_loop(void* arg) zts_util_delay(LWIP_DRIVER_LOOP_INTERVAL); } _has_exited = true; + + // + // no need to check if event was enqueued since NULL is being passed + // zts_events->enqueue(ZTS_EVENT_STACK_DOWN, NULL); } From 8a414d59eafe1c0eac35d25cc43922e76d2e7a98 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Mon, 21 Aug 2023 17:09:10 -0400 Subject: [PATCH 54/55] Fix #211: Use tcpip_input for IPv6 instead of ethernet_input --- src/VirtualTap.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/VirtualTap.cpp b/src/VirtualTap.cpp index a13dcbd..357df5b 100644 --- a/src/VirtualTap.cpp +++ b/src/VirtualTap.cpp @@ -572,7 +572,20 @@ void zts_lwip_init_interface(void* tapref, const InetAddress& ip) LOCK_TCPIP_CORE(); if (isNewNetif) { vtap->netif6 = (void*)n; - netif_add(n, NULL, NULL, NULL, (void*)vtap, zts_netif_init6, ethernet_input); + + // + // was: + // netif_add(n, NULL, NULL, NULL, (void*)vtap, zts_netif_init6, ethernet_input); + // + // but there is this documentation: + // > With NO_SYS=0, this must be set to tcpip_input for all netif types (whether ethernet, PPP, slipif, etc.) + // https://lwip.fandom.com/wiki/Writing_a_device_driver + // + // and also with ethernet_input and lwIP asserts turned on, we get: + // Assertion "Function called without core lock" failed at line 236 in /Users/brenton/development/github/libzt/ext/lwip-contrib/ports/unix/port/sys_arch.c + // + netif_add(n, NULL, NULL, NULL, (void*)vtap, zts_netif_init6, tcpip_input); + n->ip6_autoconfig_enabled = 1; vtap->_mac.copyTo(n->hwaddr, n->hwaddr_len); netif_create_ip6_linklocal_address(n, 1); From d12d43cd184b6705944d9de63e02d21f8e0b6c23 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 21 Aug 2023 15:14:37 -0700 Subject: [PATCH 55/55] Update ZeroTierOne submodule to 1.12 + ipv6 tx fix --- ext/ZeroTierOne | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ZeroTierOne b/ext/ZeroTierOne index e361272..c53c6bd 160000 --- a/ext/ZeroTierOne +++ b/ext/ZeroTierOne @@ -1 +1 @@ -Subproject commit e36127283cc58ac184a9d4497852a5ed8b9c515b +Subproject commit c53c6bd9c320ea839c525972d8afba448a58606e