Wire up PortMapper in Android
Enables UPnP port mapping for Android client on networks with UPnP routers
This commit is contained in:
parent
b9e1d53d7a
commit
bcf697cc2b
5 changed files with 89 additions and 20 deletions
|
@ -3,14 +3,21 @@ LOCAL_PATH := $(call my-dir)
|
|||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := ZeroTierOneJNI
|
||||
LOCAL_C_INCLUDES := $(ZT1)/include
|
||||
LOCAL_C_INCLUDES += $(ZT1)/node
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(ZT1)/include \
|
||||
$(ZT1)/node \
|
||||
$(ZT1)/osdep \
|
||||
$(ZT1)/ext/miniupnpc \
|
||||
$(ZT1)/ext/libnatpmp
|
||||
|
||||
LOCAL_LDLIBS := -llog -latomic
|
||||
# LOCAL_CFLAGS := -g
|
||||
|
||||
LOCAL_CFLAGS := -DZT_USE_MINIUPNPC
|
||||
|
||||
# ZeroTierOne SDK source files
|
||||
LOCAL_SRC_FILES := \
|
||||
$(ZT1)/node/C25519.cpp \
|
||||
$(ZT1)/node/C25519.cpp \
|
||||
$(ZT1)/node/Capability.cpp \
|
||||
$(ZT1)/node/CertificateOfMembership.cpp \
|
||||
$(ZT1)/node/CertificateOfOwnership.cpp \
|
||||
|
@ -35,8 +42,27 @@ LOCAL_SRC_FILES := \
|
|||
$(ZT1)/node/Tag.cpp \
|
||||
$(ZT1)/node/Topology.cpp \
|
||||
$(ZT1)/node/Trace.cpp \
|
||||
$(ZT1)/node/Utils.cpp
|
||||
$(ZT1)/node/Utils.cpp \
|
||||
$(ZT1)/osdep/OSUtils.cpp \
|
||||
$(ZT1)/osdep/PortMapper.cpp
|
||||
|
||||
# libminiupnpc and libnatpmp files
|
||||
LOCAL_SRC_FILES += \
|
||||
$(ZT1)/ext/miniupnpc/connecthostport.c \
|
||||
$(ZT1)/ext/miniupnpc/igd_desc_parse.c \
|
||||
$(ZT1)/ext/miniupnpc/minisoap.c \
|
||||
$(ZT1)/ext/miniupnpc/minissdpc.c \
|
||||
$(ZT1)/ext/miniupnpc/miniupnpc.c \
|
||||
$(ZT1)/ext/miniupnpc/miniwget.c \
|
||||
$(ZT1)/ext/miniupnpc/minixml.c \
|
||||
$(ZT1)/ext/miniupnpc/portlistingparse.c \
|
||||
$(ZT1)/ext/miniupnpc/receivedata.c \
|
||||
$(ZT1)/ext/miniupnpc/upnpcommands.c \
|
||||
$(ZT1)/ext/miniupnpc/upnpdev.c \
|
||||
$(ZT1)/ext/miniupnpc/upnperrors.c \
|
||||
$(ZT1)/ext/miniupnpc/upnpreplyparse.c \
|
||||
$(ZT1)/ext/libnatpmp/natpmp.c \
|
||||
$(ZT1)/ext/libnatpmp/getgateway.c
|
||||
|
||||
# JNI Files
|
||||
LOCAL_SRC_FILES += \
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include <ZeroTierOne.h>
|
||||
#include "Mutex.hpp"
|
||||
|
||||
#include "PortMapper.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
|
@ -58,6 +60,7 @@ namespace {
|
|||
, configListener(NULL)
|
||||
, pathChecker(NULL)
|
||||
, callbacks(NULL)
|
||||
, portMapper(NULL)
|
||||
{
|
||||
callbacks = (ZT_Node_Callbacks*)malloc(sizeof(ZT_Node_Callbacks));
|
||||
memset(callbacks, 0, sizeof(ZT_Node_Callbacks));
|
||||
|
@ -78,6 +81,9 @@ namespace {
|
|||
|
||||
free(callbacks);
|
||||
callbacks = NULL;
|
||||
|
||||
delete portMapper;
|
||||
portMapper = NULL;
|
||||
}
|
||||
|
||||
uint64_t id;
|
||||
|
@ -95,6 +101,8 @@ namespace {
|
|||
jobject pathChecker;
|
||||
|
||||
ZT_Node_Callbacks *callbacks;
|
||||
|
||||
ZeroTier::PortMapper *portMapper;
|
||||
};
|
||||
|
||||
|
||||
|
@ -833,11 +841,17 @@ JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init(
|
|||
return resultObject;
|
||||
}
|
||||
|
||||
uint64_t nodeId = ZT_Node_address(node);
|
||||
if (nodeId != 0) {
|
||||
char uniqueName[64];
|
||||
snprintf(uniqueName, sizeof(uniqueName), "ZeroTier Android/%.10llx@%u", (unsigned long long)nodeId, 9993);
|
||||
ref->portMapper = new ZeroTier::PortMapper(9993, uniqueName);
|
||||
}
|
||||
|
||||
ZeroTier::Mutex::Lock lock(nodeMapMutex);
|
||||
ref->node = node;
|
||||
nodeMap.insert(std::make_pair(ref->id, ref));
|
||||
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue