Browse Source

Better platform-specific homeDir guessing, updated build procedure

pull/1/head
Joseph Henry 10 years ago
parent
commit
973e13561c
  1. 15
      make-linux.mk
  2. 8
      make-mac.mk
  3. 10
      src/SDK_Intercept.c
  4. 78
      src/SDK_ServiceSetup.cpp

15
make-linux.mk

@ -75,8 +75,10 @@ endif
all: shared_lib check
linux_shared_lib: $(OBJS)
rm -f *.o
remove_only_intermediates:
-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
# Build liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
make -f make-liblwip.mk
@ -91,7 +93,7 @@ linux_shared_lib: $(OBJS)
check:
./check.sh build/lwip/liblwip.so
./check.sh build/linux_shared_lib/libztintercept.so
./check.sh build/
./check.sh build/android_jni_lib/arm64-v8a/libZeroTierJNI.so
./check.sh build/android_jni_lib/armeabi/libZeroTierJNI.so
@ -101,14 +103,13 @@ check:
./check.sh build/android_jni_lib/x86/libZeroTierJNI.so
./check.sh build/android_jni_lib/x86_64/libZeroTierJNI.so
# Tests
TEST_OBJDIR := build/tests
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
-$(CC) $(CC_FLAGS) -c -o $@ $<
build/tests/$(OSTYPE).%.out: tests/%.c
-$(CC) $(CC_FLAGS) -o $@ $<
$(TEST_OBJDIR):
mkdir -p $(TEST_OBJDIR)

8
make-mac.mk

@ -79,7 +79,7 @@ android_jni_lib:
#cp docs/android_zt_sdk.md build/README.md
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
$(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
@ -120,10 +120,10 @@ check:
# Tests
TEST_OBJDIR := build/tests
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
-$(CC) $(CC_FLAGS) -c -o $@ $<
build/tests/$(OSTYPE).%.out: tests/%.c
-$(CC) $(CC_FLAGS) -o $@ $<
$(TEST_OBJDIR):
mkdir -p $(TEST_OBJDIR)

10
src/SDK_Intercept.c

@ -107,11 +107,17 @@ pthread_key_t thr_id_key;
if(!realconnect){
load_symbols();
}
return 1;
#if defined(SDK_BUNDLED)
/* 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);
int thr_id = spec != NULL ? *((int*)spec) : -1;
return thr_id == INTERCEPT_ENABLED;
#else
return 1
#endif
}
// ------------------------------------------------------------------------------

78
src/SDK_ServiceSetup.cpp

@ -130,45 +130,58 @@ extern "C" {
*/
#if defined(__ANDROID__)
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
/* If you define anything else in this file it *must* follow that convention
and any corresponding Java package/classes in your Android project must match this as well */
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj)
{
JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path) {
//char * path;
homeDir = (*env)->GetStringUTFChars(env, path, NULL);
#else
void *startOneService(void *thread_id)
{
set_intercept_status(INTERCEPT_DISABLED);
#endif
#if defined(__UNITY_3D__)
int MAX_DIR_SZ = 256;
char current_dir[MAX_DIR_SZ];
getcwd(current_dir, MAX_DIR_SZ);
chdir(service_path.c_str());
zt1Service = (ZeroTier::OneService *)0;
#endif
#if defined(__ANDROID__)
homeDir = "/sdcard/zerotier";
void *startOneService(void *thread_id, string path) {
homeDir = path;
#endif
#if defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
// homeDir = "dont/run/this/in/the/simulator";
#elif TARGET_OS_IPHONE
homeDir = "ZeroTier/One";
#if defined(SDK_BUNDLED)
// Don't intercept network calls originating from ZeroTier service
set_intercept_status(INTERCEPT_DISABLED);
#endif
#endif
#if defined(__UNITY_3D__)
homeDir = "/Users/Joseph/utest2/";
#endif
// 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;
char current_dir[MAX_DIR_SZ];
getcwd(current_dir, MAX_DIR_SZ);
chdir(service_path.c_str());
#endif
#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";
#endif
#if defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
// homeDir = "dont/run/this/in/the/simulator";
#elif TARGET_OS_IPHONE
homeDir = "ZeroTier/One";
#endif
#endif
}
LOGV("homeDir = %s", homeDir.c_str());
// Where network .conf files will be stored
netDir = homeDir + "/networks.d";
zt1Service = (ZeroTier::OneService *)0;
LOGV("Starting ZT service...\n");
//Debug("Starting ZT service...");
if (!homeDir.length()) {
#if defined(__ANDROID__)
@ -190,7 +203,6 @@ extern "C" {
if ((*pi != ".")&&(*pi != "..")) {
if (!ZeroTier::OSUtils::mkdir(ptmp)) {
std::string homePathErrStr = "home path does not exist, and could not create";
//Debug(homePathErrStr.c_str());
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)
LOGV("homeDir = %s", homeDir.c_str());
//Debug(homeDir.c_str());
// Generate random port for new service instance
@ -209,7 +220,6 @@ extern "C" {
LOGV("generated port\n");
for(;;) {
zt1Service = ZeroTier::OneService::newInstance(homeDir.c_str(),servicePort);
LOGV("created new instance\n");

Loading…
Cancel
Save