Better platform-specific homeDir guessing, updated build procedure
This commit is contained in:
@@ -75,8 +75,10 @@ endif
|
|||||||
|
|
||||||
all: shared_lib check
|
all: shared_lib check
|
||||||
|
|
||||||
linux_shared_lib: $(OBJS)
|
remove_only_intermediates:
|
||||||
rm -f *.o
|
-find . -type f -name '*.o' -delete
|
||||||
|
|
||||||
|
linux_shared_lib: remove_only_intermediates $(OBJS)
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl
|
||||||
# Build liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
|
# Build liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
|
||||||
make -f make-liblwip.mk
|
make -f make-liblwip.mk
|
||||||
@@ -101,14 +103,13 @@ check:
|
|||||||
./check.sh build/android_jni_lib/x86/libZeroTierJNI.so
|
./check.sh build/android_jni_lib/x86/libZeroTierJNI.so
|
||||||
./check.sh build/android_jni_lib/x86_64/libZeroTierJNI.so
|
./check.sh build/android_jni_lib/x86_64/libZeroTierJNI.so
|
||||||
|
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
TEST_OBJDIR := build/tests
|
TEST_OBJDIR := build/tests
|
||||||
TEST_SOURCES := $(wildcard tests/*.c)
|
TEST_SOURCES := $(wildcard tests/*.c)
|
||||||
TEST_TARGETS := $(addprefix build/tests/,$(notdir $(TEST_SOURCES:.c=.out)))
|
TEST_TARGETS := $(addprefix build/tests/$(OSTYPE).,$(notdir $(TEST_SOURCES:.c=.out)))
|
||||||
|
|
||||||
build/tests/%.out: tests/%.c
|
build/tests/$(OSTYPE).%.out: tests/%.c
|
||||||
-$(CC) $(CC_FLAGS) -c -o $@ $<
|
-$(CC) $(CC_FLAGS) -o $@ $<
|
||||||
|
|
||||||
$(TEST_OBJDIR):
|
$(TEST_OBJDIR):
|
||||||
mkdir -p $(TEST_OBJDIR)
|
mkdir -p $(TEST_OBJDIR)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ android_jni_lib:
|
|||||||
#cp docs/android_zt_sdk.md build/README.md
|
#cp docs/android_zt_sdk.md build/README.md
|
||||||
|
|
||||||
osx_shared_lib: $(OBJS)
|
osx_shared_lib: $(OBJS)
|
||||||
rm -f *.o
|
-find . -type f -name '*.o' -delete
|
||||||
# Need to selectively rebuild one.cpp and OneService.cpp with ZT_SERVICE_NETCON and ZT_ONE_NO_ROOT_CHECK defined, and also NetconEthernetTap
|
# Need to selectively rebuild one.cpp and OneService.cpp with ZT_SERVICE_NETCON and ZT_ONE_NO_ROOT_CHECK defined, and also NetconEthernetTap
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl
|
||||||
# Build liblwip.so which must be placed in ZT home for zerotier-sdk-service to work
|
# Build liblwip.so which must be placed in ZT home for zerotier-sdk-service to work
|
||||||
@@ -120,10 +120,10 @@ check:
|
|||||||
# Tests
|
# Tests
|
||||||
TEST_OBJDIR := build/tests
|
TEST_OBJDIR := build/tests
|
||||||
TEST_SOURCES := $(wildcard tests/*.c)
|
TEST_SOURCES := $(wildcard tests/*.c)
|
||||||
TEST_TARGETS := $(addprefix build/tests/,$(notdir $(TEST_SOURCES:.c=.out)))
|
TEST_TARGETS := $(addprefix build/tests/$(OSTYPE).,$(notdir $(TEST_SOURCES:.c=.out)))
|
||||||
|
|
||||||
build/tests/%.out: tests/%.c
|
build/tests/$(OSTYPE).%.out: tests/%.c
|
||||||
-$(CC) $(CC_FLAGS) -c -o $@ $<
|
-$(CC) $(CC_FLAGS) -o $@ $<
|
||||||
|
|
||||||
$(TEST_OBJDIR):
|
$(TEST_OBJDIR):
|
||||||
mkdir -p $(TEST_OBJDIR)
|
mkdir -p $(TEST_OBJDIR)
|
||||||
|
|||||||
@@ -107,11 +107,17 @@ pthread_key_t thr_id_key;
|
|||||||
if(!realconnect){
|
if(!realconnect){
|
||||||
load_symbols();
|
load_symbols();
|
||||||
}
|
}
|
||||||
|
#if defined(SDK_BUNDLED)
|
||||||
return 1;
|
/* The reasoning for this check is that if you've built the SDK with SDK_BUNDLE=1, then
|
||||||
|
you've included a full ZeroTier service in the same binary as your intercept, and we
|
||||||
|
don't want to run ZeroTier network API calls through the intercept, so we must specify
|
||||||
|
which threads should be intercepted manually */
|
||||||
void *spec = pthread_getspecific(thr_id_key);
|
void *spec = pthread_getspecific(thr_id_key);
|
||||||
int thr_id = spec != NULL ? *((int*)spec) : -1;
|
int thr_id = spec != NULL ? *((int*)spec) : -1;
|
||||||
return thr_id == INTERCEPT_ENABLED;
|
return thr_id == INTERCEPT_ENABLED;
|
||||||
|
#else
|
||||||
|
return 1
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -130,45 +130,58 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
|
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
|
||||||
/* If you define anything else in this file it *must* follow that convention
|
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path) {
|
||||||
and any corresponding Java package/classes in your Android project must match this as well */
|
//char * path;
|
||||||
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj)
|
homeDir = (*env)->GetStringUTFChars(env, path, NULL);
|
||||||
{
|
|
||||||
#else
|
#else
|
||||||
void *startOneService(void *thread_id)
|
void *startOneService(void *thread_id, string path) {
|
||||||
{
|
homeDir = path;
|
||||||
set_intercept_status(INTERCEPT_DISABLED);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SDK_BUNDLED)
|
||||||
|
// Don't intercept network calls originating from ZeroTier service
|
||||||
|
set_intercept_status(INTERCEPT_DISABLED);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__UNITY_3D__)
|
// If no homeDir is provided, attempt a best guess of an appropriate ZeroTier
|
||||||
|
// homeDir according to platform and build type
|
||||||
|
if(!homeDir.length())
|
||||||
|
{
|
||||||
|
#if defined(__UNITY_3D__)
|
||||||
int MAX_DIR_SZ = 256;
|
int MAX_DIR_SZ = 256;
|
||||||
char current_dir[MAX_DIR_SZ];
|
char current_dir[MAX_DIR_SZ];
|
||||||
getcwd(current_dir, MAX_DIR_SZ);
|
getcwd(current_dir, MAX_DIR_SZ);
|
||||||
chdir(service_path.c_str());
|
chdir(service_path.c_str());
|
||||||
zt1Service = (ZeroTier::OneService *)0;
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__UNITY_3D__) && !defined(__ANDROID__) && !defined(__IOS__)
|
||||||
|
// Unity3D on a non-mobile platform
|
||||||
|
homeDir = "" + current_dir; // homeDir shall be current dir
|
||||||
|
// homeDir = "/Users/Joseph/utest2/";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
homeDir = "/sdcard/zerotier";
|
homeDir = "/sdcard/zerotier";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include "TargetConditionals.h"
|
#include "TargetConditionals.h"
|
||||||
#if TARGET_IPHONE_SIMULATOR
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
// homeDir = "dont/run/this/in/the/simulator";
|
// homeDir = "dont/run/this/in/the/simulator";
|
||||||
#elif TARGET_OS_IPHONE
|
#elif TARGET_OS_IPHONE
|
||||||
homeDir = "ZeroTier/One";
|
homeDir = "ZeroTier/One";
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(__UNITY_3D__)
|
LOGV("homeDir = %s", homeDir.c_str());
|
||||||
homeDir = "/Users/Joseph/utest2/";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
// Where network .conf files will be stored
|
||||||
netDir = homeDir + "/networks.d";
|
netDir = homeDir + "/networks.d";
|
||||||
|
|
||||||
|
zt1Service = (ZeroTier::OneService *)0;
|
||||||
LOGV("Starting ZT service...\n");
|
LOGV("Starting ZT service...\n");
|
||||||
//Debug("Starting ZT service...");
|
|
||||||
|
|
||||||
if (!homeDir.length()) {
|
if (!homeDir.length()) {
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
@@ -190,7 +203,6 @@ extern "C" {
|
|||||||
if ((*pi != ".")&&(*pi != "..")) {
|
if ((*pi != ".")&&(*pi != "..")) {
|
||||||
if (!ZeroTier::OSUtils::mkdir(ptmp)) {
|
if (!ZeroTier::OSUtils::mkdir(ptmp)) {
|
||||||
std::string homePathErrStr = "home path does not exist, and could not create";
|
std::string homePathErrStr = "home path does not exist, and could not create";
|
||||||
//Debug(homePathErrStr.c_str());
|
|
||||||
throw std::runtime_error(homePathErrStr);
|
throw std::runtime_error(homePathErrStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +211,6 @@ extern "C" {
|
|||||||
|
|
||||||
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
||||||
|
|
||||||
LOGV("homeDir = %s", homeDir.c_str());
|
|
||||||
//Debug(homeDir.c_str());
|
//Debug(homeDir.c_str());
|
||||||
|
|
||||||
// Generate random port for new service instance
|
// Generate random port for new service instance
|
||||||
@@ -209,7 +220,6 @@ extern "C" {
|
|||||||
|
|
||||||
LOGV("generated port\n");
|
LOGV("generated port\n");
|
||||||
|
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
zt1Service = ZeroTier::OneService::newInstance(homeDir.c_str(),servicePort);
|
zt1Service = ZeroTier::OneService::newInstance(homeDir.c_str(),servicePort);
|
||||||
LOGV("created new instance\n");
|
LOGV("created new instance\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user