summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Limberg <glimberg@gmail.com>2015-07-01 20:26:14 -0700
committerGrant Limberg <glimberg@gmail.com>2015-07-01 20:26:14 -0700
commit0b7cd2f40a9502a797eff49db12f6f892e319f45 (patch)
tree94b70d11b40bbea5b7ed18b5accbcf799b14762b
parent2a2e3b80b34ea04a75458af6bb26b8c389845130 (diff)
downloadinfinitytier-0b7cd2f40a9502a797eff49db12f6f892e319f45.tar.gz
infinitytier-0b7cd2f40a9502a797eff49db12f6f892e319f45.zip
change some build settings. add a lock
-rw-r--r--java/CMakeLists.txt1
-rw-r--r--java/jni/Android.mk1
-rw-r--r--java/jni/Application.mk6
-rw-r--r--java/jni/com_zerotierone_sdk_Node.cpp23
4 files changed, 25 insertions, 6 deletions
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt
index 382fd3cd..484517f8 100644
--- a/java/CMakeLists.txt
+++ b/java/CMakeLists.txt
@@ -59,6 +59,7 @@ set(src_files
set(include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/../include/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../node/
${Java_INCLUDE_DIRS})
if(WIN32)
diff --git a/java/jni/Android.mk b/java/jni/Android.mk
index 15ba3875..56e6fb80 100644
--- a/java/jni/Android.mk
+++ b/java/jni/Android.mk
@@ -4,6 +4,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := ZeroTierOneJNI
LOCAL_C_INCLUDES := $(ZT1)/include
+LOCAL_C_INCLUDES += $(ZT1)/node
LOCAL_LDLIBS := -llog
# LOCAL_CFLAGS := -g
diff --git a/java/jni/Application.mk b/java/jni/Application.mk
index 8b6c8020..0f369730 100644
--- a/java/jni/Application.mk
+++ b/java/jni/Application.mk
@@ -1,5 +1,5 @@
-APP_ABI := armeabi armeabi-v7a arm64-v8a x86
-APP_STL := gnustl_static
-APP_CPPFLAGS += -Wall -fPIE -fstack-protector -fexceptions
+NDK_TOOLCHAIN_VERSION := clang
+APP_STL := c++_static
+APP_CPPFLAGS := -O2 -fPIE -fvectorize -Wall -fstack-protector -fexceptions -fno-strict-aliasing
APP_PLATFORM := android-14
APP_ABI := all
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp
index e8f7272b..e98342e7 100644
--- a/java/jni/com_zerotierone_sdk_Node.cpp
+++ b/java/jni/com_zerotierone_sdk_Node.cpp
@@ -30,6 +30,7 @@
#include "ZT1_jnilookup.h"
#include <ZeroTierOne.h>
+#include "Mutex.hpp"
#include <map>
#include <string>
@@ -192,9 +193,9 @@ namespace {
{
LOGV("EventCallback");
JniRef *ref = (JniRef*)userData;
- if(ref->node != node)
+ if(ref->node != node && event != ZT1_EVENT_UP)
{
- LOGE("Nodes not equal. ref->node %p, node %p", ref->node, node);
+ LOGE("Nodes not equal. ref->node %p, node %p. Event: %d", ref->node, node, event);
return;
}
JNIEnv *env = NULL;
@@ -478,9 +479,11 @@ namespace {
typedef std::map<uint64_t, JniRef*> NodeMap;
static NodeMap nodeMap;
+ ZeroTier::Mutex nodeMapMutex;
ZT1_Node* findNode(uint64_t nodeId)
{
+ ZeroTier::Mutex::Lock lock(nodeMapMutex);
NodeMap::iterator found = nodeMap.find(nodeId);
if(found != nodeMap.end())
{
@@ -633,8 +636,10 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
return resultObject;
}
+ ZeroTier::Mutex::Lock lock(nodeMapMutex);
ref->node = node;
nodeMap.insert(std::make_pair(ref->id, ref));
+
return resultObject;
}
@@ -650,7 +655,12 @@ JNIEXPORT void JNICALL Java_com_zerotier_sdk_Node_node_1delete(
LOGV("Destroying ZT1_Node struct");
uint64_t nodeId = (uint64_t)id;
- NodeMap::iterator found = nodeMap.find(nodeId);
+ NodeMap::iterator found;
+ {
+ ZeroTier::Mutex::Lock lock(nodeMapMutex);
+ found = nodeMap.find(nodeId);
+ }
+
if(found != nodeMap.end())
{
JniRef *ref = found->second;
@@ -819,6 +829,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
jbyteArray addressArray = (jbyteArray)env->CallObjectMethod(addrObject, getAddressMethod);
if(addressArray == NULL)
{
+ LOGE("Unable to call getAddress()");
// unable to call getAddress()
return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
}
@@ -849,6 +860,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
}
else
{
+ LOGE("Unknown IP version");
// unknown address type
env->ReleasePrimitiveArrayCritical(addressArray, addr, 0);
return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
@@ -856,6 +868,11 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
env->ReleasePrimitiveArrayCritical(addressArray, addr, 0);
unsigned int packetLength = env->GetArrayLength(in_packetData);
+ if(packetLength == 0)
+ {
+ LOGE("Empty packet?!?");
+ return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
+ }
void *packetData = env->GetPrimitiveArrayCritical(in_packetData, NULL);
void *localData = malloc(packetLength);
memcpy(localData, packetData, packetLength);