From b84dba3ecb2f750f5b5fda39544e20f741f961a4 Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Wed, 3 Jun 2015 21:29:07 -0700
Subject: more logging
---
java/jni/com_zerotierone_sdk_Node.cpp | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
(limited to 'java/jni')
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
index f0405813..c84524fa 100644
--- a/java/jni/com_zerotierone_sdk_Node.cpp
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -416,10 +416,15 @@ namespace {
{
// set operation
jbyteArray bufferObj = env->NewByteArray(bufferSize);
+ if(env->ExceptionCheck() || bufferObj == NULL)
+ {
+ LOGE("Error creating byte array buffer!");
+ return -4;
+ }
+
env->SetByteArrayRegion(bufferObj, 0, bufferSize, (jbyte*)buffer);
bool bsecure = secure != 0;
-
return env->CallIntMethod(ref->dataStorePutListener,
dataStorePutCallbackMethod,
nameStr, bufferObj, bsecure);
@@ -736,12 +741,14 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
if(node == NULL)
{
// cannot find valid node. We should never get here.
+ LOGE("Couldn't find a valid node!");
return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
}
unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline);
if(nbtd_len < 1)
{
+ LOGE("nbtd_len < 1");
return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
}
@@ -751,6 +758,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
jclass inetAddressClass = cache.findClass("java/net/InetAddress");
if(inetAddressClass == NULL)
{
+ LOGE("Can't find InetAddress class");
// can't find java.net.InetAddress
return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
}
@@ -849,6 +857,10 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
packetData,
packetLength,
&nextBackgroundTaskDeadline);
+ if(rc != ZT1_RESULT_OK)
+ {
+ LOGE("ZT1_Node_processWirePacket returned: %d", rc);
+ }
jlong *outDeadline = env->GetLongArrayElements(out_nextBackgroundTaskDeadline, NULL);
outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
--
cgit v1.2.3
From 7cc64c5cb69f2962d32ca41f6dc12499964d22a7 Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Wed, 3 Jun 2015 21:29:19 -0700
Subject: Might help to set the enabled field on a VirtualNetworkConfig object
:)
---
java/jni/ZT1_jniutils.cpp | 1 +
1 file changed, 1 insertion(+)
(limited to 'java/jni')
diff --git a/java/jni/ZT1_jniutils.cpp b/java/jni/ZT1_jniutils.cpp
index e6404e87..36f68f9e 100644
--- a/java/jni/ZT1_jniutils.cpp
+++ b/java/jni/ZT1_jniutils.cpp
@@ -822,6 +822,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
env->SetBooleanField(vnetConfigObj, dhcpField, vnetConfig.dhcp);
env->SetBooleanField(vnetConfigObj, bridgeField, vnetConfig.bridge);
env->SetBooleanField(vnetConfigObj, broadcastEnabledField, vnetConfig.broadcastEnabled);
+ env->SetBooleanField(vnetConfigObj, enabledField, vnetConfig.enabled);
env->SetIntField(vnetConfigObj, portErrorField, vnetConfig.portError);
jclass multicastGroupClass = cache.findClass("com/zerotier/sdk/MulticastGroup");
--
cgit v1.2.3
From ced040c5033bd61a963e65e8e8525459c4b8b59d Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Tue, 9 Jun 2015 19:38:05 -0700
Subject: Logging and adding .equals() methods to MulticastGroup and
VirtualNetworkCofnig
---
java/jni/ZT1_jniutils.cpp | 10 +++---
java/jni/com_zerotierone_sdk_Node.cpp | 12 ++++---
java/src/com/zerotier/sdk/MulticastGroup.java | 4 +++
.../src/com/zerotier/sdk/VirtualNetworkConfig.java | 38 ++++++++++++++++++++++
4 files changed, 54 insertions(+), 10 deletions(-)
(limited to 'java/jni')
diff --git a/java/jni/ZT1_jniutils.cpp b/java/jni/ZT1_jniutils.cpp
index 36f68f9e..1e8a48bf 100644
--- a/java/jni/ZT1_jniutils.cpp
+++ b/java/jni/ZT1_jniutils.cpp
@@ -343,18 +343,18 @@ jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr)
{
case AF_INET6:
{
- LOGD("IPV6 Address");
+ LOGV("IPV6 Address");
sockaddr_in6 *ipv6 = (sockaddr_in6*)&addr;
port = ntohs(ipv6->sin6_port);
- LOGD("Port %d", port);
+ LOGV("Port %d", port);
}
break;
case AF_INET:
{
- LOGD("IPV4 Address");
+ LOGV("IPV4 Address");
sockaddr_in *ipv4 = (sockaddr_in*)&addr;
port = ntohs(ipv4->sin_port);
- LOGD("Port: %d", port);
+ LOGV("Port: %d", port);
}
break;
default:
@@ -818,7 +818,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
}
env->SetObjectField(vnetConfigObj, typeField, typeObject);
- env->SetIntField(vnetConfigObj, mtuField, vnetConfig.mtu);
+ env->SetIntField(vnetConfigObj, mtuField, (int)vnetConfig.mtu);
env->SetBooleanField(vnetConfigObj, dhcpField, vnetConfig.dhcp);
env->SetBooleanField(vnetConfigObj, bridgeField, vnetConfig.bridge);
env->SetBooleanField(vnetConfigObj, broadcastEnabledField, vnetConfig.broadcastEnabled);
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
index c84524fa..2a90bb85 100644
--- a/java/jni/com_zerotierone_sdk_Node.cpp
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -92,7 +92,7 @@ namespace {
enum ZT1_VirtualNetworkConfigOperation operation,
const ZT1_VirtualNetworkConfig *config)
{
- LOGD("VritualNetworkConfigFunctionCallback");
+ LOGV("VritualNetworkConfigFunctionCallback");
JniRef *ref = (JniRef*)userData;
JNIEnv *env = NULL;
ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
@@ -142,7 +142,9 @@ namespace {
const void *frameData,
unsigned int frameLength)
{
- LOGD("VirtualNetworkFrameFunctionCallback");
+ LOGV("VirtualNetworkFrameFunctionCallback");
+ unsigned char* local = (unsigned char*)frameData;
+ LOGV("Type Bytes: 0x%02x%02x", local[12], local[13]);
JniRef *ref = (JniRef*)userData;
assert(ref->node == node);
JNIEnv *env = NULL;
@@ -188,7 +190,7 @@ namespace {
void EventCallback(ZT1_Node *node,void *userData,enum ZT1_Event event, const void *data)
{
- LOGD("EventCallback");
+ LOGV("EventCallback");
JniRef *ref = (JniRef*)userData;
assert(ref->node == node);
JNIEnv *env = NULL;
@@ -436,7 +438,7 @@ namespace {
const void *buffer,
unsigned int bufferSize)
{
- LOGD("WirePacketSendFunction(%p, %p, %d)", address, buffer, bufferSize);
+ LOGV("WirePacketSendFunction(%p, %p, %d)", address, buffer, bufferSize);
JniRef *ref = (JniRef*)userData;
assert(ref->node == node);
@@ -464,7 +466,7 @@ namespace {
env->SetByteArrayRegion(bufferObj, 0, bufferSize, (jbyte*)buffer);
int retval = env->CallIntMethod(ref->packetSender, packetSenderCallbackMethod, addressObj, bufferObj);
- LOGD("JNI Packet Sender returned: %d", retval);
+ LOGV("JNI Packet Sender returned: %d", retval);
return retval;
}
diff --git a/java/src/com/zerotier/sdk/MulticastGroup.java b/java/src/com/zerotier/sdk/MulticastGroup.java
index 5c4df87a..68114424 100644
--- a/java/src/com/zerotier/sdk/MulticastGroup.java
+++ b/java/src/com/zerotier/sdk/MulticastGroup.java
@@ -33,6 +33,10 @@ public final class MulticastGroup {
private long mac;
private long adi;
+ public boolean equals(MulticastGroup other) {
+ return mac == other.mac && adi == other.adi;
+ }
+
/**
* MAC address (least significant 48 bits)
*/
diff --git a/java/src/com/zerotier/sdk/VirtualNetworkConfig.java b/java/src/com/zerotier/sdk/VirtualNetworkConfig.java
index 2be03acb..35453ddc 100644
--- a/java/src/com/zerotier/sdk/VirtualNetworkConfig.java
+++ b/java/src/com/zerotier/sdk/VirtualNetworkConfig.java
@@ -54,6 +54,44 @@ public final class VirtualNetworkConfig {
}
+ public boolean equals(VirtualNetworkConfig cfg) {
+ boolean mcgEqual = true;
+ if(multicastSubscriptions.length == cfg.multicastSubscriptions.length) {
+ for(int i = 0; i < multicastSubscriptions.length; ++i) {
+ if(!multicastSubscriptions[i].equals(cfg.multicastSubscriptions[i]))
+ {
+ return false;
+ }
+ }
+ } else {
+ mcgEqual = false;
+ }
+
+ boolean aaEqual = true;
+ if(assignedAddresses.length == cfg.assignedAddresses.length) {
+ for(int i = 0; i < assignedAddresses.length; ++i) {
+ if(!assignedAddresses[i].equals(cfg.assignedAddresses[i])) {
+ return false;
+ }
+ }
+ } else {
+ aaEqual = false;
+ }
+
+ return nwid == cfg.nwid &&
+ mac == cfg.mac &&
+ name.equals(cfg.name) &&
+ status.equals(cfg.status) &&
+ type.equals(cfg.type) &&
+ mtu == cfg.mtu &&
+ dhcp == cfg.dhcp &&
+ bridge == cfg.bridge &&
+ broadcastEnabled == cfg.broadcastEnabled &&
+ portError == cfg.portError &&
+ enabled == cfg.enabled &&
+ mcgEqual && aaEqual;
+ }
+
/**
* 64-bit ZeroTier network ID
*/
--
cgit v1.2.3
From 4dc0ff8f13a2a5d852cda9302632d58b25d045ac Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Tue, 9 Jun 2015 23:12:44 -0700
Subject: Replace calls to GetArrayElements with
GetPrimitiveArrayCritical.
This puts code accessing the data in a critical section so that the GC cannot run while JNI has access to the array. This helps with stability somewhat, but I'm still getting some crashes in the GC
---
java/jni/com_zerotierone_sdk_Node.cpp | 54 +++++++++++++++++++----------------
1 file changed, 29 insertions(+), 25 deletions(-)
(limited to 'java/jni')
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
index 2a90bb85..62fbba89 100644
--- a/java/jni/com_zerotierone_sdk_Node.cpp
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -174,9 +174,9 @@ namespace {
return;
}
- jbyte *data = env->GetByteArrayElements(dataArray, NULL);
+ void *data = env->GetPrimitiveArrayCritical(dataArray, NULL);
memcpy(data, frameData, frameLength);
- env->ReleaseByteArrayElements(dataArray, data, 0);
+ env->ReleasePrimitiveArrayCritical(dataArray, data, 0);
if(env->ExceptionCheck())
{
@@ -356,13 +356,13 @@ namespace {
if(retval > 0)
{
- jbyte *data = env->GetByteArrayElements(bufferObj, NULL);
+ void *data = env->GetPrimitiveArrayCritical(bufferObj, NULL);
memcpy(buffer, data, retval);
- env->ReleaseByteArrayElements(bufferObj, data, JNI_ABORT);
+ env->ReleasePrimitiveArrayCritical(bufferObj, data, 0);
- jlong *objSize = env->GetLongArrayElements(objectSizeObj, NULL);
+ jlong *objSize = (jlong*)env->GetPrimitiveArrayCritical(objectSizeObj, NULL);
*out_objectSize = (unsigned long)objSize[0];
- env->ReleaseLongArrayElements(objectSizeObj, objSize, JNI_ABORT);
+ env->ReleasePrimitiveArrayCritical(objectSizeObj, objSize, 0);
}
LOGI("Out Object Size: %lu", *out_objectSize);
@@ -700,7 +700,10 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processVirtualNetworkFrame(
unsigned int vlanId = (unsigned int)in_vlanId;
unsigned int frameLength = env->GetArrayLength(in_frameData);
- jbyte *frameData =env->GetByteArrayElements(in_frameData, NULL);
+ void *frameData = env->GetPrimitiveArrayCritical(in_frameData, NULL);
+ void *localData = malloc(frameLength);
+ memcpy(localData, frameData, frameLength);
+ env->ReleasePrimitiveArrayCritical(in_frameData, frameData, 0);
uint64_t nextBackgroundTaskDeadline = 0;
@@ -712,15 +715,15 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processVirtualNetworkFrame(
destMac,
etherType,
vlanId,
- (const void*)frameData,
+ (const void*)localData,
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);
+ jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL);
+ outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
+ env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0);
return createResultObject(env, rc);
}
@@ -816,8 +819,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
unsigned int addrSize = env->GetArrayLength(addressArray);
// get the address bytes
- jbyte *addr = env->GetByteArrayElements(addressArray, NULL);
-
+ jbyte *addr = (jbyte*)env->GetPrimitiveArrayCritical(addressArray, NULL);
sockaddr_storage remoteAddress = {};
@@ -842,13 +844,16 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
else
{
// unknown address type
- env->ReleaseByteArrayElements(addressArray, addr, 0);
+ env->ReleasePrimitiveArrayCritical(addressArray, addr, 0);
return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
}
-
+ env->ReleasePrimitiveArrayCritical(addressArray, addr, 0);
unsigned int packetLength = env->GetArrayLength(in_packetData);
- jbyte *packetData = env->GetByteArrayElements(in_packetData, NULL);
+ void *packetData = env->GetPrimitiveArrayCritical(in_packetData, NULL);
+ void *localData = malloc(packetLength);
+ memcpy(localData, packetData, packetLength);
+ env->ReleasePrimitiveArrayCritical(in_packetData, packetData, 0);
uint64_t nextBackgroundTaskDeadline = 0;
@@ -856,7 +861,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
node,
now,
&remoteAddress,
- packetData,
+ localData,
packetLength,
&nextBackgroundTaskDeadline);
if(rc != ZT1_RESULT_OK)
@@ -864,12 +869,11 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
LOGE("ZT1_Node_processWirePacket returned: %d", rc);
}
- jlong *outDeadline = env->GetLongArrayElements(out_nextBackgroundTaskDeadline, NULL);
- outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
- env->ReleaseLongArrayElements(out_nextBackgroundTaskDeadline, outDeadline, 0);
+ free(localData);
- env->ReleaseByteArrayElements(addressArray, addr, 0);
- env->ReleaseByteArrayElements(in_packetData, packetData, 0);
+ jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL);
+ outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
+ env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0);
return createResultObject(env, rc);
}
@@ -904,9 +908,9 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processBackgroundTasks(
ZT1_ResultCode rc = ZT1_Node_processBackgroundTasks(node, now, &nextBackgroundTaskDeadline);
- jlong *outDeadline = env->GetLongArrayElements(out_nextBackgroundTaskDeadline, NULL);
+ jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL);
outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
- env->ReleaseLongArrayElements(out_nextBackgroundTaskDeadline, outDeadline, 0);
+ env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0);
return createResultObject(env, rc);
}
--
cgit v1.2.3
From 6889fcfc28ad7df236e9883c17d73c9badb8edd5 Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Tue, 9 Jun 2015 23:24:47 -0700
Subject: Looks like it was the JNI cash causing the crash.
Forcing it to look up classes and methods instead of caching them stopped the crashes in the GC. Will investigate more later.
---
java/jni/ZT1_jnicache.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'java/jni')
diff --git a/java/jni/ZT1_jnicache.cpp b/java/jni/ZT1_jnicache.cpp
index 8d6305cb..4deec61f 100644
--- a/java/jni/ZT1_jnicache.cpp
+++ b/java/jni/ZT1_jnicache.cpp
@@ -111,7 +111,7 @@ jclass JniCache::findClass(const std::string &name)
jclass cls = (jclass)env->NewGlobalRef(localCls);
- m_classes.insert(std::make_pair(name, cls));
+ //m_classes.insert(std::make_pair(name, cls));
return cls;
}
@@ -143,7 +143,7 @@ jmethodID JniCache::findMethod(jclass cls, const std::string &methodName, const
return NULL;
}
- m_methods.insert(std::make_pair(id, mid));
+ //m_methods.insert(std::make_pair(id, mid));
return mid;
}
@@ -173,7 +173,7 @@ jmethodID JniCache::findStaticMethod(jclass cls, const std::string &methodName,
return NULL;
}
- m_staticMethods.insert(std::make_pair(id, mid));
+ //m_staticMethods.insert(std::make_pair(id, mid));
return mid;
}
@@ -203,7 +203,7 @@ jfieldID JniCache::findField(jclass cls, const std::string &fieldName, const std
return NULL;
}
- m_fields.insert(std::make_pair(id, fid));
+ //m_fields.insert(std::make_pair(id, fid));
return fid;
}
@@ -233,7 +233,7 @@ jfieldID JniCache::findStaticField(jclass cls, const std::string &fieldName, con
return NULL;
}
- m_staticFields.insert(std::make_pair(id, fid));
+ //m_staticFields.insert(std::make_pair(id, fid));
return fid;
}
--
cgit v1.2.3
From 7e84f5a7dbb50913a78311df4f748455be0e1097 Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Tue, 9 Jun 2015 23:24:54 -0700
Subject: killing whitespace
---
java/jni/com_zerotierone_sdk_Node.cpp | 2 --
1 file changed, 2 deletions(-)
(limited to 'java/jni')
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
index 62fbba89..9516db41 100644
--- a/java/jni/com_zerotierone_sdk_Node.cpp
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -719,8 +719,6 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processVirtualNetworkFrame(
frameLength,
&nextBackgroundTaskDeadline);
-
-
jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL);
outDeadline[0] = (jlong)nextBackgroundTaskDeadline;
env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0);
--
cgit v1.2.3
From 472206dfb23e8c2d285d5cdf19ba1444d07e4d52 Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Wed, 10 Jun 2015 20:16:13 -0700
Subject: Rename JniCache to JniLookup
Removed caching capabilities as the cached methods, fields, and objects appears to be broken on Android
---
java/CMakeLists.txt | 2 +-
java/jni/Android.mk | 2 +-
java/jni/ZT1_jnicache.cpp | 242 ----------------------------------
java/jni/ZT1_jnicache.h | 65 ---------
java/jni/ZT1_jnilookup.cpp | 158 ++++++++++++++++++++++
java/jni/ZT1_jnilookup.h | 54 ++++++++
java/jni/ZT1_jniutils.cpp | 132 +++++++++----------
java/jni/com_zerotierone_sdk_Node.cpp | 68 +++++-----
8 files changed, 314 insertions(+), 409 deletions(-)
delete mode 100644 java/jni/ZT1_jnicache.cpp
delete mode 100644 java/jni/ZT1_jnicache.h
create mode 100644 java/jni/ZT1_jnilookup.cpp
create mode 100644 java/jni/ZT1_jnilookup.h
(limited to 'java/jni')
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt
index db3eec1c..382fd3cd 100644
--- a/java/CMakeLists.txt
+++ b/java/CMakeLists.txt
@@ -54,7 +54,7 @@ set(src_files
../osdep/OSUtils.cpp
jni/com_zerotierone_sdk_Node.cpp
jni/ZT1_jniutils.cpp
- jni/ZT1_jnicache.cpp
+ jni/ZT1_jnilookup.cpp
)
set(include_dirs
diff --git a/java/jni/Android.mk b/java/jni/Android.mk
index bbf14348..9986c2c3 100644
--- a/java/jni/Android.mk
+++ b/java/jni/Android.mk
@@ -39,6 +39,6 @@ LOCAL_SRC_FILES := \
LOCAL_SRC_FILES += \
com_zerotierone_sdk_Node.cpp \
ZT1_jniutils.cpp \
- ZT1_jnicache.cpp
+ ZT1_jnilookup.cpp
include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file
diff --git a/java/jni/ZT1_jnicache.cpp b/java/jni/ZT1_jnicache.cpp
deleted file mode 100644
index 4deec61f..00000000
--- a/java/jni/ZT1_jnicache.cpp
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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 .
- *
- * --
- *
- * 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 "ZT1_jnicache.h"
-#include "ZT1_jniutils.h"
-
-JniCache::JniCache()
- : m_jvm(NULL)
- , m_classes()
- , m_fields()
- , m_staticFields()
- , m_methods()
- , m_staticMethods()
-{
- LOGV("JNI Cache Created");
-}
-
-JniCache::JniCache(JavaVM *jvm)
- : m_jvm(jvm)
- , m_classes()
- , m_fields()
- , m_staticFields()
- , m_methods()
- , m_staticMethods()
-{
- LOGV("JNI Cache Created");
-}
-
-JniCache::~JniCache()
-{
- LOGV("JNI Cache Destroyed");
- clearCache();
-}
-
-void JniCache::clearCache()
-{
- if(m_jvm)
- {
- JNIEnv *env = NULL;
- if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
- return;
-
- for(ClassMap::iterator iter = m_classes.begin(), end = m_classes.end();
- iter != end; ++iter)
- {
- env->DeleteGlobalRef(iter->second);
- }
- }
-
- m_classes.clear();
- m_fields.clear();
- m_staticFields.clear();
- m_methods.clear();
- m_staticMethods.clear();
-}
-
-void JniCache::setJavaVM(JavaVM *jvm)
-{
- LOGV("Assigned JVM to object");
- m_jvm = jvm;
-}
-
-
-jclass JniCache::findClass(const std::string &name)
-{
- if(!m_jvm)
- return NULL;
-
- ClassMap::iterator found = m_classes.find(name);
-
- if(found == m_classes.end())
- {
- // get the class from the JVM
- JNIEnv *env = NULL;
- if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
- {
- LOGE("Error retreiving JNI Environment");
- return NULL;
- }
-
- jclass localCls = env->FindClass(name.c_str());
- if(env->ExceptionCheck())
- {
- LOGE("Error finding class: %s", name.c_str());
- return NULL;
- }
-
- jclass cls = (jclass)env->NewGlobalRef(localCls);
-
- //m_classes.insert(std::make_pair(name, cls));
-
- return cls;
- }
-
- LOGV("Returning cached %s", name.c_str());
- return found->second;
-}
-
-
-jmethodID JniCache::findMethod(jclass cls, const std::string &methodName, const std::string &methodSig)
-{
- if(!m_jvm)
- return NULL;
-
- std::string id = methodName + methodSig;
-
- MethodMap::iterator found = m_methods.find(id);
- if(found == m_methods.end())
- {
- JNIEnv *env = NULL;
- if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
- {
- return NULL;
- }
-
- jmethodID mid = env->GetMethodID(cls, methodName.c_str(), methodSig.c_str());
- if(env->ExceptionCheck())
- {
- return NULL;
- }
-
- //m_methods.insert(std::make_pair(id, mid));
-
- return mid;
- }
-
- return found->second;
-}
-
-jmethodID JniCache::findStaticMethod(jclass cls, const std::string &methodName, const std::string &methodSig)
-{
- if(!m_jvm)
- return NULL;
-
- std::string id = methodName + methodSig;
-
- MethodMap::iterator found = m_staticMethods.find(id);
- if(found == m_staticMethods.end())
- {
- JNIEnv *env = NULL;
- if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
- {
- return NULL;
- }
-
- jmethodID mid = env->GetStaticMethodID(cls, methodName.c_str(), methodSig.c_str());
- if(env->ExceptionCheck())
- {
- return NULL;
- }
-
- //m_staticMethods.insert(std::make_pair(id, mid));
-
- return mid;
- }
-
- return found->second;
-}
-
-jfieldID JniCache::findField(jclass cls, const std::string &fieldName, const std::string &typeStr)
-{
- if(!m_jvm)
- return NULL;
-
- std::string id = fieldName + typeStr;
-
- FieldMap::iterator found = m_fields.find(id);
- if(found == m_fields.end())
- {
- JNIEnv *env = NULL;
- if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
- {
- return NULL;
- }
-
- jfieldID fid = env->GetFieldID(cls, fieldName.c_str(), typeStr.c_str());
- if(env->ExceptionCheck())
- {
- return NULL;
- }
-
- //m_fields.insert(std::make_pair(id, fid));
-
- return fid;
- }
-
- return found->second;
-}
-
-jfieldID JniCache::findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr)
-{
- if(!m_jvm)
- return NULL;
-
- std::string id = fieldName + typeStr;
-
- FieldMap::iterator found = m_staticFields.find(id);
- if(found == m_staticFields.end())
- {
- JNIEnv *env = NULL;
- if(m_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
- {
- return NULL;
- }
-
- jfieldID fid = env->GetStaticFieldID(cls, fieldName.c_str(), typeStr.c_str());
- if(env->ExceptionCheck())
- {
- return NULL;
- }
-
- //m_staticFields.insert(std::make_pair(id, fid));
-
- return fid;
- }
-
- return found->second;
-}
\ No newline at end of file
diff --git a/java/jni/ZT1_jnicache.h b/java/jni/ZT1_jnicache.h
deleted file mode 100644
index 43f43a08..00000000
--- a/java/jni/ZT1_jnicache.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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 .
- *
- * --
- *
- * 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/
- */
-
-#ifndef ZT1_JNICACHE_H_
-#define ZT1_JNICACHE_H_
-
-#include
-#include
*/
EVENT_FATAL_ERROR_IDENTITY_COLLISION,
-
- /**
- * A more recent version was observed on the network
- *
- * Right now this is only triggered if a hub or rootserver reports a
- * more recent version, and only once. It can be used to trigger a
- * software update check.
- *
- * Meta-data: {@link Version}, more recent version number
- */
- EVENT_SAW_MORE_RECENT_VERSION,
-
- /**
- * A packet failed authentication
- *
- * Meta-data: {@link InetSocketAddress} containing origin address of packet
- */
- EVENT_AUTHENTICATION_FAILURE,
-
- /**
- * A received packet was not valid
- *
- * Meta-data: {@link InetSocketAddress} containing origin address of packet
- */
- EVENT_INVALID_PACKET,
/**
* Trace (debugging) message
diff --git a/java/src/com/zerotier/sdk/EventListener.java b/java/src/com/zerotier/sdk/EventListener.java
index bb191c1d..91050aaa 100644
--- a/java/src/com/zerotier/sdk/EventListener.java
+++ b/java/src/com/zerotier/sdk/EventListener.java
@@ -41,21 +41,6 @@ public interface EventListener {
*/
public void onEvent(Event event);
- /**
- * Callback for network error events: {@link Event.EVENT_AUTHENTICATION_FAILURE}, {link Event.EVENT_INVALID_PACKET}
- *
- * @param event {@link Event} enum
- * @param source {@link InetSocketAddress} containing the origin address of the packet
- */
- public void onNetworkError(Event event, InetSocketAddress source);
-
- /**
- * Callback when the node detects that it's out of date.
- *
- * @param newVersion {@link Version} object with the latest version of ZeroTier One
- */
- public void onOutOfDate(Version newVersion);
-
/**
* Trace messages
*
--
cgit v1.2.3
From eadeac0a42888a6f2fa53e2a802c6c4e43c055b3 Mon Sep 17 00:00:00 2001
From: Grant Limberg
Date: Tue, 3 Nov 2015 19:14:11 -0800
Subject: logging of events
---
java/jni/com_zerotierone_sdk_Node.cpp | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
(limited to 'java/jni')
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
index a4c677b7..17a9917a 100644
--- a/java/jni/com_zerotierone_sdk_Node.cpp
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -238,12 +238,32 @@ namespace {
switch(event)
{
case ZT_EVENT_UP:
+ {
+ LOGD("Event Up");
+ env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject);
+ break;
+ }
case ZT_EVENT_OFFLINE:
+ {
+ LOGD("Event Offline");
+ env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject);
+ break;
+ }
case ZT_EVENT_ONLINE:
+ {
+ LOGD("Event Online");
+ env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject);
+ break;
+ }
case ZT_EVENT_DOWN:
+ {
+ LOGD("Event Down");
+ env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject);
+ break;
+ }
case ZT_EVENT_FATAL_ERROR_IDENTITY_COLLISION:
{
- LOGV("Regular Event");
+ LOGV("Identity Collision");
// call onEvent()
env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject);
}
--
cgit v1.2.3