Skip to content

Commit

Permalink
Merge pull request #253 from zerotier/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
joseph-henry authored Aug 23, 2023
2 parents 8d21a26 + d12d43c commit 2aa7302
Show file tree
Hide file tree
Showing 47 changed files with 1,699 additions and 418 deletions.
1 change: 0 additions & 1 deletion .version

This file was deleted.

82 changes: 42 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -92,6 +90,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)
Expand All @@ -116,7 +116,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
Expand All @@ -129,7 +129,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()
Expand All @@ -142,7 +142,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
Expand Down Expand Up @@ -190,15 +190,17 @@ 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")
endif()

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")
Expand All @@ -213,15 +215,15 @@ 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")
set(DEVROOT
"/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
Expand Down Expand Up @@ -277,7 +279,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)
Expand Down Expand Up @@ -396,7 +397,6 @@ else()

set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} \
${DEBUG_OPTIMIZATION} \
-DLWIP_DEBUG=1 -DLIBZT_DEBUG=1")

set(CMAKE_C_FLAGS_RELEASE
Expand All @@ -409,7 +409,6 @@ else()

set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} \
${DEBUG_OPTIMIZATION} \
-DLWIP_DEBUG=1 -DLIBZT_DEBUG=1")

set(CMAKE_CXX_FLAGS_RELEASE
Expand Down Expand Up @@ -467,37 +466,40 @@ endif()

if(ZTS_ENABLE_JAVA OR (BUILD_ANDROID AND NOT ZTS_NDK_ONLY))
message(STATUS "Looking for JNI")

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

message(STATUS "Ignore seeing \"Found JNI: NotNeeded\" below; check that JNI_INCLUDE_DIRS is valid")

#
# "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)

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

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

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()
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Peer-to-peer and cross-platform encrypted connections built right into your app

<a href="./examples">Examples</a> |
<a href="https://docs.zerotier.com/sockets/tutorial.html">Documentation</a> |
<a href="https://discuss.zerotier.com/">Community</a> |
<a href="https://github.com/zerotier/libzt/issues">Report a Bug</a>


Expand All @@ -19,7 +18,7 @@ Peer-to-peer and cross-platform encrypted connections built right into your app


<img alt="latest libzt version" src="https://img.shields.io/github/v/tag/zerotier/libzt?label=latest"/></a>
<a href="https://github.com/zerotier/libzt/commits/master"><img alt="Last Commit" src="https://img.shields.io/github/last-commit/zerotier/libzt"/></a>
<a href="https://github.com/zerotier/libzt/commits/main"><img alt="Last Commit" src="https://img.shields.io/github/last-commit/zerotier/libzt"/></a>
<a href="https://github.com/zerotier/libzt/actions"><img alt="Build Status (master branch)" src="https://img.shields.io/github/workflow/status/zerotier/libzt/CMake/master"/></a>
</div>

Expand All @@ -29,7 +28,7 @@ Peer-to-peer and cross-platform encrypted connections built right into your app
| C# | `Install-Package ZeroTier.Sockets` |<a href="https://www.nuget.org/packages/ZeroTier.Sockets/"><img src="https://img.shields.io/github/v/tag/zerotier/libzt?label=NuGet"/></a> |[C#](./examples/csharp) |
| Python | `pip install libzt`|<a href="https://pypi.org/project/libzt/"><img src="https://img.shields.io/pypi/v/libzt?label=PyPI"/></a> |[Python](./examples/python) |
| Rust | See: [crates.io/crates/libzt](https://crates.io/crates/libzt) | <img alt="version" src="https://img.shields.io/crates/v/libzt?color=blue"/>|[Rust](./examples/rust) |
| Java | `./build.sh host-jar` |<img src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/> |[Java](./examples/java) |
| Java | Install JDK, then: `./build.sh host-jar` |<img src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/> |[Java](./examples/java) |
| Linux | `brew install zerotier/tap/libzt` | <img alt="version" src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/></a>| [C/C++](./examples/c) |
| macOS | `brew install zerotier/tap/libzt`| <img alt="version" src="https://img.shields.io/github/v/tag/zerotier/libzt?label=Homebrew"/></a>| [C/C++](./examples/c) |
| iOS / iPadOS | `./build.sh iphoneos-framework` | <img src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/>| [Objective-C](./attic/objective-c), [Swift](./attic/swift) |
Expand Down Expand Up @@ -93,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

Expand Down
51 changes: 23 additions & 28 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -494,12 +496,12 @@ 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
# 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"
Expand All @@ -512,15 +514,15 @@ 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
# Package everything
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
Expand Down Expand Up @@ -596,18 +598,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/*.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/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"
Expand Down Expand Up @@ -652,21 +648,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
Expand Down Expand Up @@ -745,13 +741,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
}

Expand Down
2 changes: 1 addition & 1 deletion examples/c/callbackapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char** argv)
{
if (argc != 2) {
printf("\nUsage:\n");
printf("pingable-node <net_id>\n");
printf("callbackapi <net_id>\n");
exit(0);
}
long long int net_id = strtoull(argv[1], NULL, 16); // At least 64 bits
Expand Down
2 changes: 1 addition & 1 deletion examples/c/nonblockingclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char** argv)
{
if (argc != 5) {
printf("\nlibzt example client\n");
printf("client <id_storage_path> <net_id> <remote_addr> <remote_port>\n");
printf("nonblockingclient <id_storage_path> <net_id> <remote_addr> <remote_port>\n");
exit(0);
}
char* storage_path = argv[1];
Expand Down
4 changes: 2 additions & 2 deletions examples/c/nonblockingserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char** argv)
{
if (argc != 5) {
printf("\nlibzt example server\n");
printf("server <id_storage_path> <net_id> <local_addr> <local_port>\n");
printf("nonblockingserver <id_storage_path> <net_id> <local_addr> <local_port>\n");
exit(0);
}
char* storage_path = argv[1];
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/c/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/c/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char** argv)
{
if (argc != 2) {
printf("\nUsage:\n");
printf("pingable-node <net_id>\n");
printf("statistics <net_id>\n");
exit(0);
}
long long int net_id = strtoull(argv[1], NULL, 16); // At least 64 bits
Expand Down
4 changes: 2 additions & 2 deletions examples/java/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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) {
Expand Down Expand Up @@ -110,7 +110,7 @@ public static void main(String[] args)
/**
* (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) {
Expand Down
Loading

0 comments on commit 2aa7302

Please sign in to comment.