From 45260c4e69a8200e0a161c78fbf21600e953ef83 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 16 Oct 2017 16:45:46 -0700 Subject: [PATCH] Modification to blocking bahavior of zts_start, is now settable. Improved address family handling in JNI --- .../bindings/{cpp_simple => cpp}/client.cpp | 0 .../bindings/{cpp_simple => cpp}/server.cpp | 0 examples/bindings/java/ExampleApp.java | 13 +- examples/bindings/java/zerotier/Address.java | 4 - examples/bindings/java/zerotier/ZeroTier.java | 43 +++-- examples/bindings/scala/ExampleApp.scala | 29 ++- examples/bindings/scala/libzt.scala | 66 +++++-- include/ZT1Service.h | 2 +- include/ZeroTier.h | 165 ------------------ include/libzt.h | 2 +- src/ZT1Service.cpp | 30 ++-- src/libztJNI.cpp | 85 ++++++--- test/selftest.cpp | 2 +- 13 files changed, 199 insertions(+), 242 deletions(-) rename examples/bindings/{cpp_simple => cpp}/client.cpp (100%) rename examples/bindings/{cpp_simple => cpp}/server.cpp (100%) delete mode 100644 include/ZeroTier.h diff --git a/examples/bindings/cpp_simple/client.cpp b/examples/bindings/cpp/client.cpp similarity index 100% rename from examples/bindings/cpp_simple/client.cpp rename to examples/bindings/cpp/client.cpp diff --git a/examples/bindings/cpp_simple/server.cpp b/examples/bindings/cpp/server.cpp similarity index 100% rename from examples/bindings/cpp_simple/server.cpp rename to examples/bindings/cpp/server.cpp diff --git a/examples/bindings/java/ExampleApp.java b/examples/bindings/java/ExampleApp.java index a0cbd81..1f5c517 100644 --- a/examples/bindings/java/ExampleApp.java +++ b/examples/bindings/java/ExampleApp.java @@ -33,6 +33,7 @@ public class ExampleApp { public native int loadsymbols(); public native void startOneService(); + // load libzt.dylib or libzt.so static { System.loadLibrary("zt"); } @@ -45,11 +46,21 @@ public class ExampleApp { public void run() { System.out.println("starting libzt"); libzt.startjoin("/Users/joseph/op/zt/libzt/ztjni", "1212121212121212"); + System.out.println("started."); // start(path) will not block // startjoin(path, nwid) will block + int fd = 0, err = 0; + if ((fd = libzt.socket(libzt.AF_INET, libzt.SOCK_STREAM, 0)) < 0) { + System.out.println("error creating socket"); + return; + } + if ((err = libzt.bind(fd, "0.0.0.0", 3000)) < 0) { + System.out.println("error binding socket to virtual interface"); + return; + } } }).start(); - + while(true) { try { Thread.sleep(3000); } diff --git a/examples/bindings/java/zerotier/Address.java b/examples/bindings/java/zerotier/Address.java index 530ee27..afe9f0c 100644 --- a/examples/bindings/java/zerotier/Address.java +++ b/examples/bindings/java/zerotier/Address.java @@ -103,8 +103,4 @@ public class Address } return sock_addr; } - - public boolean isValid() { - return port != -1 && !Address().startsWith("-1.-1.-1.-1/-1"); - } } \ No newline at end of file diff --git a/examples/bindings/java/zerotier/ZeroTier.java b/examples/bindings/java/zerotier/ZeroTier.java index 30735e3..351913b 100644 --- a/examples/bindings/java/zerotier/ZeroTier.java +++ b/examples/bindings/java/zerotier/ZeroTier.java @@ -26,22 +26,12 @@ package zerotier; -import java.io.FileDescriptor; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.zip.ZipError; - public class ZeroTier { - - public static String Version() { - return "1.1.5"; - } - // Socket families + // socket families public static int AF_UNIX = 1; public static int AF_INET = 2; - // Socket types + // socket types public static int SOCK_STREAM = 1; public static int SOCK_DGRAM = 2; // fcntl flags @@ -53,23 +43,44 @@ public class ZeroTier { // fcntl cmds public static int F_GETFL = 3; public static int F_SETFL = 4; - - public native void start(String homeDir); + // basic service controls + public native void start(String homeDir, boolean blocking); public native void startjoin(String homeDir, String nwid); + public native void stop(); public native boolean running(); public native void join(String nwid); public native void leave(String nwid); + // advanced service controls + public native void get_path(); + public native int get_id(); + public native void get_6plane_addr(); + public native void get_rfc4193_addr(); + // socket API public native int socket(int family, int type, int protocol); public native int connect(int fd, String addr, int port); public native int bind(int fd, String addr, int port); - public native int accept4(int fd, String addr, int port); - public native int accept(int fd, Address addr); public native int listen(int fd, int backlog); + public native int accept(int fd, Address addr); + public native int accept4(int fd, String addr, int port); public native int close(int fd); + //public native int setsockopt(); + //public native int getsockopt(); public native int read(int fd, byte[] buf, int len); public native int write(int fd, byte[] buf, int len); public native int sendto(int fd, byte[] buf, int len, int flags, Address addr); public native int send(int fd, byte[] buf, int len, int flags); public native int recvfrom(int fd, byte[] buf, int len, int flags, Address addr); + public native int shutdown(int fd, int how); + //public native int getsockname(); + //public native int getpeername(); + //public native int gethostname(); + ///public native int sethostname(); + //public native int gethostbyname(); + //public native int poll(); + //public native int select(); public native int fcntl(int sock, int cmd, int flag); + //public native int ioctl(int fd, long request, ? ); + // stack controls + public native int add_dns(); + public native int del_dns(); } \ No newline at end of file diff --git a/examples/bindings/scala/ExampleApp.scala b/examples/bindings/scala/ExampleApp.scala index 780c719..29589b6 100644 --- a/examples/bindings/scala/ExampleApp.scala +++ b/examples/bindings/scala/ExampleApp.scala @@ -1,9 +1,34 @@ +/* + * ZeroTier SDK - Network Virtualization Everywhere + * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * -- + * + * You can be released from the requirements of the license by purchasing + * a commercial license. Buying such a license is mandatory as soon as you + * develop commercial closed-source software that incorporates or links + * directly against ZeroTier software without disclosing the source code + * of your own application. + */ + import zerotier.ZeroTier object ExampleApp extends App { - + // load libzt.dylib or libzt.so System.loadLibrary("zt") - val libzt = new ZeroTier libzt.startjoin("/Users/joseph/op/zt/libzt/ztjni", "1212121212121212") val fd = libzt.socket(2, 1, 0) diff --git a/examples/bindings/scala/libzt.scala b/examples/bindings/scala/libzt.scala index 2b4c486..9a8470d 100644 --- a/examples/bindings/scala/libzt.scala +++ b/examples/bindings/scala/libzt.scala @@ -1,44 +1,76 @@ +/* + * ZeroTier SDK - Network Virtualization Everywhere + * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * -- + * + * You can be released from the requirements of the license by purchasing + * a commercial license. Buying such a license is mandatory as soon as you + * develop commercial closed-source software that incorporates or links + * directly against ZeroTier software without disclosing the source code + * of your own application. + */ + package zerotier; class ZeroTier { - @native def start(path: String): Int + // socket families + // socket types + // basic service controls + @native def start(path: String, blocking: Boolean): Int @native def startjoin(path: String, nwid: String): Int @native def stop(): Unit @native def running(): Int @native def join(nwid: String): Unit @native def leave(nwid: String): Unit - //@native def path(): - //@native def id(): Int + // advanced service controls + //@native def get_path(): Unit + //@native def get_id(): Int //@native def get_6plane_addr(): Unit //@native def get_rfc4193_addr(): Unit + // socket API @native def socket(socket_family: Int, socket_type: Int, protocol: Int): Int - @native def connect(fd: Int, addr: Object, addrlen: Int): Int - @native def bind(fd: Int, addr: Object, addrlen: Int): Int + @native def connect(fd: Int, addr: String, port: Int): Int + @native def bind(fd: Int, addr: String, port: Int): Int @native def listen(fd: Int, backlog: Int): Int @native def accept(fd: Int, addr: Object, addrlen: Int): Int @native def accept4(fd: Int, addr: Object, addrlen: Int, flags: Int): Int + @native def close(fd: Int): Int @native def setsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int @native def getsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int - //@native def getsockname(): Int - //@native def getpeername(): Int - //@native def gethostname(): Int - //@native def sethostname(): Int - //@native def gethostbyname(): Object - @native def close(fd: Int): Int - //@native def poll(): Int - //@native def select(): Int - @native def fcntl(fd: Int, cmd: Int, flags: Int): Int - @native def ioctl(fd: Int, request: Long, argp: Object): Int + @native def read(fd: Int, buf: Object, len: Int): Int + @native def write(fd: Int, buf: Object, len: Int): Int @native def send(fd: Int, buf: Object, len: Int, flags: Int): Int @native def sendto(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int @native def sendmsg(fd: Int, msg: Object, flags: Int): Int @native def recv(fd: Int, buf: Object, len: Int, flags: Int): Int @native def recvfrom(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int @native def recvmsg(fd: Int, msg: Object, flags: Int): Int - @native def read(fd: Int, buf: Object, len: Int): Int - @native def write(fd: Int, buf: Object, len: Int): Int @native def shutdown(fd: Int, how: Int): Int + //@native def getsockname(): Int + //@native def getpeername(): Int + //@native def gethostname(): Int + //@native def sethostname(): Int + //@native def gethostbyname(): Object + //@native def poll(): Int + //@native def select(): Int + @native def fcntl(fd: Int, cmd: Int, flags: Int): Int + @native def ioctl(fd: Int, request: Long, argp: Object): Int + // stack controls //@native def add_dns(): Int //@native def del_dns(): Int } diff --git a/include/ZT1Service.h b/include/ZT1Service.h index 05794ea..d9c4117 100644 --- a/include/ZT1Service.h +++ b/include/ZT1Service.h @@ -200,7 +200,7 @@ int zts_running(); * @param path Where this instance of ZeroTier will store its identity and configuration files * @return Returns 1 if ZeroTier is currently running, and 0 if it is not */ -int zts_start(const char *path); +int zts_start(const char *path, bool blocking); /** * @brief Alternative to zts_start(). Start an instance of libzt, wait for an address to be issues, and join diff --git a/include/ZeroTier.h b/include/ZeroTier.h deleted file mode 100644 index 49affa8..0000000 --- a/include/ZeroTier.h +++ /dev/null @@ -1,165 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class ZeroTier */ - -#ifndef _Included_ZeroTier -#define _Included_ZeroTier -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: ZeroTier - * Method: ztjni_start - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_ZeroTier_ztjni_1start - (JNIEnv *, jobject, jstring); - -/* - * Class: ZeroTier - * Method: ztjni_startjoin - * Signature: (Ljava/lang/String;Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_ZeroTier_ztjni_1startjoin - (JNIEnv *, jobject, jstring, jstring); - -/* - * Class: ZeroTier - * Method: ztjni_join - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_ZeroTier_ztjni_1join - (JNIEnv *, jobject, jstring); - -/* - * Class: ZeroTier - * Method: ztjni_leave - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_ZeroTier_ztjni_1leave - (JNIEnv *, jobject, jstring); - -/* - * Class: ZeroTier - * Method: ztjni_get_addresses - * Signature: (Ljava/lang/String;)Ljava/util/ArrayList; - */ -JNIEXPORT jobject JNICALL Java_ZeroTier_ztjni_1get_1addresses - (JNIEnv *, jobject, jstring); - -/* - * Class: ZeroTier - * Method: ztjni_running - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_ZeroTier_ztjni_1running - (JNIEnv *, jobject); - -/* - * Class: ZeroTier - * Method: ztjni_socket - * Signature: (III)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1socket - (JNIEnv *, jobject, jint, jint, jint); - -/* - * Class: ZeroTier - * Method: ztjni_connect - * Signature: (ILjava/lang/String;I)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1connect - (JNIEnv *, jobject, jint, jstring, jint); - -/* - * Class: ZeroTier - * Method: ztjni_bind - * Signature: (ILjava/lang/String;I)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1bind - (JNIEnv *, jobject, jint, jstring, jint); - -/* - * Class: ZeroTier - * Method: ztjni_accept4 - * Signature: (ILjava/lang/String;I)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1accept4 - (JNIEnv *, jobject, jint, jstring, jint); - -/* - * Class: ZeroTier - * Method: ztjni_accept - * Signature: (ILAddress;)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1accept - (JNIEnv *, jobject, jint, jobject); - -/* - * Class: ZeroTier - * Method: ztjni_listen - * Signature: (II)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1listen - (JNIEnv *, jobject, jint, jint); - -/* - * Class: ZeroTier - * Method: ztjni_close - * Signature: (I)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1close - (JNIEnv *, jobject, jint); - -/* - * Class: ZeroTier - * Method: ztjni_read - * Signature: (I[BI)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1read - (JNIEnv *, jobject, jint, jbyteArray, jint); - -/* - * Class: ZeroTier - * Method: ztjni_write - * Signature: (I[BI)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1write - (JNIEnv *, jobject, jint, jbyteArray, jint); - -/* - * Class: ZeroTier - * Method: ztjni_sendto - * Signature: (I[BIILAddress;)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1sendto - (JNIEnv *, jobject, jint, jbyteArray, jint, jint, jobject); - -/* - * Class: ZeroTier - * Method: ztjni_send - * Signature: (I[BII)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1send - (JNIEnv *, jobject, jint, jbyteArray, jint, jint); - -/* - * Class: ZeroTier - * Method: ztjni_recvfrom - * Signature: (I[BIILAddress;)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1recvfrom - (JNIEnv *, jobject, jint, jbyteArray, jint, jint, jobject); - -/* - * Class: ZeroTier - * Method: ztjni_fcntl - * Signature: (III)I - */ -JNIEXPORT jint JNICALL Java_ZeroTier_ztjni_1fcntl - (JNIEnv *, jobject, jint, jint, jint); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/libzt.h b/include/libzt.h index 82462c9..7a92248 100644 --- a/include/libzt.h +++ b/include/libzt.h @@ -89,7 +89,7 @@ ZT_SOCKET_API void ZTCALL init_network_stack(); * @param nwid A 16-digit hexidecimal network identifier (e.g. Earth: `8056c2e21c000001`) * @return 0 if successful; or 1 if failed */ -ZT_SOCKET_API int ZTCALL zts_start(const char *path); +ZT_SOCKET_API int ZTCALL zts_start(const char *path, bool blocking); /** * @brief Starts libzt diff --git a/src/ZT1Service.cpp b/src/ZT1Service.cpp index 750df73..64b025d 100644 --- a/src/ZT1Service.cpp +++ b/src/ZT1Service.cpp @@ -410,7 +410,7 @@ int zts_running() return ZeroTier::zt1Service == NULL ? false : ZeroTier::zt1Service->isRunning(); } -int zts_start(const char *path) +int zts_start(const char *path, bool blocking = false) { DEBUG_EXTRA(); if (ZeroTier::zt1Service) { @@ -423,24 +423,26 @@ int zts_start(const char *path) WSAStartup(MAKEWORD(2, 2), &wsaData); // initialize WinSock. Used in Phy for loopback pipe #endif pthread_t service_thread; - return pthread_create(&service_thread, NULL, zts_start_service, NULL); + int err = pthread_create(&service_thread, NULL, zts_start_service, NULL); + if (blocking) { // block to prevent service calls before we're ready + ZT_NodeStatus status; + while (zts_running() == false || ZeroTier::zt1Service->getNode() == NULL) { + nanosleep((const struct timespec[]) {{0, (ZTO_WRAPPER_CHECK_INTERVAL * 500000)}}, NULL); + } + while (ZeroTier::zt1Service->getNode()->address() <= 0) { + nanosleep((const struct timespec[]) {{0, (ZTO_WRAPPER_CHECK_INTERVAL * 500000)}}, NULL); + } + while (status.online <= 0) { + nanosleep((const struct timespec[]) {{0, (ZTO_WRAPPER_CHECK_INTERVAL * 500000)}}, NULL); + ZeroTier::zt1Service->getNode()->status(&status); + } + } } int zts_startjoin(const char *path, const char *nwid) { DEBUG_EXTRA(); - ZT_NodeStatus status; - int err = zts_start(path); - while (zts_running() == false || ZeroTier::zt1Service->getNode() == NULL) { - nanosleep((const struct timespec[]) {{0, (ZTO_WRAPPER_CHECK_INTERVAL * 500000)}}, NULL); - } - while (ZeroTier::zt1Service->getNode()->address() <= 0) { - nanosleep((const struct timespec[]) {{0, (ZTO_WRAPPER_CHECK_INTERVAL * 500000)}}, NULL); - } - while (status.online <= 0) { - nanosleep((const struct timespec[]) {{0, (ZTO_WRAPPER_CHECK_INTERVAL * 500000)}}, NULL); - ZeroTier::zt1Service->getNode()->status(&status); - } + int err = zts_start(path, true); // only now can we attempt a join while (true) { try { diff --git a/src/libztJNI.cpp b/src/libztJNI.cpp index 8cc0ade..2d3bcc6 100644 --- a/src/libztJNI.cpp +++ b/src/libztJNI.cpp @@ -59,26 +59,71 @@ namespace ZeroTier { JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_connect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) { - struct sockaddr_in addr; - const char *str = (*env).GetStringUTFChars( addrstr, 0); - addr.sin_addr.s_addr = inet_addr(str); - addr.sin_family = AF_INET; - addr.sin_port = htons( port ); - (*env).ReleaseStringUTFChars( addrstr, str); - return zts_connect(fd, (struct sockaddr *)&addr, sizeof(addr)); + struct sockaddr_storage ss; + socklen_t namelen = sizeof(ss); + int err = 0; + if ((err = zts_getsockname(fd, (struct sockaddr*)&ss, &namelen)) < 0) { + DEBUG_ERROR("error while determining socket family"); + return -1; + } + const char *str; +#if defined(LIBZT_IPV4) + if (ss.ss_family == AF_INET) { + struct sockaddr_in in_addr; + str = (*env).GetStringUTFChars(addrstr, 0); + in_addr.sin_addr.s_addr = inet_addr(str); + in_addr.sin_family = AF_INET; + in_addr.sin_port = htons(port); + (*env).ReleaseStringUTFChars(addrstr, str); + } +#endif // LIBZT_IPV4 +#if defined(LIBZT_IPV6) + if (ss.ss_family == AF_INET6) { + struct sockaddr_in6 in_addr; + str = (*env).GetStringUTFChars(addrstr, 0); + //in_addr.sin_addr.s_addr = inet_addr(str); + in_addr.sin6_family = AF_INET6; + in_addr.sin6_port = htons(port); + (*env).ReleaseStringUTFChars(addrstr, str); + } +#endif // LIBZT_IPV6 + DEBUG_INFO("fd=%d, addr=%s, port=%d", fd, str, port); + return zts_connect(fd, (struct sockaddr *)&ss, sizeof(in_addr)); } JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_bind(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) { - struct sockaddr_in addr; - const char *str = (*env).GetStringUTFChars( addrstr, 0); + struct sockaddr_storage ss; + socklen_t namelen = sizeof(ss); + int err = 0; + if ((err = zts_getsockname(fd, (struct sockaddr*)&ss, &namelen)) < 0) { + DEBUG_ERROR("error while determining socket family"); + return -1; + } + const char *str; +#if defined(LIBZT_IPV4) + if (ss.ss_family == AF_INET) { + struct sockaddr_in in_addr; + str = (*env).GetStringUTFChars(addrstr, 0); + in_addr.sin_addr.s_addr = inet_addr(str); + in_addr.sin_family = AF_INET; + in_addr.sin_port = htons(port); + (*env).ReleaseStringUTFChars(addrstr, str); + } +#endif // LIBZT_IPV4 +#if defined(LIBZT_IPV6) + if (ss.ss_family == AF_INET6) { + struct sockaddr_in6 in_addr; + str = (*env).GetStringUTFChars(addrstr, 0); + //in_addr.sin_addr.s_addr = inet_addr(str); + in_addr.sin6_family = AF_INET6; + in_addr.sin6_port = htons(port); + (*env).ReleaseStringUTFChars(addrstr, str); + } +#endif // LIBZT_IPV6 DEBUG_INFO("fd=%d, addr=%s, port=%d", fd, str, port); - addr.sin_addr.s_addr = inet_addr(str); - addr.sin_family = AF_INET; - addr.sin_port = htons( port ); - (*env).ReleaseStringUTFChars( addrstr, str); - return zts_bind(fd, (struct sockaddr *)&addr, sizeof(addr)); + return zts_bind(fd, (struct sockaddr *)&ss, sizeof(in_addr)); } #if defined(__linux__) @@ -88,10 +133,10 @@ namespace ZeroTier { struct sockaddr_in addr; char *str; // = env->GetStringUTFChars(addrstr, NULL); - (*env).ReleaseStringUTFChars( addrstr, str); + (*env).ReleaseStringUTFChars(addrstr, str); addr.sin_addr.s_addr = inet_addr(str); addr.sin_family = AF_INET; - addr.sin_port = htons( port ); + addr.sin_port = htons(port); return zts_accept4(fd, (struct sockaddr *)&addr, sizeof(addr), flags); } #endif @@ -103,7 +148,7 @@ namespace ZeroTier { // TODO: Send addr info back to Javaland addr.sin_addr.s_addr = inet_addr(""); addr.sin_family = AF_INET; - addr.sin_port = htons( port ); + addr.sin_port = htons(port); return zts_accept(fd, (struct sockaddr *)&addr, (socklen_t *)sizeof(addr)); } @@ -190,7 +235,7 @@ namespace ZeroTier { (*env).ReleaseByteArrayElements((_jbyteArray *)buf, body, 0); return read_bytes; } - + JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_setsockopt( JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen) @@ -242,10 +287,10 @@ namespace ZeroTier { /* ZeroTier service controls (for JNI wrapper) */ /****************************************************************************/ - JNIEXPORT void JNICALL Java_zerotier_ZeroTier_start(JNIEnv *env, jobject thisObj, jstring path) + JNIEXPORT void JNICALL Java_zerotier_ZeroTier_start(JNIEnv *env, jobject thisObj, jstring path, jboolean blocking) { if (path) { - zts_start(env->GetStringUTFChars(path, NULL)); + zts_start(env->GetStringUTFChars(path, NULL), blocking); } } diff --git a/test/selftest.cpp b/test/selftest.cpp index ca2c655..431bc85 100644 --- a/test/selftest.cpp +++ b/test/selftest.cpp @@ -1932,7 +1932,7 @@ int ZT_control_semantics_test(bool *passed) DEBUG_TEST("---\n"); sleep(1); */ - zts_start(path); + zts_start(path, false); zts_join(nwid); zts_leave(nwid); zts_stop();