Skip to content

Commit

Permalink
Merge branch 'dev' into java-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanbouwel committed Sep 6, 2023
2 parents 44bff66 + 729e463 commit a55152a
Show file tree
Hide file tree
Showing 29 changed files with 1,476 additions and 249 deletions.
80 changes: 40 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,7 +190,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")
Expand All @@ -200,7 +200,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")
Expand All @@ -215,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 @@ -279,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 @@ -398,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 @@ -411,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 @@ -469,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
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
Part of the ZeroTier SDK
<img alt="" src="https://i.imgur.com/BwSHwE3.png" class="doxyhidden"> </img>

Peer-to-peer and cross-platform encrypted connections built right into your app or service. No drivers, no root, and no host configuration.
P2P cross-platform encrypted sockets library using ZeroTier

<br>

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

<a href="https://docs.zerotier.com/sockets/tutorial.html">Docs</a> |
<a href="https://github.com/zerotier/libzt/issues">Report an issue</a>

<a href="https://www.twitter.com/zerotier"><img alt="@zerotier" src="https://img.shields.io/twitter/follow/zerotier?style=social"/></a>
<a href="https://old.reddit.com/r/zerotier"><img alt="r/zerotier" src="https://img.shields.io/reddit/subreddit-subscribers/zerotier?style=social"/></a>


<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/actions"><img alt="Build Status (master branch)" src="https://img.shields.io/github/workflow/status/zerotier/libzt/CMake/master"/></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/actions/workflow/status/zerotier/libzt/selftest.yml?branch=main"/></a>
</div>

| Language/Platform | Installation | Version | Example |
| Language/Platform | Install | Version | Example |
|:----------|:---------|:---|:---|
| C/C++ | [Build from source](#build-from-source) | <img alt="version" src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/></a>| [C/C++](./examples/c) |
| 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) |
Expand Down Expand Up @@ -51,7 +49,7 @@ int main()
}
```

# Build from source
# Build from source (optional)

```
git submodule update --init
Expand Down Expand Up @@ -88,11 +86,9 @@ Important directories:
|`cache`| Contains build system caches that can safely be deleted after use.|
|`pkg`| Contains project, script and spec files to generate packages.|

# Self-hosting (Optional)

We provide ways for your app or enterprise to function independently from any of our services if desired.
# Self-hosting

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.
If you'd like to use your own infrastructure we make it easy to [set up your own controllers and roots](https://docs.zerotier.com/self-hosting/introduction).

# Help

Expand Down
6 changes: 4 additions & 2 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 @@ -520,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
Expand Down Expand Up @@ -601,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"
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
2 changes: 1 addition & 1 deletion ext/ZeroTierOne
Submodule ZeroTierOne updated 1106 files
43 changes: 43 additions & 0 deletions include/ZeroTierSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -1274,6 +1282,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
Expand All @@ -1297,6 +1323,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()`.
Expand Down
7 changes: 0 additions & 7 deletions include/version.h

This file was deleted.

0 comments on commit a55152a

Please sign in to comment.