summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/README.md4
-rw-r--r--java/build.xml46
-rw-r--r--java/jni/Android.mk42
-rw-r--r--java/jni/Application.mk3
-rw-r--r--java/jni/ZT1_jniutils.cpp347
-rw-r--r--java/jni/ZT1_jniutils.h25
-rw-r--r--java/jni/com_zerotierone_sdk_Node.cpp1070
-rw-r--r--java/jni/com_zerotierone_sdk_Node.h133
-rw-r--r--java/src/com/zerotierone/sdk/DataStoreGetListener.java38
-rw-r--r--java/src/com/zerotierone/sdk/DataStorePutListener.java37
-rw-r--r--java/src/com/zerotierone/sdk/Event.java38
-rw-r--r--java/src/com/zerotierone/sdk/EventListener.java34
-rw-r--r--java/src/com/zerotierone/sdk/MulticastGroup.java35
-rw-r--r--java/src/com/zerotierone/sdk/Node.java235
-rw-r--r--java/src/com/zerotierone/sdk/NodeStatus.java53
-rw-r--r--java/src/com/zerotierone/sdk/PacketSender.java38
-rw-r--r--java/src/com/zerotierone/sdk/Peer.java80
-rw-r--r--java/src/com/zerotierone/sdk/PeerRole.java34
-rw-r--r--java/src/com/zerotierone/sdk/PhysicalPeerPath.java65
-rw-r--r--java/src/com/zerotierone/sdk/ResultCode.java45
-rw-r--r--java/src/com/zerotierone/sdk/Version.java37
-rw-r--r--java/src/com/zerotierone/sdk/VirtualNetworkConfig.java111
-rw-r--r--java/src/com/zerotierone/sdk/VirtualNetworkConfigListener.java38
-rw-r--r--java/src/com/zerotierone/sdk/VirtualNetworkConfigOperation.java34
-rw-r--r--java/src/com/zerotierone/sdk/VirtualNetworkFrameListener.java40
-rw-r--r--java/src/com/zerotierone/sdk/VirtualNetworkStatus.java36
-rw-r--r--java/src/com/zerotierone/sdk/VirtualNetworkType.java32
27 files changed, 2730 insertions, 0 deletions
diff --git a/java/README.md b/java/README.md
new file mode 100644
index 00000000..10735691
--- /dev/null
+++ b/java/README.md
@@ -0,0 +1,4 @@
+ZeroTier One SDK - Android JNI Wrapper
+=====
+
+To Build: <path to Android-ndk>/ndk-build ZT1=<path to ZeroTierOne root>
diff --git a/java/build.xml b/java/build.xml
new file mode 100644
index 00000000..af05cd00
--- /dev/null
+++ b/java/build.xml
@@ -0,0 +1,46 @@
+<project default="build" name="ZeroTierOneSDK">
+ <property environment="env"/>
+
+ <target name="clean">
+ <delete dir="bin" failonerror="false"/>
+ <delete dir="classes" failonerror="false"/>
+ <delete dir="libs" failonerror="false"/>
+ <delete dir="obj" failonerror="false"/>
+ </target>
+
+ <target name="build">
+ <echo message="os.name = ${os.name}"/>
+ <echo message="os.arch = ${os.arch}"/>
+ <echo message="ant.java.version = ${ant.java.version}"/>
+ <echo message="java.version = ${java.version}"/>
+ <mkdir dir="bin"/>
+ <mkdir dir="classes"/>
+ <javac srcdir="src"
+ destdir="classes"
+ classpath="${env.ANDROID_PLATFORM}/android.jar"
+ includeantruntime="false"/>
+ <exec dir="jni" executable="${env.NDK_BUILD_LOC}" failonerror="true">
+ <arg value="ZT1=${user.dir}/../"/>
+ </exec>
+ <jar destfile="bin/ZeroTierOneSDK.jar" basedir="classes"/>
+ </target>
+
+<!-- <target name="android" depends="build">
+ <echo message="OS is Android, installing..."/>
+ <copy file="libs/armeabi/libZeroTierOneJNI.so"
+ tofile="${aproj_loc}/libs/armeabi/libZeroTierOneJNI.so"
+ overwrite="true"/>
+ <copy file="libs/arm64-v8a/libZeroTierOneJNI.so"
+ tofile="${aproj_loc}/libs/arm64-v8a/libZeroTierOneJNI.so"
+ overwrite="true"/>
+ <copy file="libs/armeabi-v7a/libZeroTierOneJNI.so"
+ tofile="${aproj_loc}/libs/armeabi-v7a/libZeroTierOneJNI.so"
+ overwrite="true"/>
+ <copy file="libs/x86/libZeroTierOneJNI.so"
+ tofile="${aproj_loc}/libs/x86/libZeroTierOneJNI.so"
+ overwrite="true"/>
+ <copy file="bin/ZeroTierOneSDK.jar"
+ tofile="${aproj_loc}/libs/ZeroTierOneSDK.jar"
+ overwrite="true"/>
+ </target> -->
+</project> \ No newline at end of file
diff --git a/java/jni/Android.mk b/java/jni/Android.mk
new file mode 100644
index 00000000..136b6c81
--- /dev/null
+++ b/java/jni/Android.mk
@@ -0,0 +1,42 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := ZeroTierOneJNI
+LOCAL_C_INCLUDES := $(ZT1)/include
+
+# ZeroTierOne SDK source files
+LOCAL_SRC_FILES := \
+ $(ZT1)/ext/lz4/lz4.c \
+ $(ZT1)/ext/json-parser/json.c \
+ $(ZT1)/ext/http-parser/http_parser.c \
+ $(ZT1)/node/C25519.cpp \
+ $(ZT1)/node/CertificateOfMembership.cpp \
+ $(ZT1)/node/Defaults.cpp \
+ $(ZT1)/node/Dictionary.cpp \
+ $(ZT1)/node/Identity.cpp \
+ $(ZT1)/node/IncomingPacket.cpp \
+ $(ZT1)/node/InetAddress.cpp \
+ $(ZT1)/node/Multicaster.cpp \
+ $(ZT1)/node/Network.cpp \
+ $(ZT1)/node/NetworkConfig.cpp \
+ $(ZT1)/node/Node.cpp \
+ $(ZT1)/node/OutboundMulticast.cpp \
+ $(ZT1)/node/Packet.cpp \
+ $(ZT1)/node/Peer.cpp \
+ $(ZT1)/node/Poly1305.cpp \
+ $(ZT1)/node/Salsa20.cpp \
+ $(ZT1)/node/SelfAwareness.cpp \
+ $(ZT1)/node/SHA512.cpp \
+ $(ZT1)/node/Switch.cpp \
+ $(ZT1)/node/Topology.cpp \
+ $(ZT1)/node/Utils.cpp \
+ $(ZT1)/osdep/Http.cpp \
+ $(ZT1)/osdep/OSUtils.cpp
+
+# JNI Files
+LOCAL_SRC_FILES += \
+ com_zerotierone_sdk_Node.cpp \
+ ZT1_jniutils.cpp
+
+include $(BUILD_SHARED_LIBRARY) \ No newline at end of file
diff --git a/java/jni/Application.mk b/java/jni/Application.mk
new file mode 100644
index 00000000..11c5c2cf
--- /dev/null
+++ b/java/jni/Application.mk
@@ -0,0 +1,3 @@
+APP_ABI := armeabi armeabi-v7a arm64-v8a x86
+APP_STL := gnustl_static
+APP_CPPFLAGS += -fexceptions \ No newline at end of file
diff --git a/java/jni/ZT1_jniutils.cpp b/java/jni/ZT1_jniutils.cpp
new file mode 100644
index 00000000..87340f12
--- /dev/null
+++ b/java/jni/ZT1_jniutils.cpp
@@ -0,0 +1,347 @@
+#include "ZT1_jniutils.h"
+#include <string>
+#include <assert.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+namespace
+{
+ static jclass arrayListClass = NULL;
+ static jmethodID arrayList_constructor = NULL;
+ static jmethodID arrayList_add = NULL;
+
+ static jclass inetAddressClass = NULL;
+ static jmethodID inetAddress_getByAddress = NULL;
+}
+
+jobject createResultObject(JNIEnv *env, ZT1_ResultCode code)
+{
+ // cache the class so we don't have to
+ // look it up every time we need to create a java
+ // ResultCode object
+ static jclass resultClass = NULL;
+
+ jobject resultObject = NULL;
+
+ if(resultClass == NULL)
+ {
+ resultClass = env->FindClass("com/zerotierone/sdk/ResultCode");
+ if(resultClass == NULL)
+ {
+ return NULL; // exception thrown
+ }
+ }
+
+ std::string fieldName;
+ switch(code)
+ {
+ case ZT1_RESULT_OK:
+ fieldName = "ZT1_RESULT_OK";
+ break;
+ case ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY:
+ fieldName = "ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY";
+ break;
+ case ZT1_RESULT_FATAL_ERROR_DATA_STORE_FAILED:
+ fieldName = "ZT1_RESULT_FATAL_ERROR_DATA_STORE_FAILED";
+ break;
+ case ZT1_RESULT_ERROR_NETWORK_NOT_FOUND:
+ fieldName = "ZT1_RESULT_ERROR_NETWORK_NOT_FOUND";
+ break;
+ case ZT1_RESULT_FATAL_ERROR_INTERNAL:
+ default:
+ fieldName = "ZT1_RESULT_FATAL_ERROR_INTERNAL";
+ break;
+ }
+
+ jfieldID enumField = env->GetStaticFieldID(resultClass, fieldName.c_str(), "Lcom/zerotierone/sdk/ResultCode;");
+
+ resultObject = env->GetStaticObjectField(resultClass, enumField);
+
+ return resultObject;
+}
+
+
+jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status)
+{
+ static jclass statusClass = NULL;
+
+ jobject statusObject = NULL;
+
+ if(statusClass == NULL)
+ {
+ statusClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkStatus");
+ if(statusClass == NULL)
+ {
+ return NULL; // exception thrown
+ }
+ }
+
+ std::string fieldName;
+ switch(status)
+ {
+ case ZT1_NETWORK_STATUS_REQUESTING_CONFIGURATION:
+ fieldName = "NETWORK_STATUS_REQUESTING_CONFIGURATION";
+ break;
+ case ZT1_NETWORK_STATUS_OK:
+ fieldName = "NETWORK_STATUS_OK";
+ break;
+ case ZT1_NETWORK_STATUS_ACCESS_DENIED:
+ fieldName = "NETWORK_STATUS_ACCESS_DENIED";
+ break;
+ case ZT1_NETWORK_STATUS_NOT_FOUND:
+ fieldName = "NETWORK_STATUS_NOT_FOUND";
+ break;
+ case ZT1_NETWORK_STATUS_PORT_ERROR:
+ fieldName = "NETWORK_STATUS_PORT_ERROR";
+ break;
+ case ZT1_NETWORK_STATUS_CLIENT_TOO_OLD:
+ fieldName = "NETWORK_STATUS_CLIENT_TOO_OLD";
+ break;
+ }
+
+ jfieldID enumField = env->GetStaticFieldID(statusClass, fieldName.c_str(), "Lcom/zerotierone/sdk/VirtualNetworkStatus;");
+
+ statusObject = env->GetStaticObjectField(statusClass, enumField);
+
+ return statusObject;
+}
+
+jobject createEvent(JNIEnv *env, ZT1_Event event)
+{
+ static jclass eventClass = NULL;
+ jobject eventObject = NULL;
+
+ if(eventClass == NULL)
+ {
+ eventClass = env->FindClass("com/zerotierone/sdk/Event");
+ if(eventClass == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ std::string fieldName;
+ switch(event)
+ {
+ case ZT1_EVENT_UP:
+ fieldName = "EVENT_UP";
+ break;
+ case ZT1_EVENT_OFFLINE:
+ fieldName = "EVENT_OFFLINE";
+ break;
+ case ZT1_EVENT_DOWN:
+ fieldName = "EVENT_DOWN";
+ break;
+ case ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION:
+ fieldName = "EVENT_FATAL_ERROR_IDENTITY_COLLISION";
+ break;
+ case ZT1_EVENT_AUTHENTICATION_FAILURE:
+ fieldName = "EVENT_AUTHENTICATION_FAILURE";
+ break;
+ case ZT1_EVENT_INVALID_PACKET:
+ fieldName = "EVENT_INVALID_PACKET";
+ break;
+ case ZT1_EVENT_TRACE:
+ fieldName = "EVENT_TRACE";
+ break;
+ }
+
+ jfieldID enumField = env->GetStaticFieldID(eventClass, fieldName.c_str(), "Lcom/zerotierone/sdk/Event;");
+
+ eventObject = env->GetStaticObjectField(eventClass, enumField);
+
+ return eventObject;
+}
+
+jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type)
+{
+ static jclass vntypeClass = NULL;
+ jobject vntypeObject = NULL;
+
+ if(vntypeClass == NULL)
+ {
+ vntypeClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkType");
+ if(vntypeClass == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ std::string fieldName;
+ switch(type)
+ {
+ case ZT1_NETWORK_TYPE_PRIVATE:
+ fieldName = "NETWORK_TYPE_PRIVATE";
+ break;
+ case ZT1_NETWORK_TYPE_PUBLIC:
+ fieldName = "NETWORK_TYPE_PUBLIC";
+ break;
+ }
+
+ jfieldID enumField = env->GetStaticFieldID(vntypeClass, fieldName.c_str(), "Lcom/zerotierone/sdk/VirtyalNetworkType;");
+ vntypeObject = env->GetStaticObjectField(vntypeClass, enumField);
+ return vntypeObject;
+}
+
+jobject newArrayList(JNIEnv *env)
+{
+ if(arrayListClass == NULL)
+ {
+ arrayListClass = env->FindClass("java/util/ArrayList");
+ if(arrayListClass == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(arrayList_constructor == NULL)
+ {
+ arrayList_constructor = env->GetMethodID(
+ arrayListClass, "<init>", "()V");
+ if(arrayList_constructor == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ jobject arrayListObj = env->NewObject(arrayListClass, arrayList_constructor);
+
+ return arrayListObj;
+}
+
+bool appendItemToArrayList(JNIEnv *env, jobject array, jobject object)
+{
+ assert(array != NULL);
+ assert(object != NULL);
+
+ if(arrayList_add == NULL)
+ {
+ arrayList_add = env->GetMethodID(arrayListClass, "add", "(Ljava.lang.Object;)Z");
+ if(arrayList_add == NULL)
+ {
+ return false;
+ }
+ }
+
+ return env->CallBooleanMethod(array, arrayList_add, object);
+}
+
+jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr)
+{
+ if(inetAddressClass == NULL)
+ {
+ inetAddressClass = env->FindClass("java/net/InetAddress");
+ if(inetAddressClass == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(inetAddress_getByAddress == NULL)
+ {
+ inetAddress_getByAddress = env->GetStaticMethodID(
+ inetAddressClass, "getByAddress", "([B)Ljava/net/InetAddress;");
+ if(inetAddress_getByAddress == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ jobject inetAddressObj = NULL;
+ switch(addr.ss_family)
+ {
+ case AF_INET6:
+ {
+ sockaddr_in6 *ipv6 = (sockaddr_in6*)&addr;
+ jbyteArray buff = env->NewByteArray(16);
+ if(buff == NULL)
+ {
+ return NULL;
+ }
+
+ env->SetByteArrayRegion(buff, 0, 16, (jbyte*)ipv6->sin6_addr.s6_addr);
+ inetAddressObj = env->CallStaticObjectMethod(
+ inetAddressClass, inetAddress_getByAddress, buff);
+ }
+ break;
+ case AF_INET:
+ {
+ sockaddr_in *ipv4 = (sockaddr_in*)&addr;
+ jbyteArray buff = env->NewByteArray(4);
+ if(buff == NULL)
+ {
+ return NULL;
+ }
+
+ env->SetByteArrayRegion(buff, 0, 4, (jbyte*)&ipv4->sin_addr);
+ inetAddressObj = env->CallStaticObjectMethod(
+ inetAddressClass, inetAddress_getByAddress, buff);
+ }
+ break;
+ }
+
+ return inetAddressObj;
+}
+
+jobject newMulticastGroup(JNIEnv *env, const ZT1_MulticastGroup &mc)
+{
+ static jclass multicastGroupClass = NULL;
+ static jmethodID multicastGroup_constructor = NULL;
+
+ static jfieldID macField = NULL;
+ static jfieldID adiField = NULL;
+
+ if(multicastGroupClass == NULL)
+ {
+ multicastGroupClass = env->FindClass("com/zerotierone/sdk/MulticastGroup");
+ if(multicastGroupClass == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(multicastGroup_constructor == NULL)
+ {
+ multicastGroup_constructor = env->GetMethodID(
+ multicastGroupClass, "<init>", "()V");
+ if(multicastGroup_constructor == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ jobject multicastGroupObj = env->NewObject(multicastGroupClass, multicastGroup_constructor);
+ if(multicastGroupObj == NULL)
+ {
+ return NULL;
+ }
+
+ if(macField == NULL)
+ {
+ macField = env->GetFieldID(multicastGroupClass, "mac", "J");
+ if(macField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(adiField == NULL)
+ {
+ adiField = env->GetFieldID(multicastGroupClass, "adi", "J");
+ if(adiField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ env->SetLongField(multicastGroupObj, macField, mc.mac);
+ env->SetLongField(multicastGroupObj, adiField, mc.adi);
+
+ return multicastGroupObj;
+}
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file
diff --git a/java/jni/ZT1_jniutils.h b/java/jni/ZT1_jniutils.h
new file mode 100644
index 00000000..e881e394
--- /dev/null
+++ b/java/jni/ZT1_jniutils.h
@@ -0,0 +1,25 @@
+#ifndef ZT1_jniutils_h_
+#define ZT1_jniutils_h_
+#include <jni.h>
+#include <ZeroTierOne.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+jobject createResultObject(JNIEnv *env, ZT1_ResultCode code);
+jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status);
+jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type);
+jobject createEvent(JNIEnv *env, ZT1_Event event);
+
+jobject newArrayList(JNIEnv *env);
+bool appendItemToArrayList(JNIEnv *env, jobject array, jobject object);
+
+jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr);
+
+jobject newMulticastGroup(JNIEnv *env, const ZT1_MulticastGroup &mc);
+#ifdef __cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
new file mode 100644
index 00000000..c728f47e
--- /dev/null
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -0,0 +1,1070 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+#include "com_zerotierone_sdk_Node.h"
+#include "ZT1_jniutils.h"
+
+#include <ZeroTierOne.h>
+
+#include <map>
+#include <string>
+#include <assert.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+namespace {
+ struct JniRef
+ {
+ JniRef()
+ : env(NULL)
+ , node(NULL)
+ , dataStoreGetListener(NULL)
+ , dataStorePutListener(NULL)
+ , packetSender(NULL)
+ , frameListener(NULL)
+ , configListener(NULL)
+ {}
+ uint64_t id;
+
+ JNIEnv *env;
+
+ ZT1_Node *node;
+
+ jobject dataStoreGetListener;
+ jobject dataStorePutListener;
+ jobject packetSender;
+ jobject frameListener;
+ jobject configListener;
+ };
+
+
+ int VirtualNetworkConfigFunctionCallback(ZT1_Node *node,void *userData,uint64_t,enum ZT1_VirtualNetworkConfigOperation,const ZT1_VirtualNetworkConfig *)
+ {
+ JniRef *ref = (JniRef*)userData;
+ assert(ref->node == node);
+
+ JNIEnv *env = ref->env;
+
+ return 0;
+ }
+
+ void VirtualNetworkFrameFunctionCallback(ZT1_Node *node,void *userData,uint64_t,uint64_t,uint64_t,unsigned int,unsigned int,const void *,unsigned int)
+ {
+ JniRef *ref = (JniRef*)userData;
+ assert(ref->node == node);
+
+ JNIEnv *env = ref->env;
+ }
+
+ void EventCallback(ZT1_Node *node,void *userData,enum ZT1_Event,const void *)
+ {
+ JniRef *ref = (JniRef*)userData;
+ assert(ref->node == node);
+
+ JNIEnv *env = ref->env;
+ }
+
+ long DataStoreGetFunction(ZT1_Node *node,void *userData,const char *,void *,unsigned long,unsigned long,unsigned long *)
+ {
+ JniRef *ref = (JniRef*)userData;
+ assert(ref->node == node);
+
+ JNIEnv *env = ref->env;
+
+ return 0;
+ }
+
+ int DataStorePutFunction(ZT1_Node *node,void *userData,const char *,const void *,unsigned long,int)
+ {
+ JniRef *ref = (JniRef*)userData;
+ assert(ref->node == node);
+
+ JNIEnv *env = ref->env;
+
+ return 0;
+ }
+
+ int WirePacketSendFunction(ZT1_Node *node,void *userData,const struct sockaddr_storage *,unsigned int,const void *,unsigned int)
+ {
+ JniRef *ref = (JniRef*)userData;
+ assert(ref->node == node);
+
+ JNIEnv *env = ref->env;
+
+ return 0;
+ }
+
+ typedef std::map<uint64_t, JniRef*> NodeMap;
+ static NodeMap nodeMap;
+
+ ZT1_Node* findNode(uint64_t nodeId)
+ {
+ NodeMap::iterator found = nodeMap.find(nodeId);
+ if(found != nodeMap.end())
+ {
+ JniRef *ref = found->second;
+ return ref->node;
+ }
+ return NULL;
+ }
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: node_init
+ * Signature: (J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init(
+ JNIEnv *env, jobject obj, jlong now)
+{
+ jobject resultObject = createResultObject(env, ZT1_RESULT_OK);
+
+ ZT1_Node *node;
+ JniRef *ref = new JniRef;
+
+ ZT1_ResultCode rc = ZT1_Node_new(
+ &node,
+ ref,
+ (uint64_t)now,
+ &DataStoreGetFunction,
+ &DataStorePutFunction,
+ &WirePacketSendFunction,
+ &VirtualNetworkFrameFunctionCallback,
+ &VirtualNetworkConfigFunctionCallback,
+ &EventCallback);
+
+ if(rc != ZT1_RESULT_OK)
+ {
+ resultObject = createResultObject(env, rc);
+ if(node)
+ {
+ ZT1_Node_delete(node);
+ node = NULL;
+ }
+ delete ref;
+ ref = NULL;
+ return resultObject;
+ }
+
+
+ ref->id = (uint64_t)now;
+ ref->env = env;
+ ref->node = node;
+
+ jclass cls = env->GetObjectClass(obj);
+ jfieldID fid = env->GetFieldID(
+ cls, "getListener", "Lcom/zerotierone/sdk/DataStoreGetListener;");
+
+ if(fid == NULL)
+ {
+ return NULL; // exception already thrown
+ }
+
+ ref->dataStoreGetListener = env->GetObjectField(obj, fid);
+ if(ref->dataStoreGetListener == NULL)
+ {
+ return NULL;
+ }
+
+ fid = env->GetFieldID(
+ cls, "putListener", "Lcom/zerotierone/sdk/DataStorePutLisetner;");
+
+ if(fid == NULL)
+ {
+ return NULL; // exception already thrown
+ }
+
+ ref->dataStorePutListener = env->GetObjectField(obj, fid);
+ if(ref->dataStorePutListener == NULL)
+ {
+ return NULL;
+ }
+
+ fid = env->GetFieldID(
+ cls, "sender", "Lcom/zerotierone/sdk/PacketSender;");
+ if(fid == NULL)
+ {
+ return NULL; // exception already thrown
+ }
+
+ ref->packetSender = env->GetObjectField(obj, fid);
+ if(ref->packetSender == NULL)
+ {
+ return NULL;
+ }
+
+ fid = env->GetFieldID(
+ cls, "frameListener", "Lcom/zerotierone/sdk/VirtualNetworkFrameListener;");
+ if(fid == NULL)
+ {
+ return NULL; // exception already thrown
+ }
+
+ ref->frameListener = env->GetObjectField(obj, fid);
+ if(ref->frameListener = NULL)
+ {
+ return NULL;
+ }
+
+ fid = env->GetFieldID(
+ cls, "configListener", "Lcom/zerotierone/sdk/VirtualNetworkConfigListener;");
+ if(fid == NULL)
+ {
+ return NULL; // exception already thrown
+ }
+
+ ref->configListener = env->GetObjectField(obj, fid);
+ if(ref->configListener == NULL)
+ {
+ return NULL;
+ }
+
+ nodeMap.insert(std::make_pair(ref->id, ref));
+
+ return resultObject;
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: node_delete
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_zerotierone_sdk_Node_node_1delete(
+ JNIEnv *env, jobject obj, jlong id)
+{
+ uint64_t nodeId = (uint64_t)id;
+
+ NodeMap::iterator found = nodeMap.find(nodeId);
+ if(found != nodeMap.end())
+ {
+ JniRef *ref = found->second;
+ nodeMap.erase(found);
+
+ ZT1_Node_delete(ref->node);
+
+ delete ref;
+ ref = NULL;
+ }
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: processVirtualNetworkFrame
+ * Signature: (JJJJJII[B[J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processVirtualNetworkFrame(
+ JNIEnv *env, jobject obj,
+ jlong id,
+ jlong in_now,
+ jlong in_nwid,
+ jlong in_sourceMac,
+ jlong in_destMac,
+ jint in_etherType,
+ jint in_vlanId,
+ jbyteArray in_frameData,
+ jlongArray out_nextBackgroundTaskDeadline)
+{
+ uint64_t nodeId = (uint64_t) id;
+
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline);
+ if(nbtd_len < 1)
+ {
+ // array for next background task length has 0 elements!
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t now = (uint64_t)in_now;
+ uint64_t nwid = (uint64_t)in_nwid;
+ uint64_t sourceMac = (uint64_t)in_sourceMac;
+ uint64_t destMac = (uint64_t)in_destMac;
+ unsigned int etherType = (unsigned int)in_etherType;
+ unsigned int vlanId = (unsigned int)in_vlanId;
+
+ unsigned int frameLength = env->GetArrayLength(in_frameData);
+ jbyte *frameData =env->GetByteArrayElements(in_frameData, NULL);
+
+ uint64_t nextBackgroundTaskDeadline = 0;
+
+ ZT1_ResultCode rc = ZT1_Node_processVirtualNetworkFrame(
+ node,
+ now,
+ nwid,
+ sourceMac,
+ destMac,
+ etherType,
+ vlanId,
+ (const void*)frameData,
+ frameLength,
+ &nextBackgroundTaskDeadline);
+
+ jlong *outDeadline = env->GetLongArrayElements(out_nextBackgroundTaskDeadline, NULL);
+ outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
+ env->ReleaseLongArrayElements(out_nextBackgroundTaskDeadline, outDeadline, 0);
+
+ env->ReleaseByteArrayElements(in_frameData, frameData, 0);
+
+ return createResultObject(env, rc);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: processWirePacket
+ * Signature: (JJLjava/net/InetAddress;I[B[J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processWirePacket(
+ JNIEnv *env, jobject obj,
+ jlong id,
+ jlong in_now,
+ jobject in_remoteAddress,
+ jint in_linkDesparation,
+ jbyteArray in_packetData,
+ jlongArray out_nextBackgroundTaskDeadline)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline);
+ if(nbtd_len < 1)
+ {
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t now = (uint64_t)in_now;
+ unsigned int linkDesparation = (unsigned int)in_linkDesparation;
+
+ // get the java.net.InetAddress class and getAddress() method
+ jclass inetAddressClass = env->FindClass("java/net/InetAddress");
+ if(inetAddressClass == NULL)
+ {
+ // can't find java.net.InetAddress
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ jmethodID getAddressMethod = env->GetMethodID(
+ inetAddressClass, "getAddress", "()[B");
+ if(getAddressMethod == NULL)
+ {
+ // cant find InetAddress.getAddres()
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ // Call InetAddress.getAddress()
+ jbyteArray addressArray = (jbyteArray)env->CallObjectMethod(in_remoteAddress, getAddressMethod);
+ if(addressArray == NULL)
+ {
+ // unable to call getAddress()
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ unsigned int addrSize = env->GetArrayLength(addressArray);
+ // get the address bytes
+ jbyte *addr = env->GetByteArrayElements(addressArray, NULL);
+
+
+ sockaddr_storage remoteAddress = {};
+
+ if(addrSize == 16)
+ {
+ // IPV6 address
+ sockaddr_in6 ipv6 = {};
+ ipv6.sin6_family = AF_INET6;
+ memcpy(ipv6.sin6_addr.s6_addr, addr, 16);
+ memcpy(&remoteAddress, &ipv6, sizeof(sockaddr_in6));
+ }
+ else if(addrSize = 4)
+ {
+ // IPV4 address
+ sockaddr_in ipv4 = {};
+ ipv4.sin_family = AF_INET;
+ memcpy(&ipv4.sin_addr, addr, 4);
+ memcpy(&remoteAddress, &ipv4, sizeof(sockaddr_in));
+ }
+ else
+ {
+ // unknown address type
+ env->ReleaseByteArrayElements(addressArray, addr, 0);
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+
+ unsigned int packetLength = env->GetArrayLength(in_packetData);
+ jbyte *packetData = env->GetByteArrayElements(in_packetData, NULL);
+
+ uint64_t nextBackgroundTaskDeadline = 0;
+
+ ZT1_ResultCode rc = ZT1_Node_processWirePacket(
+ node,
+ now,
+ &remoteAddress,
+ linkDesparation,
+ packetData,
+ packetLength,
+ &nextBackgroundTaskDeadline);
+
+ jlong *outDeadline = env->GetLongArrayElements(out_nextBackgroundTaskDeadline, NULL);
+ outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
+ env->ReleaseLongArrayElements(out_nextBackgroundTaskDeadline, outDeadline, 0);
+
+ env->ReleaseByteArrayElements(addressArray, addr, 0);
+ env->ReleaseByteArrayElements(in_packetData, packetData, 0);
+
+ return createResultObject(env, ZT1_RESULT_OK);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: processBackgroundTasks
+ * Signature: (JJ[J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processBackgroundTasks(
+ JNIEnv *env, jobject obj,
+ jlong id,
+ jlong in_now,
+ jlongArray out_nextBackgroundTaskDeadline)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline);
+ if(nbtd_len < 1)
+ {
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t now = (uint64_t)in_now;
+ uint64_t nextBackgroundTaskDeadline = 0;
+
+ ZT1_ResultCode rc = ZT1_Node_processBackgroundTasks(node, now, &nextBackgroundTaskDeadline);
+
+ jlong *outDeadline = env->GetLongArrayElements(out_nextBackgroundTaskDeadline, NULL);
+ outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
+ env->ReleaseLongArrayElements(out_nextBackgroundTaskDeadline, outDeadline, 0);
+
+ return createResultObject(env, rc);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: join
+ * Signature: (JJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_join(
+ JNIEnv *env, jobject obj, jlong id, jlong in_nwid)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t nwid = (uint64_t)in_nwid;
+
+ ZT1_ResultCode rc = ZT1_Node_join(node, nwid);
+
+ return createResultObject(env, rc);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: leave
+ * Signature: (JJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_leave(
+ JNIEnv *env, jobject obj, jlong id, jlong in_nwid)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t nwid = (uint64_t)in_nwid;
+
+ ZT1_ResultCode rc = ZT1_Node_leave(node, nwid);
+
+ return createResultObject(env, rc);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: multicastSubscribe
+ * Signature: (JJJJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_multicastSubscribe(
+ JNIEnv *env, jobject obj,
+ jlong id,
+ jlong in_nwid,
+ jlong in_multicastGroup,
+ jlong in_multicastAdi)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t nwid = (uint64_t)in_nwid;
+ uint64_t multicastGroup = (uint64_t)in_multicastGroup;
+ uint64_t multicastAdi = (uint64_t)in_multicastAdi;
+
+ ZT1_ResultCode rc = ZT1_Node_multicastSubscribe(
+ node, nwid, multicastGroup, multicastAdi);
+
+ return createResultObject(env, rc);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: multicastUnsubscribe
+ * Signature: (JJJJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_multicastUnsubscribe(
+ JNIEnv *env, jobject obj,
+ jlong id,
+ jlong in_nwid,
+ jlong in_multicastGroup,
+ jlong in_multicastAdi)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
+
+ uint64_t nwid = (uint64_t)in_nwid;
+ uint64_t multicastGroup = (uint64_t)in_multicastGroup;
+ uint64_t multicastAdi = (uint64_t)in_multicastAdi;
+
+ ZT1_ResultCode rc = ZT1_Node_multicastUnsubscribe(
+ node, nwid, multicastGroup, multicastAdi);
+
+ return createResultObject(env, rc);
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: address
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_zerotierone_sdk_Node_address(
+ JNIEnv *env , jobject obj, jlong id)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return 0;
+ }
+
+ uint64_t address = ZT1_Node_address(node);
+ return (jlong)address;
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: status
+ * Signature: (J)Lcom/zerotierone/sdk/NodeStatus;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_status
+ (JNIEnv *env, jobject obj, jlong id)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return 0;
+ }
+
+ // static so we only have to look these up once
+ static jclass nodeStatusClass = NULL;
+ static jmethodID nodeStatusConstructor = NULL;
+
+ // create a com.zerotierone.sdk.NodeStatus object
+ if(nodeStatusClass == NULL)
+ {
+ nodeStatusClass = env->FindClass("com/zerotierone/sdk/NodeStatus");
+ if(nodeStatusClass == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(nodeStatusConstructor == NULL)
+ {
+ nodeStatusConstructor = env->GetMethodID(
+ nodeStatusClass, "<init>", "()V");
+ if(nodeStatusConstructor == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ jobject nodeStatusObj = env->NewObject(nodeStatusClass, nodeStatusConstructor);
+ if(nodeStatusObj == NULL)
+ {
+ return NULL;
+ }
+
+ ZT1_NodeStatus nodeStatus;
+ ZT1_Node_status(node, &nodeStatus);
+
+ static jfieldID addressField = NULL;
+ static jfieldID publicIdentityField = NULL;
+ static jfieldID secretIdentityField = NULL;
+ static jfieldID onlineField = NULL;
+
+ if(addressField == NULL)
+ {
+ addressField = env->GetFieldID(nodeStatusClass, "address", "J");
+ if(addressField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(publicIdentityField == NULL)
+ {
+ publicIdentityField = env->GetFieldID(nodeStatusClass, "publicIdentity", "Ljava/lang/String;");
+ if(publicIdentityField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(secretIdentityField == NULL)
+ {
+ secretIdentityField = env->GetFieldID(nodeStatusClass, "secretIdentity", "Ljava/lang/String;");
+ if(secretIdentityField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(onlineField == NULL)
+ {
+ onlineField = env->GetFieldID(nodeStatusClass, "online", "Z");
+ if(onlineField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ env->SetLongField(nodeStatusObj, addressField, nodeStatus.address);
+
+ jstring pubIdentStr = env->NewStringUTF(nodeStatus.publicIdentity);
+ if(pubIdentStr == NULL)
+ {
+ return NULL; // out of memory
+ }
+ env->SetObjectField(nodeStatusObj, publicIdentityField, pubIdentStr);
+
+ jstring secIdentStr = env->NewStringUTF(nodeStatus.secretIdentity);
+ if(secIdentStr == NULL)
+ {
+ return NULL; // out of memory
+ }
+ env->SetObjectField(nodeStatusObj, secretIdentityField, secIdentStr);
+
+ env->SetBooleanField(nodeStatusObj, onlineField, nodeStatus.online);
+
+ return nodeStatusObj;
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: networkConfig
+ * Signature: (J)Lcom/zerotierone/sdk/VirtualNetworkConfig;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_networkConfig(
+ JNIEnv *env, jobject obj, jlong id, jlong nwid)
+{
+ uint64_t nodeId = (uint64_t) id;
+ ZT1_Node *node = findNode(nodeId);
+ if(node == NULL)
+ {
+ // cannot find valid node. We should never get here.
+ return 0;
+ }
+
+ // create a com.zerotierone.sdk.VirtualNetworkConfig object
+ jclass vnetConfigClass = env->FindClass("com/zerotierone/sdk/VirtualNetworkConfig");
+ if(vnetConfigClass == NULL)
+ {
+ return NULL;
+ }
+
+ jmethodID vnetConfigConstructor = env->GetMethodID(
+ vnetConfigClass, "<init>", "()V");
+ if(vnetConfigConstructor == NULL)
+ {
+ return NULL;
+ }
+
+ jobject vnetConfigObj = env->NewObject(vnetConfigClass, vnetConfigConstructor);
+ if(vnetConfigObj == NULL)
+ {
+ return NULL;
+ }
+
+ ZT1_VirtualNetworkConfig *vnetConfig = ZT1_Node_networkConfig(node, nwid);
+
+ static jfieldID nwidField = NULL;
+ static jfieldID macField = NULL;
+ static jfieldID nameField = NULL;
+ static jfieldID statusField = NULL;
+ static jfieldID typeField = NULL;
+ static jfieldID mtuField = NULL;
+ static jfieldID dhcpField = NULL;
+ static jfieldID bridgeField = NULL;
+ static jfieldID broadcastEnabledField = NULL;
+ static jfieldID portErrorField = NULL;
+ static jfieldID enabledField = NULL;
+ static jfieldID netconfRevisionField = NULL;
+ static jfieldID multicastSubscriptionsField = NULL;
+ static jfieldID assignedAddressesField = NULL;
+
+ if(nwidField == NULL)
+ {
+ nwidField = env->GetFieldID(vnetConfigClass, "nwid", "J");
+ if(nwidField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(macField == NULL)
+ {
+ macField = env->GetFieldID(vnetConfigClass, "mac", "J");
+ if(macField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(nameField == NULL)
+ {
+ nameField = env->GetFieldID(vnetConfigClass, "name", "Ljava/lang/String;");
+ if(nameField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(statusField == NULL)
+ {
+ statusField = env->GetFieldID(vnetConfigClass, "status", "Lcom/zerotierone/sdk/VirtualNetworStatus;");
+ if(statusField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(typeField == NULL)
+ {
+ typeField = env->GetFieldID(vnetConfigClass, "type", "Lcom/zerotierone/sdk/VirtualNetworkType;");
+ if(typeField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(mtuField == NULL)
+ {
+ mtuField = env->GetFieldID(vnetConfigClass, "mtu", "I");
+ if(mtuField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(dhcpField == NULL)
+ {
+ dhcpField = env->GetFieldID(vnetConfigClass, "dhcp", "Z");
+ if(dhcpField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(bridgeField == NULL)
+ {
+ bridgeField = env->GetFieldID(vnetConfigClass, "bridge", "Z");
+ if(bridgeField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(broadcastEnabledField == NULL)
+ {
+ broadcastEnabledField = env->GetFieldID(vnetConfigClass, "broadcastEnabled", "Z");
+ if(broadcastEnabledField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(portErrorField == NULL)
+ {
+ portErrorField == env->GetFieldID(vnetConfigClass, "portError", "Z");
+ if(portErrorField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(enabledField == NULL)
+ {
+ enabledField = env->GetFieldID(vnetConfigClass, "enabled", "Z");
+ if(enabledField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(netconfRevisionField == NULL)
+ {
+ netconfRevisionField = env->GetFieldID(vnetConfigClass, "netconfRevision", "J");
+ if(netconfRevisionField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(multicastSubscriptionsField == NULL)
+ {
+ multicastSubscriptionsField = env->GetFieldID(vnetConfigClass, "multicastSubscriptions", "Ljava/util/ArrayList;");
+ if(multicastSubscriptionsField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(assignedAddressesField == NULL)
+ {
+ assignedAddressesField = env->GetFieldID(vnetConfigClass, "assignedAddresses", "Ljava/util/ArrayList;");
+ if(assignedAddressesField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ env->SetLongField(vnetConfigObj, nwidField, vnetConfig->nwid);
+ env->SetLongField(vnetConfigObj, macField, vnetConfig->mac);
+ jstring nameStr = env->NewStringUTF(vnetConfig->name);
+ if(nameStr == NULL)
+ {
+ return NULL; // out of memory
+ }
+ env->SetObjectField(vnetConfigObj, nameField, nameStr);
+
+ jobject statusObject = createVirtualNetworkStatus(env, vnetConfig->status);
+ if(statusObject == NULL)
+ {
+ return NULL;
+ }
+ env->SetObjectField(vnetConfigObj, statusField, statusObject);
+
+ jobject typeObject = createVirtualNetworkType(env, vnetConfig->type);
+ if(typeObject == NULL)
+ {
+ return NULL;
+ }
+ env->SetObjectField(vnetConfigObj, typeField, typeObject);
+
+ env->SetIntField(vnetConfigObj, mtuField, vnetConfig->mtu);
+ env->SetBooleanField(vnetConfigObj, dhcpField, vnetConfig->dhcp);
+ env->SetBooleanField(vnetConfigObj, bridgeField, vnetConfig->bridge);
+ env->SetBooleanField(vnetConfigObj, broadcastEnabledField, vnetConfig->broadcastEnabled);
+ env->SetBooleanField(vnetConfigObj, portErrorField, vnetConfig->portError);
+
+
+ jobject mcastSubsArrayObj = newArrayList(env);
+ for(unsigned int i = 0; i < vnetConfig->multicastSubscriptionCount; ++i)
+ {
+ jobject mcastObj = newMulticastGroup(env, vnetConfig->multicastSubscriptions[i]);
+ appendItemToArrayList(env, mcastSubsArrayObj, mcastObj);
+ }
+ env->SetObjectField(vnetConfigObj, multicastSubscriptionsField, mcastSubsArrayObj);
+
+
+ jobject assignedAddrArrayObj = newArrayList(env);
+ for(unsigned int i = 0; i < vnetConfig->assignedAddressCount; ++i)
+ {
+ jobject inetAddrObj = newInetAddress(env, vnetConfig->assignedAddresses[i]);
+ appendItemToArrayList(env, assignedAddrArrayObj, inetAddrObj);
+ }
+
+ env->SetObjectField(vnetConfigObj, assignedAddressesField, assignedAddrArrayObj);
+
+ ZT1_Node_freeQueryResult(node, vnetConfig);
+ vnetConfig = NULL;
+
+ return vnetConfigObj;
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: version
+ * Signature: (J)Lcom/zerotierone/sdk/Version;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_version(
+ JNIEnv *env, jobject obj)
+{
+ // create a com.zerotierone.sdk.Version object
+ jclass versionClass = env->FindClass("com/zerotierone/sdk/Version");
+ if(versionClass == NULL)
+ {
+ return NULL;
+ }
+
+ jmethodID versionConstructor = env->GetMethodID(
+ versionClass, "<init>", "()V");
+ if(versionConstructor == NULL)
+ {
+ return NULL;
+ }
+
+ jobject versionObj = env->NewObject(versionClass, versionConstructor);
+ if(versionObj == NULL)
+ {
+ return NULL;
+ }
+
+ int major = 0;
+ int minor = 0;
+ int revision = 0;
+ unsigned long featureFlags = 0;
+
+ ZT1_version(&major, &minor, &revision, &featureFlags);
+
+ // copy data to Version object
+ static jfieldID majorField = NULL;
+ static jfieldID minorField = NULL;
+ static jfieldID revisionField = NULL;
+ static jfieldID featureFlagsField = NULL;
+
+ if(majorField == NULL)
+ {
+ majorField = env->GetFieldID(versionClass, "major", "I");
+ if(majorField = NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(minorField == NULL)
+ {
+ minorField = env->GetFieldID(versionClass, "minor", "I");
+ if(minorField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(revisionField == NULL)
+ {
+ revisionField = env->GetFieldID(versionClass, "revision", "I");
+ if(revisionField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ if(featureFlagsField == NULL)
+ {
+ featureFlagsField = env->GetFieldID(versionClass, "featureFlags", "J");
+ if(featureFlagsField == NULL)
+ {
+ return NULL;
+ }
+ }
+
+ env->SetIntField(versionObj, majorField, (jint)major);
+ env->SetIntField(versionObj, minorField, (jint)minor);
+ env->SetIntField(versionObj, revisionField, (jint)revision);
+ env->SetLongField(versionObj, featureFlagsField, (jlong)featureFlags);
+
+
+ return versionObj;
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: peers
+ * Signature: (J)Ljava/util/ArrayList;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_peers(
+ JNIEnv *env, jobject obj, jlong id)
+{
+ return NULL;
+}
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: networks
+ * Signature: (J)Ljava/util/ArrayList;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_networks(
+ JNIEnv *env, jobject obj, jlong id)
+{
+ return NULL;
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif \ No newline at end of file
diff --git a/java/jni/com_zerotierone_sdk_Node.h b/java/jni/com_zerotierone_sdk_Node.h
new file mode 100644
index 00000000..fefc9fc5
--- /dev/null
+++ b/java/jni/com_zerotierone_sdk_Node.h
@@ -0,0 +1,133 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class com_zerotierone_sdk_Node */
+
+#ifndef _Included_com_zerotierone_sdk_Node
+#define _Included_com_zerotierone_sdk_Node
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: node_init
+ * Signature: (J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_node_1init
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: node_delete
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_zerotierone_sdk_Node_node_1delete
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: processVirtualNetworkFrame
+ * Signature: (JJJJJII[B[J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processVirtualNetworkFrame
+ (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong, jint, jint, jbyteArray, jlongArray);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: processWirePacket
+ * Signature: (JJLjava/net/InetAddress;I[B[J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processWirePacket
+ (JNIEnv *, jobject, jlong, jlong, jobject, jint, jbyteArray, jlongArray);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: processBackgroundTasks
+ * Signature: (JJ[J)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processBackgroundTasks
+ (JNIEnv *, jobject, jlong, jlong, jlongArray);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: join
+ * Signature: (JJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_join
+ (JNIEnv *, jobject, jlong, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: leave
+ * Signature: (JJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_leave
+ (JNIEnv *, jobject, jlong, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: multicastSubscribe
+ * Signature: (JJJJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_multicastSubscribe
+ (JNIEnv *, jobject, jlong, jlong, jlong, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: multicastUnsubscribe
+ * Signature: (JJJJ)Lcom/zerotierone/sdk/ResultCode;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_multicastUnsubscribe
+ (JNIEnv *, jobject, jlong, jlong, jlong, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: address
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_zerotierone_sdk_Node_address
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: status
+ * Signature: (J)Lcom/zerotierone/sdk/NodeStatus;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_status
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: networkConfig
+ * Signature: (JJ)Lcom/zerotierone/sdk/VirtualNetworkConfig;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_networkConfig
+ (JNIEnv *, jobject, jlong, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: version
+ * Signature: ()Lcom/zerotierone/sdk/Version;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_version
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: peers
+ * Signature: (J)Ljava/util/ArrayList;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_peers
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_zerotierone_sdk_Node
+ * Method: networks
+ * Signature: (J)Ljava/util/ArrayList;
+ */
+JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_networks
+ (JNIEnv *, jobject, jlong);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/java/src/com/zerotierone/sdk/DataStoreGetListener.java b/java/src/com/zerotierone/sdk/DataStoreGetListener.java
new file mode 100644
index 00000000..60e1c3e8
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/DataStoreGetListener.java
@@ -0,0 +1,38 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+import java.nio.ByteBuffer;
+
+public interface DataStoreGetListener {
+ public int onDataStoreGet(Node node,
+ String name,
+ ByteBuffer buffer,
+ long bufferSize,
+ long index,
+ Long out_objectSize);
+}
diff --git a/java/src/com/zerotierone/sdk/DataStorePutListener.java b/java/src/com/zerotierone/sdk/DataStorePutListener.java
new file mode 100644
index 00000000..4e9404d9
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/DataStorePutListener.java
@@ -0,0 +1,37 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+import java.nio.ByteBuffer;
+
+public interface DataStorePutListener {
+ public int onDataStorePut(Node node,
+ String name,
+ ByteBuffer buffer,
+ long bufferSize,
+ boolean secure);
+}
diff --git a/java/src/com/zerotierone/sdk/Event.java b/java/src/com/zerotierone/sdk/Event.java
new file mode 100644
index 00000000..c5558676
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/Event.java
@@ -0,0 +1,38 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+public enum Event {
+ EVENT_UP,
+ EVENT_OFFLINE,
+ EVENT_DOWN,
+ EVENT_FATAL_ERROR_IDENTITY_COLLISION,
+ EVENT_AUTHENTICATION_FAILURE,
+ EVENT_INVALID_PACKET,
+ EVENT_TRACE
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/EventListener.java b/java/src/com/zerotierone/sdk/EventListener.java
new file mode 100644
index 00000000..9e3e4d24
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/EventListener.java
@@ -0,0 +1,34 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+import java.nio.ByteBuffer;
+
+public interface EventListener {
+ public void onEvent(Node node,Event event, ByteBuffer buffer);
+}
diff --git a/java/src/com/zerotierone/sdk/MulticastGroup.java b/java/src/com/zerotierone/sdk/MulticastGroup.java
new file mode 100644
index 00000000..89ba206f
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/MulticastGroup.java
@@ -0,0 +1,35 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+
+public class MulticastGroup {
+ private MulticastGroup() {}
+
+ private long mac;
+ private long adi;
+}
diff --git a/java/src/com/zerotierone/sdk/Node.java b/java/src/com/zerotierone/sdk/Node.java
new file mode 100644
index 00000000..34a67cb7
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/Node.java
@@ -0,0 +1,235 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+import java.nio.ByteBuffer;
+import java.lang.Long;
+import java.net.InetAddress;
+import java.util.ArrayList;
+
+public class Node {
+ static {
+ System.loadLibrary("ZeroTierOneJNI");
+ }
+
+ private static final String TAG = "NODE";
+
+ /**
+ * Node ID for JNI purposes.
+ * Currently set to the now value passed in at the constructor
+ *
+ * -1 if the node has already been closed
+ */
+ private long nodeId;
+
+ private final DataStoreGetListener getListener;
+ private final DataStorePutListener putListener;
+ private final PacketSender sender;
+ private final VirtualNetworkFrameListener frameListener;
+ private final VirtualNetworkConfigListener configListener;
+
+ public Node(long now,
+ DataStoreGetListener getListener,
+ DataStorePutListener putListener,
+ PacketSender sender,
+ VirtualNetworkFrameListener frameListener,
+ VirtualNetworkConfigListener configListener)
+ {
+ this.nodeId = now;
+
+ this.getListener = getListener;
+ this.putListener = putListener;
+ this.sender = sender;
+ this.frameListener = frameListener;
+ this.configListener = configListener;
+
+ ResultCode rc = node_init(now);
+ if(rc != ResultCode.RESULT_OK)
+ {
+ // TODO: Throw Exception
+ }
+ }
+
+ public void close() {
+ if(nodeId != -1) {
+ node_delete(nodeId);
+ nodeId = -1;
+ }
+ }
+
+ @Override
+ protected void finalize() {
+ close();
+ }
+
+ public ResultCode processVirtualNetworkFrame(
+ long now,
+ long nwid,
+ long sourceMac,
+ long destMac,
+ int etherType,
+ int vlanId,
+ byte[] frameData,
+ long[] nextBackgroundTaskDeadline) {
+ return processVirtualNetworkFrame(
+ nodeId, now, nwid, sourceMac, destMac, etherType, vlanId,
+ frameData, nextBackgroundTaskDeadline);
+ }
+
+ public ResultCode processWirePacket(
+ long now,
+ InetAddress remoteAddress,
+ int linkDesperation,
+ byte[] packetData,
+ long[] nextBackgroundTaskDeadline) {
+ return processWirePacket(
+ nodeId, now, remoteAddress, linkDesperation, packetData,
+ nextBackgroundTaskDeadline);
+ }
+
+ public ResultCode processBackgroundTasks(long now, long[] nextBackgroundTaskDeadline) {
+ return processBackgroundTasks(nodeId, now, nextBackgroundTaskDeadline);
+ }
+
+ public ResultCode join(long nwid) {
+ return join(nodeId, nwid);
+ }
+
+ public ResultCode leave(long nwid) {
+ return leave(nodeId, nwid);
+ }
+
+ public ResultCode multicastSubscribe(
+ long nwid,
+ long multicastGroup) {
+ return multicastSubscribe(nodeId, nwid, multicastGroup, 0);
+ }
+
+ public ResultCode multicastSubscribe(
+ long nwid,
+ long multicastGroup,
+ long multicastAdi) {
+ return multicastSubscribe(nodeId, nwid, multicastGroup, multicastAdi);
+ }
+
+ public ResultCode multicastUnsubscribe(
+ long nwid,
+ long multicastGroup) {
+ return multicastUnsubscribe(nodeId, nwid, multicastGroup, 0);
+ }
+
+ public ResultCode multicastUnsubscribe(
+ long nwid,
+ long multicastGroup,
+ long multicastAdi) {
+ return multicastUnsubscribe(nodeId, nwid, multicastGroup, multicastAdi);
+ }
+
+ public long address() {
+ return address(nodeId);
+ }
+
+ public NodeStatus status() {
+ return status(nodeId);
+ }
+
+ public ArrayList<Peer> peers() {
+ return peers(nodeId);
+ }
+
+ public VirtualNetworkConfig networkConfig(long nwid) {
+ return networkConfig(nodeId, nwid);
+ }
+
+ public ArrayList<VirtualNetworkConfig> networks() {
+ return networks(nodeId);
+ }
+
+ public Version getVersion() {
+ return version();
+ }
+
+ /**
+ * function declarations for JNI
+ */
+ private native ResultCode node_init(long now);
+
+ private native void node_delete(long nodeId);
+
+ private native ResultCode processVirtualNetworkFrame(
+ long nodeId,
+ long now,
+ long nwid,
+ long sourceMac,
+ long destMac,
+ int etherType,
+ int vlanId,
+ byte[] frameData,
+ long[] nextBackgroundTaskDeadline);
+
+ private native ResultCode processWirePacket(
+ long nodeId,
+ long now,
+ InetAddress remoteAddress,
+ int linkDesperation,
+ byte[] packetData,
+ long[] nextBackgroundTaskDeadline);
+
+ private native ResultCode processBackgroundTasks(
+ long nodeId,
+ long now,
+ long[] nextBackgroundTaskDeadline);
+
+ private native ResultCode join(long nodeId, long nwid);
+
+ private native ResultCode leave(long nodeId, long nwid);
+
+ private native ResultCode multicastSubscribe(
+ long nodeId,
+ long nwid,
+ long multicastGroup,
+ long multicastAdi);
+
+ private native ResultCode multicastUnsubscribe(
+ long nodeId,
+ long nwid,
+ long multicastGroup,
+ long multicastAdi);
+
+ private native long address(long nodeId);
+
+ private native NodeStatus status(long nodeId);
+
+ private native VirtualNetworkConfig networkConfig(long nodeId, long nwid);
+
+ private native Version version();
+
+ private native ArrayList<Peer> peers(long nodeId);
+
+ private native ArrayList<VirtualNetworkConfig> networks(long nodeId);
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/NodeStatus.java b/java/src/com/zerotierone/sdk/NodeStatus.java
new file mode 100644
index 00000000..fdf5284e
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/NodeStatus.java
@@ -0,0 +1,53 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+public class NodeStatus {
+ private long address;
+ private String publicIdentity;
+ private String secretIdentity;
+ private boolean online;
+
+ private NodeStatus() {}
+
+ public final long getAddres() {
+ return address;
+ }
+
+ public final String getPublicIdentity() {
+ return publicIdentity;
+ }
+
+ public final String getSecretIdentity() {
+ return secretIdentity;
+ }
+
+ public final boolean isOnline() {
+ return online;
+ }
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/PacketSender.java b/java/src/com/zerotierone/sdk/PacketSender.java
new file mode 100644
index 00000000..0e007ffb
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/PacketSender.java
@@ -0,0 +1,38 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+import java.nio.ByteBuffer;
+
+
+public interface PacketSender {
+ public int onSendPacketRequested(Node node,
+ String addr,
+ int linkDesc,
+ ByteBuffer packetData,
+ long dataLength);
+}
diff --git a/java/src/com/zerotierone/sdk/Peer.java b/java/src/com/zerotierone/sdk/Peer.java
new file mode 100644
index 00000000..cd2268b4
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/Peer.java
@@ -0,0 +1,80 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+import java.util.ArrayList;
+
+public class Peer {
+ private long address;
+ private long lastUnicastFrame;
+ private long lastMulticastFrame;
+ private int versionMajor;
+ private int versionMinor;
+ private int versionRev;
+ private int latency;
+ private PeerRole role;
+ private ArrayList<PhysicalPeerPath> paths;
+
+ private Peer() {}
+
+ public final long address() {
+ return address;
+ }
+
+ public final long lastUnicastFrame() {
+ return lastUnicastFrame;
+ }
+
+ public final long lastMulticastFrame() {
+ return lastMulticastFrame;
+ }
+
+ public final int versionMajor() {
+ return versionMajor;
+ }
+
+ public final int versionMinor() {
+ return versionMinor;
+ }
+
+ public final int versionRev() {
+ return versionRev;
+ }
+
+ public final int latency() {
+ return latency;
+ }
+
+ public final PeerRole role() {
+ return role;
+ }
+
+ public final ArrayList<PhysicalPeerPath> paths() {
+ return paths;
+ }
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/PeerRole.java b/java/src/com/zerotierone/sdk/PeerRole.java
new file mode 100644
index 00000000..979b1a98
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/PeerRole.java
@@ -0,0 +1,34 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+public enum PeerRole {
+ PEER_ROLE_LEAF,
+ PEER_ROLE_HUB,
+ PEER_ROLE_SUPERNODE
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/PhysicalPeerPath.java b/java/src/com/zerotierone/sdk/PhysicalPeerPath.java
new file mode 100644
index 00000000..1eb69f65
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/PhysicalPeerPath.java
@@ -0,0 +1,65 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+import java.net.InetAddress;
+
+public class PhysicalPeerPath {
+ private InetAddress address;
+ private long lastSend;
+ private long lastReceive;
+ private boolean fixed;
+ private boolean active;
+ private boolean preferred;
+
+ private PhysicalPeerPath() {}
+
+ public final InetAddress address() {
+ return address;
+ }
+
+ public final long lastSend() {
+ return lastSend;
+ }
+
+ public final long lastReceive() {
+ return lastReceive;
+ }
+
+ public final boolean isFixed() {
+ return fixed;
+ }
+
+ public final boolean isActive() {
+ return active;
+ }
+
+ public final boolean isPreferred() {
+ return preferred;
+ }
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/ResultCode.java b/java/src/com/zerotierone/sdk/ResultCode.java
new file mode 100644
index 00000000..7597c0f2
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/ResultCode.java
@@ -0,0 +1,45 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+public enum ResultCode {
+
+ RESULT_OK(0),
+ RESULT_FATAL_ERROR_OUT_OF_MEMORY(1),
+ RESULT_FATAL_ERROR_DATA_STORE_FAILED(2),
+ RESULT_FATAL_ERROR_INTERNAL(3),
+ RESULT_ERROR_NETWORK_NOT_FOUND(1000);
+
+ private final int id;
+ ResultCode(int id) { this.id = id; }
+ public int getValue() { return id; }
+
+ public boolean isFatal(int id) {
+ return (id > 0 && id < 1000);
+ }
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/Version.java b/java/src/com/zerotierone/sdk/Version.java
new file mode 100644
index 00000000..abdaab9e
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/Version.java
@@ -0,0 +1,37 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+public class Version {
+ public Version() {}
+
+ public int major = 0;
+ public int minor = 0;
+ public int revision = 0;
+ public long featureFlags = 0;
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/VirtualNetworkConfig.java b/java/src/com/zerotierone/sdk/VirtualNetworkConfig.java
new file mode 100644
index 00000000..5e06b55f
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/VirtualNetworkConfig.java
@@ -0,0 +1,111 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+package com.zerotierone.sdk;
+
+import java.lang.String;
+import java.util.ArrayList;
+import java.net.InetAddress;
+
+public class VirtualNetworkConfig {
+ public static final int MAX_MULTICAST_SUBSCRIPTIONS = 4096;
+ public static final int ZT1_MAX_ZT_ASSIGNED_ADDRESSES = 16;
+
+ private long nwid;
+ private long mac;
+ private String name;
+ private VirtualNetworkStatus status;
+ private VirtualNetworkType type;
+ private int mtu;
+ private boolean dhcp;
+ private boolean bridge;
+ private boolean broadcastEnabled;
+ private boolean portError;
+ private boolean enabled;
+ private long netconfRevision;
+ private ArrayList<MulticastGroup> multicastSubscriptions;
+ private ArrayList<InetAddress> assignedAddresses;
+
+ private VirtualNetworkConfig() {
+
+ }
+
+ public final long networkId() {
+ return nwid;
+ }
+ public final long macAddress() {
+ return mac;
+ }
+
+ public final String name() {
+ return name;
+ }
+
+ public final VirtualNetworkStatus networkStatus() {
+ return status;
+ }
+
+ public final VirtualNetworkType networkType() {
+ return type;
+ }
+
+ public final int mtu() {
+ return mtu;
+ }
+
+ public final boolean isDhcpAvailable() {
+ return dhcp;
+ }
+
+ public final boolean isBridgeEnabled() {
+ return bridge;
+ }
+
+ public final boolean broadcastEnabled() {
+ return broadcastEnabled;
+ }
+
+ public final boolean portError() {
+ return portError;
+ }
+
+ public final boolean isEnabled() {
+ return enabled;
+ }
+
+ public final long netconfRevision() {
+ return netconfRevision;
+ }
+
+ public final ArrayList<MulticastGroup> multicastSubscriptions() {
+ return multicastSubscriptions;
+ }
+
+ public final ArrayList<InetAddress> assignedAddresses() {
+ return assignedAddresses;
+ }
+}
diff --git a/java/src/com/zerotierone/sdk/VirtualNetworkConfigListener.java b/java/src/com/zerotierone/sdk/VirtualNetworkConfigListener.java
new file mode 100644
index 00000000..78d11987
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/VirtualNetworkConfigListener.java
@@ -0,0 +1,38 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+
+package com.zerotierone.sdk;
+
+
+public interface VirtualNetworkConfigListener {
+ public void onNetworkConfigurationUpdated(
+ Node node,
+ long someValue,
+ VirtualNetworkConfigOperation op,
+ VirtualNetworkConfig config);
+} \ No newline at end of file
diff --git a/java/src/com/zerotierone/sdk/VirtualNetworkConfigOperation.java b/java/src/com/zerotierone/sdk/VirtualNetworkConfigOperation.java
new file mode 100644
index 00000000..2bf6ce09
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/VirtualNetworkConfigOperation.java
@@ -0,0 +1,34 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+public enum VirtualNetworkConfigOperation {
+ VIRTUAL_NETWORK_CONFIG_OPERATION_UP,
+ VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE,
+ VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN,
+ VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY
+}
diff --git a/java/src/com/zerotierone/sdk/VirtualNetworkFrameListener.java b/java/src/com/zerotierone/sdk/VirtualNetworkFrameListener.java
new file mode 100644
index 00000000..fed5d95c
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/VirtualNetworkFrameListener.java
@@ -0,0 +1,40 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+import java.nio.ByteBuffer;
+
+public interface VirtualNetworkFrameListener {
+ void onVirtualNetworkFrame(Node node,
+ long nwid,
+ long srcMac,
+ long destMac,
+ long etherType,
+ long vlanId,
+ ByteBuffer frameData,
+ long len);
+}
diff --git a/java/src/com/zerotierone/sdk/VirtualNetworkStatus.java b/java/src/com/zerotierone/sdk/VirtualNetworkStatus.java
new file mode 100644
index 00000000..1102d2ea
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/VirtualNetworkStatus.java
@@ -0,0 +1,36 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+public enum VirtualNetworkStatus {
+ NETWORK_STATUS_REQUESTING_CONFIGURATION,
+ NETWORK_STATUS_OK,
+ NETWORK_STATUS_ACCESS_DENIED,
+ NETWORK_STATUS_NOT_FOUND,
+ NETWORK_STATUS_PORT_ERROR,
+ NETWORK_STATUS_CLIENT_TOO_OLD
+}
diff --git a/java/src/com/zerotierone/sdk/VirtualNetworkType.java b/java/src/com/zerotierone/sdk/VirtualNetworkType.java
new file mode 100644
index 00000000..b4a8ce2f
--- /dev/null
+++ b/java/src/com/zerotierone/sdk/VirtualNetworkType.java
@@ -0,0 +1,32 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package com.zerotierone.sdk;
+
+public enum VirtualNetworkType {
+ NETWORK_TYPE_PRIVATE,
+ NETWORK_TYPE_PUBLIC
+}