فهرست منبع

Rename JniCache to JniLookup

Removed caching capabilities as the cached methods, fields, and objects appears to be broken on Android
Grant Limberg 10 سال پیش
والد
کامیت
472206dfb2
7فایلهای تغییر یافته به همراه266 افزوده شده و 361 حذف شده
  1. 1 1
      java/CMakeLists.txt
  2. 1 1
      java/jni/Android.mk
  3. 0 242
      java/jni/ZT1_jnicache.cpp
  4. 158 0
      java/jni/ZT1_jnilookup.cpp
  5. 6 17
      java/jni/ZT1_jnilookup.h
  6. 66 66
      java/jni/ZT1_jniutils.cpp
  7. 34 34
      java/jni/com_zerotierone_sdk_Node.cpp

+ 1 - 1
java/CMakeLists.txt

@@ -54,7 +54,7 @@ set(src_files
     ../osdep/OSUtils.cpp
     ../osdep/OSUtils.cpp
     jni/com_zerotierone_sdk_Node.cpp
     jni/com_zerotierone_sdk_Node.cpp
     jni/ZT1_jniutils.cpp
     jni/ZT1_jniutils.cpp
-    jni/ZT1_jnicache.cpp
+    jni/ZT1_jnilookup.cpp
     )
     )
 
 
 set(include_dirs
 set(include_dirs

+ 1 - 1
java/jni/Android.mk

@@ -39,6 +39,6 @@ LOCAL_SRC_FILES := \
 LOCAL_SRC_FILES += \
 LOCAL_SRC_FILES += \
 	com_zerotierone_sdk_Node.cpp \
 	com_zerotierone_sdk_Node.cpp \
 	ZT1_jniutils.cpp \
 	ZT1_jniutils.cpp \
-	ZT1_jnicache.cpp
+	ZT1_jnilookup.cpp
 
 
 include $(BUILD_SHARED_LIBRARY)
 include $(BUILD_SHARED_LIBRARY)

+ 0 - 242
java/jni/ZT1_jnicache.cpp

@@ -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 <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 "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;
-}

+ 158 - 0
java/jni/ZT1_jnilookup.cpp

@@ -0,0 +1,158 @@
+/*
+ * 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 "ZT1_jnilookup.h"
+#include "ZT1_jniutils.h"
+
+JniLookup::JniLookup()
+    : m_jvm(NULL)
+{
+    LOGV("JNI Cache Created");
+}
+
+JniLookup::JniLookup(JavaVM *jvm)
+    : m_jvm(jvm)
+{
+    LOGV("JNI Cache Created");
+}
+
+JniLookup::~JniLookup()
+{
+    LOGV("JNI Cache Destroyed");
+}
+
+
+void JniLookup::setJavaVM(JavaVM *jvm)
+{ 
+    LOGV("Assigned JVM to object");
+    m_jvm = jvm; 
+}
+
+
+jclass JniLookup::findClass(const std::string &name)
+{
+    if(!m_jvm)
+        return NULL;
+
+    // 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 cls = env->FindClass(name.c_str());
+    if(env->ExceptionCheck())
+    {
+        LOGE("Error finding class: %s", name.c_str());
+        return NULL;
+    }
+
+    return cls;
+}
+
+
+jmethodID JniLookup::findMethod(jclass cls, const std::string &methodName, const std::string &methodSig)
+{
+    if(!m_jvm)
+        return NULL;
+
+    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;
+    }
+
+    return mid;
+}
+
+jmethodID JniLookup::findStaticMethod(jclass cls, const std::string &methodName, const std::string &methodSig)
+{
+    if(!m_jvm)
+        return NULL;
+
+    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;
+    }
+
+    return mid;
+}
+
+jfieldID JniLookup::findField(jclass cls, const std::string &fieldName, const std::string &typeStr)
+{
+    if(!m_jvm)
+        return NULL;
+
+    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;
+    }
+
+    return fid;
+}
+
+jfieldID JniLookup::findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr)
+{
+    if(!m_jvm)
+        return NULL;
+
+    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;
+    }
+
+    return fid;
+}

+ 6 - 17
java/jni/ZT1_jnicache.h → java/jni/ZT1_jnilookup.h

@@ -25,8 +25,8 @@
  * LLC. Start here: http://www.zerotier.com/
  * LLC. Start here: http://www.zerotier.com/
  */
  */
 
 
-#ifndef ZT1_JNICACHE_H_
-#define ZT1_JNICACHE_H_
+#ifndef ZT1_JNILOOKUP_H_
+#define ZT1_JNILOOKUP_H_
 
 
 #include <jni.h>
 #include <jni.h>
 #include <map>
 #include <map>
@@ -34,14 +34,13 @@
 
 
 
 
 
 
-class JniCache {
+class JniLookup {
 public:
 public:
-    JniCache();
-    JniCache(JavaVM *jvm);
-    ~JniCache();
+    JniLookup();
+    JniLookup(JavaVM *jvm);
+    ~JniLookup();
 
 
     void setJavaVM(JavaVM *jvm);
     void setJavaVM(JavaVM *jvm);
-    void clearCache();
 
 
     jclass findClass(const std::string &name);
     jclass findClass(const std::string &name);
     jmethodID findMethod(jclass cls, const std::string &methodName, const std::string &methodSig);
     jmethodID findMethod(jclass cls, const std::string &methodName, const std::string &methodSig);
@@ -49,17 +48,7 @@ public:
     jfieldID findField(jclass cls, const std::string &fieldName, const std::string &typeStr);
     jfieldID findField(jclass cls, const std::string &fieldName, const std::string &typeStr);
     jfieldID findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr);
     jfieldID findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr);
 private:
 private:
-    typedef std::map<std::string, jmethodID> MethodMap;
-    typedef std::map<std::string, jfieldID> FieldMap;
-    typedef std::map<std::string, jclass> ClassMap;
-
     JavaVM *m_jvm;
     JavaVM *m_jvm;
-    ClassMap m_classes;
-    FieldMap m_fields;
-    FieldMap m_staticFields;
-    MethodMap m_methods;
-    MethodMap m_staticMethods;
-
 };
 };
 
 
 #endif
 #endif

+ 66 - 66
java/jni/ZT1_jniutils.cpp

@@ -1,9 +1,9 @@
 #include "ZT1_jniutils.h"
 #include "ZT1_jniutils.h"
-#include "ZT1_jnicache.h"
+#include "ZT1_jnilookup.h"
 #include <string>
 #include <string>
 #include <assert.h>
 #include <assert.h>
 
 
-extern JniCache cache;
+extern JniLookup lookup;
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
@@ -15,7 +15,7 @@ jobject createResultObject(JNIEnv *env, ZT1_ResultCode code)
     
     
     jobject resultObject = NULL;
     jobject resultObject = NULL;
 
 
-    resultClass = cache.findClass("com/zerotier/sdk/ResultCode");
+    resultClass = lookup.findClass("com/zerotier/sdk/ResultCode");
     if(resultClass == NULL)
     if(resultClass == NULL)
     {
     {
         LOGE("Couldnt find ResultCode class");
         LOGE("Couldnt find ResultCode class");
@@ -48,7 +48,7 @@ jobject createResultObject(JNIEnv *env, ZT1_ResultCode code)
         break;
         break;
     }
     }
 
 
-    jfieldID enumField = cache.findStaticField(resultClass, fieldName.c_str(), "Lcom/zerotier/sdk/ResultCode;");
+    jfieldID enumField = lookup.findStaticField(resultClass, fieldName.c_str(), "Lcom/zerotier/sdk/ResultCode;");
     if(env->ExceptionCheck() || enumField == NULL) 
     if(env->ExceptionCheck() || enumField == NULL) 
     {
     {
         LOGE("Error on FindStaticField");
         LOGE("Error on FindStaticField");
@@ -68,7 +68,7 @@ jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status)
 {
 {
     jobject statusObject = NULL;
     jobject statusObject = NULL;
 
 
-    jclass statusClass = cache.findClass("com/zerotier/sdk/VirtualNetworkStatus");
+    jclass statusClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkStatus");
     if(statusClass == NULL)
     if(statusClass == NULL)
     {
     {
         return NULL; // exception thrown
         return NULL; // exception thrown
@@ -97,7 +97,7 @@ jobject createVirtualNetworkStatus(JNIEnv *env, ZT1_VirtualNetworkStatus status)
         break;
         break;
     }
     }
 
 
-    jfieldID enumField = cache.findStaticField(statusClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkStatus;");
+    jfieldID enumField = lookup.findStaticField(statusClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkStatus;");
 
 
     statusObject = env->GetStaticObjectField(statusClass, enumField);
     statusObject = env->GetStaticObjectField(statusClass, enumField);
 
 
@@ -109,7 +109,7 @@ jobject createEvent(JNIEnv *env, ZT1_Event event)
     jclass eventClass = NULL;
     jclass eventClass = NULL;
     jobject eventObject = NULL;
     jobject eventObject = NULL;
 
 
-    eventClass = cache.findClass("com/zerotier/sdk/Event");
+    eventClass = lookup.findClass("com/zerotier/sdk/Event");
     if(eventClass == NULL)
     if(eventClass == NULL)
     {
     {
         return NULL;
         return NULL;
@@ -147,7 +147,7 @@ jobject createEvent(JNIEnv *env, ZT1_Event event)
         break;
         break;
     }
     }
 
 
-    jfieldID enumField = cache.findStaticField(eventClass, fieldName.c_str(), "Lcom/zerotier/sdk/Event;");
+    jfieldID enumField = lookup.findStaticField(eventClass, fieldName.c_str(), "Lcom/zerotier/sdk/Event;");
 
 
     eventObject = env->GetStaticObjectField(eventClass, enumField);
     eventObject = env->GetStaticObjectField(eventClass, enumField);
 
 
@@ -159,7 +159,7 @@ jobject createPeerRole(JNIEnv *env, ZT1_PeerRole role)
     jclass peerRoleClass = NULL;
     jclass peerRoleClass = NULL;
     jobject peerRoleObject = NULL;
     jobject peerRoleObject = NULL;
 
 
-    peerRoleClass = cache.findClass("com/zerotier/sdk/PeerRole");
+    peerRoleClass = lookup.findClass("com/zerotier/sdk/PeerRole");
     if(peerRoleClass == NULL)
     if(peerRoleClass == NULL)
     {
     {
         return NULL;
         return NULL;
@@ -179,7 +179,7 @@ jobject createPeerRole(JNIEnv *env, ZT1_PeerRole role)
         break;
         break;
     }
     }
 
 
-    jfieldID enumField = cache.findStaticField(peerRoleClass, fieldName.c_str(), "Lcom/zerotier/sdk/PeerRole;");
+    jfieldID enumField = lookup.findStaticField(peerRoleClass, fieldName.c_str(), "Lcom/zerotier/sdk/PeerRole;");
 
 
     peerRoleObject = env->GetStaticObjectField(peerRoleClass, enumField);
     peerRoleObject = env->GetStaticObjectField(peerRoleClass, enumField);
 
 
@@ -191,7 +191,7 @@ jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type)
     jclass vntypeClass = NULL;
     jclass vntypeClass = NULL;
     jobject vntypeObject = NULL;
     jobject vntypeObject = NULL;
 
 
-    vntypeClass = cache.findClass("com/zerotier/sdk/VirtualNetworkType");
+    vntypeClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkType");
     if(env->ExceptionCheck() || vntypeClass == NULL)
     if(env->ExceptionCheck() || vntypeClass == NULL)
     {
     {
         return NULL;
         return NULL;
@@ -208,7 +208,7 @@ jobject createVirtualNetworkType(JNIEnv *env, ZT1_VirtualNetworkType type)
         break;
         break;
     }
     }
 
 
-    jfieldID enumField = cache.findStaticField(vntypeClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkType;");
+    jfieldID enumField = lookup.findStaticField(vntypeClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkType;");
     vntypeObject = env->GetStaticObjectField(vntypeClass, enumField);
     vntypeObject = env->GetStaticObjectField(vntypeClass, enumField);
     return vntypeObject;
     return vntypeObject;
 }
 }
@@ -218,7 +218,7 @@ jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT1_VirtualNetworkConfi
     jclass vnetConfigOpClass = NULL;
     jclass vnetConfigOpClass = NULL;
     jobject vnetConfigOpObject = NULL;
     jobject vnetConfigOpObject = NULL;
 
 
-    vnetConfigOpClass = cache.findClass("com/zerotier/sdk/VirtualNetworkConfigOperation");
+    vnetConfigOpClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfigOperation");
     if(env->ExceptionCheck() || vnetConfigOpClass == NULL)
     if(env->ExceptionCheck() || vnetConfigOpClass == NULL)
     {
     {
         return NULL;
         return NULL;
@@ -241,7 +241,7 @@ jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT1_VirtualNetworkConfi
         break;
         break;
     }
     }
 
 
-    jfieldID enumField = cache.findStaticField(vnetConfigOpClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;");
+    jfieldID enumField = lookup.findStaticField(vnetConfigOpClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;");
     vnetConfigOpObject = env->GetStaticObjectField(vnetConfigOpClass, enumField);
     vnetConfigOpObject = env->GetStaticObjectField(vnetConfigOpClass, enumField);
     return vnetConfigOpObject;
     return vnetConfigOpObject;
 }
 }
@@ -252,14 +252,14 @@ jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr)
     jclass inetAddressClass = NULL;
     jclass inetAddressClass = NULL;
     jmethodID inetAddress_getByAddress = NULL;
     jmethodID inetAddress_getByAddress = NULL;
 
 
-    inetAddressClass = cache.findClass("java/net/InetAddress");
+    inetAddressClass = lookup.findClass("java/net/InetAddress");
     if(env->ExceptionCheck() || inetAddressClass == NULL)
     if(env->ExceptionCheck() || inetAddressClass == NULL)
     {
     {
         LOGE("Error finding InetAddress class");
         LOGE("Error finding InetAddress class");
         return NULL;
         return NULL;
     }
     }
 
 
-    inetAddress_getByAddress = cache.findStaticMethod(
+    inetAddress_getByAddress = lookup.findStaticMethod(
         inetAddressClass, "getByAddress", "([B)Ljava/net/InetAddress;");
         inetAddressClass, "getByAddress", "([B)Ljava/net/InetAddress;");
     if(env->ExceptionCheck() || inetAddress_getByAddress == NULL)
     if(env->ExceptionCheck() || inetAddress_getByAddress == NULL)
     {
     {
@@ -315,7 +315,7 @@ jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr)
     jclass inetSocketAddressClass = NULL;
     jclass inetSocketAddressClass = NULL;
     jmethodID inetSocketAddress_constructor = NULL;
     jmethodID inetSocketAddress_constructor = NULL;
 
 
-    inetSocketAddressClass = cache.findClass("java/net/InetSocketAddress");
+    inetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress");
     if(env->ExceptionCheck() || inetSocketAddressClass == NULL)
     if(env->ExceptionCheck() || inetSocketAddressClass == NULL)
     {
     {
         LOGE("Error finding InetSocketAddress Class");
         LOGE("Error finding InetSocketAddress Class");
@@ -330,7 +330,7 @@ jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr)
         return NULL;
         return NULL;
     }
     }
 
 
-    inetSocketAddress_constructor = cache.findMethod(
+    inetSocketAddress_constructor = lookup.findMethod(
         inetSocketAddressClass, "<init>", "(Ljava/net/InetAddress;I)V");
         inetSocketAddressClass, "<init>", "(Ljava/net/InetAddress;I)V");
     if(env->ExceptionCheck() || inetSocketAddress_constructor == NULL)
     if(env->ExceptionCheck() || inetSocketAddress_constructor == NULL)
     {
     {
@@ -380,13 +380,13 @@ jobject newMulticastGroup(JNIEnv *env, const ZT1_MulticastGroup &mc)
     jfieldID macField = NULL;
     jfieldID macField = NULL;
     jfieldID adiField = NULL;
     jfieldID adiField = NULL;
 
 
-    multicastGroupClass = cache.findClass("com/zerotier/sdk/MulticastGroup");
+    multicastGroupClass = lookup.findClass("com/zerotier/sdk/MulticastGroup");
     if(env->ExceptionCheck() || multicastGroupClass == NULL)
     if(env->ExceptionCheck() || multicastGroupClass == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    multicastGroup_constructor = cache.findMethod(
+    multicastGroup_constructor = lookup.findMethod(
         multicastGroupClass, "<init>", "()V");
         multicastGroupClass, "<init>", "()V");
     if(env->ExceptionCheck() || multicastGroup_constructor == NULL)
     if(env->ExceptionCheck() || multicastGroup_constructor == NULL)
     {
     {
@@ -399,13 +399,13 @@ jobject newMulticastGroup(JNIEnv *env, const ZT1_MulticastGroup &mc)
         return NULL;
         return NULL;
     }
     }
 
 
-    macField = cache.findField(multicastGroupClass, "mac", "J");
+    macField = lookup.findField(multicastGroupClass, "mac", "J");
     if(env->ExceptionCheck() || macField == NULL)
     if(env->ExceptionCheck() || macField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    adiField = cache.findField(multicastGroupClass, "adi", "J");
+    adiField = lookup.findField(multicastGroupClass, "adi", "J");
     if(env->ExceptionCheck() || adiField == NULL)
     if(env->ExceptionCheck() || adiField == NULL)
     {
     {
         return NULL;
         return NULL;
@@ -431,56 +431,56 @@ jobject newPeerPhysicalPath(JNIEnv *env, const ZT1_PeerPhysicalPath &ppp)
 
 
     jmethodID ppp_constructor = NULL;
     jmethodID ppp_constructor = NULL;
 
 
-    pppClass = cache.findClass("com/zerotier/sdk/PeerPhysicalPath");
+    pppClass = lookup.findClass("com/zerotier/sdk/PeerPhysicalPath");
     if(env->ExceptionCheck() || pppClass == NULL)
     if(env->ExceptionCheck() || pppClass == NULL)
     {
     {
         LOGE("Error finding PeerPhysicalPath class");
         LOGE("Error finding PeerPhysicalPath class");
         return NULL;
         return NULL;
     }
     }
 
 
-    addressField = cache.findField(pppClass, "address", "Ljava/net/InetSocketAddress;");
+    addressField = lookup.findField(pppClass, "address", "Ljava/net/InetSocketAddress;");
     if(env->ExceptionCheck() || addressField == NULL)
     if(env->ExceptionCheck() || addressField == NULL)
     {
     {
         LOGE("Error finding address field");
         LOGE("Error finding address field");
         return NULL;
         return NULL;
     }
     }
 
 
-    lastSendField = cache.findField(pppClass, "lastSend", "J");
+    lastSendField = lookup.findField(pppClass, "lastSend", "J");
     if(env->ExceptionCheck() || lastSendField == NULL)
     if(env->ExceptionCheck() || lastSendField == NULL)
     {
     {
         LOGE("Error finding lastSend field");
         LOGE("Error finding lastSend field");
         return NULL;
         return NULL;
     }
     }
 
 
-    lastReceiveField = cache.findField(pppClass, "lastReceive", "J");
+    lastReceiveField = lookup.findField(pppClass, "lastReceive", "J");
     if(env->ExceptionCheck() || lastReceiveField == NULL)
     if(env->ExceptionCheck() || lastReceiveField == NULL)
     {
     {
         LOGE("Error finding lastReceive field");
         LOGE("Error finding lastReceive field");
         return NULL;
         return NULL;
     }
     }
 
 
-    fixedField = cache.findField(pppClass, "fixed", "Z");
+    fixedField = lookup.findField(pppClass, "fixed", "Z");
     if(env->ExceptionCheck() || fixedField == NULL)
     if(env->ExceptionCheck() || fixedField == NULL)
     {
     {
         LOGE("Error finding fixed field");
         LOGE("Error finding fixed field");
         return NULL;
         return NULL;
     }
     }
 
 
-    activeField = cache.findField(pppClass, "active", "Z");
+    activeField = lookup.findField(pppClass, "active", "Z");
     if(env->ExceptionCheck() || activeField == NULL)
     if(env->ExceptionCheck() || activeField == NULL)
     {
     {
         LOGE("Error finding active field");
         LOGE("Error finding active field");
         return NULL;
         return NULL;
     }
     }
 
 
-    preferredField = cache.findField(pppClass, "preferred", "Z");
+    preferredField = lookup.findField(pppClass, "preferred", "Z");
     if(env->ExceptionCheck() || preferredField == NULL)
     if(env->ExceptionCheck() || preferredField == NULL)
     {
     {
         LOGE("Error finding preferred field");
         LOGE("Error finding preferred field");
         return NULL;
         return NULL;
     }
     }
 
 
-    ppp_constructor = cache.findMethod(pppClass, "<init>", "()V");
+    ppp_constructor = lookup.findMethod(pppClass, "<init>", "()V");
     if(env->ExceptionCheck() || ppp_constructor == NULL)
     if(env->ExceptionCheck() || ppp_constructor == NULL)
     {
     {
         LOGE("Error finding PeerPhysicalPath constructor");
         LOGE("Error finding PeerPhysicalPath constructor");
@@ -532,77 +532,77 @@ jobject newPeer(JNIEnv *env, const ZT1_Peer &peer)
 
 
     jmethodID peer_constructor = NULL;
     jmethodID peer_constructor = NULL;
 
 
-    peerClass = cache.findClass("com/zerotier/sdk/Peer");
+    peerClass = lookup.findClass("com/zerotier/sdk/Peer");
     if(env->ExceptionCheck() || peerClass == NULL)
     if(env->ExceptionCheck() || peerClass == NULL)
     {
     {
         LOGE("Error finding Peer class");
         LOGE("Error finding Peer class");
         return NULL;
         return NULL;
     }
     }
 
 
-    addressField = cache.findField(peerClass, "address", "J");
+    addressField = lookup.findField(peerClass, "address", "J");
     if(env->ExceptionCheck() || addressField == NULL)
     if(env->ExceptionCheck() || addressField == NULL)
     {
     {
         LOGE("Error finding address field of Peer object");
         LOGE("Error finding address field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    lastUnicastFrameField = cache.findField(peerClass, "lastUnicastFrame", "J");
+    lastUnicastFrameField = lookup.findField(peerClass, "lastUnicastFrame", "J");
     if(env->ExceptionCheck() || lastUnicastFrameField == NULL)
     if(env->ExceptionCheck() || lastUnicastFrameField == NULL)
     {
     {
         LOGE("Error finding lastUnicastFrame field of Peer object");
         LOGE("Error finding lastUnicastFrame field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    lastMulticastFrameField = cache.findField(peerClass, "lastMulticastFrame", "J");
+    lastMulticastFrameField = lookup.findField(peerClass, "lastMulticastFrame", "J");
     if(env->ExceptionCheck() || lastMulticastFrameField == NULL)
     if(env->ExceptionCheck() || lastMulticastFrameField == NULL)
     {
     {
         LOGE("Error finding lastMulticastFrame field of Peer object");
         LOGE("Error finding lastMulticastFrame field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    versionMajorField = cache.findField(peerClass, "versionMajor", "I");
+    versionMajorField = lookup.findField(peerClass, "versionMajor", "I");
     if(env->ExceptionCheck() || versionMajorField == NULL)
     if(env->ExceptionCheck() || versionMajorField == NULL)
     {
     {
         LOGE("Error finding versionMajor field of Peer object");
         LOGE("Error finding versionMajor field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    versionMinorField = cache.findField(peerClass, "versionMinor", "I");
+    versionMinorField = lookup.findField(peerClass, "versionMinor", "I");
     if(env->ExceptionCheck() || versionMinorField == NULL)
     if(env->ExceptionCheck() || versionMinorField == NULL)
     {
     {
         LOGE("Error finding versionMinor field of Peer object");
         LOGE("Error finding versionMinor field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    versionRevField = cache.findField(peerClass, "versionRev", "I");
+    versionRevField = lookup.findField(peerClass, "versionRev", "I");
     if(env->ExceptionCheck() || versionRevField == NULL)
     if(env->ExceptionCheck() || versionRevField == NULL)
     {
     {
         LOGE("Error finding versionRev field of Peer object");
         LOGE("Error finding versionRev field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    latencyField = cache.findField(peerClass, "latency", "I");
+    latencyField = lookup.findField(peerClass, "latency", "I");
     if(env->ExceptionCheck() || latencyField == NULL)
     if(env->ExceptionCheck() || latencyField == NULL)
     {
     {
         LOGE("Error finding latency field of Peer object");
         LOGE("Error finding latency field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    roleField = cache.findField(peerClass, "role", "Lcom/zerotier/sdk/PeerRole;");
+    roleField = lookup.findField(peerClass, "role", "Lcom/zerotier/sdk/PeerRole;");
     if(env->ExceptionCheck() || roleField == NULL)
     if(env->ExceptionCheck() || roleField == NULL)
     {
     {
         LOGE("Error finding role field of Peer object");
         LOGE("Error finding role field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    pathsField = cache.findField(peerClass, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;");
+    pathsField = lookup.findField(peerClass, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;");
     if(env->ExceptionCheck() || pathsField == NULL)
     if(env->ExceptionCheck() || pathsField == NULL)
     {
     {
         LOGE("Error finding paths field of Peer object");
         LOGE("Error finding paths field of Peer object");
         return NULL;
         return NULL;
     }
     }
 
 
-    peer_constructor = cache.findMethod(peerClass, "<init>", "()V");
+    peer_constructor = lookup.findMethod(peerClass, "<init>", "()V");
     if(env->ExceptionCheck() || peer_constructor == NULL)
     if(env->ExceptionCheck() || peer_constructor == NULL)
     {
     {
         LOGE("Error finding Peer constructor");
         LOGE("Error finding Peer constructor");
@@ -625,7 +625,7 @@ jobject newPeer(JNIEnv *env, const ZT1_Peer &peer)
     env->SetIntField(peerObject, latencyField, peer.latency);
     env->SetIntField(peerObject, latencyField, peer.latency);
     env->SetObjectField(peerObject, roleField, createPeerRole(env, peer.role));
     env->SetObjectField(peerObject, roleField, createPeerRole(env, peer.role));
 
 
-    jclass peerPhysicalPathClass = cache.findClass("com/zerotier/sdk/PeerPhysicalPath");
+    jclass peerPhysicalPathClass = lookup.findClass("com/zerotier/sdk/PeerPhysicalPath");
     if(env->ExceptionCheck() || peerPhysicalPathClass == NULL)
     if(env->ExceptionCheck() || peerPhysicalPathClass == NULL)
     {
     {
         LOGE("Error finding PeerPhysicalPath class");
         LOGE("Error finding PeerPhysicalPath class");
@@ -675,14 +675,14 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
     jfieldID multicastSubscriptionsField = NULL;
     jfieldID multicastSubscriptionsField = NULL;
     jfieldID assignedAddressesField = NULL;
     jfieldID assignedAddressesField = NULL;
 
 
-    vnetConfigClass = cache.findClass("com/zerotier/sdk/VirtualNetworkConfig");
+    vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig");
     if(vnetConfigClass == NULL)
     if(vnetConfigClass == NULL)
     {
     {
         LOGE("Couldn't find com.zerotier.sdk.VirtualNetworkConfig");
         LOGE("Couldn't find com.zerotier.sdk.VirtualNetworkConfig");
         return NULL;
         return NULL;
     }
     }
 
 
-    vnetConfig_constructor = cache.findMethod(
+    vnetConfig_constructor = lookup.findMethod(
         vnetConfigClass, "<init>", "()V");
         vnetConfigClass, "<init>", "()V");
     if(env->ExceptionCheck() || vnetConfig_constructor == NULL)
     if(env->ExceptionCheck() || vnetConfig_constructor == NULL)
     {
     {
@@ -697,98 +697,98 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
         return NULL;
         return NULL;
     }
     }
 
 
-    nwidField = cache.findField(vnetConfigClass, "nwid", "J");
+    nwidField = lookup.findField(vnetConfigClass, "nwid", "J");
     if(env->ExceptionCheck() || nwidField == NULL)
     if(env->ExceptionCheck() || nwidField == NULL)
     {
     {
         LOGE("Error getting nwid field");
         LOGE("Error getting nwid field");
         return NULL;
         return NULL;
     }
     }
 
 
-    macField = cache.findField(vnetConfigClass, "mac", "J");
+    macField = lookup.findField(vnetConfigClass, "mac", "J");
     if(env->ExceptionCheck() || macField == NULL)
     if(env->ExceptionCheck() || macField == NULL)
     {
     {
         LOGE("Error getting mac field");
         LOGE("Error getting mac field");
         return NULL;
         return NULL;
     }
     }
 
 
-    nameField = cache.findField(vnetConfigClass, "name", "Ljava/lang/String;");
+    nameField = lookup.findField(vnetConfigClass, "name", "Ljava/lang/String;");
     if(env->ExceptionCheck() || nameField == NULL)
     if(env->ExceptionCheck() || nameField == NULL)
     {
     {
         LOGE("Error getting name field");
         LOGE("Error getting name field");
         return NULL;
         return NULL;
     }
     }
 
 
-    statusField = cache.findField(vnetConfigClass, "status", "Lcom/zerotier/sdk/VirtualNetworkStatus;");
+    statusField = lookup.findField(vnetConfigClass, "status", "Lcom/zerotier/sdk/VirtualNetworkStatus;");
     if(env->ExceptionCheck() || statusField == NULL)
     if(env->ExceptionCheck() || statusField == NULL)
     {
     {
         LOGE("Error getting status field");
         LOGE("Error getting status field");
         return NULL;
         return NULL;
     }
     }
 
 
-    typeField = cache.findField(vnetConfigClass, "type", "Lcom/zerotier/sdk/VirtualNetworkType;");
+    typeField = lookup.findField(vnetConfigClass, "type", "Lcom/zerotier/sdk/VirtualNetworkType;");
     if(env->ExceptionCheck() || typeField == NULL)
     if(env->ExceptionCheck() || typeField == NULL)
     {
     {
         LOGE("Error getting type field");
         LOGE("Error getting type field");
         return NULL;
         return NULL;
     }
     }
 
 
-    mtuField = cache.findField(vnetConfigClass, "mtu", "I");
+    mtuField = lookup.findField(vnetConfigClass, "mtu", "I");
     if(env->ExceptionCheck() || mtuField == NULL)
     if(env->ExceptionCheck() || mtuField == NULL)
     {
     {
         LOGE("Error getting mtu field");
         LOGE("Error getting mtu field");
         return NULL;
         return NULL;
     }
     }
 
 
-    dhcpField = cache.findField(vnetConfigClass, "dhcp", "Z");
+    dhcpField = lookup.findField(vnetConfigClass, "dhcp", "Z");
     if(env->ExceptionCheck() || dhcpField == NULL)
     if(env->ExceptionCheck() || dhcpField == NULL)
     {
     {
         LOGE("Error getting dhcp field");
         LOGE("Error getting dhcp field");
         return NULL;
         return NULL;
     }
     }
 
 
-    bridgeField = cache.findField(vnetConfigClass, "bridge", "Z");
+    bridgeField = lookup.findField(vnetConfigClass, "bridge", "Z");
     if(env->ExceptionCheck() || bridgeField == NULL)
     if(env->ExceptionCheck() || bridgeField == NULL)
     {
     {
         LOGE("Error getting bridge field");
         LOGE("Error getting bridge field");
         return NULL;
         return NULL;
     }
     }
 
 
-    broadcastEnabledField = cache.findField(vnetConfigClass, "broadcastEnabled", "Z");
+    broadcastEnabledField = lookup.findField(vnetConfigClass, "broadcastEnabled", "Z");
     if(env->ExceptionCheck() || broadcastEnabledField == NULL)
     if(env->ExceptionCheck() || broadcastEnabledField == NULL)
     {
     {
         LOGE("Error getting broadcastEnabled field");
         LOGE("Error getting broadcastEnabled field");
         return NULL;
         return NULL;
     }
     }
 
 
-    portErrorField = cache.findField(vnetConfigClass, "portError", "I");
+    portErrorField = lookup.findField(vnetConfigClass, "portError", "I");
     if(env->ExceptionCheck() || portErrorField == NULL)
     if(env->ExceptionCheck() || portErrorField == NULL)
     {
     {
         LOGE("Error getting portError field");
         LOGE("Error getting portError field");
         return NULL;
         return NULL;
     }
     }
 
 
-    enabledField = cache.findField(vnetConfigClass, "enabled", "Z");
+    enabledField = lookup.findField(vnetConfigClass, "enabled", "Z");
     if(env->ExceptionCheck() || enabledField == NULL)
     if(env->ExceptionCheck() || enabledField == NULL)
     {
     {
         LOGE("Error getting enabled field");
         LOGE("Error getting enabled field");
         return NULL;
         return NULL;
     }
     }
 
 
-    netconfRevisionField = cache.findField(vnetConfigClass, "netconfRevision", "J");
+    netconfRevisionField = lookup.findField(vnetConfigClass, "netconfRevision", "J");
     if(env->ExceptionCheck() || netconfRevisionField == NULL)
     if(env->ExceptionCheck() || netconfRevisionField == NULL)
     {
     {
         LOGE("Error getting netconfRevision field");
         LOGE("Error getting netconfRevision field");
         return NULL;
         return NULL;
     }
     }
 
 
-    multicastSubscriptionsField = cache.findField(vnetConfigClass, "multicastSubscriptions", "[Lcom/zerotier/sdk/MulticastGroup;");
+    multicastSubscriptionsField = lookup.findField(vnetConfigClass, "multicastSubscriptions", "[Lcom/zerotier/sdk/MulticastGroup;");
     if(env->ExceptionCheck() || multicastSubscriptionsField == NULL)
     if(env->ExceptionCheck() || multicastSubscriptionsField == NULL)
     {
     {
         LOGE("Error getting multicastSubscriptions field");
         LOGE("Error getting multicastSubscriptions field");
         return NULL;
         return NULL;
     }
     }
 
 
-    assignedAddressesField = cache.findField(vnetConfigClass, "assignedAddresses", "[Ljava/net/InetSocketAddress;");
+    assignedAddressesField = lookup.findField(vnetConfigClass, "assignedAddresses", "[Ljava/net/InetSocketAddress;");
     if(env->ExceptionCheck() || assignedAddressesField == NULL)
     if(env->ExceptionCheck() || assignedAddressesField == NULL)
     {
     {
         LOGE("Error getting assignedAddresses field");
         LOGE("Error getting assignedAddresses field");
@@ -825,7 +825,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
     env->SetBooleanField(vnetConfigObj, enabledField, vnetConfig.enabled);
     env->SetBooleanField(vnetConfigObj, enabledField, vnetConfig.enabled);
     env->SetIntField(vnetConfigObj, portErrorField, vnetConfig.portError);
     env->SetIntField(vnetConfigObj, portErrorField, vnetConfig.portError);
 
 
-    jclass multicastGroupClass = cache.findClass("com/zerotier/sdk/MulticastGroup");
+    jclass multicastGroupClass = lookup.findClass("com/zerotier/sdk/MulticastGroup");
     if(env->ExceptionCheck() || multicastGroupClass == NULL) 
     if(env->ExceptionCheck() || multicastGroupClass == NULL) 
     {
     {
         LOGE("Error finding MulticastGroup class");
         LOGE("Error finding MulticastGroup class");
@@ -850,7 +850,7 @@ jobject newNetworkConfig(JNIEnv *env, const ZT1_VirtualNetworkConfig &vnetConfig
     }
     }
     env->SetObjectField(vnetConfigObj, multicastSubscriptionsField, mcastSubsArrayObj);
     env->SetObjectField(vnetConfigObj, multicastSubscriptionsField, mcastSubsArrayObj);
 
 
-    jclass inetSocketAddressClass = cache.findClass("java/net/InetSocketAddress");
+    jclass inetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress");
     if(env->ExceptionCheck() || inetSocketAddressClass == NULL)
     if(env->ExceptionCheck() || inetSocketAddressClass == NULL)
     {
     {
         LOGE("Error finding InetSocketAddress class");
         LOGE("Error finding InetSocketAddress class");
@@ -887,13 +887,13 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev, long featureFlags
     jclass versionClass = NULL;
     jclass versionClass = NULL;
     jmethodID versionConstructor = NULL;
     jmethodID versionConstructor = NULL;
 
 
-    versionClass = cache.findClass("com/zerotier/sdk/Version");
+    versionClass = lookup.findClass("com/zerotier/sdk/Version");
     if(env->ExceptionCheck() || versionClass == NULL)
     if(env->ExceptionCheck() || versionClass == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    versionConstructor = cache.findMethod(
+    versionConstructor = lookup.findMethod(
         versionClass, "<init>", "()V");
         versionClass, "<init>", "()V");
     if(env->ExceptionCheck() || versionConstructor == NULL)
     if(env->ExceptionCheck() || versionConstructor == NULL)
     {
     {
@@ -912,25 +912,25 @@ jobject newVersion(JNIEnv *env, int major, int minor, int rev, long featureFlags
     jfieldID revisionField = NULL;
     jfieldID revisionField = NULL;
     jfieldID featureFlagsField = NULL;
     jfieldID featureFlagsField = NULL;
 
 
-    majorField = cache.findField(versionClass, "major", "I");
+    majorField = lookup.findField(versionClass, "major", "I");
     if(env->ExceptionCheck() || majorField == NULL)
     if(env->ExceptionCheck() || majorField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    minorField = cache.findField(versionClass, "minor", "I");
+    minorField = lookup.findField(versionClass, "minor", "I");
     if(env->ExceptionCheck() || minorField == NULL)
     if(env->ExceptionCheck() || minorField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    revisionField = cache.findField(versionClass, "revision", "I");
+    revisionField = lookup.findField(versionClass, "revision", "I");
     if(env->ExceptionCheck() || revisionField == NULL)
     if(env->ExceptionCheck() || revisionField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    featureFlagsField = cache.findField(versionClass, "featureFlags", "J");
+    featureFlagsField = lookup.findField(versionClass, "featureFlags", "J");
     if(env->ExceptionCheck() || featureFlagsField == NULL)
     if(env->ExceptionCheck() || featureFlagsField == NULL)
     {
     {
         return NULL;
         return NULL;

+ 34 - 34
java/jni/com_zerotierone_sdk_Node.cpp

@@ -27,7 +27,7 @@
 
 
 #include "com_zerotierone_sdk_Node.h"
 #include "com_zerotierone_sdk_Node.h"
 #include "ZT1_jniutils.h"
 #include "ZT1_jniutils.h"
-#include "ZT1_jnicache.h"
+#include "ZT1_jnilookup.h"
 
 
 #include <ZeroTierOne.h>
 #include <ZeroTierOne.h>
 
 
@@ -36,8 +36,8 @@
 #include <assert.h>
 #include <assert.h>
 #include <string.h>
 #include <string.h>
 
 
-// global static JNI Cache Object
-JniCache cache;
+// global static JNI Lookup Object
+JniLookup lookup;
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
@@ -104,7 +104,7 @@ namespace {
             return -1;
             return -1;
         }
         }
 
 
-        jmethodID configListenerCallbackMethod = cache.findMethod(configListenerClass,
+        jmethodID configListenerCallbackMethod = lookup.findMethod(configListenerClass,
             "onNetworkConfigurationUpdated",
             "onNetworkConfigurationUpdated",
             "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I");
             "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I");
         if(configListenerCallbackMethod == NULL)
         if(configListenerCallbackMethod == NULL)
@@ -158,7 +158,7 @@ namespace {
             return;
             return;
         }
         }
 
 
-        jmethodID frameListenerCallbackMethod = cache.findMethod(
+        jmethodID frameListenerCallbackMethod = lookup.findMethod(
             frameListenerClass,
             frameListenerClass,
             "onVirtualNetworkFrame", "(JJJJJ[B)V");
             "onVirtualNetworkFrame", "(JJJJJ[B)V");
         if(env->ExceptionCheck() || frameListenerCallbackMethod == NULL)
         if(env->ExceptionCheck() || frameListenerCallbackMethod == NULL)
@@ -204,7 +204,7 @@ namespace {
             return;
             return;
         }
         }
 
 
-        jmethodID onEventMethod = cache.findMethod(eventListenerClass,
+        jmethodID onEventMethod = lookup.findMethod(eventListenerClass,
             "onEvent", "(Lcom/zerotier/sdk/Event;)V");
             "onEvent", "(Lcom/zerotier/sdk/Event;)V");
         if(onEventMethod == NULL)
         if(onEventMethod == NULL)
         {
         {
@@ -213,7 +213,7 @@ namespace {
         }
         }
 
 
 
 
-        jmethodID onOutOfDateMethod = cache.findMethod(eventListenerClass,
+        jmethodID onOutOfDateMethod = lookup.findMethod(eventListenerClass,
             "onOutOfDate", "(Lcom/zerotier/sdk/Version;)V");
             "onOutOfDate", "(Lcom/zerotier/sdk/Version;)V");
         if(onOutOfDateMethod == NULL)
         if(onOutOfDateMethod == NULL)
         {
         {
@@ -222,7 +222,7 @@ namespace {
         }
         }
 
 
 
 
-        jmethodID onNetworkErrorMethod = cache.findMethod(eventListenerClass,
+        jmethodID onNetworkErrorMethod = lookup.findMethod(eventListenerClass,
             "onNetworkError", "(Lcom/zerotier/sdk/Event;Ljava/net/InetSocketAddress;)V");
             "onNetworkError", "(Lcom/zerotier/sdk/Event;Ljava/net/InetSocketAddress;)V");
         if(onNetworkErrorMethod == NULL)
         if(onNetworkErrorMethod == NULL)
         {
         {
@@ -231,7 +231,7 @@ namespace {
         }
         }
 
 
 
 
-        jmethodID onTraceMethod = cache.findMethod(eventListenerClass,
+        jmethodID onTraceMethod = lookup.findMethod(eventListenerClass,
             "onTrace", "(Ljava/lang/String;)V");
             "onTrace", "(Ljava/lang/String;)V");
         if(onTraceMethod == NULL)
         if(onTraceMethod == NULL)
         {
         {
@@ -316,7 +316,7 @@ namespace {
             return -2;
             return -2;
         }
         }
 
 
-        jmethodID dataStoreGetCallbackMethod = cache.findMethod(
+        jmethodID dataStoreGetCallbackMethod = lookup.findMethod(
             dataStoreGetClass,
             dataStoreGetClass,
             "onDataStoreGet",
             "onDataStoreGet",
             "(Ljava/lang/String;[BJ[J)J");
             "(Ljava/lang/String;[BJ[J)J");
@@ -388,7 +388,7 @@ namespace {
             return -1;
             return -1;
         }
         }
 
 
-        jmethodID dataStorePutCallbackMethod = cache.findMethod(
+        jmethodID dataStorePutCallbackMethod = lookup.findMethod(
             dataStorePutClass,
             dataStorePutClass,
             "onDataStorePut",
             "onDataStorePut",
             "(Ljava/lang/String;[BZ)I");
             "(Ljava/lang/String;[BZ)I");
@@ -398,7 +398,7 @@ namespace {
             return -2;
             return -2;
         }
         }
 
 
-        jmethodID deleteMethod = cache.findMethod(dataStorePutClass,
+        jmethodID deleteMethod = lookup.findMethod(dataStorePutClass,
             "onDelete", "(Ljava/lang/String;)I");
             "onDelete", "(Ljava/lang/String;)I");
         if(deleteMethod == NULL)
         if(deleteMethod == NULL)
         {
         {
@@ -453,7 +453,7 @@ namespace {
             return -1;
             return -1;
         }
         }
 
 
-        jmethodID packetSenderCallbackMethod = cache.findMethod(packetSenderClass,
+        jmethodID packetSenderCallbackMethod = lookup.findMethod(packetSenderClass,
             "onSendPacketRequested", "(Ljava/net/InetSocketAddress;[B)I");
             "onSendPacketRequested", "(Ljava/net/InetSocketAddress;[B)I");
         if(packetSenderCallbackMethod == NULL)
         if(packetSenderCallbackMethod == NULL)
         {
         {
@@ -487,13 +487,13 @@ namespace {
 
 
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) 
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) 
 {
 {
-    cache.setJavaVM(vm);
+    lookup.setJavaVM(vm);
     return JNI_VERSION_1_6;
     return JNI_VERSION_1_6;
 }
 }
 
 
 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
 {
 {
-    cache.clearCache();
+
 }
 }
 
 
 
 
@@ -514,7 +514,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
     env->GetJavaVM(&ref->jvm);
     env->GetJavaVM(&ref->jvm);
 
 
     jclass cls = env->GetObjectClass(obj);
     jclass cls = env->GetObjectClass(obj);
-    jfieldID fid = cache.findField(
+    jfieldID fid = lookup.findField(
         cls, "getListener", "Lcom/zerotier/sdk/DataStoreGetListener;");
         cls, "getListener", "Lcom/zerotier/sdk/DataStoreGetListener;");
 
 
     if(fid == NULL)
     if(fid == NULL)
@@ -529,7 +529,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
     }
     }
     ref->dataStoreGetListener = env->NewGlobalRef(tmp);
     ref->dataStoreGetListener = env->NewGlobalRef(tmp);
 
 
-    fid = cache.findField(
+    fid = lookup.findField(
         cls, "putListener", "Lcom/zerotier/sdk/DataStorePutListener;");
         cls, "putListener", "Lcom/zerotier/sdk/DataStorePutListener;");
 
 
     if(fid == NULL)
     if(fid == NULL)
@@ -544,7 +544,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
     }
     }
     ref->dataStorePutListener = env->NewGlobalRef(tmp);
     ref->dataStorePutListener = env->NewGlobalRef(tmp);
 
 
-    fid = cache.findField(
+    fid = lookup.findField(
         cls, "sender", "Lcom/zerotier/sdk/PacketSender;");
         cls, "sender", "Lcom/zerotier/sdk/PacketSender;");
     if(fid == NULL)
     if(fid == NULL)
     {
     {
@@ -558,7 +558,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
     }
     }
     ref->packetSender = env->NewGlobalRef(tmp);
     ref->packetSender = env->NewGlobalRef(tmp);
 
 
-    fid = cache.findField(
+    fid = lookup.findField(
         cls, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;");
         cls, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;");
     if(fid == NULL)
     if(fid == NULL)
     {
     {
@@ -572,7 +572,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
     }
     }
     ref->frameListener = env->NewGlobalRef(tmp);
     ref->frameListener = env->NewGlobalRef(tmp);
 
 
-    fid = cache.findField(
+    fid = lookup.findField(
         cls, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;");
         cls, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;");
     if(fid == NULL)
     if(fid == NULL)
     {
     {
@@ -586,7 +586,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
     }
     }
     ref->configListener = env->NewGlobalRef(tmp);
     ref->configListener = env->NewGlobalRef(tmp);
 
 
-    fid = cache.findField(
+    fid = lookup.findField(
         cls, "eventListener", "Lcom/zerotier/sdk/EventListener;");
         cls, "eventListener", "Lcom/zerotier/sdk/EventListener;");
     if(fid == NULL)
     if(fid == NULL)
     {
     {
@@ -758,7 +758,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
     uint64_t now = (uint64_t)in_now;
     uint64_t now = (uint64_t)in_now;
 
 
     // get the java.net.InetSocketAddress class and getAddress() method
     // get the java.net.InetSocketAddress class and getAddress() method
-    jclass inetAddressClass = cache.findClass("java/net/InetAddress");
+    jclass inetAddressClass = lookup.findClass("java/net/InetAddress");
     if(inetAddressClass == NULL)
     if(inetAddressClass == NULL)
     {
     {
         LOGE("Can't find InetAddress class");
         LOGE("Can't find InetAddress class");
@@ -766,7 +766,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
     }
     }
 
 
-    jmethodID getAddressMethod = cache.findMethod(
+    jmethodID getAddressMethod = lookup.findMethod(
         inetAddressClass, "getAddress", "()[B");
         inetAddressClass, "getAddress", "()[B");
     if(getAddressMethod == NULL)
     if(getAddressMethod == NULL)
     {
     {
@@ -774,13 +774,13 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
     }
     }
 
 
-    jclass InetSocketAddressClass = cache.findClass("java/net/InetSocketAddress");
+    jclass InetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress");
     if(InetSocketAddressClass == NULL)
     if(InetSocketAddressClass == NULL)
     {
     {
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
     }
     }
 
 
-    jmethodID inetSockGetAddressMethod = cache.findMethod(
+    jmethodID inetSockGetAddressMethod = lookup.findMethod(
         InetSocketAddressClass, "getAddress", "()Ljava/net/InetAddress;");
         InetSocketAddressClass, "getAddress", "()Ljava/net/InetAddress;");
 
 
     jobject addrObject = env->CallObjectMethod(in_remoteAddress, inetSockGetAddressMethod);
     jobject addrObject = env->CallObjectMethod(in_remoteAddress, inetSockGetAddressMethod);
@@ -790,7 +790,7 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket(
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
         return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL);
     }
     }
 
 
-    jmethodID inetSock_getPort = cache.findMethod(
+    jmethodID inetSock_getPort = lookup.findMethod(
         InetSocketAddressClass, "getPort", "()I");
         InetSocketAddressClass, "getPort", "()I");
 
 
     if(env->ExceptionCheck() || inetSock_getPort == NULL) 
     if(env->ExceptionCheck() || inetSock_getPort == NULL) 
@@ -1059,13 +1059,13 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status
     jmethodID nodeStatusConstructor = NULL;
     jmethodID nodeStatusConstructor = NULL;
 
 
     // create a com.zerotier.sdk.NodeStatus object
     // create a com.zerotier.sdk.NodeStatus object
-    nodeStatusClass = cache.findClass("com/zerotier/sdk/NodeStatus");
+    nodeStatusClass = lookup.findClass("com/zerotier/sdk/NodeStatus");
     if(nodeStatusClass == NULL)
     if(nodeStatusClass == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
     
     
-    nodeStatusConstructor = cache.findMethod(
+    nodeStatusConstructor = lookup.findMethod(
         nodeStatusClass, "<init>", "()V");
         nodeStatusClass, "<init>", "()V");
     if(nodeStatusConstructor == NULL)
     if(nodeStatusConstructor == NULL)
     {
     {
@@ -1086,25 +1086,25 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status
     jfieldID secretIdentityField = NULL;
     jfieldID secretIdentityField = NULL;
     jfieldID onlineField = NULL;
     jfieldID onlineField = NULL;
 
 
-    addressField = cache.findField(nodeStatusClass, "address", "J");
+    addressField = lookup.findField(nodeStatusClass, "address", "J");
     if(addressField == NULL)
     if(addressField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    publicIdentityField = cache.findField(nodeStatusClass, "publicIdentity", "Ljava/lang/String;");
+    publicIdentityField = lookup.findField(nodeStatusClass, "publicIdentity", "Ljava/lang/String;");
     if(publicIdentityField == NULL)
     if(publicIdentityField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    secretIdentityField = cache.findField(nodeStatusClass, "secretIdentity", "Ljava/lang/String;");
+    secretIdentityField = lookup.findField(nodeStatusClass, "secretIdentity", "Ljava/lang/String;");
     if(secretIdentityField == NULL)
     if(secretIdentityField == NULL)
     {
     {
         return NULL;
         return NULL;
     }
     }
 
 
-    onlineField = cache.findField(nodeStatusClass, "online", "Z");
+    onlineField = lookup.findField(nodeStatusClass, "online", "Z");
     if(onlineField == NULL)
     if(onlineField == NULL)
     {
     {
         return NULL;
         return NULL;
@@ -1207,7 +1207,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_peers(
         return NULL;
         return NULL;
     }
     }
 
 
-    jclass peerClass = cache.findClass("com/zerotier/sdk/Peer");
+    jclass peerClass = lookup.findClass("com/zerotier/sdk/Peer");
     if(env->ExceptionCheck() || peerClass == NULL)
     if(env->ExceptionCheck() || peerClass == NULL)
     {
     {
         LOGE("Error finding Peer class");
         LOGE("Error finding Peer class");
@@ -1265,7 +1265,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_networks(
         return NULL;
         return NULL;
     }
     }
 
 
-    jclass vnetConfigClass = cache.findClass("com/zerotier/sdk/VirtualNetworkConfig");
+    jclass vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig");
     if(env->ExceptionCheck() || vnetConfigClass == NULL)
     if(env->ExceptionCheck() || vnetConfigClass == NULL)
     {
     {
         LOGE("Error finding VirtualNetworkConfig class");
         LOGE("Error finding VirtualNetworkConfig class");