diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-04-22 19:29:13 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-04-22 19:29:13 -0700 |
commit | 321b67c73cfe945f399acd83a8ee22b2c556acd5 (patch) | |
tree | 5a4584824aca8d56303829a429059b54725b9fc3 | |
parent | 5df253fa699d744bea175d9c3a99f41969e93a27 (diff) | |
download | infinitytier-321b67c73cfe945f399acd83a8ee22b2c556acd5.tar.gz infinitytier-321b67c73cfe945f399acd83a8ee22b2c556acd5.zip |
add a findNode() function to reduce copypasta
Signed-off-by: Grant Limberg <glimberg@gmail.com>
-rw-r--r-- | java/jni/com_zerotierone_sdk_Node.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/java/jni/com_zerotierone_sdk_Node.cpp b/java/jni/com_zerotierone_sdk_Node.cpp index bb284bc9..60c53f04 100644 --- a/java/jni/com_zerotierone_sdk_Node.cpp +++ b/java/jni/com_zerotierone_sdk_Node.cpp @@ -154,6 +154,17 @@ namespace { return resultObject; } + + ZT1_Node* findNode(uint64_t nodeId) + { + NodeMap::iterator found = nodeMap.find(nodeId); + if(found != nodeMap.end()) + { + JniRef *ref = found->second; + return ref->node; + } + return NULL; + } } /* @@ -309,8 +320,9 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processVirtualNetworkFra jlongArray out_nextBackgroundTaskDeadline) { uint64_t nodeId = (uint64_t) id; - NodeMap::iterator found = nodeMap.find(nodeId); - if(found == nodeMap.end()) + + ZT1_Node *node = findNode(nodeId); + if(node == NULL) { // cannot find valid node. We should never get here. return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL); @@ -323,8 +335,6 @@ JNIEXPORT jobject JNICALL Java_com_zerotierone_sdk_Node_processVirtualNetworkFra return createResultObject(env, ZT1_RESULT_FATAL_ERROR_INTERNAL); } - ZT1_Node *node = found->second; - uint64_t now = (uint64_t)in_now; uint64_t nwid = (uint64_t)in_nwid; uint64_t sourceMac = (uint64_t)in_sourceMac; |