diff --git a/zerotierone/java/CMakeLists.txt b/zerotierone/java/CMakeLists.txt deleted file mode 100644 index 008b747..0000000 --- a/zerotierone/java/CMakeLists.txt +++ /dev/null @@ -1,91 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -project(ZeroTierOneJNI) - -find_package(Java COMPONENTS Development) -message("JAVA_HOME: $ENV{JAVA_HOME}") - -if(WIN32) -set(Java_INCLUDE_DIRS $ENV{JAVA_HOME}/include) -endif() - -if(APPLE) -set(Java_INCLUDE_DIRS "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/JavaVM.framework/Headers") -endif() - -message("Java Include Dirs: ${Java_INCLUDE_DIRS}") - -if(WIN32) - add_definitions(-DNOMINMAX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /W3 /MP") -endif() - -if(APPLE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch i386 -arch x86_64 -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -mmacosx-version-min=10.7 -Wno-unused-private-field") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti") -endif() - -set(src_files - ../ext/lz4/lz4.c - ../ext/json-parser/json.c - ../ext/http-parser/http_parser.c - ../node/C25519.cpp - ../node/CertificateOfMembership.cpp - ../node/Defaults.cpp - ../node/Dictionary.cpp - ../node/Identity.cpp - ../node/IncomingPacket.cpp - ../node/InetAddress.cpp - ../node/Multicaster.cpp - ../node/Network.cpp - ../node/NetworkConfig.cpp - ../node/Node.cpp - ../node/OutboundMulticast.cpp - ../node/Packet.cpp - ../node/Peer.cpp - ../node/Poly1305.cpp - ../node/Salsa20.cpp - ../node/SelfAwareness.cpp - ../node/SHA512.cpp - ../node/Switch.cpp - ../node/Topology.cpp - ../node/Utils.cpp - ../osdep/Http.cpp - ../osdep/OSUtils.cpp - jni/com_zerotierone_sdk_Node.cpp - jni/ZT_jniutils.cpp - jni/ZT_jnicache.cpp - ) - -set(include_dirs - ${CMAKE_CURRENT_SOURCE_DIR}/../include/ - ${CMAKE_CURRENT_SOURCE_DIR}/../node/ - ${Java_INCLUDE_DIRS}) - -if(WIN32) - set(include_dirs - ${include_dirs} - ${Java_INCLUDE_DIRS}/win32) -endif() - -include_directories( - ${include_dirs} - ) - -add_library(${PROJECT_NAME} SHARED ${src_files}) - -if(APPLE) - set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".jnilib") -endif() - -set(link_libs ) - -if(WIN32) - set(link_libs - wsock32 - ws2_32 - - ) -endif() - -target_link_libraries(${PROJECT_NAME} ${link_libs}) \ No newline at end of file diff --git a/zerotierone/java/README.md b/zerotierone/java/README.md deleted file mode 100644 index 2650ec3..0000000 --- a/zerotierone/java/README.md +++ /dev/null @@ -1,17 +0,0 @@ -ZeroTier One SDK - Android JNI Wrapper -===== - - -Building ------ - -Reqires: - -* JDK -* ANT -* Android NDK - -Required Environment Variables: - -* NDK\_BUILD\_LOC - Path do the ndk-build script in the Android NDK -* ANDROID\_PLATFORM - path to the directory android.jar lives (on Windows: C:\Users\\AppData\Local\Android\sdk\platforms\android-21) diff --git a/zerotierone/java/build.xml b/zerotierone/java/build.xml deleted file mode 100644 index 4604ad6..0000000 --- a/zerotierone/java/build.xml +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/zerotierone/java/jni/Android.mk b/zerotierone/java/jni/Android.mk deleted file mode 100644 index ebd8937..0000000 --- a/zerotierone/java/jni/Android.mk +++ /dev/null @@ -1,46 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := ZeroTierOneJNI -LOCAL_C_INCLUDES := $(ZT1)/include -LOCAL_C_INCLUDES += $(ZT1)/node -LOCAL_LDLIBS := -llog -latomic -# LOCAL_CFLAGS := -g - -# ZeroTierOne SDK source files -LOCAL_SRC_FILES := \ - $(ZT1)/node/C25519.cpp \ - $(ZT1)/node/Capability.cpp \ - $(ZT1)/node/CertificateOfMembership.cpp \ - $(ZT1)/node/CertificateOfOwnership.cpp \ - $(ZT1)/node/Identity.cpp \ - $(ZT1)/node/IncomingPacket.cpp \ - $(ZT1)/node/InetAddress.cpp \ - $(ZT1)/node/Membership.cpp \ - $(ZT1)/node/Multicaster.cpp \ - $(ZT1)/node/Network.cpp \ - $(ZT1)/node/NetworkConfig.cpp \ - $(ZT1)/node/Node.cpp \ - $(ZT1)/node/OutboundMulticast.cpp \ - $(ZT1)/node/Packet.cpp \ - $(ZT1)/node/Path.cpp \ - $(ZT1)/node/Peer.cpp \ - $(ZT1)/node/Poly1305.cpp \ - $(ZT1)/node/Revocation.cpp \ - $(ZT1)/node/Salsa20.cpp \ - $(ZT1)/node/SelfAwareness.cpp \ - $(ZT1)/node/SHA512.cpp \ - $(ZT1)/node/Switch.cpp \ - $(ZT1)/node/Tag.cpp \ - $(ZT1)/node/Topology.cpp \ - $(ZT1)/node/Utils.cpp - - -# JNI Files -LOCAL_SRC_FILES += \ - com_zerotierone_sdk_Node.cpp \ - ZT_jniutils.cpp \ - ZT_jnilookup.cpp - -include $(BUILD_SHARED_LIBRARY) \ No newline at end of file diff --git a/zerotierone/java/jni/Application.mk b/zerotierone/java/jni/Application.mk deleted file mode 100644 index 6950c0e..0000000 --- a/zerotierone/java/jni/Application.mk +++ /dev/null @@ -1,5 +0,0 @@ -# NDK_TOOLCHAIN_VERSION := clang3.5 -APP_STL := gnustl_static -APP_CPPFLAGS := -O3 -fPIC -fPIE -Wall -fstack-protector -fexceptions -fno-strict-aliasing -Wno-deprecated-register -DZT_NO_TYPE_PUNNING=1 -APP_PLATFORM := android-14 -APP_ABI := all diff --git a/zerotierone/java/jni/ZT_jnilookup.cpp b/zerotierone/java/jni/ZT_jnilookup.cpp deleted file mode 100644 index be52a36..0000000 --- a/zerotierone/java/jni/ZT_jnilookup.cpp +++ /dev/null @@ -1,158 +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 . - * - * -- - * - * 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 "ZT_jnilookup.h" -#include "ZT_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; -} \ No newline at end of file diff --git a/zerotierone/java/jni/ZT_jnilookup.h b/zerotierone/java/jni/ZT_jnilookup.h deleted file mode 100644 index f5bd97d..0000000 --- a/zerotierone/java/jni/ZT_jnilookup.h +++ /dev/null @@ -1,54 +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 . - * - * -- - * - * 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/ - */ - -#ifndef ZT_JNILOOKUP_H_ -#define ZT_JNILOOKUP_H_ - -#include -#include -#include - - - -class JniLookup { -public: - JniLookup(); - JniLookup(JavaVM *jvm); - ~JniLookup(); - - void setJavaVM(JavaVM *jvm); - - jclass findClass(const std::string &name); - jmethodID findMethod(jclass cls, const std::string &methodName, const std::string &methodSig); - jmethodID findStaticMethod(jclass cls, const std::string &methodName, const std::string &methodSig); - jfieldID findField(jclass cls, const std::string &fieldName, const std::string &typeStr); - jfieldID findStaticField(jclass cls, const std::string &fieldName, const std::string &typeStr); -private: - JavaVM *m_jvm; -}; - -#endif \ No newline at end of file diff --git a/zerotierone/java/jni/ZT_jniutils.cpp b/zerotierone/java/jni/ZT_jniutils.cpp deleted file mode 100644 index 7bdc761..0000000 --- a/zerotierone/java/jni/ZT_jniutils.cpp +++ /dev/null @@ -1,941 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 . - */ - -#include "ZT_jniutils.h" -#include "ZT_jnilookup.h" -#include -#include - -extern JniLookup lookup; - -#ifdef __cplusplus -extern "C" { -#endif - -jobject createResultObject(JNIEnv *env, ZT_ResultCode code) -{ - jclass resultClass = NULL; - - jobject resultObject = NULL; - - resultClass = lookup.findClass("com/zerotier/sdk/ResultCode"); - if(resultClass == NULL) - { - LOGE("Couldnt find ResultCode class"); - return NULL; // exception thrown - } - - std::string fieldName; - switch(code) - { - case ZT_RESULT_OK: - LOGV("ZT_RESULT_OK"); - fieldName = "RESULT_OK"; - break; - case ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY: - LOGV("ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY"); - fieldName = "RESULT_FATAL_ERROR_OUT_OF_MEMORY"; - break; - case ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED: - LOGV("RESULT_FATAL_ERROR_DATA_STORE_FAILED"); - fieldName = "RESULT_FATAL_ERROR_DATA_STORE_FAILED"; - break; - case ZT_RESULT_ERROR_NETWORK_NOT_FOUND: - LOGV("RESULT_FATAL_ERROR_DATA_STORE_FAILED"); - fieldName = "RESULT_ERROR_NETWORK_NOT_FOUND"; - break; - case ZT_RESULT_FATAL_ERROR_INTERNAL: - default: - LOGV("RESULT_FATAL_ERROR_DATA_STORE_FAILED"); - fieldName = "RESULT_FATAL_ERROR_INTERNAL"; - break; - } - - jfieldID enumField = lookup.findStaticField(resultClass, fieldName.c_str(), "Lcom/zerotier/sdk/ResultCode;"); - if(env->ExceptionCheck() || enumField == NULL) - { - LOGE("Error on FindStaticField"); - return NULL; - } - - resultObject = env->GetStaticObjectField(resultClass, enumField); - if(env->ExceptionCheck() || resultObject == NULL) - { - LOGE("Error on GetStaticObjectField"); - } - return resultObject; -} - - -jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status) -{ - jobject statusObject = NULL; - - jclass statusClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkStatus"); - if(statusClass == NULL) - { - return NULL; // exception thrown - } - - std::string fieldName; - switch(status) - { - case ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION: - fieldName = "NETWORK_STATUS_REQUESTING_CONFIGURATION"; - break; - case ZT_NETWORK_STATUS_OK: - fieldName = "NETWORK_STATUS_OK"; - break; - case ZT_NETWORK_STATUS_ACCESS_DENIED: - fieldName = "NETWORK_STATUS_ACCESS_DENIED"; - break; - case ZT_NETWORK_STATUS_NOT_FOUND: - fieldName = "NETWORK_STATUS_NOT_FOUND"; - break; - case ZT_NETWORK_STATUS_PORT_ERROR: - fieldName = "NETWORK_STATUS_PORT_ERROR"; - break; - case ZT_NETWORK_STATUS_CLIENT_TOO_OLD: - fieldName = "NETWORK_STATUS_CLIENT_TOO_OLD"; - break; - } - - jfieldID enumField = lookup.findStaticField(statusClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkStatus;"); - - statusObject = env->GetStaticObjectField(statusClass, enumField); - - return statusObject; -} - -jobject createEvent(JNIEnv *env, ZT_Event event) -{ - jclass eventClass = NULL; - jobject eventObject = NULL; - - eventClass = lookup.findClass("com/zerotier/sdk/Event"); - if(eventClass == NULL) - { - return NULL; - } - - std::string fieldName; - switch(event) - { - case ZT_EVENT_UP: - fieldName = "EVENT_UP"; - break; - case ZT_EVENT_OFFLINE: - fieldName = "EVENT_OFFLINE"; - break; - case ZT_EVENT_ONLINE: - fieldName = "EVENT_ONLINE"; - break; - case ZT_EVENT_DOWN: - fieldName = "EVENT_DOWN"; - break; - case ZT_EVENT_FATAL_ERROR_IDENTITY_COLLISION: - fieldName = "EVENT_FATAL_ERROR_IDENTITY_COLLISION"; - break; - case ZT_EVENT_TRACE: - fieldName = "EVENT_TRACE"; - break; - case ZT_EVENT_USER_MESSAGE: - break; - } - - jfieldID enumField = lookup.findStaticField(eventClass, fieldName.c_str(), "Lcom/zerotier/sdk/Event;"); - - eventObject = env->GetStaticObjectField(eventClass, enumField); - - return eventObject; -} - -jobject createPeerRole(JNIEnv *env, ZT_PeerRole role) -{ - jclass peerRoleClass = NULL; - jobject peerRoleObject = NULL; - - peerRoleClass = lookup.findClass("com/zerotier/sdk/PeerRole"); - if(peerRoleClass == NULL) - { - return NULL; - } - - std::string fieldName; - switch(role) - { - case ZT_PEER_ROLE_LEAF: - fieldName = "PEER_ROLE_LEAF"; - break; - case ZT_PEER_ROLE_MOON: - fieldName = "PEER_ROLE_MOON"; - break; - case ZT_PEER_ROLE_PLANET: - fieldName = "PEER_ROLE_PLANET"; - break; - } - - jfieldID enumField = lookup.findStaticField(peerRoleClass, fieldName.c_str(), "Lcom/zerotier/sdk/PeerRole;"); - - peerRoleObject = env->GetStaticObjectField(peerRoleClass, enumField); - - return peerRoleObject; -} - -jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type) -{ - jclass vntypeClass = NULL; - jobject vntypeObject = NULL; - - vntypeClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkType"); - if(env->ExceptionCheck() || vntypeClass == NULL) - { - return NULL; - } - - std::string fieldName; - switch(type) - { - case ZT_NETWORK_TYPE_PRIVATE: - fieldName = "NETWORK_TYPE_PRIVATE"; - break; - case ZT_NETWORK_TYPE_PUBLIC: - fieldName = "NETWORK_TYPE_PUBLIC"; - break; - } - - jfieldID enumField = lookup.findStaticField(vntypeClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkType;"); - vntypeObject = env->GetStaticObjectField(vntypeClass, enumField); - return vntypeObject; -} - -jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT_VirtualNetworkConfigOperation op) -{ - jclass vnetConfigOpClass = NULL; - jobject vnetConfigOpObject = NULL; - - vnetConfigOpClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfigOperation"); - if(env->ExceptionCheck() || vnetConfigOpClass == NULL) - { - return NULL; - } - - std::string fieldName; - switch(op) - { - case ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP: - fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_UP"; - break; - case ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE: - fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE"; - break; - case ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN: - fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN"; - break; - case ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY: - fieldName = "VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY"; - break; - } - - jfieldID enumField = lookup.findStaticField(vnetConfigOpClass, fieldName.c_str(), "Lcom/zerotier/sdk/VirtualNetworkConfigOperation;"); - vnetConfigOpObject = env->GetStaticObjectField(vnetConfigOpClass, enumField); - return vnetConfigOpObject; -} - -jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr) -{ - LOGV("newInetAddress"); - jclass inetAddressClass = NULL; - jmethodID inetAddress_getByAddress = NULL; - - inetAddressClass = lookup.findClass("java/net/InetAddress"); - if(env->ExceptionCheck() || inetAddressClass == NULL) - { - LOGE("Error finding InetAddress class"); - return NULL; - } - - inetAddress_getByAddress = lookup.findStaticMethod( - inetAddressClass, "getByAddress", "([B)Ljava/net/InetAddress;"); - if(env->ExceptionCheck() || inetAddress_getByAddress == NULL) - { - LOGE("Erorr finding getByAddress() static method"); - return NULL; - } - - jobject inetAddressObj = NULL; - switch(addr.ss_family) - { - case AF_INET6: - { - sockaddr_in6 *ipv6 = (sockaddr_in6*)&addr; - jbyteArray buff = env->NewByteArray(16); - if(buff == NULL) - { - LOGE("Error creating IPV6 byte array"); - return NULL; - } - - env->SetByteArrayRegion(buff, 0, 16, (jbyte*)ipv6->sin6_addr.s6_addr); - inetAddressObj = env->CallStaticObjectMethod( - inetAddressClass, inetAddress_getByAddress, buff); - } - break; - case AF_INET: - { - sockaddr_in *ipv4 = (sockaddr_in*)&addr; - jbyteArray buff = env->NewByteArray(4); - if(buff == NULL) - { - LOGE("Error creating IPV4 byte array"); - return NULL; - } - - env->SetByteArrayRegion(buff, 0, 4, (jbyte*)&ipv4->sin_addr); - inetAddressObj = env->CallStaticObjectMethod( - inetAddressClass, inetAddress_getByAddress, buff); - } - break; - } - if(env->ExceptionCheck() || inetAddressObj == NULL) { - LOGE("Error creating InetAddress object"); - return NULL; - } - - return inetAddressObj; -} - -jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr) -{ - LOGV("newInetSocketAddress Called"); - jclass inetSocketAddressClass = NULL; - jmethodID inetSocketAddress_constructor = NULL; - - inetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress"); - if(env->ExceptionCheck() || inetSocketAddressClass == NULL) - { - LOGE("Error finding InetSocketAddress Class"); - return NULL; - } - - jobject inetAddressObject = NULL; - - if(addr.ss_family != 0) - { - inetAddressObject = newInetAddress(env, addr); - - if(env->ExceptionCheck() || inetAddressObject == NULL) - { - LOGE("Error creating new inet address"); - return NULL; - } - } - else - { - return NULL; - } - - inetSocketAddress_constructor = lookup.findMethod( - inetSocketAddressClass, "", "(Ljava/net/InetAddress;I)V"); - if(env->ExceptionCheck() || inetSocketAddress_constructor == NULL) - { - LOGE("Error finding InetSocketAddress constructor"); - return NULL; - } - - int port = 0; - switch(addr.ss_family) - { - case AF_INET6: - { - LOGV("IPV6 Address"); - sockaddr_in6 *ipv6 = (sockaddr_in6*)&addr; - port = ntohs(ipv6->sin6_port); - LOGV("Port %d", port); - } - break; - case AF_INET: - { - LOGV("IPV4 Address"); - sockaddr_in *ipv4 = (sockaddr_in*)&addr; - port = ntohs(ipv4->sin_port); - LOGV("Port: %d", port); - } - break; - default: - { - break; - } - } - - - jobject inetSocketAddressObject = env->NewObject(inetSocketAddressClass, inetSocketAddress_constructor, inetAddressObject, port); - if(env->ExceptionCheck() || inetSocketAddressObject == NULL) { - LOGE("Error creating InetSocketAddress object"); - } - return inetSocketAddressObject; -} - -jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp) -{ - LOGV("newPeerPhysicalPath Called"); - jclass pppClass = NULL; - - jfieldID addressField = NULL; - jfieldID lastSendField = NULL; - jfieldID lastReceiveField = NULL; - jfieldID preferredField = NULL; - - jmethodID ppp_constructor = NULL; - - pppClass = lookup.findClass("com/zerotier/sdk/PeerPhysicalPath"); - if(env->ExceptionCheck() || pppClass == NULL) - { - LOGE("Error finding PeerPhysicalPath class"); - return NULL; - } - - addressField = lookup.findField(pppClass, "address", "Ljava/net/InetSocketAddress;"); - if(env->ExceptionCheck() || addressField == NULL) - { - LOGE("Error finding address field"); - return NULL; - } - - lastSendField = lookup.findField(pppClass, "lastSend", "J"); - if(env->ExceptionCheck() || lastSendField == NULL) - { - LOGE("Error finding lastSend field"); - return NULL; - } - - lastReceiveField = lookup.findField(pppClass, "lastReceive", "J"); - if(env->ExceptionCheck() || lastReceiveField == NULL) - { - LOGE("Error finding lastReceive field"); - return NULL; - } - - preferredField = lookup.findField(pppClass, "preferred", "Z"); - if(env->ExceptionCheck() || preferredField == NULL) - { - LOGE("Error finding preferred field"); - return NULL; - } - - ppp_constructor = lookup.findMethod(pppClass, "", "()V"); - if(env->ExceptionCheck() || ppp_constructor == NULL) - { - LOGE("Error finding PeerPhysicalPath constructor"); - return NULL; - } - - jobject pppObject = env->NewObject(pppClass, ppp_constructor); - if(env->ExceptionCheck() || pppObject == NULL) - { - LOGE("Error creating PPP object"); - return NULL; // out of memory - } - - jobject addressObject = newInetSocketAddress(env, ppp.address); - if(env->ExceptionCheck() || addressObject == NULL) { - LOGE("Error creating InetSocketAddress object"); - return NULL; - } - - env->SetObjectField(pppObject, addressField, addressObject); - env->SetLongField(pppObject, lastSendField, ppp.lastSend); - env->SetLongField(pppObject, lastReceiveField, ppp.lastReceive); - env->SetBooleanField(pppObject, preferredField, ppp.preferred); - - if(env->ExceptionCheck()) { - LOGE("Exception assigning fields to PeerPhysicalPath object"); - } - - return pppObject; -} - -jobject newPeer(JNIEnv *env, const ZT_Peer &peer) -{ - LOGV("newPeer called"); - - jclass peerClass = NULL; - - jfieldID addressField = NULL; - jfieldID versionMajorField = NULL; - jfieldID versionMinorField = NULL; - jfieldID versionRevField = NULL; - jfieldID latencyField = NULL; - jfieldID roleField = NULL; - jfieldID pathsField = NULL; - - jmethodID peer_constructor = NULL; - - peerClass = lookup.findClass("com/zerotier/sdk/Peer"); - if(env->ExceptionCheck() || peerClass == NULL) - { - LOGE("Error finding Peer class"); - return NULL; - } - - addressField = lookup.findField(peerClass, "address", "J"); - if(env->ExceptionCheck() || addressField == NULL) - { - LOGE("Error finding address field of Peer object"); - return NULL; - } - - versionMajorField = lookup.findField(peerClass, "versionMajor", "I"); - if(env->ExceptionCheck() || versionMajorField == NULL) - { - LOGE("Error finding versionMajor field of Peer object"); - return NULL; - } - - versionMinorField = lookup.findField(peerClass, "versionMinor", "I"); - if(env->ExceptionCheck() || versionMinorField == NULL) - { - LOGE("Error finding versionMinor field of Peer object"); - return NULL; - } - - versionRevField = lookup.findField(peerClass, "versionRev", "I"); - if(env->ExceptionCheck() || versionRevField == NULL) - { - LOGE("Error finding versionRev field of Peer object"); - return NULL; - } - - latencyField = lookup.findField(peerClass, "latency", "I"); - if(env->ExceptionCheck() || latencyField == NULL) - { - LOGE("Error finding latency field of Peer object"); - return NULL; - } - - roleField = lookup.findField(peerClass, "role", "Lcom/zerotier/sdk/PeerRole;"); - if(env->ExceptionCheck() || roleField == NULL) - { - LOGE("Error finding role field of Peer object"); - return NULL; - } - - pathsField = lookup.findField(peerClass, "paths", "[Lcom/zerotier/sdk/PeerPhysicalPath;"); - if(env->ExceptionCheck() || pathsField == NULL) - { - LOGE("Error finding paths field of Peer object"); - return NULL; - } - - peer_constructor = lookup.findMethod(peerClass, "", "()V"); - if(env->ExceptionCheck() || peer_constructor == NULL) - { - LOGE("Error finding Peer constructor"); - return NULL; - } - - jobject peerObject = env->NewObject(peerClass, peer_constructor); - if(env->ExceptionCheck() || peerObject == NULL) - { - LOGE("Error creating Peer object"); - return NULL; // out of memory - } - - env->SetLongField(peerObject, addressField, (jlong)peer.address); - env->SetIntField(peerObject, versionMajorField, peer.versionMajor); - env->SetIntField(peerObject, versionMinorField, peer.versionMinor); - env->SetIntField(peerObject, versionRevField, peer.versionRev); - env->SetIntField(peerObject, latencyField, peer.latency); - env->SetObjectField(peerObject, roleField, createPeerRole(env, peer.role)); - - jclass peerPhysicalPathClass = lookup.findClass("com/zerotier/sdk/PeerPhysicalPath"); - if(env->ExceptionCheck() || peerPhysicalPathClass == NULL) - { - LOGE("Error finding PeerPhysicalPath class"); - return NULL; - } - - jobjectArray arrayObject = env->NewObjectArray( - peer.pathCount, peerPhysicalPathClass, NULL); - if(env->ExceptionCheck() || arrayObject == NULL) - { - LOGE("Error creating PeerPhysicalPath[] array"); - return NULL; - } - - for(unsigned int i = 0; i < peer.pathCount; ++i) - { - jobject path = newPeerPhysicalPath(env, peer.paths[i]); - - env->SetObjectArrayElement(arrayObject, i, path); - if(env->ExceptionCheck()) { - LOGE("exception assigning PeerPhysicalPath to array"); - break; - } - } - - env->SetObjectField(peerObject, pathsField, arrayObject); - - return peerObject; -} - -jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &vnetConfig) -{ - jclass vnetConfigClass = NULL; - jmethodID vnetConfig_constructor = NULL; - jfieldID nwidField = NULL; - jfieldID macField = NULL; - jfieldID nameField = NULL; - jfieldID statusField = NULL; - jfieldID typeField = NULL; - jfieldID mtuField = NULL; - jfieldID dhcpField = NULL; - jfieldID bridgeField = NULL; - jfieldID broadcastEnabledField = NULL; - jfieldID portErrorField = NULL; - jfieldID netconfRevisionField = NULL; - jfieldID assignedAddressesField = NULL; - jfieldID routesField = NULL; - - vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig"); - if(vnetConfigClass == NULL) - { - LOGE("Couldn't find com.zerotier.sdk.VirtualNetworkConfig"); - return NULL; - } - - vnetConfig_constructor = lookup.findMethod( - vnetConfigClass, "", "()V"); - if(env->ExceptionCheck() || vnetConfig_constructor == NULL) - { - LOGE("Couldn't find VirtualNetworkConfig Constructor"); - return NULL; - } - - jobject vnetConfigObj = env->NewObject(vnetConfigClass, vnetConfig_constructor); - if(env->ExceptionCheck() || vnetConfigObj == NULL) - { - LOGE("Error creating new VirtualNetworkConfig object"); - return NULL; - } - - nwidField = lookup.findField(vnetConfigClass, "nwid", "J"); - if(env->ExceptionCheck() || nwidField == NULL) - { - LOGE("Error getting nwid field"); - return NULL; - } - - macField = lookup.findField(vnetConfigClass, "mac", "J"); - if(env->ExceptionCheck() || macField == NULL) - { - LOGE("Error getting mac field"); - return NULL; - } - - nameField = lookup.findField(vnetConfigClass, "name", "Ljava/lang/String;"); - if(env->ExceptionCheck() || nameField == NULL) - { - LOGE("Error getting name field"); - return NULL; - } - - statusField = lookup.findField(vnetConfigClass, "status", "Lcom/zerotier/sdk/VirtualNetworkStatus;"); - if(env->ExceptionCheck() || statusField == NULL) - { - LOGE("Error getting status field"); - return NULL; - } - - typeField = lookup.findField(vnetConfigClass, "type", "Lcom/zerotier/sdk/VirtualNetworkType;"); - if(env->ExceptionCheck() || typeField == NULL) - { - LOGE("Error getting type field"); - return NULL; - } - - mtuField = lookup.findField(vnetConfigClass, "mtu", "I"); - if(env->ExceptionCheck() || mtuField == NULL) - { - LOGE("Error getting mtu field"); - return NULL; - } - - dhcpField = lookup.findField(vnetConfigClass, "dhcp", "Z"); - if(env->ExceptionCheck() || dhcpField == NULL) - { - LOGE("Error getting dhcp field"); - return NULL; - } - - bridgeField = lookup.findField(vnetConfigClass, "bridge", "Z"); - if(env->ExceptionCheck() || bridgeField == NULL) - { - LOGE("Error getting bridge field"); - return NULL; - } - - broadcastEnabledField = lookup.findField(vnetConfigClass, "broadcastEnabled", "Z"); - if(env->ExceptionCheck() || broadcastEnabledField == NULL) - { - LOGE("Error getting broadcastEnabled field"); - return NULL; - } - - portErrorField = lookup.findField(vnetConfigClass, "portError", "I"); - if(env->ExceptionCheck() || portErrorField == NULL) - { - LOGE("Error getting portError field"); - return NULL; - } - - netconfRevisionField = lookup.findField(vnetConfigClass, "netconfRevision", "J"); - if(env->ExceptionCheck() || netconfRevisionField == NULL) - { - LOGE("Error getting netconfRevision field"); - return NULL; - } - - assignedAddressesField = lookup.findField(vnetConfigClass, "assignedAddresses", - "[Ljava/net/InetSocketAddress;"); - if(env->ExceptionCheck() || assignedAddressesField == NULL) - { - LOGE("Error getting assignedAddresses field"); - return NULL; - } - - routesField = lookup.findField(vnetConfigClass, "routes", - "[Lcom/zerotier/sdk/VirtualNetworkRoute;"); - if(env->ExceptionCheck() || routesField == NULL) - { - LOGE("Error getting routes field"); - return NULL; - } - - env->SetLongField(vnetConfigObj, nwidField, vnetConfig.nwid); - env->SetLongField(vnetConfigObj, macField, vnetConfig.mac); - jstring nameStr = env->NewStringUTF(vnetConfig.name); - if(env->ExceptionCheck() || nameStr == NULL) - { - return NULL; // out of memory - } - env->SetObjectField(vnetConfigObj, nameField, nameStr); - - jobject statusObject = createVirtualNetworkStatus(env, vnetConfig.status); - if(env->ExceptionCheck() || statusObject == NULL) - { - return NULL; - } - env->SetObjectField(vnetConfigObj, statusField, statusObject); - - jobject typeObject = createVirtualNetworkType(env, vnetConfig.type); - if(env->ExceptionCheck() || typeObject == NULL) - { - return NULL; - } - env->SetObjectField(vnetConfigObj, typeField, typeObject); - - env->SetIntField(vnetConfigObj, mtuField, (int)vnetConfig.mtu); - env->SetBooleanField(vnetConfigObj, dhcpField, vnetConfig.dhcp); - env->SetBooleanField(vnetConfigObj, bridgeField, vnetConfig.bridge); - env->SetBooleanField(vnetConfigObj, broadcastEnabledField, vnetConfig.broadcastEnabled); - env->SetIntField(vnetConfigObj, portErrorField, vnetConfig.portError); - - jclass inetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress"); - if(env->ExceptionCheck() || inetSocketAddressClass == NULL) - { - LOGE("Error finding InetSocketAddress class"); - return NULL; - } - - jobjectArray assignedAddrArrayObj = env->NewObjectArray( - vnetConfig.assignedAddressCount, inetSocketAddressClass, NULL); - if(env->ExceptionCheck() || assignedAddrArrayObj == NULL) - { - LOGE("Error creating InetSocketAddress[] array"); - return NULL; - } - - for(unsigned int i = 0; i < vnetConfig.assignedAddressCount; ++i) - { - jobject inetAddrObj = newInetSocketAddress(env, vnetConfig.assignedAddresses[i]); - env->SetObjectArrayElement(assignedAddrArrayObj, i, inetAddrObj); - if(env->ExceptionCheck()) - { - LOGE("Error assigning InetSocketAddress to array"); - return NULL; - } - } - - env->SetObjectField(vnetConfigObj, assignedAddressesField, assignedAddrArrayObj); - - jclass virtualNetworkRouteClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkRoute"); - if(env->ExceptionCheck() || virtualNetworkRouteClass == NULL) - { - LOGE("Error finding VirtualNetworkRoute class"); - return NULL; - } - - jobjectArray routesArrayObj = env->NewObjectArray( - vnetConfig.routeCount, virtualNetworkRouteClass, NULL); - if(env->ExceptionCheck() || routesArrayObj == NULL) - { - LOGE("Error creating VirtualNetworkRoute[] array"); - return NULL; - } - - for(unsigned int i = 0; i < vnetConfig.routeCount; ++i) - { - jobject routeObj = newVirtualNetworkRoute(env, vnetConfig.routes[i]); - env->SetObjectArrayElement(routesArrayObj, i, routeObj); - if(env->ExceptionCheck()) - { - LOGE("Error assigning VirtualNetworkRoute to array"); - return NULL; - } - } - - env->SetObjectField(vnetConfigObj, routesField, routesArrayObj); - - return vnetConfigObj; -} - -jobject newVersion(JNIEnv *env, int major, int minor, int rev) -{ - // create a com.zerotier.sdk.Version object - jclass versionClass = NULL; - jmethodID versionConstructor = NULL; - - versionClass = lookup.findClass("com/zerotier/sdk/Version"); - if(env->ExceptionCheck() || versionClass == NULL) - { - return NULL; - } - - versionConstructor = lookup.findMethod( - versionClass, "", "()V"); - if(env->ExceptionCheck() || versionConstructor == NULL) - { - return NULL; - } - - jobject versionObj = env->NewObject(versionClass, versionConstructor); - if(env->ExceptionCheck() || versionObj == NULL) - { - return NULL; - } - - // copy data to Version object - jfieldID majorField = NULL; - jfieldID minorField = NULL; - jfieldID revisionField = NULL; - - majorField = lookup.findField(versionClass, "major", "I"); - if(env->ExceptionCheck() || majorField == NULL) - { - return NULL; - } - - minorField = lookup.findField(versionClass, "minor", "I"); - if(env->ExceptionCheck() || minorField == NULL) - { - return NULL; - } - - revisionField = lookup.findField(versionClass, "revision", "I"); - if(env->ExceptionCheck() || revisionField == NULL) - { - return NULL; - } - - env->SetIntField(versionObj, majorField, (jint)major); - env->SetIntField(versionObj, minorField, (jint)minor); - env->SetIntField(versionObj, revisionField, (jint)rev); - - return versionObj; -} - -jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route) -{ - jclass virtualNetworkRouteClass = NULL; - jmethodID routeConstructor = NULL; - - virtualNetworkRouteClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkRoute"); - if(env->ExceptionCheck() || virtualNetworkRouteClass == NULL) - { - return NULL; - } - - routeConstructor = lookup.findMethod(virtualNetworkRouteClass, "", "()V"); - if(env->ExceptionCheck() || routeConstructor == NULL) - { - return NULL; - } - - jobject routeObj = env->NewObject(virtualNetworkRouteClass, routeConstructor); - if(env->ExceptionCheck() || routeObj == NULL) - { - return NULL; - } - - jfieldID targetField = NULL; - jfieldID viaField = NULL; - jfieldID flagsField = NULL; - jfieldID metricField = NULL; - - targetField = lookup.findField(virtualNetworkRouteClass, "target", - "Ljava/net/InetSocketAddress;"); - if(env->ExceptionCheck() || targetField == NULL) - { - return NULL; - } - - viaField = lookup.findField(virtualNetworkRouteClass, "via", - "Ljava/net/InetSocketAddress;"); - if(env->ExceptionCheck() || targetField == NULL) - { - return NULL; - } - - flagsField = lookup.findField(virtualNetworkRouteClass, "flags", "I"); - if(env->ExceptionCheck() || flagsField == NULL) - { - return NULL; - } - - metricField = lookup.findField(virtualNetworkRouteClass, "metric", "I"); - if(env->ExceptionCheck() || metricField == NULL) - { - return NULL; - } - - jobject targetObj = newInetSocketAddress(env, route.target); - jobject viaObj = newInetSocketAddress(env, route.via); - - env->SetObjectField(routeObj, targetField, targetObj); - env->SetObjectField(routeObj, viaField, viaObj); - env->SetIntField(routeObj, flagsField, (jint)route.flags); - env->SetIntField(routeObj, metricField, (jint)route.metric); - - return routeObj; -} - -#ifdef __cplusplus -} -#endif - diff --git a/zerotierone/java/jni/ZT_jniutils.h b/zerotierone/java/jni/ZT_jniutils.h deleted file mode 100644 index e35d4f4..0000000 --- a/zerotierone/java/jni/ZT_jniutils.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 . - */ - -#ifndef ZT_jniutils_h_ -#define ZT_jniutils_h_ -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define LOG_TAG "ZeroTierOneJNI" - -#if __ANDROID__ -#include -#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) -#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) -#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) -#else -#define LOGV(...) fprintf(stdout, __VA_ARGS__) -#define LOGI(...) fprintf(stdout, __VA_ARGS__) -#define LOGD(...) fprintf(stdout, __VA_ARGS__) -#define LOGE(...) fprintf(stdout, __VA_ARGS__) -#endif - -jobject createResultObject(JNIEnv *env, ZT_ResultCode code); -jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status); -jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type); -jobject createEvent(JNIEnv *env, ZT_Event event); -jobject createPeerRole(JNIEnv *env, ZT_PeerRole role); -jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT_VirtualNetworkConfigOperation op); - -jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr); -jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr); - -jobject newMulticastGroup(JNIEnv *env, const ZT_MulticastGroup &mc); - -jobject newPeer(JNIEnv *env, const ZT_Peer &peer); -jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp); - -jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &config); - -jobject newVersion(JNIEnv *env, int major, int minor, int rev); - -jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/zerotierone/java/jni/com_zerotierone_sdk_Node.cpp b/zerotierone/java/jni/com_zerotierone_sdk_Node.cpp deleted file mode 100644 index eb62d98..0000000 --- a/zerotierone/java/jni/com_zerotierone_sdk_Node.cpp +++ /dev/null @@ -1,1381 +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 . - * - * -- - * - * 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 "com_zerotierone_sdk_Node.h" -#include "ZT_jniutils.h" -#include "ZT_jnilookup.h" - -#include -#include "Mutex.hpp" - -#include -#include -#include -#include - -// global static JNI Lookup Object -JniLookup lookup; - -#ifdef __cplusplus -extern "C" { -#endif - -namespace { - struct JniRef - { - JniRef() - : jvm(NULL) - , node(NULL) - , dataStoreGetListener(NULL) - , dataStorePutListener(NULL) - , packetSender(NULL) - , eventListener(NULL) - , frameListener(NULL) - , configListener(NULL) - , callbacks(NULL) - { - callbacks = (ZT_Node_Callbacks*)malloc(sizeof(ZT_Node_Callbacks)); - memset(callbacks, 0, sizeof(ZT_Node_Callbacks)); - } - - ~JniRef() - { - JNIEnv *env = NULL; - jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - env->DeleteGlobalRef(dataStoreGetListener); - env->DeleteGlobalRef(dataStorePutListener); - env->DeleteGlobalRef(packetSender); - env->DeleteGlobalRef(eventListener); - env->DeleteGlobalRef(frameListener); - env->DeleteGlobalRef(configListener); - - free(callbacks); - callbacks = NULL; - } - - uint64_t id; - - JavaVM *jvm; - - ZT_Node *node; - - jobject dataStoreGetListener; - jobject dataStorePutListener; - jobject packetSender; - jobject eventListener; - jobject frameListener; - jobject configListener; - - ZT_Node_Callbacks *callbacks; - }; - - - int VirtualNetworkConfigFunctionCallback( - ZT_Node *node, - void *userData, - uint64_t nwid, - void **, - enum ZT_VirtualNetworkConfigOperation operation, - const ZT_VirtualNetworkConfig *config) - { - LOGV("VritualNetworkConfigFunctionCallback"); - JniRef *ref = (JniRef*)userData; - JNIEnv *env = NULL; - ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - jclass configListenerClass = env->GetObjectClass(ref->configListener); - if(configListenerClass == NULL) - { - LOGE("Couldn't find class for VirtualNetworkConfigListener instance"); - return -1; - } - - jmethodID configListenerCallbackMethod = lookup.findMethod(configListenerClass, - "onNetworkConfigurationUpdated", - "(JLcom/zerotier/sdk/VirtualNetworkConfigOperation;Lcom/zerotier/sdk/VirtualNetworkConfig;)I"); - if(configListenerCallbackMethod == NULL) - { - LOGE("Couldn't find onVirtualNetworkFrame() method"); - return -2; - } - - jobject operationObject = createVirtualNetworkConfigOperation(env, operation); - if(operationObject == NULL) - { - LOGE("Error creating VirtualNetworkConfigOperation object"); - return -3; - } - - jobject networkConfigObject = newNetworkConfig(env, *config); - if(networkConfigObject == NULL) - { - LOGE("Error creating VirtualNetworkConfig object"); - return -4; - } - - return env->CallIntMethod( - ref->configListener, - configListenerCallbackMethod, - (jlong)nwid, operationObject, networkConfigObject); - } - - void VirtualNetworkFrameFunctionCallback(ZT_Node *node, - void *userData, - uint64_t nwid, - void**, - uint64_t sourceMac, - uint64_t destMac, - unsigned int etherType, - unsigned int vlanid, - const void *frameData, - unsigned int frameLength) - { - LOGV("VirtualNetworkFrameFunctionCallback"); - unsigned char* local = (unsigned char*)frameData; - LOGV("Type Bytes: 0x%02x%02x", local[12], local[13]); - JniRef *ref = (JniRef*)userData; - assert(ref->node == node); - JNIEnv *env = NULL; - ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - - jclass frameListenerClass = env->GetObjectClass(ref->frameListener); - if(env->ExceptionCheck() || frameListenerClass == NULL) - { - LOGE("Couldn't find class for VirtualNetworkFrameListener instance"); - return; - } - - jmethodID frameListenerCallbackMethod = lookup.findMethod( - frameListenerClass, - "onVirtualNetworkFrame", "(JJJJJ[B)V"); - if(env->ExceptionCheck() || frameListenerCallbackMethod == NULL) - { - LOGE("Couldn't find onVirtualNetworkFrame() method"); - return; - } - - jbyteArray dataArray = env->NewByteArray(frameLength); - if(env->ExceptionCheck() || dataArray == NULL) - { - LOGE("Couldn't create frame data array"); - return; - } - - void *data = env->GetPrimitiveArrayCritical(dataArray, NULL); - memcpy(data, frameData, frameLength); - env->ReleasePrimitiveArrayCritical(dataArray, data, 0); - - if(env->ExceptionCheck()) - { - LOGE("Error setting frame data to array"); - return; - } - - env->CallVoidMethod(ref->frameListener, frameListenerCallbackMethod, (jlong)nwid, (jlong)sourceMac, (jlong)destMac, (jlong)etherType, (jlong)vlanid, dataArray); - } - - - void EventCallback(ZT_Node *node, - void *userData, - enum ZT_Event event, - const void *data) - { - LOGV("EventCallback"); - JniRef *ref = (JniRef*)userData; - if(ref->node != node && event != ZT_EVENT_UP) - { - LOGE("Nodes not equal. ref->node %p, node %p. Event: %d", ref->node, node, event); - return; - } - JNIEnv *env = NULL; - ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - - jclass eventListenerClass = env->GetObjectClass(ref->eventListener); - if(eventListenerClass == NULL) - { - LOGE("Couldn't class for EventListener instance"); - return; - } - - jmethodID onEventMethod = lookup.findMethod(eventListenerClass, - "onEvent", "(Lcom/zerotier/sdk/Event;)V"); - if(onEventMethod == NULL) - { - LOGE("Couldn't find onEvent method"); - return; - } - - jmethodID onTraceMethod = lookup.findMethod(eventListenerClass, - "onTrace", "(Ljava/lang/String;)V"); - if(onTraceMethod == NULL) - { - LOGE("Couldn't find onTrace method"); - return; - } - - jobject eventObject = createEvent(env, event); - if(eventObject == NULL) - { - return; - } - - switch(event) - { - case ZT_EVENT_UP: - { - LOGD("Event Up"); - env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject); - break; - } - case ZT_EVENT_OFFLINE: - { - LOGD("Event Offline"); - env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject); - break; - } - case ZT_EVENT_ONLINE: - { - LOGD("Event Online"); - env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject); - break; - } - case ZT_EVENT_DOWN: - { - LOGD("Event Down"); - env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject); - break; - } - case ZT_EVENT_FATAL_ERROR_IDENTITY_COLLISION: - { - LOGV("Identity Collision"); - // call onEvent() - env->CallVoidMethod(ref->eventListener, onEventMethod, eventObject); - } - break; - case ZT_EVENT_TRACE: - { - LOGV("Trace Event"); - // call onTrace() - if(data != NULL) - { - const char* message = (const char*)data; - jstring messageStr = env->NewStringUTF(message); - env->CallVoidMethod(ref->eventListener, onTraceMethod, messageStr); - } - } - break; - case ZT_EVENT_USER_MESSAGE: - break; - } - } - - long DataStoreGetFunction(ZT_Node *node, - void *userData, - const char *objectName, - void *buffer, - unsigned long bufferSize, - unsigned long bufferIndex, - unsigned long *out_objectSize) - { - JniRef *ref = (JniRef*)userData; - JNIEnv *env = NULL; - ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - jclass dataStoreGetClass = env->GetObjectClass(ref->dataStoreGetListener); - if(dataStoreGetClass == NULL) - { - LOGE("Couldn't find class for DataStoreGetListener instance"); - return -2; - } - - jmethodID dataStoreGetCallbackMethod = lookup.findMethod( - dataStoreGetClass, - "onDataStoreGet", - "(Ljava/lang/String;[BJ[J)J"); - if(dataStoreGetCallbackMethod == NULL) - { - LOGE("Couldn't find onDataStoreGet method"); - return -2; - } - - jstring nameStr = env->NewStringUTF(objectName); - if(nameStr == NULL) - { - LOGE("Error creating name string object"); - return -2; // out of memory - } - - jbyteArray bufferObj = env->NewByteArray(bufferSize); - if(bufferObj == NULL) - { - LOGE("Error creating byte[] buffer of size: %lu", bufferSize); - return -2; - } - - jlongArray objectSizeObj = env->NewLongArray(1); - if(objectSizeObj == NULL) - { - LOGE("Error creating long[1] array for actual object size"); - return -2; // couldn't create long[1] array - } - - LOGV("Calling onDataStoreGet(%s, %p, %lu, %p)", - objectName, buffer, bufferIndex, objectSizeObj); - - long retval = (long)env->CallLongMethod( - ref->dataStoreGetListener, dataStoreGetCallbackMethod, - nameStr, bufferObj, (jlong)bufferIndex, objectSizeObj); - - if(retval > 0) - { - void *data = env->GetPrimitiveArrayCritical(bufferObj, NULL); - memcpy(buffer, data, retval); - env->ReleasePrimitiveArrayCritical(bufferObj, data, 0); - - jlong *objSize = (jlong*)env->GetPrimitiveArrayCritical(objectSizeObj, NULL); - *out_objectSize = (unsigned long)objSize[0]; - env->ReleasePrimitiveArrayCritical(objectSizeObj, objSize, 0); - } - - LOGV("Out Object Size: %lu", *out_objectSize); - - return retval; - } - - int DataStorePutFunction(ZT_Node *node, - void *userData, - const char *objectName, - const void *buffer, - unsigned long bufferSize, - int secure) - { - JniRef *ref = (JniRef*)userData; - JNIEnv *env = NULL; - ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - - jclass dataStorePutClass = env->GetObjectClass(ref->dataStorePutListener); - if(dataStorePutClass == NULL) - { - LOGE("Couldn't find class for DataStorePutListener instance"); - return -1; - } - - jmethodID dataStorePutCallbackMethod = lookup.findMethod( - dataStorePutClass, - "onDataStorePut", - "(Ljava/lang/String;[BZ)I"); - if(dataStorePutCallbackMethod == NULL) - { - LOGE("Couldn't find onDataStorePut method"); - return -2; - } - - jmethodID deleteMethod = lookup.findMethod(dataStorePutClass, - "onDelete", "(Ljava/lang/String;)I"); - if(deleteMethod == NULL) - { - LOGE("Couldn't find onDelete method"); - return -3; - } - - jstring nameStr = env->NewStringUTF(objectName); - - if(buffer == NULL) - { - LOGD("JNI: Delete file: %s", objectName); - // delete operation - return env->CallIntMethod( - ref->dataStorePutListener, deleteMethod, nameStr); - } - else - { - LOGD("JNI: Write file: %s", objectName); - // set operation - jbyteArray bufferObj = env->NewByteArray(bufferSize); - if(env->ExceptionCheck() || bufferObj == NULL) - { - LOGE("Error creating byte array buffer!"); - return -4; - } - - env->SetByteArrayRegion(bufferObj, 0, bufferSize, (jbyte*)buffer); - bool bsecure = secure != 0; - - return env->CallIntMethod(ref->dataStorePutListener, - dataStorePutCallbackMethod, - nameStr, bufferObj, bsecure); - } - } - - int WirePacketSendFunction(ZT_Node *node, - void *userData, - const struct sockaddr_storage *localAddress, - const struct sockaddr_storage *remoteAddress, - const void *buffer, - unsigned int bufferSize, - unsigned int ttl) - { - LOGV("WirePacketSendFunction(%p, %p, %p, %d)", localAddress, remoteAddress, buffer, bufferSize); - JniRef *ref = (JniRef*)userData; - assert(ref->node == node); - - JNIEnv *env = NULL; - ref->jvm->GetEnv((void**)&env, JNI_VERSION_1_6); - - - jclass packetSenderClass = env->GetObjectClass(ref->packetSender); - if(packetSenderClass == NULL) - { - LOGE("Couldn't find class for PacketSender instance"); - return -1; - } - - jmethodID packetSenderCallbackMethod = lookup.findMethod(packetSenderClass, - "onSendPacketRequested", "(Ljava/net/InetSocketAddress;Ljava/net/InetSocketAddress;[BI)I"); - if(packetSenderCallbackMethod == NULL) - { - LOGE("Couldn't find onSendPacketRequested method"); - return -2; - } - - jobject localAddressObj = NULL; - if(memcmp(localAddress, &ZT_SOCKADDR_NULL, sizeof(sockaddr_storage)) != 0) - { - localAddressObj = newInetSocketAddress(env, *localAddress); - } - - jobject remoteAddressObj = newInetSocketAddress(env, *remoteAddress); - jbyteArray bufferObj = env->NewByteArray(bufferSize); - env->SetByteArrayRegion(bufferObj, 0, bufferSize, (jbyte*)buffer); - int retval = env->CallIntMethod(ref->packetSender, packetSenderCallbackMethod, localAddressObj, remoteAddressObj, bufferObj); - - LOGV("JNI Packet Sender returned: %d", retval); - return retval; - } - - typedef std::map NodeMap; - static NodeMap nodeMap; - ZeroTier::Mutex nodeMapMutex; - - ZT_Node* findNode(uint64_t nodeId) - { - ZeroTier::Mutex::Lock lock(nodeMapMutex); - NodeMap::iterator found = nodeMap.find(nodeId); - if(found != nodeMap.end()) - { - JniRef *ref = found->second; - return ref->node; - } - return NULL; - } -} - -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) -{ - lookup.setJavaVM(vm); - return JNI_VERSION_1_6; -} - -JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) -{ - -} - - -/* - * Class: com_zerotier_sdk_Node - * Method: node_init - * Signature: (J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init( - JNIEnv *env, jobject obj, jlong now) -{ - LOGV("Creating ZT_Node struct"); - jobject resultObject = createResultObject(env, ZT_RESULT_OK); - - ZT_Node *node; - JniRef *ref = new JniRef; - ref->id = (uint64_t)now; - env->GetJavaVM(&ref->jvm); - - jclass cls = env->GetObjectClass(obj); - jfieldID fid = lookup.findField( - cls, "getListener", "Lcom/zerotier/sdk/DataStoreGetListener;"); - - if(fid == NULL) - { - return NULL; // exception already thrown - } - - jobject tmp = env->GetObjectField(obj, fid); - if(tmp == NULL) - { - return NULL; - } - ref->dataStoreGetListener = env->NewGlobalRef(tmp); - - fid = lookup.findField( - cls, "putListener", "Lcom/zerotier/sdk/DataStorePutListener;"); - - if(fid == NULL) - { - return NULL; // exception already thrown - } - - tmp = env->GetObjectField(obj, fid); - if(tmp == NULL) - { - return NULL; - } - ref->dataStorePutListener = env->NewGlobalRef(tmp); - - fid = lookup.findField( - cls, "sender", "Lcom/zerotier/sdk/PacketSender;"); - if(fid == NULL) - { - return NULL; // exception already thrown - } - - tmp = env->GetObjectField(obj, fid); - if(tmp == NULL) - { - return NULL; - } - ref->packetSender = env->NewGlobalRef(tmp); - - fid = lookup.findField( - cls, "frameListener", "Lcom/zerotier/sdk/VirtualNetworkFrameListener;"); - if(fid == NULL) - { - return NULL; // exception already thrown - } - - tmp = env->GetObjectField(obj, fid); - if(tmp == NULL) - { - return NULL; - } - ref->frameListener = env->NewGlobalRef(tmp); - - fid = lookup.findField( - cls, "configListener", "Lcom/zerotier/sdk/VirtualNetworkConfigListener;"); - if(fid == NULL) - { - return NULL; // exception already thrown - } - - tmp = env->GetObjectField(obj, fid); - if(tmp == NULL) - { - return NULL; - } - ref->configListener = env->NewGlobalRef(tmp); - - fid = lookup.findField( - cls, "eventListener", "Lcom/zerotier/sdk/EventListener;"); - if(fid == NULL) - { - return NULL; - } - - tmp = env->GetObjectField(obj, fid); - if(tmp == NULL) - { - return NULL; - } - ref->eventListener = env->NewGlobalRef(tmp); - - ref->callbacks->dataStoreGetFunction = &DataStoreGetFunction; - ref->callbacks->dataStorePutFunction = &DataStorePutFunction; - ref->callbacks->wirePacketSendFunction = &WirePacketSendFunction; - ref->callbacks->virtualNetworkFrameFunction = &VirtualNetworkFrameFunctionCallback; - ref->callbacks->virtualNetworkConfigFunction = &VirtualNetworkConfigFunctionCallback; - ref->callbacks->eventCallback = &EventCallback; - - ZT_ResultCode rc = ZT_Node_new( - &node, - ref, - ref->callbacks, - (uint64_t)now); - - if(rc != ZT_RESULT_OK) - { - LOGE("Error creating Node: %d", rc); - resultObject = createResultObject(env, rc); - if(node) - { - ZT_Node_delete(node); - node = NULL; - } - delete ref; - ref = NULL; - return resultObject; - } - - ZeroTier::Mutex::Lock lock(nodeMapMutex); - ref->node = node; - nodeMap.insert(std::make_pair(ref->id, ref)); - - - return resultObject; -} - -/* - * Class: com_zerotier_sdk_Node - * Method: node_delete - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_zerotier_sdk_Node_node_1delete( - JNIEnv *env, jobject obj, jlong id) -{ - LOGV("Destroying ZT_Node struct"); - uint64_t nodeId = (uint64_t)id; - - NodeMap::iterator found; - { - ZeroTier::Mutex::Lock lock(nodeMapMutex); - found = nodeMap.find(nodeId); - } - - if(found != nodeMap.end()) - { - JniRef *ref = found->second; - nodeMap.erase(found); - - ZT_Node_delete(ref->node); - - delete ref; - ref = NULL; - } - else - { - LOGE("Attempted to delete a node that doesn't exist!"); - } -} - -/* - * Class: com_zerotier_sdk_Node - * Method: processVirtualNetworkFrame - * Signature: (JJJJJII[B[J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processVirtualNetworkFrame( - JNIEnv *env, jobject obj, - jlong id, - jlong in_now, - jlong in_nwid, - jlong in_sourceMac, - jlong in_destMac, - jint in_etherType, - jint in_vlanId, - jbyteArray in_frameData, - jlongArray out_nextBackgroundTaskDeadline) -{ - uint64_t nodeId = (uint64_t) id; - - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline); - if(nbtd_len < 1) - { - // array for next background task length has 0 elements! - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t now = (uint64_t)in_now; - uint64_t nwid = (uint64_t)in_nwid; - uint64_t sourceMac = (uint64_t)in_sourceMac; - uint64_t destMac = (uint64_t)in_destMac; - unsigned int etherType = (unsigned int)in_etherType; - unsigned int vlanId = (unsigned int)in_vlanId; - - unsigned int frameLength = env->GetArrayLength(in_frameData); - void *frameData = env->GetPrimitiveArrayCritical(in_frameData, NULL); - void *localData = malloc(frameLength); - memcpy(localData, frameData, frameLength); - env->ReleasePrimitiveArrayCritical(in_frameData, frameData, 0); - - uint64_t nextBackgroundTaskDeadline = 0; - - ZT_ResultCode rc = ZT_Node_processVirtualNetworkFrame( - node, - now, - nwid, - sourceMac, - destMac, - etherType, - vlanId, - (const void*)localData, - frameLength, - &nextBackgroundTaskDeadline); - - jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL); - outDeadline[0] = (jlong)nextBackgroundTaskDeadline; - env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: processWirePacket - * Signature: (JJLjava/net/InetSocketAddress;I[B[J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket( - JNIEnv *env, jobject obj, - jlong id, - jlong in_now, - jobject in_localAddress, - jobject in_remoteAddress, - jbyteArray in_packetData, - jlongArray out_nextBackgroundTaskDeadline) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - LOGE("Couldn't find a valid node!"); - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline); - if(nbtd_len < 1) - { - LOGE("nbtd_len < 1"); - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t now = (uint64_t)in_now; - - // get the java.net.InetSocketAddress class and getAddress() method - jclass inetAddressClass = lookup.findClass("java/net/InetAddress"); - if(inetAddressClass == NULL) - { - LOGE("Can't find InetAddress class"); - // can't find java.net.InetAddress - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - jmethodID getAddressMethod = lookup.findMethod( - inetAddressClass, "getAddress", "()[B"); - if(getAddressMethod == NULL) - { - // cant find InetAddress.getAddres() - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - jclass InetSocketAddressClass = lookup.findClass("java/net/InetSocketAddress"); - if(InetSocketAddressClass == NULL) - { - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - jmethodID inetSockGetAddressMethod = lookup.findMethod( - InetSocketAddressClass, "getAddress", "()Ljava/net/InetAddress;"); - - jobject localAddrObj = NULL; - if(in_localAddress != NULL) - { - localAddrObj = env->CallObjectMethod(in_localAddress, inetSockGetAddressMethod); - } - - jobject remoteAddrObject = env->CallObjectMethod(in_remoteAddress, inetSockGetAddressMethod); - - if(remoteAddrObject == NULL) - { - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - jmethodID inetSock_getPort = lookup.findMethod( - InetSocketAddressClass, "getPort", "()I"); - - if(env->ExceptionCheck() || inetSock_getPort == NULL) - { - LOGE("Couldn't find getPort method on InetSocketAddress"); - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - // call InetSocketAddress.getPort() - int remotePort = env->CallIntMethod(in_remoteAddress, inetSock_getPort); - if(env->ExceptionCheck()) - { - LOGE("Exception calling InetSocketAddress.getPort()"); - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - // Call InetAddress.getAddress() - jbyteArray remoteAddressArray = (jbyteArray)env->CallObjectMethod(remoteAddrObject, getAddressMethod); - if(remoteAddressArray == NULL) - { - LOGE("Unable to call getAddress()"); - // unable to call getAddress() - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - unsigned int addrSize = env->GetArrayLength(remoteAddressArray); - - - sockaddr_storage localAddress = {}; - - if(localAddrObj == NULL) - { - localAddress = ZT_SOCKADDR_NULL; - } - else - { - int localPort = env->CallIntMethod(in_localAddress, inetSock_getPort); - jbyteArray localAddressArray = (jbyteArray)env->CallObjectMethod(localAddrObj, getAddressMethod); - if(localAddressArray != NULL) - { - - unsigned int localAddrSize = env->GetArrayLength(localAddressArray); - jbyte *addr = (jbyte*)env->GetPrimitiveArrayCritical(localAddressArray, NULL); - - if(localAddrSize == 16) - { - sockaddr_in6 ipv6 = {}; - ipv6.sin6_family = AF_INET6; - ipv6.sin6_port = htons(localPort); - memcpy(ipv6.sin6_addr.s6_addr, addr, 16); - memcpy(&localAddress, &ipv6, sizeof(sockaddr_in6)); - } - else if(localAddrSize) - { - // IPV4 address - sockaddr_in ipv4 = {}; - ipv4.sin_family = AF_INET; - ipv4.sin_port = htons(localPort); - memcpy(&ipv4.sin_addr, addr, 4); - memcpy(&localAddress, &ipv4, sizeof(sockaddr_in)); - } - else - { - localAddress = ZT_SOCKADDR_NULL; - } - env->ReleasePrimitiveArrayCritical(localAddressArray, addr, 0); - } - } - - // get the address bytes - jbyte *addr = (jbyte*)env->GetPrimitiveArrayCritical(remoteAddressArray, NULL); - sockaddr_storage remoteAddress = {}; - - if(addrSize == 16) - { - // IPV6 address - sockaddr_in6 ipv6 = {}; - ipv6.sin6_family = AF_INET6; - ipv6.sin6_port = htons(remotePort); - memcpy(ipv6.sin6_addr.s6_addr, addr, 16); - memcpy(&remoteAddress, &ipv6, sizeof(sockaddr_in6)); - } - else if(addrSize == 4) - { - // IPV4 address - sockaddr_in ipv4 = {}; - ipv4.sin_family = AF_INET; - ipv4.sin_port = htons(remotePort); - memcpy(&ipv4.sin_addr, addr, 4); - memcpy(&remoteAddress, &ipv4, sizeof(sockaddr_in)); - } - else - { - LOGE("Unknown IP version"); - // unknown address type - env->ReleasePrimitiveArrayCritical(remoteAddressArray, addr, 0); - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - env->ReleasePrimitiveArrayCritical(remoteAddressArray, addr, 0); - - unsigned int packetLength = env->GetArrayLength(in_packetData); - if(packetLength == 0) - { - LOGE("Empty packet?!?"); - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - void *packetData = env->GetPrimitiveArrayCritical(in_packetData, NULL); - void *localData = malloc(packetLength); - memcpy(localData, packetData, packetLength); - env->ReleasePrimitiveArrayCritical(in_packetData, packetData, 0); - - uint64_t nextBackgroundTaskDeadline = 0; - - ZT_ResultCode rc = ZT_Node_processWirePacket( - node, - now, - &localAddress, - &remoteAddress, - localData, - packetLength, - &nextBackgroundTaskDeadline); - if(rc != ZT_RESULT_OK) - { - LOGE("ZT_Node_processWirePacket returned: %d", rc); - } - - free(localData); - - jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL); - outDeadline[0] = (jlong)nextBackgroundTaskDeadline; - env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: processBackgroundTasks - * Signature: (JJ[J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processBackgroundTasks( - JNIEnv *env, jobject obj, - jlong id, - jlong in_now, - jlongArray out_nextBackgroundTaskDeadline) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - unsigned int nbtd_len = env->GetArrayLength(out_nextBackgroundTaskDeadline); - if(nbtd_len < 1) - { - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t now = (uint64_t)in_now; - uint64_t nextBackgroundTaskDeadline = 0; - - ZT_ResultCode rc = ZT_Node_processBackgroundTasks(node, now, &nextBackgroundTaskDeadline); - - jlong *outDeadline = (jlong*)env->GetPrimitiveArrayCritical(out_nextBackgroundTaskDeadline, NULL); - outDeadline[0] = (jlong)nextBackgroundTaskDeadline; - env->ReleasePrimitiveArrayCritical(out_nextBackgroundTaskDeadline, outDeadline, 0); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: join - * Signature: (JJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_join( - JNIEnv *env, jobject obj, jlong id, jlong in_nwid) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t nwid = (uint64_t)in_nwid; - - ZT_ResultCode rc = ZT_Node_join(node, nwid, NULL); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: leave - * Signature: (JJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_leave( - JNIEnv *env, jobject obj, jlong id, jlong in_nwid) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t nwid = (uint64_t)in_nwid; - - ZT_ResultCode rc = ZT_Node_leave(node, nwid, NULL); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: multicastSubscribe - * Signature: (JJJJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_multicastSubscribe( - JNIEnv *env, jobject obj, - jlong id, - jlong in_nwid, - jlong in_multicastGroup, - jlong in_multicastAdi) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t nwid = (uint64_t)in_nwid; - uint64_t multicastGroup = (uint64_t)in_multicastGroup; - unsigned long multicastAdi = (unsigned long)in_multicastAdi; - - ZT_ResultCode rc = ZT_Node_multicastSubscribe( - node, nwid, multicastGroup, multicastAdi); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: multicastUnsubscribe - * Signature: (JJJJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_multicastUnsubscribe( - JNIEnv *env, jobject obj, - jlong id, - jlong in_nwid, - jlong in_multicastGroup, - jlong in_multicastAdi) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return createResultObject(env, ZT_RESULT_FATAL_ERROR_INTERNAL); - } - - uint64_t nwid = (uint64_t)in_nwid; - uint64_t multicastGroup = (uint64_t)in_multicastGroup; - unsigned long multicastAdi = (unsigned long)in_multicastAdi; - - ZT_ResultCode rc = ZT_Node_multicastUnsubscribe( - node, nwid, multicastGroup, multicastAdi); - - return createResultObject(env, rc); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: address - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_com_zerotier_sdk_Node_address( - JNIEnv *env , jobject obj, jlong id) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return 0; - } - - uint64_t address = ZT_Node_address(node); - return (jlong)address; -} - -/* - * Class: com_zerotier_sdk_Node - * Method: status - * Signature: (J)Lcom/zerotier/sdk/NodeStatus; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status - (JNIEnv *env, jobject obj, jlong id) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return 0; - } - - jclass nodeStatusClass = NULL; - jmethodID nodeStatusConstructor = NULL; - - // create a com.zerotier.sdk.NodeStatus object - nodeStatusClass = lookup.findClass("com/zerotier/sdk/NodeStatus"); - if(nodeStatusClass == NULL) - { - return NULL; - } - - nodeStatusConstructor = lookup.findMethod( - nodeStatusClass, "", "()V"); - if(nodeStatusConstructor == NULL) - { - return NULL; - } - - jobject nodeStatusObj = env->NewObject(nodeStatusClass, nodeStatusConstructor); - if(nodeStatusObj == NULL) - { - return NULL; - } - - ZT_NodeStatus nodeStatus; - ZT_Node_status(node, &nodeStatus); - - jfieldID addressField = NULL; - jfieldID publicIdentityField = NULL; - jfieldID secretIdentityField = NULL; - jfieldID onlineField = NULL; - - addressField = lookup.findField(nodeStatusClass, "address", "J"); - if(addressField == NULL) - { - return NULL; - } - - publicIdentityField = lookup.findField(nodeStatusClass, "publicIdentity", "Ljava/lang/String;"); - if(publicIdentityField == NULL) - { - return NULL; - } - - secretIdentityField = lookup.findField(nodeStatusClass, "secretIdentity", "Ljava/lang/String;"); - if(secretIdentityField == NULL) - { - return NULL; - } - - onlineField = lookup.findField(nodeStatusClass, "online", "Z"); - if(onlineField == NULL) - { - return NULL; - } - - env->SetLongField(nodeStatusObj, addressField, nodeStatus.address); - - jstring pubIdentStr = env->NewStringUTF(nodeStatus.publicIdentity); - if(pubIdentStr == NULL) - { - return NULL; // out of memory - } - env->SetObjectField(nodeStatusObj, publicIdentityField, pubIdentStr); - - jstring secIdentStr = env->NewStringUTF(nodeStatus.secretIdentity); - if(secIdentStr == NULL) - { - return NULL; // out of memory - } - env->SetObjectField(nodeStatusObj, secretIdentityField, secIdentStr); - - env->SetBooleanField(nodeStatusObj, onlineField, nodeStatus.online); - - return nodeStatusObj; -} - -/* - * Class: com_zerotier_sdk_Node - * Method: networkConfig - * Signature: (J)Lcom/zerotier/sdk/VirtualNetworkConfig; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_networkConfig( - JNIEnv *env, jobject obj, jlong id, jlong nwid) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return 0; - } - - ZT_VirtualNetworkConfig *vnetConfig = ZT_Node_networkConfig(node, nwid); - - jobject vnetConfigObject = newNetworkConfig(env, *vnetConfig); - - ZT_Node_freeQueryResult(node, vnetConfig); - - return vnetConfigObject; -} - -/* - * Class: com_zerotier_sdk_Node - * Method: version - * Signature: (J)Lcom/zerotier/sdk/Version; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_version( - JNIEnv *env, jobject obj) -{ - int major = 0; - int minor = 0; - int revision = 0; - - ZT_version(&major, &minor, &revision); - - return newVersion(env, major, minor, revision); -} - -/* - * Class: com_zerotier_sdk_Node - * Method: peers - * Signature: (J)[Lcom/zerotier/sdk/Peer; - */ -JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_peers( - JNIEnv *env, jobject obj, jlong id) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return 0; - } - - ZT_PeerList *peerList = ZT_Node_peers(node); - - if(peerList == NULL) - { - LOGE("ZT_Node_peers returned NULL"); - return NULL; - } - - int peerCount = peerList->peerCount * 100; - LOGV("Ensure Local Capacity: %d", peerCount); - if(env->EnsureLocalCapacity(peerCount)) - { - LOGE("EnsureLocalCapacity failed!!"); - ZT_Node_freeQueryResult(node, peerList); - return NULL; - } - - jclass peerClass = lookup.findClass("com/zerotier/sdk/Peer"); - if(env->ExceptionCheck() || peerClass == NULL) - { - LOGE("Error finding Peer class"); - ZT_Node_freeQueryResult(node, peerList); - return NULL; - } - - jobjectArray peerArrayObj = env->NewObjectArray( - peerList->peerCount, peerClass, NULL); - - if(env->ExceptionCheck() || peerArrayObj == NULL) - { - LOGE("Error creating Peer[] array"); - ZT_Node_freeQueryResult(node, peerList); - return NULL; - } - - - for(unsigned int i = 0; i < peerList->peerCount; ++i) - { - jobject peerObj = newPeer(env, peerList->peers[i]); - env->SetObjectArrayElement(peerArrayObj, i, peerObj); - if(env->ExceptionCheck()) - { - LOGE("Error assigning Peer object to array"); - break; - } - } - - ZT_Node_freeQueryResult(node, peerList); - peerList = NULL; - - return peerArrayObj; -} - -/* - * Class: com_zerotier_sdk_Node - * Method: networks - * Signature: (J)[Lcom/zerotier/sdk/VirtualNetworkConfig; - */ -JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_networks( - JNIEnv *env, jobject obj, jlong id) -{ - uint64_t nodeId = (uint64_t) id; - ZT_Node *node = findNode(nodeId); - if(node == NULL) - { - // cannot find valid node. We should never get here. - return 0; - } - - ZT_VirtualNetworkList *networkList = ZT_Node_networks(node); - if(networkList == NULL) - { - return NULL; - } - - jclass vnetConfigClass = lookup.findClass("com/zerotier/sdk/VirtualNetworkConfig"); - if(env->ExceptionCheck() || vnetConfigClass == NULL) - { - LOGE("Error finding VirtualNetworkConfig class"); - ZT_Node_freeQueryResult(node, networkList); - return NULL; - } - - jobjectArray networkListObject = env->NewObjectArray( - networkList->networkCount, vnetConfigClass, NULL); - if(env->ExceptionCheck() || networkListObject == NULL) - { - LOGE("Error creating VirtualNetworkConfig[] array"); - ZT_Node_freeQueryResult(node, networkList); - return NULL; - } - - for(unsigned int i = 0; i < networkList->networkCount; ++i) - { - jobject networkObject = newNetworkConfig(env, networkList->networks[i]); - env->SetObjectArrayElement(networkListObject, i, networkObject); - if(env->ExceptionCheck()) - { - LOGE("Error assigning VirtualNetworkConfig object to array"); - break; - } - } - - ZT_Node_freeQueryResult(node, networkList); - - return networkListObject; -} - -#ifdef __cplusplus -} // extern "C" -#endif \ No newline at end of file diff --git a/zerotierone/java/jni/com_zerotierone_sdk_Node.h b/zerotierone/java/jni/com_zerotierone_sdk_Node.h deleted file mode 100644 index 7c1011a..0000000 --- a/zerotierone/java/jni/com_zerotierone_sdk_Node.h +++ /dev/null @@ -1,133 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_zerotier_sdk_Node */ - -#ifndef _Included_com_zerotierone_sdk_Node -#define _Included_com_zerotierone_sdk_Node -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_zerotier_sdk_Node - * Method: node_init - * Signature: (J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_node_1init - (JNIEnv *, jobject, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: node_delete - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_zerotier_sdk_Node_node_1delete - (JNIEnv *, jobject, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: processVirtualNetworkFrame - * Signature: (JJJJJII[B[J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processVirtualNetworkFrame - (JNIEnv *, jobject, jlong, jlong, jlong, jlong, jlong, jint, jint, jbyteArray, jlongArray); - -/* - * Class: com_zerotier_sdk_Node - * Method: processWirePacket - * Signature: (JJLjava/net/InetSockAddress;Ljava/net/InetSockAddress;[B[J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processWirePacket - (JNIEnv *, jobject, jlong, jlong, jobject, jobject, jbyteArray, jlongArray); - -/* - * Class: com_zerotier_sdk_Node - * Method: processBackgroundTasks - * Signature: (JJ[J)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_processBackgroundTasks - (JNIEnv *, jobject, jlong, jlong, jlongArray); - -/* - * Class: com_zerotier_sdk_Node - * Method: join - * Signature: (JJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_join - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: leave - * Signature: (JJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_leave - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: multicastSubscribe - * Signature: (JJJJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_multicastSubscribe - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: multicastUnsubscribe - * Signature: (JJJJ)Lcom/zerotier/sdk/ResultCode; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_multicastUnsubscribe - (JNIEnv *, jobject, jlong, jlong, jlong, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: address - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_com_zerotier_sdk_Node_address - (JNIEnv *, jobject, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: status - * Signature: (J)Lcom/zerotier/sdk/NodeStatus; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_status - (JNIEnv *, jobject, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: networkConfig - * Signature: (JJ)Lcom/zerotier/sdk/VirtualNetworkConfig; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_networkConfig - (JNIEnv *, jobject, jlong, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: version - * Signature: ()Lcom/zerotier/sdk/Version; - */ -JNIEXPORT jobject JNICALL Java_com_zerotier_sdk_Node_version - (JNIEnv *, jobject); - -/* - * Class: com_zerotier_sdk_Node - * Method: peers - * Signature: (J)[Lcom/zerotier/sdk/Peer; - */ -JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_peers - (JNIEnv *, jobject, jlong); - -/* - * Class: com_zerotier_sdk_Node - * Method: networks - * Signature: (J)[Lcom/zerotier/sdk/VirtualNetworkConfig; - */ -JNIEXPORT jobjectArray JNICALL Java_com_zerotier_sdk_Node_networks - (JNIEnv *, jobject, jlong); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/zerotierone/java/src/com/zerotier/sdk/DataStoreGetListener.java b/zerotierone/java/src/com/zerotier/sdk/DataStoreGetListener.java deleted file mode 100644 index b525be6..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/DataStoreGetListener.java +++ /dev/null @@ -1,58 +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 . - * - * -- - * - * 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/ - */ -package com.zerotier.sdk; - -public interface DataStoreGetListener { - - /** - * Function to get an object from the data store - * - *

Object names can contain forward slash (/) path separators. They will - * never contain .. or backslash (\), so this is safe to map as a Unix-style - * path if the underlying storage permits. For security reasons we recommend - * returning errors if .. or \ are used.

- * - *

The function must return the actual number of bytes read. If the object - * doesn't exist, it should return -1. -2 should be returned on other errors - * such as errors accessing underlying storage.

- * - *

If the read doesn't fit in the buffer, the max number of bytes should be - * read. The caller may call the function multiple times to read the whole - * object.

- * - * @param name Name of the object in the data store - * @param out_buffer buffer to put the object in - * @param bufferIndex index in the object to start reading - * @param out_objectSize long[1] to be set to the actual size of the object if it exists. - * @return the actual number of bytes read. - */ - public long onDataStoreGet( - String name, - byte[] out_buffer, - long bufferIndex, - long[] out_objectSize); -} diff --git a/zerotierone/java/src/com/zerotier/sdk/DataStorePutListener.java b/zerotierone/java/src/com/zerotier/sdk/DataStorePutListener.java deleted file mode 100644 index 77e5502..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/DataStorePutListener.java +++ /dev/null @@ -1,59 +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 . - * - * -- - * - * 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/ - */ -package com.zerotier.sdk; - -public interface DataStorePutListener { - - /** - * Function to store an object in the data store - * - *

If secure is true, the file should be set readable and writable only - * to the user running ZeroTier One. What this means is platform-specific.

- * - *

Name semantics are the same as {@link DataStoreGetListener}. This must return - * zero on success. You can return any OS-specific error code on failure, as these - * may be visible in logs or error messages and might aid in debugging.

- * - * @param name Object name - * @param buffer data to store - * @param secure set to user read/write only. - * @return 0 on success. - */ - public int onDataStorePut( - String name, - byte[] buffer, - boolean secure); - - /** - * Function to delete an object from the data store - * - * @param name Object name - * @return 0 on success. - */ - public int onDelete( - String name); -} diff --git a/zerotierone/java/src/com/zerotier/sdk/Event.java b/zerotierone/java/src/com/zerotier/sdk/Event.java deleted file mode 100644 index 22d350e..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/Event.java +++ /dev/null @@ -1,98 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -public enum Event { - /** - * Node has been initialized - * - * This is the first event generated, and is always sent. It may occur - * before Node's constructor returns. - */ - EVENT_UP, - - /** - * Node is offline -- network does not seem to be reachable by any available strategy - */ - EVENT_OFFLINE, - - /** - * Node is online -- at least one upstream node appears reachable - * - * Meta-data: none - */ - EVENT_ONLINE, - - /** - * Node is shutting down - * - *

This is generated within Node's destructor when it is being shut down. - * It's done for convenience, since cleaning up other state in the event - * handler may appear more idiomatic.

- */ - EVENT_DOWN, - - /** - * Your identity has collided with another node's ZeroTier address - * - *

This happens if two different public keys both hash (via the algorithm - * in Identity::generate()) to the same 40-bit ZeroTier address.

- * - *

This is something you should "never" see, where "never" is defined as - * once per 2^39 new node initializations / identity creations. If you do - * see it, you're going to see it very soon after a node is first - * initialized.

- * - *

This is reported as an event rather than a return code since it's - * detected asynchronously via error messages from authoritative nodes.

- * - *

If this occurs, you must shut down and delete the node, delete the - * identity.secret record/file from the data store, and restart to generate - * a new identity. If you don't do this, you will not be able to communicate - * with other nodes.

- * - *

We'd automate this process, but we don't think silently deleting - * private keys or changing our address without telling the calling code - * is good form. It violates the principle of least surprise.

- * - *

You can technically get away with not handling this, but we recommend - * doing so in a mature reliable application. Besides, handling this - * condition is a good way to make sure it never arises. It's like how - * umbrellas prevent rain and smoke detectors prevent fires. They do, right?

- */ - EVENT_FATAL_ERROR_IDENTITY_COLLISION, - - /** - * Trace (debugging) message - * - *

These events are only generated if this is a TRACE-enabled build.

- * - *

Meta-data: {@link String}, TRACE message

- */ - EVENT_TRACE -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/EventListener.java b/zerotierone/java/src/com/zerotier/sdk/EventListener.java deleted file mode 100644 index 91050aa..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/EventListener.java +++ /dev/null @@ -1,52 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.net.InetSocketAddress; -import java.lang.String; - -/** - * Interface to handle callbacks for ZeroTier One events. - */ -public interface EventListener { - /** - * Callback for events with no other associated metadata - * - * @param event {@link Event} enum - */ - public void onEvent(Event event); - - /** - * Trace messages - * - *

These events are only generated if the underlying ZeroTierOne SDK is a TRACE-enabled build.

- * - * @param message the trace message - */ - public void onTrace(String message); -} diff --git a/zerotierone/java/src/com/zerotier/sdk/NativeUtils.java b/zerotierone/java/src/com/zerotier/sdk/NativeUtils.java deleted file mode 100644 index 07e1ef5..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/NativeUtils.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.zerotier.sdk; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Simple library class for working with JNI (Java Native Interface) - * - * @see http://adamheinrich.com/2012/how-to-load-native-jni-library-from-jar - * - * @author Adam Heirnich , http://www.adamh.cz - */ -public class NativeUtils { - - /** - * Private constructor - this class will never be instanced - */ - private NativeUtils() { - } - - /** - * Loads library from current JAR archive - * - * The file from JAR is copied into system temporary directory and then loaded. The temporary file is deleted after exiting. - * Method uses String as filename because the pathname is "abstract", not system-dependent. - * - * @param filename The filename inside JAR as absolute path (beginning with '/'), e.g. /package/File.ext - * @throws IOException If temporary file creation or read/write operation fails - * @throws IllegalArgumentException If source file (param path) does not exist - * @throws IllegalArgumentException If the path is not absolute or if the filename is shorter than three characters (restriction of {@see File#createTempFile(java.lang.String, java.lang.String)}). - */ - public static void loadLibraryFromJar(String path) throws IOException { - - if (!path.startsWith("/")) { - throw new IllegalArgumentException("The path has to be absolute (start with '/')."); - } - - // Obtain filename from path - String[] parts = path.split("/"); - String filename = (parts.length > 1) ? parts[parts.length - 1] : null; - - // Split filename to prexif and suffix (extension) - String prefix = ""; - String suffix = null; - if (filename != null) { - parts = filename.split("\\.", 2); - prefix = parts[0]; - suffix = (parts.length > 1) ? "."+parts[parts.length - 1] : null; // Thanks, davs! :-) - } - - // Check if the filename is okay - if (filename == null || prefix.length() < 3) { - throw new IllegalArgumentException("The filename has to be at least 3 characters long."); - } - - // Prepare temporary file - File temp = File.createTempFile(prefix, suffix); - temp.deleteOnExit(); - - if (!temp.exists()) { - throw new FileNotFoundException("File " + temp.getAbsolutePath() + " does not exist."); - } - - // Prepare buffer for data copying - byte[] buffer = new byte[1024]; - int readBytes; - - // Open and check input stream - InputStream is = NativeUtils.class.getResourceAsStream(path); - if (is == null) { - throw new FileNotFoundException("File " + path + " was not found inside JAR."); - } - - // Open output stream and copy data between source file in JAR and the temporary file - OutputStream os = new FileOutputStream(temp); - try { - while ((readBytes = is.read(buffer)) != -1) { - os.write(buffer, 0, readBytes); - } - } finally { - // If read/write fails, close streams safely before throwing an exception - os.close(); - is.close(); - } - - // Finally, load the library - System.load(temp.getAbsolutePath()); - } -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/Node.java b/zerotierone/java/src/com/zerotier/sdk/Node.java deleted file mode 100644 index 4bc6e18..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/Node.java +++ /dev/null @@ -1,434 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.io.IOException; - -/** - * A ZeroTier One node - */ -public class Node { - static { - try { - System.loadLibrary("ZeroTierOneJNI"); - } catch (UnsatisfiedLinkError e) { - try { - if(System.getProperty("os.name").startsWith("Windows")) { - System.out.println("Arch: " + System.getProperty("sun.arch.data.model")); - if(System.getProperty("sun.arch.data.model").equals("64")) { - NativeUtils.loadLibraryFromJar("/lib/ZeroTierOneJNI_win64.dll"); - } else { - NativeUtils.loadLibraryFromJar("/lib/ZeroTierOneJNI_win32.dll"); - } - } else if(System.getProperty("os.name").startsWith("Mac")) { - NativeUtils.loadLibraryFromJar("/lib/libZeroTierOneJNI.jnilib"); - } else { - // TODO: Linux - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - } - - private static final String TAG = "NODE"; - - /** - * Node ID for JNI purposes. - * Currently set to the now value passed in at the constructor - * - * -1 if the node has already been closed - */ - private long nodeId; - - private final DataStoreGetListener getListener; - private final DataStorePutListener putListener; - private final PacketSender sender; - private final EventListener eventListener; - private final VirtualNetworkFrameListener frameListener; - private final VirtualNetworkConfigListener configListener; - - /** - * Create a new ZeroTier One node - * - *

Note that this can take a few seconds the first time it's called, as it - * will generate an identity.

- * - * @param now Current clock in milliseconds - * @param getListener User written instance of the {@link DataStoreGetListener} interface called to get objects from persistent storage. This instance must be unique per Node object. - * @param putListener User written intstance of the {@link DataStorePutListener} interface called to put objects in persistent storage. This instance must be unique per Node object. - * @param sender - * @param eventListener User written instance of the {@link EventListener} interface to receive status updates and non-fatal error notices. This instance must be unique per Node object. - * @param frameListener - * @param configListener User written instance of the {@link VirtualNetworkConfigListener} interface to be called when virtual LANs are created, deleted, or their config parameters change. This instance must be unique per Node object. - */ - public Node(long now, - DataStoreGetListener getListener, - DataStorePutListener putListener, - PacketSender sender, - EventListener eventListener, - VirtualNetworkFrameListener frameListener, - VirtualNetworkConfigListener configListener) throws NodeException - { - this.nodeId = now; - - this.getListener = getListener; - this.putListener = putListener; - this.sender = sender; - this.eventListener = eventListener; - this.frameListener = frameListener; - this.configListener = configListener; - - ResultCode rc = node_init(now); - if(rc != ResultCode.RESULT_OK) - { - // TODO: Throw Exception - throw new NodeException(rc.toString()); - } - } - - /** - * Close this Node. - * - *

The Node object can no longer be used once this method is called.

- */ - public void close() { - if(nodeId != -1) { - node_delete(nodeId); - nodeId = -1; - } - } - - @Override - protected void finalize() { - close(); - } - - /** - * Process a frame from a virtual network port - * - * @param now Current clock in milliseconds - * @param nwid ZeroTier 64-bit virtual network ID - * @param sourceMac Source MAC address (least significant 48 bits) - * @param destMac Destination MAC address (least significant 48 bits) - * @param etherType 16-bit Ethernet frame type - * @param vlanId 10-bit VLAN ID or 0 if none - * @param frameData Frame payload data - * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks() - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode processVirtualNetworkFrame( - long now, - long nwid, - long sourceMac, - long destMac, - int etherType, - int vlanId, - byte[] frameData, - long[] nextBackgroundTaskDeadline) { - return processVirtualNetworkFrame( - nodeId, now, nwid, sourceMac, destMac, etherType, vlanId, - frameData, nextBackgroundTaskDeadline); - } - - /** - * Process a packet received from the physical wire - * - * @param now Current clock in milliseconds - * @param remoteAddress Origin of packet - * @param packetData Packet data - * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks() - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode processWirePacket( - long now, - InetSocketAddress localAddress, - InetSocketAddress remoteAddress, - byte[] packetData, - long[] nextBackgroundTaskDeadline) { - return processWirePacket( - nodeId, now, localAddress, remoteAddress, packetData, - nextBackgroundTaskDeadline); - } - - /** - * Perform periodic background operations - * - * @param now Current clock in milliseconds - * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks() - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode processBackgroundTasks(long now, long[] nextBackgroundTaskDeadline) { - return processBackgroundTasks(nodeId, now, nextBackgroundTaskDeadline); - } - - /** - * Join a network - * - *

This may generate calls to the port config callback before it returns, - * or these may be deffered if a netconf is not available yet.

- * - *

If we are already a member of the network, nothing is done and OK is - * returned.

- * - * @param nwid 64-bit ZeroTier network ID - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode join(long nwid) { - return join(nodeId, nwid); - } - - /** - * Leave a network - * - *

If a port has been configured for this network this will generate a call - * to the port config callback with a NULL second parameter to indicate that - * the port is now deleted.

- * - * @param nwid 64-bit network ID - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode leave(long nwid) { - return leave(nodeId, nwid); - } - - /** - * Subscribe to an Ethernet multicast group - * - *

For IPv4 ARP, the implementation must subscribe to 0xffffffffffff (the - * broadcast address) but with an ADI equal to each IPv4 address in host - * byte order. This converts ARP from a non-scalable broadcast protocol to - * a scalable multicast protocol with perfect address specificity.

- * - *

If this is not done, ARP will not work reliably.

- * - *

Multiple calls to subscribe to the same multicast address will have no - * effect. It is perfectly safe to do this.

- * - *

This does not generate an update call to the {@link VirtualNetworkConfigListener#onNetworkConfigurationUpdated} method.

- * - * @param nwid 64-bit network ID - * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits) - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode multicastSubscribe( - long nwid, - long multicastGroup) { - return multicastSubscribe(nodeId, nwid, multicastGroup, 0); - } - - /** - * Subscribe to an Ethernet multicast group - * - *

ADI stands for additional distinguishing information. This defaults to zero - * and is rarely used. Right now its only use is to enable IPv4 ARP to scale, - * and this must be done.

- * - *

For IPv4 ARP, the implementation must subscribe to 0xffffffffffff (the - * broadcast address) but with an ADI equal to each IPv4 address in host - * byte order. This converts ARP from a non-scalable broadcast protocol to - * a scalable multicast protocol with perfect address specificity.

- * - *

If this is not done, ARP will not work reliably.

- * - *

Multiple calls to subscribe to the same multicast address will have no - * effect. It is perfectly safe to do this.

- * - *

This does not generate an update call to the {@link VirtualNetworkConfigListener#onNetworkConfigurationUpdated} method.

- * - * @param nwid 64-bit network ID - * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits) - * @param multicastAdi Multicast ADI (least significant 32 bits only, default: 0) - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode multicastSubscribe( - long nwid, - long multicastGroup, - long multicastAdi) { - return multicastSubscribe(nodeId, nwid, multicastGroup, multicastAdi); - } - - - /** - * Unsubscribe from an Ethernet multicast group (or all groups) - * - *

If multicastGroup is zero (0), this will unsubscribe from all groups. If - * you are not subscribed to a group this has no effect.

- * - *

This does not generate an update call to the {@link VirtualNetworkConfigListener#onNetworkConfigurationUpdated} method.

- * - * @param nwid 64-bit network ID - * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits) - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode multicastUnsubscribe( - long nwid, - long multicastGroup) { - return multicastUnsubscribe(nodeId, nwid, multicastGroup, 0); - } - - /** - * Unsubscribe from an Ethernet multicast group (or all groups) - * - *

If multicastGroup is zero (0), this will unsubscribe from all groups. If - * you are not subscribed to a group this has no effect.

- * - *

This does not generate an update call to the {@link VirtualNetworkConfigListener#onNetworkConfigurationUpdated} method.

- * - *

ADI stands for additional distinguishing information. This defaults to zero - * and is rarely used. Right now its only use is to enable IPv4 ARP to scale, - * and this must be done.

- * - * @param nwid 64-bit network ID - * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits) - * @param multicastAdi Multicast ADI (least significant 32 bits only, default: 0) - * @return OK (0) or error code if a fatal error condition has occurred - */ - public ResultCode multicastUnsubscribe( - long nwid, - long multicastGroup, - long multicastAdi) { - return multicastUnsubscribe(nodeId, nwid, multicastGroup, multicastAdi); - } - - /** - * Get this node's 40-bit ZeroTier address - * - * @return ZeroTier address (least significant 40 bits of 64-bit int) - */ - public long address() { - return address(nodeId); - } - - /** - * Get the status of this node - * - * @return @{link NodeStatus} struct with the current node status. - */ - public NodeStatus status() { - return status(nodeId); - } - - /** - * Get a list of known peer nodes - * - * @return List of known peers or NULL on failure - */ - public Peer[] peers() { - return peers(nodeId); - } - - /** - * Get the status of a virtual network - * - * @param nwid 64-bit network ID - * @return {@link VirtualNetworkConfig} or NULL if we are not a member of this network - */ - public VirtualNetworkConfig networkConfig(long nwid) { - return networkConfig(nodeId, nwid); - } - - /** - * Enumerate and get status of all networks - * - * @return List of networks or NULL on failure - */ - public VirtualNetworkConfig[] networks() { - return networks(nodeId); - } - - /** - * Get ZeroTier One version - * - * @return {@link Version} object with ZeroTierOne version information. - */ - public Version getVersion() { - return version(); - } - - // - // function declarations for JNI - // - private native ResultCode node_init(long now); - - private native void node_delete(long nodeId); - - private native ResultCode processVirtualNetworkFrame( - long nodeId, - long now, - long nwid, - long sourceMac, - long destMac, - int etherType, - int vlanId, - byte[] frameData, - long[] nextBackgroundTaskDeadline); - - private native ResultCode processWirePacket( - long nodeId, - long now, - InetSocketAddress localAddress, - InetSocketAddress remoteAddress, - byte[] packetData, - long[] nextBackgroundTaskDeadline); - - private native ResultCode processBackgroundTasks( - long nodeId, - long now, - long[] nextBackgroundTaskDeadline); - - private native ResultCode join(long nodeId, long nwid); - - private native ResultCode leave(long nodeId, long nwid); - - private native ResultCode multicastSubscribe( - long nodeId, - long nwid, - long multicastGroup, - long multicastAdi); - - private native ResultCode multicastUnsubscribe( - long nodeId, - long nwid, - long multicastGroup, - long multicastAdi); - - private native long address(long nodeId); - - private native NodeStatus status(long nodeId); - - private native VirtualNetworkConfig networkConfig(long nodeId, long nwid); - - private native Version version(); - - private native Peer[] peers(long nodeId); - - private native VirtualNetworkConfig[] networks(long nodeId); -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/NodeException.java b/zerotierone/java/src/com/zerotier/sdk/NodeException.java deleted file mode 100644 index 1fdef72..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/NodeException.java +++ /dev/null @@ -1,36 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.lang.RuntimeException; - -public class NodeException extends RuntimeException { - public NodeException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/NodeStatus.java b/zerotierone/java/src/com/zerotier/sdk/NodeStatus.java deleted file mode 100644 index 94376d8..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/NodeStatus.java +++ /dev/null @@ -1,69 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -public final class NodeStatus { - private long address; - private String publicIdentity; - private String secretIdentity; - private boolean online; - - private NodeStatus() {} - - /** - * 40-bit ZeroTier address of this node - */ - public final long getAddres() { - return address; - } - - /** - * Public identity in string-serialized form (safe to send to others) - * - *

This identity will remain valid as long as the node exists.

- */ - public final String getPublicIdentity() { - return publicIdentity; - } - - /** - * Full identity including secret key in string-serialized form - * - *

This identity will remain valid as long as the node exists.

- */ - public final String getSecretIdentity() { - return secretIdentity; - } - - /** - * True if some kind of connectivity appears available - */ - public final boolean isOnline() { - return online; - } -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/PacketSender.java b/zerotierone/java/src/com/zerotier/sdk/PacketSender.java deleted file mode 100644 index 22893ec..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/PacketSender.java +++ /dev/null @@ -1,50 +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 . - * - * -- - * - * 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/ - */ -package com.zerotier.sdk; - -import java.net.InetSocketAddress; - - -public interface PacketSender { - /** - * Function to send a ZeroTier packet out over the wire - * - *

The function must return zero on success and may return any error code - * on failure. Note that success does not (of course) guarantee packet - * delivery. It only means that the packet appears to have been sent.

- * - * @param localAddr {@link InetSocketAddress} to send from. Set to null if not specified. - * @param remoteAddr {@link InetSocketAddress} to send to - * @param packetData data to send - * @return 0 on success, any error code on failure. - */ - public int onSendPacketRequested( - InetSocketAddress localAddr, - InetSocketAddress remoteAddr, - byte[] packetData, - int ttl); -} diff --git a/zerotierone/java/src/com/zerotier/sdk/Peer.java b/zerotierone/java/src/com/zerotier/sdk/Peer.java deleted file mode 100644 index eb3d713..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/Peer.java +++ /dev/null @@ -1,94 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.util.ArrayList; - -/** - * Peer status result - */ -public final class Peer { - private long address; - private int versionMajor; - private int versionMinor; - private int versionRev; - private int latency; - private PeerRole role; - private PeerPhysicalPath[] paths; - - private Peer() {} - - /** - * ZeroTier address (40 bits) - */ - public final long address() { - return address; - } - - /** - * Remote major version or -1 if not known - */ - public final int versionMajor() { - return versionMajor; - } - - /** - * Remote minor version or -1 if not known - */ - public final int versionMinor() { - return versionMinor; - } - - /** - * Remote revision or -1 if not known - */ - public final int versionRev() { - return versionRev; - } - - /** - * Last measured latency in milliseconds or zero if unknown - */ - public final int latency() { - return latency; - } - - /** - * What trust hierarchy role does this device have? - */ - public final PeerRole role() { - return role; - } - - /** - * Known network paths to peer - */ - public final PeerPhysicalPath[] paths() { - return paths; - } -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/PeerPhysicalPath.java b/zerotierone/java/src/com/zerotier/sdk/PeerPhysicalPath.java deleted file mode 100644 index 3f9a861..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/PeerPhysicalPath.java +++ /dev/null @@ -1,78 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.net.InetSocketAddress; - -/** - * Physical network path to a peer - */ -public final class PeerPhysicalPath { - private InetSocketAddress address; - private long lastSend; - private long lastReceive; - private boolean fixed; - private boolean preferred; - - private PeerPhysicalPath() {} - - /** - * Address of endpoint - */ - public final InetSocketAddress address() { - return address; - } - - /** - * Time of last send in milliseconds or 0 for never - */ - public final long lastSend() { - return lastSend; - } - - /** - * Time of last receive in milliseconds or 0 for never - */ - public final long lastReceive() { - return lastReceive; - } - - /** - * Is path fixed? (i.e. not learned, static) - */ - public final boolean isFixed() { - return fixed; - } - - /** - * Is path preferred? - */ - public final boolean isPreferred() { - return preferred; - } -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/PeerRole.java b/zerotierone/java/src/com/zerotier/sdk/PeerRole.java deleted file mode 100644 index fce183d..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/PeerRole.java +++ /dev/null @@ -1,45 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -public enum PeerRole { - /** - * An ordinary node - */ - PEER_ROLE_LEAF, - - /** - * moon root - */ - PEER_ROLE_MOON, - - /** - * planetary root - */ - PEER_ROLE_PLANET -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/ResultCode.java b/zerotierone/java/src/com/zerotier/sdk/ResultCode.java deleted file mode 100644 index 5da82b3..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/ResultCode.java +++ /dev/null @@ -1,74 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -/** - * Function return code: OK (0) or error results - * - *

Use {@link ResultCode#isFatal) to check for a fatal error. If a fatal error - * occurs, the node should be considered to not be working correctly. These - * indicate serious problems like an inaccessible data store or a compile - * problem.

- */ -public enum ResultCode { - /** - * Operation completed normally - */ - RESULT_OK(0), - - // Fatal errors (> 0, < 1000) - /** - * Ran out of memory - */ - RESULT_FATAL_ERROR_OUT_OF_MEMORY(1), - - /** - * Data store is not writable or has failed - */ - RESULT_FATAL_ERROR_DATA_STORE_FAILED(2), - - /** - * Internal error (e.g. unexpected exception indicating bug or build problem) - */ - RESULT_FATAL_ERROR_INTERNAL(3), - - // non-fatal errors - - /** - * Network ID not valid - */ - RESULT_ERROR_NETWORK_NOT_FOUND(1000); - - private final int id; - ResultCode(int id) { this.id = id; } - public int getValue() { return id; } - - public boolean isFatal(int id) { - return (id > 0 && id < 1000); - } -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/Version.java b/zerotierone/java/src/com/zerotier/sdk/Version.java deleted file mode 100644 index c93c259..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/Version.java +++ /dev/null @@ -1,36 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -public final class Version { - private Version() {} - - public int major = 0; - public int minor = 0; - public int revision = 0; -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfig.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfig.java deleted file mode 100644 index 64512da..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfig.java +++ /dev/null @@ -1,210 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.lang.Comparable; -import java.lang.Override; -import java.lang.String; -import java.util.ArrayList; -import java.net.InetSocketAddress; - -public final class VirtualNetworkConfig implements Comparable { - public static final int MAX_MULTICAST_SUBSCRIPTIONS = 4096; - public static final int ZT_MAX_ZT_ASSIGNED_ADDRESSES = 16; - - private long nwid; - private long mac; - private String name; - private VirtualNetworkStatus status; - private VirtualNetworkType type; - private int mtu; - private boolean dhcp; - private boolean bridge; - private boolean broadcastEnabled; - private int portError; - private boolean enabled; - private long netconfRevision; - private InetSocketAddress[] assignedAddresses; - private VirtualNetworkRoute[] routes; - - private VirtualNetworkConfig() { - - } - - public boolean equals(VirtualNetworkConfig cfg) { - boolean aaEqual = true; - if(assignedAddresses.length == cfg.assignedAddresses.length) { - for(int i = 0; i < assignedAddresses.length; ++i) { - if(!assignedAddresses[i].equals(cfg.assignedAddresses[i])) { - aaEqual = false; - } - } - } else { - aaEqual = false; - } - - boolean routesEqual = true; - if(routes.length == cfg.routes.length) { - for (int i = 0; i < routes.length; ++i) { - if (!routes[i].equals(cfg.routes[i])) { - routesEqual = false; - } - } - } else { - routesEqual = false; - } - - return nwid == cfg.nwid && - mac == cfg.mac && - name.equals(cfg.name) && - status.equals(cfg.status) && - type.equals(cfg.type) && - mtu == cfg.mtu && - dhcp == cfg.dhcp && - bridge == cfg.bridge && - broadcastEnabled == cfg.broadcastEnabled && - portError == cfg.portError && - enabled == cfg.enabled && - aaEqual && routesEqual; - } - - public int compareTo(VirtualNetworkConfig cfg) { - if(cfg.nwid == this.nwid) { - return 0; - } else { - return this.nwid > cfg.nwid ? 1 : -1; - } - } - - /** - * 64-bit ZeroTier network ID - */ - public final long networkId() { - return nwid; - } - - /** - * Ethernet MAC (40 bits) that should be assigned to port - */ - public final long macAddress() { - return mac; - } - - /** - * Network name (from network configuration master) - */ - public final String name() { - return name; - } - - /** - * Network configuration request status - */ - public final VirtualNetworkStatus networkStatus() { - return status; - } - - /** - * Network type - */ - public final VirtualNetworkType networkType() { - return type; - } - - /** - * Maximum interface MTU - */ - public final int mtu() { - return mtu; - } - - /** - * If the network this port belongs to indicates DHCP availability - * - *

This is a suggestion. The underlying implementation is free to ignore it - * for security or other reasons. This is simply a netconf parameter that - * means 'DHCP is available on this network.'

- */ - public final boolean isDhcpAvailable() { - return dhcp; - } - - /** - * If this port is allowed to bridge to other networks - * - *

This is informational. If this is false, bridged packets will simply - * be dropped and bridging won't work.

- */ - public final boolean isBridgeEnabled() { - return bridge; - } - - /** - * If true, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic - */ - public final boolean broadcastEnabled() { - return broadcastEnabled; - } - - /** - * If the network is in PORT_ERROR state, this is the error most recently returned by the port config callback - */ - public final int portError() { - return portError; - } - - /** - * Network config revision as reported by netconf master - * - *

If this is zero, it means we're still waiting for our netconf.

- */ - public final long netconfRevision() { - return netconfRevision; - } - - /** - * ZeroTier-assigned addresses (in {@link java.net.InetSocketAddress} objects) - * - * For IP, the port number of the sockaddr_XX structure contains the number - * of bits in the address netmask. Only the IP address and port are used. - * Other fields like interface number can be ignored. - * - * This is only used for ZeroTier-managed address assignments sent by the - * virtual network's configuration master. - */ - public final InetSocketAddress[] assignedAddresses() { - return assignedAddresses; - } - - /** - * ZeroTier-assigned routes (in {@link com.zerotier.sdk.VirtualNetworkRoute} objects) - * - * @return - */ - public final VirtualNetworkRoute[] routes() { return routes; } -} diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfigListener.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfigListener.java deleted file mode 100644 index 15ae301..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfigListener.java +++ /dev/null @@ -1,60 +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 . - * - * -- - * - * 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/ - */ - - -package com.zerotier.sdk; - - -public interface VirtualNetworkConfigListener { - /** - * Callback called to update virtual network port configuration - * - *

This can be called at any time to update the configuration of a virtual - * network port. The parameter after the network ID specifies whether this - * port is being brought up, updated, brought down, or permanently deleted. - * - * This in turn should be used by the underlying implementation to create - * and configure tap devices at the OS (or virtual network stack) layer.

- * - * This should not call {@link Node#multicastSubscribe} or other network-modifying - * methods, as this could cause a deadlock in multithreaded or interrupt - * driven environments. - * - * This must return 0 on success. It can return any OS-dependent error code - * on failure, and this results in the network being placed into the - * PORT_ERROR state. - * - * @param nwid network id - * @param op {@link VirtualNetworkConfigOperation} enum describing the configuration operation - * @param config {@link VirtualNetworkConfig} object with the new configuration - * @return 0 on success - */ - public int onNetworkConfigurationUpdated( - long nwid, - VirtualNetworkConfigOperation op, - VirtualNetworkConfig config); -} \ No newline at end of file diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfigOperation.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfigOperation.java deleted file mode 100644 index b70eb47..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkConfigOperation.java +++ /dev/null @@ -1,49 +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 . - * - * -- - * - * 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/ - */ -package com.zerotier.sdk; - -public enum VirtualNetworkConfigOperation { - /** - * Network is coming up (either for the first time or after service restart) - */ - VIRTUAL_NETWORK_CONFIG_OPERATION_UP, - - /** - * Network configuration has been updated - */ - VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE, - - /** - * Network is going down (not permanently) - */ - VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN, - - /** - * Network is going down permanently (leave/delete) - */ - VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY -} diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkFrameListener.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkFrameListener.java deleted file mode 100644 index 9ad3228..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkFrameListener.java +++ /dev/null @@ -1,48 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -public interface VirtualNetworkFrameListener { - /** - * Function to send a frame out to a virtual network port - * - * @param nwid ZeroTier One network ID - * @param srcMac source MAC address - * @param destMac destination MAC address - * @param ethertype - * @param vlanId - * @param frameData data to send - */ - public void onVirtualNetworkFrame( - long nwid, - long srcMac, - long destMac, - long etherType, - long vlanId, - byte[] frameData); -} diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkRoute.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkRoute.java deleted file mode 100644 index b89dce7..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkRoute.java +++ /dev/null @@ -1,102 +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 . - * - * -- - * - * 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/ - */ - -package com.zerotier.sdk; - -import java.net.InetSocketAddress; - -public final class VirtualNetworkRoute implements Comparable -{ - private VirtualNetworkRoute() { - target = null; - via = null; - flags = 0; - metric = 0; - } - - /** - * Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default - */ - public InetSocketAddress target; - - /** - * Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway) - */ - public InetSocketAddress via; - - /** - * Route flags - */ - public int flags; - - /** - * Route metric (not currently used) - */ - public int metric; - - - @Override - public int compareTo(VirtualNetworkRoute other) { - return target.toString().compareTo(other.target.toString()); - } - - public boolean equals(VirtualNetworkRoute other) { - boolean targetEquals; - if (target == null && other.target == null) { - targetEquals = true; - } - else if (target == null && other.target != null) { - targetEquals = false; - } - else if (target != null && other.target == null) { - targetEquals = false; - } - else { - targetEquals = target.equals(other.target); - } - - - boolean viaEquals; - if (via == null && other.via == null) { - viaEquals = true; - } - else if (via == null && other.via != null) { - viaEquals = false; - } - else if (via != null && other.via == null) { - viaEquals = false; - } - else { - viaEquals = via.equals(other.via); - } - - return viaEquals && - viaEquals && - flags == other.flags && - metric == other.metric; - } -} diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkStatus.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkStatus.java deleted file mode 100644 index 2d00561..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkStatus.java +++ /dev/null @@ -1,59 +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 . - * - * -- - * - * 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/ - */ -package com.zerotier.sdk; - -public enum VirtualNetworkStatus { - /** - * Waiting for network configuration (also means revision == 0) - */ - NETWORK_STATUS_REQUESTING_CONFIGURATION, - - /** - * Configuration received and we are authorized - */ - NETWORK_STATUS_OK, - - /** - * Netconf master told us 'nope' - */ - NETWORK_STATUS_ACCESS_DENIED, - - /** - * Netconf master exists, but this virtual network does not - */ - NETWORK_STATUS_NOT_FOUND, - - /** - * Initialization of network failed or other internal error - */ - NETWORK_STATUS_PORT_ERROR, - - /** - * ZeroTier One version too old - */ - NETWORK_STATUS_CLIENT_TOO_OLD -} diff --git a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkType.java b/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkType.java deleted file mode 100644 index ab1f4e0..0000000 --- a/zerotierone/java/src/com/zerotier/sdk/VirtualNetworkType.java +++ /dev/null @@ -1,39 +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 . - * - * -- - * - * 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/ - */ -package com.zerotier.sdk; - -public enum VirtualNetworkType { - /** - * Private networks are authorized via certificates of membership - */ - NETWORK_TYPE_PRIVATE, - - /** - * Public networks have no access control -- they'll always be AUTHORIZED - */ - NETWORK_TYPE_PUBLIC -} diff --git a/zerotierone/service/ControlPlane.cpp b/zerotierone/service/ControlPlane.cpp deleted file mode 100644 index e0be5f7..0000000 --- a/zerotierone/service/ControlPlane.cpp +++ /dev/null @@ -1,553 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 . - */ - -#include "ControlPlane.hpp" -#include "OneService.hpp" - -#include "../version.h" -#include "../include/ZeroTierOne.h" - -#ifdef ZT_USE_SYSTEM_HTTP_PARSER -#include -#else -#include "../ext/http-parser/http_parser.h" -#endif - -#include "../ext/json/json.hpp" - -#include "../controller/EmbeddedNetworkController.hpp" - -#include "../node/InetAddress.hpp" -#include "../node/Node.hpp" -#include "../node/Utils.hpp" -#include "../node/World.hpp" - -#include "../osdep/OSUtils.hpp" - -namespace ZeroTier { - -namespace { - -static void _networkToJson(nlohmann::json &nj,const ZT_VirtualNetworkConfig *nc,const std::string &portDeviceName,const OneService::NetworkSettings &localSettings) -{ - char tmp[256]; - - const char *nstatus = "",*ntype = ""; - switch(nc->status) { - case ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION: nstatus = "REQUESTING_CONFIGURATION"; break; - case ZT_NETWORK_STATUS_OK: nstatus = "OK"; break; - case ZT_NETWORK_STATUS_ACCESS_DENIED: nstatus = "ACCESS_DENIED"; break; - case ZT_NETWORK_STATUS_NOT_FOUND: nstatus = "NOT_FOUND"; break; - case ZT_NETWORK_STATUS_PORT_ERROR: nstatus = "PORT_ERROR"; break; - case ZT_NETWORK_STATUS_CLIENT_TOO_OLD: nstatus = "CLIENT_TOO_OLD"; break; - } - switch(nc->type) { - case ZT_NETWORK_TYPE_PRIVATE: ntype = "PRIVATE"; break; - case ZT_NETWORK_TYPE_PUBLIC: ntype = "PUBLIC"; break; - } - - Utils::snprintf(tmp,sizeof(tmp),"%.16llx",nc->nwid); - nj["id"] = tmp; - nj["nwid"] = tmp; - Utils::snprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)((nc->mac >> 40) & 0xff),(unsigned int)((nc->mac >> 32) & 0xff),(unsigned int)((nc->mac >> 24) & 0xff),(unsigned int)((nc->mac >> 16) & 0xff),(unsigned int)((nc->mac >> 8) & 0xff),(unsigned int)(nc->mac & 0xff)); - nj["mac"] = tmp; - nj["name"] = nc->name; - nj["status"] = nstatus; - nj["type"] = ntype; - nj["mtu"] = nc->mtu; - nj["dhcp"] = (bool)(nc->dhcp != 0); - nj["bridge"] = (bool)(nc->bridge != 0); - nj["broadcastEnabled"] = (bool)(nc->broadcastEnabled != 0); - nj["portError"] = nc->portError; - nj["netconfRevision"] = nc->netconfRevision; - nj["portDeviceName"] = portDeviceName; - nj["allowManaged"] = localSettings.allowManaged; - nj["allowGlobal"] = localSettings.allowGlobal; - nj["allowDefault"] = localSettings.allowDefault; - - nlohmann::json aa = nlohmann::json::array(); - for(unsigned int i=0;iassignedAddressCount;++i) { - aa.push_back(reinterpret_cast(&(nc->assignedAddresses[i]))->toString()); - } - nj["assignedAddresses"] = aa; - - nlohmann::json ra = nlohmann::json::array(); - for(unsigned int i=0;irouteCount;++i) { - nlohmann::json rj; - rj["target"] = reinterpret_cast(&(nc->routes[i].target))->toString(); - if (nc->routes[i].via.ss_family == nc->routes[i].target.ss_family) - rj["via"] = reinterpret_cast(&(nc->routes[i].via))->toIpString(); - else rj["via"] = nlohmann::json(); - rj["flags"] = (int)nc->routes[i].flags; - rj["metric"] = (int)nc->routes[i].metric; - ra.push_back(rj); - } - nj["routes"] = ra; -} - -static void _peerToJson(nlohmann::json &pj,const ZT_Peer *peer) -{ - char tmp[256]; - - const char *prole = ""; - switch(peer->role) { - case ZT_PEER_ROLE_LEAF: prole = "LEAF"; break; - case ZT_PEER_ROLE_MOON: prole = "MOON"; break; - case ZT_PEER_ROLE_PLANET: prole = "PLANET"; break; - } - - Utils::snprintf(tmp,sizeof(tmp),"%.10llx",peer->address); - pj["address"] = tmp; - pj["versionMajor"] = peer->versionMajor; - pj["versionMinor"] = peer->versionMinor; - pj["versionRev"] = peer->versionRev; - Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d",peer->versionMajor,peer->versionMinor,peer->versionRev); - pj["version"] = tmp; - pj["latency"] = peer->latency; - pj["role"] = prole; - - nlohmann::json pa = nlohmann::json::array(); - for(unsigned int i=0;ipathCount;++i) { - nlohmann::json j; - j["address"] = reinterpret_cast(&(peer->paths[i].address))->toString(); - j["lastSend"] = peer->paths[i].lastSend; - j["lastReceive"] = peer->paths[i].lastReceive; - j["trustedPathId"] = peer->paths[i].trustedPathId; - j["linkQuality"] = (double)peer->paths[i].linkQuality / (double)ZT_PATH_LINK_QUALITY_MAX; - j["active"] = (bool)(peer->paths[i].expired == 0); - j["expired"] = (bool)(peer->paths[i].expired != 0); - j["preferred"] = (bool)(peer->paths[i].preferred != 0); - pa.push_back(j); - } - pj["paths"] = pa; -} - -static void _moonToJson(nlohmann::json &mj,const World &world) -{ - char tmp[64]; - Utils::snprintf(tmp,sizeof(tmp),"%.16llx",world.id()); - mj["id"] = tmp; - mj["timestamp"] = world.timestamp(); - mj["signature"] = Utils::hex(world.signature().data,(unsigned int)world.signature().size()); - mj["updatesMustBeSignedBy"] = Utils::hex(world.updatesMustBeSignedBy().data,(unsigned int)world.updatesMustBeSignedBy().size()); - nlohmann::json ra = nlohmann::json::array(); - for(std::vector::const_iterator r(world.roots().begin());r!=world.roots().end();++r) { - nlohmann::json rj; - rj["identity"] = r->identity.toString(false); - nlohmann::json eps = nlohmann::json::array(); - for(std::vector::const_iterator a(r->stableEndpoints.begin());a!=r->stableEndpoints.end();++a) - eps.push_back(a->toString()); - rj["stableEndpoints"] = eps; - ra.push_back(rj); - } - mj["roots"] = ra; - mj["waiting"] = false; -} - -} // anonymous namespace - -ControlPlane::ControlPlane(OneService *svc,Node *n) : - _svc(svc), - _node(n), - _controller((EmbeddedNetworkController *)0) -{ -} - -unsigned int ControlPlane::handleRequest( - const InetAddress &fromAddress, - unsigned int httpMethod, - const std::string &path, - const std::map &headers, - const std::string &body, - std::string &responseBody, - std::string &responseContentType) -{ - char tmp[256]; - unsigned int scode = 404; - nlohmann::json res; - std::vector ps(OSUtils::split(path.c_str(),"/","","")); - std::map urlArgs; - - Mutex::Lock _l(_lock); - - /* Note: this is kind of restricted in what it'll take. It does not support - * URL encoding, and /'s in URL args will screw it up. But the only URL args - * it really uses in ?jsonp=funcionName, and otherwise it just takes simple - * paths to simply-named resources. */ - if (ps.size() > 0) { - std::size_t qpos = ps[ps.size() - 1].find('?'); - if (qpos != std::string::npos) { - std::string args(ps[ps.size() - 1].substr(qpos + 1)); - ps[ps.size() - 1] = ps[ps.size() - 1].substr(0,qpos); - std::vector asplit(OSUtils::split(args.c_str(),"&","","")); - for(std::vector::iterator a(asplit.begin());a!=asplit.end();++a) { - std::size_t eqpos = a->find('='); - if (eqpos == std::string::npos) - urlArgs[*a] = ""; - else urlArgs[a->substr(0,eqpos)] = a->substr(eqpos + 1); - } - } - } - - bool isAuth = false; - { - std::map::const_iterator ah(headers.find("x-zt1-auth")); - if ((ah != headers.end())&&(_authTokens.count(ah->second) > 0)) { - isAuth = true; - } else { - ah = urlArgs.find("auth"); - if ((ah != urlArgs.end())&&(_authTokens.count(ah->second) > 0)) - isAuth = true; - } - } - -#ifdef __SYNOLOGY__ - #include - // Authenticate via Synology's built-in cgi script - if (!isAuth) { - /* - fprintf(stderr, "path = %s\n", path.c_str()); - fprintf(stderr, "headers.size=%d\n", headers.size()); - std::map::const_iterator it(headers.begin()); - while(it != headers.end()) { - fprintf(stderr,"header[%s] = %s\n", (it->first).c_str(), (it->second).c_str()); - it++; - } - */ - // parse out url args - int synotoken_pos = path.find("SynoToken"); - int argpos = path.find("?"); - if(synotoken_pos != std::string::npos && argpos != std::string::npos) { - std::string cookie = path.substr(argpos+1, synotoken_pos-(argpos+1)); - std::string synotoken = path.substr(synotoken_pos); - std::string cookie_val = cookie.substr(cookie.find("=")+1); - std::string synotoken_val = synotoken.substr(synotoken.find("=")+1); - // Set necessary env for auth script - std::map::const_iterator ah2(headers.find("x-forwarded-for")); - setenv("HTTP_COOKIE", cookie_val.c_str(), true); - setenv("HTTP_X_SYNO_TOKEN", synotoken_val.c_str(), true); - setenv("REMOTE_ADDR", ah2->second.c_str(),true); - //fprintf(stderr, "HTTP_COOKIE: %s\n",std::getenv ("HTTP_COOKIE")); - //fprintf(stderr, "HTTP_X_SYNO_TOKEN: %s\n",std::getenv ("HTTP_X_SYNO_TOKEN")); - //fprintf(stderr, "REMOTE_ADDR: %s\n",std::getenv ("REMOTE_ADDR")); - // check synology web auth - char user[256], buf[1024]; - FILE *fp = NULL; - bzero(user, 256); - fp = popen("/usr/syno/synoman/webman/modules/authenticate.cgi", "r"); - if(!fp) - isAuth = false; - else { - bzero(buf, sizeof(buf)); - fread(buf, 1024, 1, fp); - if(strlen(buf) > 0) { - snprintf(user, 256, "%s", buf); - isAuth = true; - } - } - pclose(fp); - } - } -#endif - - if (httpMethod == HTTP_GET) { - if (isAuth) { - if (ps[0] == "status") { - ZT_NodeStatus status; - _node->status(&status); - - Utils::snprintf(tmp,sizeof(tmp),"%.10llx",status.address); - res["address"] = tmp; - res["publicIdentity"] = status.publicIdentity; - res["online"] = (bool)(status.online != 0); - res["tcpFallbackActive"] = _svc->tcpFallbackActive(); - res["versionMajor"] = ZEROTIER_ONE_VERSION_MAJOR; - res["versionMinor"] = ZEROTIER_ONE_VERSION_MINOR; - res["versionRev"] = ZEROTIER_ONE_VERSION_REVISION; - res["versionBuild"] = ZEROTIER_ONE_VERSION_BUILD; - Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d",ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); - res["version"] = tmp; - res["clock"] = OSUtils::now(); - - World planet(_node->planet()); - res["planetWorldId"] = planet.id(); - res["planetWorldTimestamp"] = planet.timestamp(); - -#ifdef ZT_ENABLE_CLUSTER - nlohmann::json cj; - ZT_ClusterStatus cs; - _node->clusterStatus(&cs); - if (cs.clusterSize >= 1) { - nlohmann::json cja = nlohmann::json::array(); - for(unsigned int i=0;i moons(_node->moons()); - if (ps.size() == 1) { - // Return [array] of all moons - - res = nlohmann::json::array(); - for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) { - nlohmann::json mj; - _moonToJson(mj,*m); - res.push_back(mj); - } - - scode = 200; - } else { - // Return a single moon by ID - - const uint64_t id = Utils::hexStrToU64(ps[1].c_str()); - for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) { - if (m->id() == id) { - _moonToJson(res,*m); - scode = 200; - break; - } - } - - } - } else if (ps[0] == "network") { - ZT_VirtualNetworkList *nws = _node->networks(); - if (nws) { - if (ps.size() == 1) { - // Return [array] of all networks - - res = nlohmann::json::array(); - for(unsigned long i=0;inetworkCount;++i) { - OneService::NetworkSettings localSettings; - _svc->getNetworkSettings(nws->networks[i].nwid,localSettings); - nlohmann::json nj; - _networkToJson(nj,&(nws->networks[i]),_svc->portDeviceName(nws->networks[i].nwid),localSettings); - res.push_back(nj); - } - - scode = 200; - } else if (ps.size() == 2) { - // Return a single network by ID or 404 if not found - - const uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); - for(unsigned long i=0;inetworkCount;++i) { - if (nws->networks[i].nwid == wantnw) { - OneService::NetworkSettings localSettings; - _svc->getNetworkSettings(nws->networks[i].nwid,localSettings); - _networkToJson(res,&(nws->networks[i]),_svc->portDeviceName(nws->networks[i].nwid),localSettings); - scode = 200; - break; - } - } - - } else scode = 404; - _node->freeQueryResult((void *)nws); - } else scode = 500; - } else if (ps[0] == "peer") { - ZT_PeerList *pl = _node->peers(); - if (pl) { - if (ps.size() == 1) { - // Return [array] of all peers - - res = nlohmann::json::array(); - for(unsigned long i=0;ipeerCount;++i) { - nlohmann::json pj; - _peerToJson(pj,&(pl->peers[i])); - res.push_back(pj); - } - - scode = 200; - } else if (ps.size() == 2) { - // Return a single peer by ID or 404 if not found - - uint64_t wantp = Utils::hexStrToU64(ps[1].c_str()); - for(unsigned long i=0;ipeerCount;++i) { - if (pl->peers[i].address == wantp) { - _peerToJson(res,&(pl->peers[i])); - scode = 200; - break; - } - } - - } else scode = 404; - _node->freeQueryResult((void *)pl); - } else scode = 500; - } else { - if (_controller) { - scode = _controller->handleControlPlaneHttpGET(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); - } else scode = 404; - } - - } else scode = 401; // isAuth == false - } else if ((httpMethod == HTTP_POST)||(httpMethod == HTTP_PUT)) { - if (isAuth) { - - if (ps[0] == "moon") { - if (ps.size() == 2) { - - uint64_t seed = 0; - try { - nlohmann::json j(OSUtils::jsonParse(body)); - if (j.is_object()) { - seed = Utils::hexStrToU64(OSUtils::jsonString(j["seed"],"0").c_str()); - } - } catch ( ... ) { - // discard invalid JSON - } - - std::vector moons(_node->moons()); - const uint64_t id = Utils::hexStrToU64(ps[1].c_str()); - for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) { - if (m->id() == id) { - _moonToJson(res,*m); - scode = 200; - break; - } - } - - if ((scode != 200)&&(seed != 0)) { - char tmp[64]; - Utils::snprintf(tmp,sizeof(tmp),"%.16llx",id); - res["id"] = tmp; - res["roots"] = nlohmann::json::array(); - res["timestamp"] = 0; - res["signature"] = nlohmann::json(); - res["updatesMustBeSignedBy"] = nlohmann::json(); - res["waiting"] = true; - _node->orbit(id,seed); - } - - } else scode = 404; - } else if (ps[0] == "network") { - if (ps.size() == 2) { - - uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); - _node->join(wantnw,(void *)0); // does nothing if we are a member - ZT_VirtualNetworkList *nws = _node->networks(); - if (nws) { - for(unsigned long i=0;inetworkCount;++i) { - if (nws->networks[i].nwid == wantnw) { - OneService::NetworkSettings localSettings; - _svc->getNetworkSettings(nws->networks[i].nwid,localSettings); - - try { - nlohmann::json j(OSUtils::jsonParse(body)); - if (j.is_object()) { - nlohmann::json &allowManaged = j["allowManaged"]; - if (allowManaged.is_boolean()) localSettings.allowManaged = (bool)allowManaged; - nlohmann::json &allowGlobal = j["allowGlobal"]; - if (allowGlobal.is_boolean()) localSettings.allowGlobal = (bool)allowGlobal; - nlohmann::json &allowDefault = j["allowDefault"]; - if (allowDefault.is_boolean()) localSettings.allowDefault = (bool)allowDefault; - } - } catch ( ... ) { - // discard invalid JSON - } - - _svc->setNetworkSettings(nws->networks[i].nwid,localSettings); - _networkToJson(res,&(nws->networks[i]),_svc->portDeviceName(nws->networks[i].nwid),localSettings); - - scode = 200; - break; - } - } - _node->freeQueryResult((void *)nws); - } else scode = 500; - - } else scode = 404; - } else { - if (_controller) - scode = _controller->handleControlPlaneHttpPOST(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); - else scode = 404; - } - - } else scode = 401; // isAuth == false - } else if (httpMethod == HTTP_DELETE) { - if (isAuth) { - - if (ps[0] == "moon") { - if (ps.size() == 2) { - _node->deorbit(Utils::hexStrToU64(ps[1].c_str())); - res["result"] = true; - scode = 200; - } // else 404 - } else if (ps[0] == "network") { - ZT_VirtualNetworkList *nws = _node->networks(); - if (nws) { - if (ps.size() == 2) { - uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); - for(unsigned long i=0;inetworkCount;++i) { - if (nws->networks[i].nwid == wantnw) { - _node->leave(wantnw,(void **)0); - res["result"] = true; - scode = 200; - break; - } - } - } // else 404 - _node->freeQueryResult((void *)nws); - } else scode = 500; - } else { - if (_controller) - scode = _controller->handleControlPlaneHttpDELETE(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); - else scode = 404; - } - - } else scode = 401; // isAuth = false - } else { - scode = 400; - } - - if (responseBody.length() == 0) { - if ((res.is_object())||(res.is_array())) - responseBody = OSUtils::jsonDump(res); - else responseBody = "{}"; - responseContentType = "application/json"; - } - - // Wrap result in jsonp function call if the user included a jsonp= url argument. - // Also double-check isAuth since forbidding this without auth feels safer. - std::map::const_iterator jsonp(urlArgs.find("jsonp")); - if ((isAuth)&&(jsonp != urlArgs.end())&&(responseContentType == "application/json")) { - if (responseBody.length() > 0) - responseBody = jsonp->second + "(" + responseBody + ");"; - else responseBody = jsonp->second + "(null);"; - responseContentType = "application/javascript"; - } - - return scode; -} - -} // namespace ZeroTier diff --git a/zerotierone/service/ControlPlane.hpp b/zerotierone/service/ControlPlane.hpp deleted file mode 100644 index a1f743c..0000000 --- a/zerotierone/service/ControlPlane.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 . - */ - -#ifndef ZT_ONE_CONTROLPLANE_HPP -#define ZT_ONE_CONTROLPLANE_HPP - -#include -#include -#include - -#include "../include/ZeroTierOne.h" - -#include "../node/Mutex.hpp" - -namespace ZeroTier { - -class OneService; -class Node; -class EmbeddedNetworkController; -struct InetAddress; - -/** - * HTTP control plane and static web server - */ -class ControlPlane -{ -public: - ControlPlane(OneService *svc,Node *n); - - /** - * Set controller, which will be available under /controller - * - * @param c Network controller instance - */ - inline void setController(EmbeddedNetworkController *c) - { - Mutex::Lock _l(_lock); - _controller = c; - } - - /** - * Add an authentication token for API access - */ - inline void addAuthToken(const char *tok) - { - Mutex::Lock _l(_lock); - _authTokens.insert(std::string(tok)); - } - - /** - * Handle HTTP request - * - * @param fromAddress Originating IP address of request - * @param httpMethod HTTP method (as defined in ext/http-parser/http_parser.h) - * @param path Request path - * @param headers Request headers - * @param body Request body - * @param responseBody Result parameter: fill with response data - * @param responseContentType Result parameter: fill with content type - * @return HTTP response code - */ - unsigned int handleRequest( - const InetAddress &fromAddress, - unsigned int httpMethod, - const std::string &path, - const std::map &headers, - const std::string &body, - std::string &responseBody, - std::string &responseContentType); - -private: - OneService *const _svc; - Node *const _node; - EmbeddedNetworkController *_controller; - std::set _authTokens; - Mutex _lock; -}; - -} // namespace ZeroTier - -#endif diff --git a/zerotierone/windows/ZeroTierOne/ServiceBase.cpp b/zerotierone/windows/ZeroTierOne/ServiceBase.cpp deleted file mode 100644 index 59d384c..0000000 --- a/zerotierone/windows/ZeroTierOne/ServiceBase.cpp +++ /dev/null @@ -1,563 +0,0 @@ -/****************************** Module Header ******************************\ -* Module Name: ServiceBase.cpp -* Project: CppWindowsService -* Copyright (c) Microsoft Corporation. -* -* Provides a base class for a service that will exist as part of a service -* application. CServiceBase must be derived from when creating a new service -* class. -* -* This source is subject to the Microsoft Public License. -* See http://www.microsoft.com/en-us/openness/resources/licenses.aspx#MPL. -* All other rights reserved. -* -* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, -* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. -\***************************************************************************/ - -#pragma region Includes -#include "ServiceBase.h" -#include -#include -#include -#pragma endregion - - -#pragma region Static Members - -// Initialize the singleton service instance. -CServiceBase *CServiceBase::s_service = NULL; - - -// -// FUNCTION: CServiceBase::Run(CServiceBase &) -// -// PURPOSE: Register the executable for a service with the Service Control -// Manager (SCM). After you call Run(ServiceBase), the SCM issues a Start -// command, which results in a call to the OnStart method in the service. -// This method blocks until the service has stopped. -// -// PARAMETERS: -// * service - the reference to a CServiceBase object. It will become the -// singleton service instance of this service application. -// -// RETURN VALUE: If the function succeeds, the return value is TRUE. If the -// function fails, the return value is FALSE. To get extended error -// information, call GetLastError. -// -BOOL CServiceBase::Run(CServiceBase &service) -{ - s_service = &service; - - SERVICE_TABLE_ENTRYA serviceTable[] = - { - { service.m_name, ServiceMain }, - { NULL, NULL } - }; - - // Connects the main thread of a service process to the service control - // manager, which causes the thread to be the service control dispatcher - // thread for the calling process. This call returns when the service has - // stopped. The process should simply terminate when the call returns. - return StartServiceCtrlDispatcher(serviceTable); -} - - -// -// FUNCTION: CServiceBase::ServiceMain(DWORD, PWSTR *) -// -// PURPOSE: Entry point for the service. It registers the handler function -// for the service and starts the service. -// -// PARAMETERS: -// * dwArgc - number of command line arguments -// * lpszArgv - array of command line arguments -// -void WINAPI CServiceBase::ServiceMain(DWORD dwArgc, PSTR *pszArgv) -{ - assert(s_service != NULL); - - // Register the handler function for the service - s_service->m_statusHandle = RegisterServiceCtrlHandler( - s_service->m_name, ServiceCtrlHandler); - if (s_service->m_statusHandle == NULL) - { - throw GetLastError(); - } - - // Start the service. - s_service->Start(dwArgc, pszArgv); -} - - -// -// FUNCTION: CServiceBase::ServiceCtrlHandler(DWORD) -// -// PURPOSE: The function is called by the SCM whenever a control code is -// sent to the service. -// -// PARAMETERS: -// * dwCtrlCode - the control code. This parameter can be one of the -// following values: -// -// SERVICE_CONTROL_CONTINUE -// SERVICE_CONTROL_INTERROGATE -// SERVICE_CONTROL_NETBINDADD -// SERVICE_CONTROL_NETBINDDISABLE -// SERVICE_CONTROL_NETBINDREMOVE -// SERVICE_CONTROL_PARAMCHANGE -// SERVICE_CONTROL_PAUSE -// SERVICE_CONTROL_SHUTDOWN -// SERVICE_CONTROL_STOP -// -// This parameter can also be a user-defined control code ranges from 128 -// to 255. -// -void WINAPI CServiceBase::ServiceCtrlHandler(DWORD dwCtrl) -{ - switch (dwCtrl) - { - case SERVICE_CONTROL_STOP: s_service->Stop(); break; - case SERVICE_CONTROL_PAUSE: s_service->Pause(); break; - case SERVICE_CONTROL_CONTINUE: s_service->Continue(); break; - case SERVICE_CONTROL_SHUTDOWN: s_service->Shutdown(); break; - case SERVICE_CONTROL_INTERROGATE: break; - default: break; - } -} - -#pragma endregion - - -#pragma region Service Constructor and Destructor - -// -// FUNCTION: CServiceBase::CServiceBase(PWSTR, BOOL, BOOL, BOOL) -// -// PURPOSE: The constructor of CServiceBase. It initializes a new instance -// of the CServiceBase class. The optional parameters (fCanStop, -/// fCanShutdown and fCanPauseContinue) allow you to specify whether the -// service can be stopped, paused and continued, or be notified when system -// shutdown occurs. -// -// PARAMETERS: -// * pszServiceName - the name of the service -// * fCanStop - the service can be stopped -// * fCanShutdown - the service is notified when system shutdown occurs -// * fCanPauseContinue - the service can be paused and continued -// -CServiceBase::CServiceBase(PSTR pszServiceName, - BOOL fCanStop, - BOOL fCanShutdown, - BOOL fCanPauseContinue) -{ - // Service name must be a valid string and cannot be NULL. - m_name = (pszServiceName == NULL) ? "" : pszServiceName; - - m_statusHandle = NULL; - - // The service runs in its own process. - m_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - - // The service is starting. - m_status.dwCurrentState = SERVICE_START_PENDING; - - // The accepted commands of the service. - DWORD dwControlsAccepted = 0; - if (fCanStop) - dwControlsAccepted |= SERVICE_ACCEPT_STOP; - if (fCanShutdown) - dwControlsAccepted |= SERVICE_ACCEPT_SHUTDOWN; - if (fCanPauseContinue) - dwControlsAccepted |= SERVICE_ACCEPT_PAUSE_CONTINUE; - m_status.dwControlsAccepted = dwControlsAccepted; - - m_status.dwWin32ExitCode = NO_ERROR; - m_status.dwServiceSpecificExitCode = 0; - m_status.dwCheckPoint = 0; - m_status.dwWaitHint = 0; -} - - -// -// FUNCTION: CServiceBase::~CServiceBase() -// -// PURPOSE: The virtual destructor of CServiceBase. -// -CServiceBase::~CServiceBase(void) -{ -} - -#pragma endregion - - -#pragma region Service Start, Stop, Pause, Continue, and Shutdown - -// -// FUNCTION: CServiceBase::Start(DWORD, PWSTR *) -// -// PURPOSE: The function starts the service. It calls the OnStart virtual -// function in which you can specify the actions to take when the service -// starts. If an error occurs during the startup, the error will be logged -// in the Application event log, and the service will be stopped. -// -// PARAMETERS: -// * dwArgc - number of command line arguments -// * lpszArgv - array of command line arguments -// -void CServiceBase::Start(DWORD dwArgc, PSTR *pszArgv) -{ - try - { - // Tell SCM that the service is starting. - SetServiceStatus(SERVICE_START_PENDING); - - // Perform service-specific initialization. - OnStart(dwArgc, pszArgv); - - // Tell SCM that the service is started. - SetServiceStatus(SERVICE_RUNNING); - } - catch (DWORD dwError) - { - // Log the error. - WriteErrorLogEntry("Service Start", dwError); - - // Set the service status to be stopped. - SetServiceStatus(SERVICE_STOPPED, dwError); - } - catch (...) - { - // Log the error. - WriteEventLogEntry("Service failed to start.", EVENTLOG_ERROR_TYPE); - - // Set the service status to be stopped. - SetServiceStatus(SERVICE_STOPPED); - } -} - - -// -// FUNCTION: CServiceBase::OnStart(DWORD, PWSTR *) -// -// PURPOSE: When implemented in a derived class, executes when a Start -// command is sent to the service by the SCM or when the operating system -// starts (for a service that starts automatically). Specifies actions to -// take when the service starts. Be sure to periodically call -// CServiceBase::SetServiceStatus() with SERVICE_START_PENDING if the -// procedure is going to take long time. You may also consider spawning a -// new thread in OnStart to perform time-consuming initialization tasks. -// -// PARAMETERS: -// * dwArgc - number of command line arguments -// * lpszArgv - array of command line arguments -// -void CServiceBase::OnStart(DWORD dwArgc, PSTR *pszArgv) -{ -} - - -// -// FUNCTION: CServiceBase::Stop() -// -// PURPOSE: The function stops the service. It calls the OnStop virtual -// function in which you can specify the actions to take when the service -// stops. If an error occurs, the error will be logged in the Application -// event log, and the service will be restored to the original state. -// -void CServiceBase::Stop() -{ - DWORD dwOriginalState = m_status.dwCurrentState; - try - { - // Tell SCM that the service is stopping. - SetServiceStatus(SERVICE_STOP_PENDING); - - // Perform service-specific stop operations. - OnStop(); - - // Tell SCM that the service is stopped. - SetServiceStatus(SERVICE_STOPPED); - } - catch (DWORD dwError) - { - // Log the error. - WriteErrorLogEntry("Service Stop", dwError); - - // Set the orginal service status. - SetServiceStatus(dwOriginalState); - } - catch (...) - { - // Log the error. - WriteEventLogEntry("Service failed to stop.", EVENTLOG_ERROR_TYPE); - - // Set the orginal service status. - SetServiceStatus(dwOriginalState); - } -} - - -// -// FUNCTION: CServiceBase::OnStop() -// -// PURPOSE: When implemented in a derived class, executes when a Stop -// command is sent to the service by the SCM. Specifies actions to take -// when a service stops running. Be sure to periodically call -// CServiceBase::SetServiceStatus() with SERVICE_STOP_PENDING if the -// procedure is going to take long time. -// -void CServiceBase::OnStop() -{ -} - - -// -// FUNCTION: CServiceBase::Pause() -// -// PURPOSE: The function pauses the service if the service supports pause -// and continue. It calls the OnPause virtual function in which you can -// specify the actions to take when the service pauses. If an error occurs, -// the error will be logged in the Application event log, and the service -// will become running. -// -void CServiceBase::Pause() -{ - try - { - // Tell SCM that the service is pausing. - SetServiceStatus(SERVICE_PAUSE_PENDING); - - // Perform service-specific pause operations. - OnPause(); - - // Tell SCM that the service is paused. - SetServiceStatus(SERVICE_PAUSED); - } - catch (DWORD dwError) - { - // Log the error. - WriteErrorLogEntry("Service Pause", dwError); - - // Tell SCM that the service is still running. - SetServiceStatus(SERVICE_RUNNING); - } - catch (...) - { - // Log the error. - WriteEventLogEntry("Service failed to pause.", EVENTLOG_ERROR_TYPE); - - // Tell SCM that the service is still running. - SetServiceStatus(SERVICE_RUNNING); - } -} - - -// -// FUNCTION: CServiceBase::OnPause() -// -// PURPOSE: When implemented in a derived class, executes when a Pause -// command is sent to the service by the SCM. Specifies actions to take -// when a service pauses. -// -void CServiceBase::OnPause() -{ -} - - -// -// FUNCTION: CServiceBase::Continue() -// -// PURPOSE: The function resumes normal functioning after being paused if -// the service supports pause and continue. It calls the OnContinue virtual -// function in which you can specify the actions to take when the service -// continues. If an error occurs, the error will be logged in the -// Application event log, and the service will still be paused. -// -void CServiceBase::Continue() -{ - try - { - // Tell SCM that the service is resuming. - SetServiceStatus(SERVICE_CONTINUE_PENDING); - - // Perform service-specific continue operations. - OnContinue(); - - // Tell SCM that the service is running. - SetServiceStatus(SERVICE_RUNNING); - } - catch (DWORD dwError) - { - // Log the error. - WriteErrorLogEntry("Service Continue", dwError); - - // Tell SCM that the service is still paused. - SetServiceStatus(SERVICE_PAUSED); - } - catch (...) - { - // Log the error. - WriteEventLogEntry("Service failed to resume.", EVENTLOG_ERROR_TYPE); - - // Tell SCM that the service is still paused. - SetServiceStatus(SERVICE_PAUSED); - } -} - - -// -// FUNCTION: CServiceBase::OnContinue() -// -// PURPOSE: When implemented in a derived class, OnContinue runs when a -// Continue command is sent to the service by the SCM. Specifies actions to -// take when a service resumes normal functioning after being paused. -// -void CServiceBase::OnContinue() -{ -} - - -// -// FUNCTION: CServiceBase::Shutdown() -// -// PURPOSE: The function executes when the system is shutting down. It -// calls the OnShutdown virtual function in which you can specify what -// should occur immediately prior to the system shutting down. If an error -// occurs, the error will be logged in the Application event log. -// -void CServiceBase::Shutdown() -{ - try - { - // Perform service-specific shutdown operations. - OnShutdown(); - - // Tell SCM that the service is stopped. - SetServiceStatus(SERVICE_STOPPED); - } - catch (DWORD dwError) - { - // Log the error. - WriteErrorLogEntry("Service Shutdown", dwError); - } - catch (...) - { - // Log the error. - WriteEventLogEntry("Service failed to shut down.", EVENTLOG_ERROR_TYPE); - } -} - - -// -// FUNCTION: CServiceBase::OnShutdown() -// -// PURPOSE: When implemented in a derived class, executes when the system -// is shutting down. Specifies what should occur immediately prior to the -// system shutting down. -// -void CServiceBase::OnShutdown() -{ -} - -#pragma endregion - - -#pragma region Helper Functions - -// -// FUNCTION: CServiceBase::SetServiceStatus(DWORD, DWORD, DWORD) -// -// PURPOSE: The function sets the service status and reports the status to -// the SCM. -// -// PARAMETERS: -// * dwCurrentState - the state of the service -// * dwWin32ExitCode - error code to report -// * dwWaitHint - estimated time for pending operation, in milliseconds -// -void CServiceBase::SetServiceStatus(DWORD dwCurrentState, - DWORD dwWin32ExitCode, - DWORD dwWaitHint) -{ - static DWORD dwCheckPoint = 1; - - // Fill in the SERVICE_STATUS structure of the service. - - m_status.dwCurrentState = dwCurrentState; - m_status.dwWin32ExitCode = dwWin32ExitCode; - m_status.dwWaitHint = dwWaitHint; - - m_status.dwCheckPoint = - ((dwCurrentState == SERVICE_RUNNING) || - (dwCurrentState == SERVICE_STOPPED)) ? - 0 : dwCheckPoint++; - - // Report the status of the service to the SCM. - ::SetServiceStatus(m_statusHandle, &m_status); -} - - -// -// FUNCTION: CServiceBase::WriteEventLogEntry(PWSTR, WORD) -// -// PURPOSE: Log a message to the Application event log. -// -// PARAMETERS: -// * pszMessage - string message to be logged. -// * wType - the type of event to be logged. The parameter can be one of -// the following values. -// -// EVENTLOG_SUCCESS -// EVENTLOG_AUDIT_FAILURE -// EVENTLOG_AUDIT_SUCCESS -// EVENTLOG_ERROR_TYPE -// EVENTLOG_INFORMATION_TYPE -// EVENTLOG_WARNING_TYPE -// -void CServiceBase::WriteEventLogEntry(PSTR pszMessage, WORD wType) -{ - HANDLE hEventSource = NULL; - LPCSTR lpszStrings[2] = { NULL, NULL }; - - hEventSource = RegisterEventSource(NULL, m_name); - if (hEventSource) - { - lpszStrings[0] = m_name; - lpszStrings[1] = pszMessage; - - ReportEvent(hEventSource, // Event log handle - wType, // Event type - 0, // Event category - 0, // Event identifier - NULL, // No security identifier - 2, // Size of lpszStrings array - 0, // No binary data - lpszStrings, // Array of strings - NULL // No binary data - ); - - DeregisterEventSource(hEventSource); - } -} - - -// -// FUNCTION: CServiceBase::WriteErrorLogEntry(PWSTR, DWORD) -// -// PURPOSE: Log an error message to the Application event log. -// -// PARAMETERS: -// * pszFunction - the function that gives the error -// * dwError - the error code -// -void CServiceBase::WriteErrorLogEntry(PSTR pszFunction, DWORD dwError) -{ - char szMessage[260]; - StringCchPrintf(szMessage, ARRAYSIZE(szMessage), - "%s failed w/err 0x%08lx", pszFunction, dwError); - WriteEventLogEntry(szMessage, EVENTLOG_ERROR_TYPE); -} - -#pragma endregion \ No newline at end of file diff --git a/zerotierone/windows/ZeroTierOne/ServiceBase.h b/zerotierone/windows/ZeroTierOne/ServiceBase.h deleted file mode 100644 index 6d62b1f..0000000 --- a/zerotierone/windows/ZeroTierOne/ServiceBase.h +++ /dev/null @@ -1,122 +0,0 @@ -/****************************** Module Header ******************************\ -* Module Name: ServiceBase.h -* Project: CppWindowsService -* Copyright (c) Microsoft Corporation. -* -* Provides a base class for a service that will exist as part of a service -* application. CServiceBase must be derived from when creating a new service -* class. -* -* This source is subject to the Microsoft Public License. -* See http://www.microsoft.com/en-us/openness/resources/licenses.aspx#MPL. -* All other rights reserved. -* -* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, -* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. -\***************************************************************************/ - -#pragma once - -#include -#include - -class CServiceBase -{ -public: - - // Register the executable for a service with the Service Control Manager - // (SCM). After you call Run(ServiceBase), the SCM issues a Start command, - // which results in a call to the OnStart method in the service. This - // method blocks until the service has stopped. - static BOOL Run(CServiceBase &service); - - // Service object constructor. The optional parameters (fCanStop, - // fCanShutdown and fCanPauseContinue) allow you to specify whether the - // service can be stopped, paused and continued, or be notified when - // system shutdown occurs. - CServiceBase(LPSTR pszServiceName, - BOOL fCanStop = TRUE, - BOOL fCanShutdown = TRUE, - BOOL fCanPauseContinue = FALSE); - - // Service object destructor. - virtual ~CServiceBase(void); - - // Stop the service. - void Stop(); - -protected: - - // When implemented in a derived class, executes when a Start command is - // sent to the service by the SCM or when the operating system starts - // (for a service that starts automatically). Specifies actions to take - // when the service starts. - virtual void OnStart(DWORD dwArgc, PSTR *pszArgv); - - // When implemented in a derived class, executes when a Stop command is - // sent to the service by the SCM. Specifies actions to take when a - // service stops running. - virtual void OnStop(); - - // When implemented in a derived class, executes when a Pause command is - // sent to the service by the SCM. Specifies actions to take when a - // service pauses. - virtual void OnPause(); - - // When implemented in a derived class, OnContinue runs when a Continue - // command is sent to the service by the SCM. Specifies actions to take - // when a service resumes normal functioning after being paused. - virtual void OnContinue(); - - // When implemented in a derived class, executes when the system is - // shutting down. Specifies what should occur immediately prior to the - // system shutting down. - virtual void OnShutdown(); - - // Set the service status and report the status to the SCM. - void SetServiceStatus(DWORD dwCurrentState, - DWORD dwWin32ExitCode = NO_ERROR, - DWORD dwWaitHint = 0); - - // Log a message to the Application event log. - void WriteEventLogEntry(PSTR pszMessage, WORD wType); - - // Log an error message to the Application event log. - void WriteErrorLogEntry(PSTR pszFunction, - DWORD dwError = GetLastError()); - -private: - - // Entry point for the service. It registers the handler function for the - // service and starts the service. - static void WINAPI ServiceMain(DWORD dwArgc, LPSTR *lpszArgv); - - // The function is called by the SCM whenever a control code is sent to - // the service. - static void WINAPI ServiceCtrlHandler(DWORD dwCtrl); - - // Start the service. - void Start(DWORD dwArgc, PSTR *pszArgv); - - // Pause the service. - void Pause(); - - // Resume the service after being paused. - void Continue(); - - // Execute when the system is shutting down. - void Shutdown(); - - // The singleton service instance. - static CServiceBase *s_service; - - // The name of the service - LPSTR m_name; - - // The status of the service - SERVICE_STATUS m_status; - - // The service status handle - SERVICE_STATUS_HANDLE m_statusHandle; -}; \ No newline at end of file diff --git a/zerotierone/windows/ZeroTierOne/ServiceInstaller.cpp b/zerotierone/windows/ZeroTierOne/ServiceInstaller.cpp deleted file mode 100644 index d302d9f..0000000 --- a/zerotierone/windows/ZeroTierOne/ServiceInstaller.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/****************************** Module Header ******************************\ -* Module Name: ServiceInstaller.cpp -* Project: CppWindowsService -* Copyright (c) Microsoft Corporation. -* -* The file implements functions that install and uninstall the service. -* -* This source is subject to the Microsoft Public License. -* See http://www.microsoft.com/en-us/openness/resources/licenses.aspx#MPL. -* All other rights reserved. -* -* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, -* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. -\***************************************************************************/ - -#pragma region "Includes" -#include -#include -#include "ServiceInstaller.h" -#pragma endregion - - -// -// FUNCTION: InstallService -// -// PURPOSE: Install the current application as a service to the local -// service control manager database. -// -// PARAMETERS: -// * pszServiceName - the name of the service to be installed -// * pszDisplayName - the display name of the service -// * dwStartType - the service start option. This parameter can be one of -// the following values: SERVICE_AUTO_START, SERVICE_BOOT_START, -// SERVICE_DEMAND_START, SERVICE_DISABLED, SERVICE_SYSTEM_START. -// * pszDependencies - a pointer to a double null-terminated array of null- -// separated names of services or load ordering groups that the system -// must start before this service. -// * pszAccount - the name of the account under which the service runs. -// * pszPassword - the password to the account name. -// -// NOTE: If the function fails to install the service, it prints the error -// in the standard output stream for users to diagnose the problem. -// -std::string InstallService(PSTR pszServiceName, - PSTR pszDisplayName, - DWORD dwStartType, - PSTR pszDependencies, - PSTR pszAccount, - PSTR pszPassword) -{ - std::string ret; - char szPathTmp[MAX_PATH],szPath[MAX_PATH]; - SC_HANDLE schSCManager = NULL; - SC_HANDLE schService = NULL; - - if (GetModuleFileName(NULL, szPathTmp, ARRAYSIZE(szPath)) == 0) - { - ret = "GetModuleFileName failed, unable to get path to self"; - goto Cleanup; - } - - // Quote path in case it contains spaces - _snprintf_s(szPath,sizeof(szPath),"\"%s\"",szPathTmp); - - // Open the local default service control manager database - schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | - SC_MANAGER_CREATE_SERVICE); - if (schSCManager == NULL) - { - ret = "OpenSCManager failed"; - goto Cleanup; - } - - // Install the service into SCM by calling CreateService - schService = CreateService( - schSCManager, // SCManager database - pszServiceName, // Name of service - pszDisplayName, // Name to display - SERVICE_QUERY_STATUS, // Desired access - SERVICE_WIN32_OWN_PROCESS, // Service type - dwStartType, // Service start type - SERVICE_ERROR_NORMAL, // Error control type - szPath, // Service's binary - NULL, // No load ordering group - NULL, // No tag identifier - pszDependencies, // Dependencies - pszAccount, // Service running account - pszPassword // Password of the account - ); - if (schService == NULL) - { - ret = "CreateService failed"; - goto Cleanup; - } - -Cleanup: - // Centralized cleanup for all allocated resources. - if (schSCManager) - { - CloseServiceHandle(schSCManager); - schSCManager = NULL; - } - if (schService) - { - CloseServiceHandle(schService); - schService = NULL; - } - - return ret; -} - - -// -// FUNCTION: UninstallService -// -// PURPOSE: Stop and remove the service from the local service control -// manager database. -// -// PARAMETERS: -// * pszServiceName - the name of the service to be removed. -// -// NOTE: If the function fails to uninstall the service, it prints the -// error in the standard output stream for users to diagnose the problem. -// -std::string UninstallService(PSTR pszServiceName) -{ - std::string ret; - SC_HANDLE schSCManager = NULL; - SC_HANDLE schService = NULL; - SERVICE_STATUS ssSvcStatus = {}; - - // Open the local default service control manager database - schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); - if (schSCManager == NULL) - { - ret = "OpenSCManager failed"; - goto Cleanup; - } - - // Open the service with delete, stop, and query status permissions - schService = OpenService(schSCManager, pszServiceName, SERVICE_STOP | - SERVICE_QUERY_STATUS | DELETE); - if (schService == NULL) - { - ret = "OpenService failed (is service installed?)"; - goto Cleanup; - } - - // Try to stop the service - if (ControlService(schService, SERVICE_CONTROL_STOP, &ssSvcStatus)) - { - Sleep(500); - - while (QueryServiceStatus(schService, &ssSvcStatus)) - { - if (ssSvcStatus.dwCurrentState == SERVICE_STOP_PENDING) - { - Sleep(500); - } - else break; - } - } - - // Now remove the service by calling DeleteService. - if (!DeleteService(schService)) - { - ret = "DeleteService failed (is service running?)"; - goto Cleanup; - } - -Cleanup: - // Centralized cleanup for all allocated resources. - if (schSCManager) - { - CloseServiceHandle(schSCManager); - schSCManager = NULL; - } - if (schService) - { - CloseServiceHandle(schService); - schService = NULL; - } - - return ret; -} diff --git a/zerotierone/windows/ZeroTierOne/ServiceInstaller.h b/zerotierone/windows/ZeroTierOne/ServiceInstaller.h deleted file mode 100644 index ee9856d..0000000 --- a/zerotierone/windows/ZeroTierOne/ServiceInstaller.h +++ /dev/null @@ -1,64 +0,0 @@ -/****************************** Module Header ******************************\ -* Module Name: ServiceInstaller.h -* Project: CppWindowsService -* Copyright (c) Microsoft Corporation. -* -* The file declares functions that install and uninstall the service. -* -* This source is subject to the Microsoft Public License. -* See http://www.microsoft.com/en-us/openness/resources/licenses.aspx#MPL. -* All other rights reserved. -* -* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, -* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. -\***************************************************************************/ - -#pragma once - -#include - -// -// FUNCTION: InstallService -// -// PURPOSE: Install the current application as a service to the local -// service control manager database. -// -// PARAMETERS: -// * pszServiceName - the name of the service to be installed -// * pszDisplayName - the display name of the service -// * dwStartType - the service start option. This parameter can be one of -// the following values: SERVICE_AUTO_START, SERVICE_BOOT_START, -// SERVICE_DEMAND_START, SERVICE_DISABLED, SERVICE_SYSTEM_START. -// * pszDependencies - a pointer to a double null-terminated array of null- -// separated names of services or load ordering groups that the system -// must start before this service. -// * pszAccount - the name of the account under which the service runs. -// * pszPassword - the password to the account name. -// -// NOTE: If the function fails to install the service, it prints the error -// in the standard output stream for users to diagnose the problem. -// -// modified for ZT1 to return an error or empty string on success -std::string InstallService(PSTR pszServiceName, - PSTR pszDisplayName, - DWORD dwStartType, - PSTR pszDependencies, - PSTR pszAccount, - PSTR pszPassword); - - -// -// FUNCTION: UninstallService -// -// PURPOSE: Stop and remove the service from the local service control -// manager database. -// -// PARAMETERS: -// * pszServiceName - the name of the service to be removed. -// -// NOTE: If the function fails to uninstall the service, it prints the -// error in the standard output stream for users to diagnose the problem. -// -// Also modified to return rather than print errors -std::string UninstallService(PSTR pszServiceName); diff --git a/zerotierone/windows/ZeroTierOne/ZeroTierOne.aps b/zerotierone/windows/ZeroTierOne/ZeroTierOne.aps deleted file mode 100644 index 1de4112..0000000 Binary files a/zerotierone/windows/ZeroTierOne/ZeroTierOne.aps and /dev/null differ diff --git a/zerotierone/windows/ZeroTierOne/ZeroTierOne.rc b/zerotierone/windows/ZeroTierOne/ZeroTierOne.rc deleted file mode 100644 index 0d7c7a7..0000000 Binary files a/zerotierone/windows/ZeroTierOne/ZeroTierOne.rc and /dev/null differ diff --git a/zerotierone/windows/ZeroTierOne/ZeroTierOne.vcxproj b/zerotierone/windows/ZeroTierOne/ZeroTierOne.vcxproj deleted file mode 100644 index d0b027f..0000000 --- a/zerotierone/windows/ZeroTierOne/ZeroTierOne.vcxproj +++ /dev/null @@ -1,322 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {B00A4957-5977-4AC1-9EF4-571DC27EADA2} - ZeroTierOne - - - - Application - true - v140 - MultiByte - - - Application - true - v140 - MultiByte - - - Application - false - v140 - true - MultiByte - - - Application - false - v140 - true - MultiByte - - - - - - - - - - - - - - - - - - - .exe - $(SolutionDir)\Build\$(Platform)\$(Configuration)\ - zerotier-one_x86 - - - .exe - $(SolutionDir)\Build\$(Platform)\$(Configuration)\ - zerotier-one_x86 - - - .exe - $(SolutionDir)\Build\$(Platform)\$(Configuration)\ - zerotier-one_x64 - - - .exe - $(SolutionDir)\Build\$(Platform)\$(Configuration)\ - zerotier-one_x64 - - - - Level3 - Disabled - true - - - NOMINMAX;STATICLIB;WIN32;ZT_TRACE;ZT_USE_MINIUPNPC;MINIUPNP_STATICLIB;ZT_SOFTWARE_UPDATE_DEFAULT="disable";%(PreprocessorDefinitions) - 4996 - - - true - wsock32.lib;ws2_32.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) - false - - - - - Level3 - Disabled - true - - - NOMINMAX;STATICLIB;WIN32;ZT_TRACE;ZT_RULES_ENGINE_DEBUGGING;ZT_USE_MINIUPNPC;MINIUPNP_STATICLIB;ZT_SOFTWARE_UPDATE_DEFAULT="disable";%(PreprocessorDefinitions) - false - 4996 - - - true - wsock32.lib;ws2_32.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) - false - "notelemetry.obj" %(AdditionalOptions) - - - - - Level3 - MaxSpeed - true - true - true - - - STATICLIB;ZT_SALSA20_SSE;ZT_USE_MINIUPNPC;MINIUPNP_STATICLIB;WIN32;NOMINMAX;ZT_SOFTWARE_UPDATE_DEFAULT="apply";%(PreprocessorDefinitions) - MultiThreaded - NoExtensions - true - AnySuitable - Speed - true - 4996 - - - true - true - true - wsock32.lib;ws2_32.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) - false - - - - - Level3 - MaxSpeed - true - true - true - - - STATICLIB;ZT_SOFTWARE_UPDATE_DEFAULT="apply";ZT_SALSA20_SSE;ZT_USE_MINIUPNPC;MINIUPNP_STATICLIB;WIN32;NOMINMAX;%(PreprocessorDefinitions) - MultiThreaded - NotSet - true - AnySuitable - Speed - true - 4996 - - - true - true - true - wsock32.lib;ws2_32.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) - false - - - - - - \ No newline at end of file diff --git a/zerotierone/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters b/zerotierone/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters deleted file mode 100644 index 1b7b469..0000000 --- a/zerotierone/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters +++ /dev/null @@ -1,497 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {67b1c0f8-b018-4169-9c14-7032ed12c786} - - - {40761a4c-e8db-4a91-9cab-7afef332f4a8} - - - {da3b8126-840c-45db-8abe-9d7e7976f8be} - - - {6054dfae-4ed2-4d69-8cf5-d6f27646f2d7} - - - {9944293a-4a1a-40e9-b92a-eff31fe87e2c} - - - {ca21bd6b-ff4e-4f9e-bedd-c9f603d2d0d6} - - - {e1743b3c-1d18-47f1-ab5a-f5703c19f1df} - - - {71865460-d693-4c73-84f6-dbff42f49df6} - - - {17ae9a01-d39f-4c6d-a800-8f2cd0804c96} - - - {7784af31-5b60-4300-b07e-44cf864c54db} - - - {f8a1c208-15b8-4d85-a4cb-11d2b82f2d1e} - - - {43f75f84-c70d-4d44-a0ef-28a7a399abd4} - - - {0da07a2f-8922-4827-ac51-29ca3f30f881} - - - {b74916eb-bb6c-4449-a2a2-fa0b17f60121} - - - {bf604491-14c4-4a74-81a6-6105d07c5c7c} - - - {5423fb64-896b-432e-a19d-88d4467f89f9} - - - {56cc3ab8-3336-4a22-9471-c267ee46cd54} - - - {d7292d0d-72a0-4ed6-b717-21debb120737} - - - {409ec37e-ff36-4c13-b18d-52d6052e0ca2} - - - {3cad34c8-c436-43ae-8323-57803637c832} - - - {ff20532b-d9a2-440d-a7b4-b49e26a9b2f8} - - - - - Source Files\service - - - Source Files\service - - - Source Files\osdep - - - Source Files\osdep - - - Source Files\osdep - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\ext\http-parser - - - Source Files - - - Source Files\windows\ZeroTierOne - - - Source Files\windows\ZeroTierOne - - - Source Files\windows\ZeroTierOne - - - Source Files\node - - - Source Files\node - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\ext\miniupnpc - - - Source Files\osdep - - - Source Files\ext\libnatpmp - - - Source Files\ext\libnatpmp - - - Source Files\ext\libnatpmp - - - Source Files\osdep - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\node - - - Source Files\controller - - - Source Files\controller - - - Source Files\service - - - Source Files\node - - - - - Header Files - - - Header Files - - - Header Files\include - - - Header Files\osdep - - - Header Files\osdep - - - Header Files\osdep - - - Header Files\osdep - - - Header Files\osdep - - - Header Files\service - - - Header Files\service - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\ext\http-parser - - - Header Files\windows\ZeroTierOne - - - Header Files\windows\ZeroTierOne - - - Header Files\windows\ZeroTierOne - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\node - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\ext\miniupnpc - - - Header Files\osdep - - - Header Files\ext\libnatpmp - - - Header Files\ext\libnatpmp - - - Header Files\ext\libnatpmp - - - Header Files\osdep - - - Header Files\osdep - - - Header Files\service - - - Header Files\ext\json - - - Header Files\node - - - - - Resource Files - - - \ No newline at end of file diff --git a/zerotierone/windows/ZeroTierOne/ZeroTierOneService.cpp b/zerotierone/windows/ZeroTierOne/ZeroTierOneService.cpp deleted file mode 100644 index 8e0b9c3..0000000 --- a/zerotierone/windows/ZeroTierOne/ZeroTierOneService.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 . - */ - -#pragma region Includes - -#include -#include -#include -#include - -#include "ZeroTierOneService.h" - -#include "../../version.h" -#include "../../include/ZeroTierOne.h" - -#include "../../node/Constants.hpp" -#include "../../node/Utils.hpp" -#include "../../osdep/OSUtils.hpp" -#include "../../service/OneService.hpp" - -#pragma endregion // Includes - -#ifdef ZT_DEBUG_SERVICE -FILE *SVCDBGfile = (FILE *)0; -ZeroTier::Mutex SVCDBGfile_m; -#endif - -ZeroTierOneService::ZeroTierOneService() : - CServiceBase(ZT_SERVICE_NAME,TRUE,TRUE,FALSE), - _service((ZeroTier::OneService *)0) -{ -#ifdef ZT_DEBUG_SERVICE - SVCDBGfile_m.lock(); - if (!SVCDBGfile) - SVCDBGfile = fopen(ZT_DEBUG_SERVICE,"a"); - SVCDBGfile_m.unlock(); -#endif - - ZT_SVCDBG("ZeroTierOneService::ZeroTierOneService()\r\n"); -} - -ZeroTierOneService::~ZeroTierOneService(void) -{ - ZT_SVCDBG("ZeroTierOneService::~ZeroTierOneService()\r\n"); - -#ifdef ZT_DEBUG_SERVICE - SVCDBGfile_m.lock(); - if (SVCDBGfile) { - fclose(SVCDBGfile); - SVCDBGfile = (FILE *)0; - } - SVCDBGfile_m.unlock(); -#endif -} - -void ZeroTierOneService::threadMain() - throw() -{ - ZT_SVCDBG("ZeroTierOneService::threadMain()\r\n"); - -restart_node: - try { - { - ZeroTier::Mutex::Lock _l(_lock); - delete _service; - _service = (ZeroTier::OneService *)0; // in case newInstance() fails - _service = ZeroTier::OneService::newInstance( - ZeroTier::OneService::platformDefaultHomePath().c_str(), - ZT_DEFAULT_PORT); - } - switch(_service->run()) { - case ZeroTier::OneService::ONE_UNRECOVERABLE_ERROR: { - std::string err("ZeroTier One encountered an unrecoverable error: "); - err.append(_service->fatalErrorMessage()); - err.append(" (restarting in 5 seconds)"); - WriteEventLogEntry(const_cast (err.c_str()),EVENTLOG_ERROR_TYPE); - Sleep(5000); - } goto restart_node; - - case ZeroTier::OneService::ONE_IDENTITY_COLLISION: { - std::string homeDir(ZeroTier::OneService::platformDefaultHomePath()); - delete _service; - _service = (ZeroTier::OneService *)0; - std::string oldid; - ZeroTier::OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str(),oldid); - if (oldid.length()) { - ZeroTier::OSUtils::writeFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret.saved_after_collision").c_str(),oldid); - ZeroTier::OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str()); - ZeroTier::OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.public").c_str()); - } - } goto restart_node; - - default: // normal termination - break; - } - } catch ( ... ) { - // sanity check, shouldn't happen since Node::run() should catch all its own errors - // could also happen if we're out of memory though! - WriteEventLogEntry("unexpected exception (out of memory?) (trying again in 5 seconds)",EVENTLOG_ERROR_TYPE); - Sleep(5000); - goto restart_node; - } - - { - ZeroTier::Mutex::Lock _l(_lock); - delete _service; - _service = (ZeroTier::OneService *)0; - } -} - -void ZeroTierOneService::OnStart(DWORD dwArgc, LPSTR *lpszArgv) -{ - ZT_SVCDBG("ZeroTierOneService::OnStart()\r\n"); - - try { - _thread = ZeroTier::Thread::start(this); - } catch ( ... ) { - throw (DWORD)ERROR_EXCEPTION_IN_SERVICE; - } -} - -void ZeroTierOneService::OnStop() -{ - ZT_SVCDBG("ZeroTierOneService::OnStop()\r\n"); - - _lock.lock(); - ZeroTier::OneService *s = _service; - _lock.unlock(); - - if (s) { - s->terminate(); - ZeroTier::Thread::join(_thread); - } -} - -void ZeroTierOneService::OnShutdown() -{ - ZT_SVCDBG("ZeroTierOneService::OnShutdown()\r\n"); - - // stop thread on system shutdown (if it hasn't happened already) - OnStop(); -} diff --git a/zerotierone/windows/ZeroTierOne/ZeroTierOneService.h b/zerotierone/windows/ZeroTierOne/ZeroTierOneService.h deleted file mode 100644 index 9c23d0f..0000000 --- a/zerotierone/windows/ZeroTierOne/ZeroTierOneService.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 . - */ - -#pragma once - -#include - -#include "ServiceBase.h" - -#include - -#include "../../node/Mutex.hpp" -#include "../../osdep/Thread.hpp" -#include "../../service/OneService.hpp" - -// Uncomment to make debugging Windows services suck slightly less hard. -//#define ZT_DEBUG_SERVICE "C:\\ZeroTierOneServiceDebugLog.txt" - -#ifdef ZT_DEBUG_SERVICE -extern FILE *SVCDBGfile; -extern ZeroTier::Mutex SVCDBGfile_m; -#define ZT_SVCDBG(f,...) { SVCDBGfile_m.lock(); fprintf(SVCDBGfile,f,##__VA_ARGS__); fflush(SVCDBGfile); SVCDBGfile_m.unlock(); } -#else -#define ZT_SVCDBG(f,...) {} -#endif - -#define ZT_SERVICE_NAME "ZeroTierOneService" -#define ZT_SERVICE_DISPLAY_NAME "ZeroTier One" -#define ZT_SERVICE_START_TYPE SERVICE_AUTO_START -#define ZT_SERVICE_DEPENDENCIES "" -//#define ZT_SERVICE_ACCOUNT "NT AUTHORITY\\LocalService" -#define ZT_SERVICE_ACCOUNT NULL -#define ZT_SERVICE_PASSWORD NULL - -class ZeroTierOneService : public CServiceBase -{ -public: - ZeroTierOneService(); - virtual ~ZeroTierOneService(void); - - /** - * Thread main method; do not call elsewhere - */ - void threadMain() - throw(); - -protected: - virtual void OnStart(DWORD dwArgc, PSTR *pszArgv); - virtual void OnStop(); - virtual void OnShutdown(); - -private: - ZeroTier::OneService *volatile _service; - ZeroTier::Mutex _lock; - ZeroTier::Thread _thread; -}; diff --git a/zerotierone/windows/ZeroTierOne/resource.h b/zerotierone/windows/ZeroTierOne/resource.h deleted file mode 100644 index 1aad215..0000000 --- a/zerotierone/windows/ZeroTierOne/resource.h +++ /dev/null @@ -1,14 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by ZeroTierOne.rc - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/zerotierone/AUTHORS.md b/zto/AUTHORS.md similarity index 100% rename from zerotierone/AUTHORS.md rename to zto/AUTHORS.md diff --git a/zerotierone/COPYING b/zto/COPYING similarity index 100% rename from zerotierone/COPYING rename to zto/COPYING diff --git a/zerotierone/LICENSE.GPL-2 b/zto/LICENSE.GPL-2 similarity index 100% rename from zerotierone/LICENSE.GPL-2 rename to zto/LICENSE.GPL-2 diff --git a/zerotierone/LICENSE.GPL-3 b/zto/LICENSE.GPL-3 similarity index 100% rename from zerotierone/LICENSE.GPL-3 rename to zto/LICENSE.GPL-3 diff --git a/zerotierone/Makefile b/zto/Makefile similarity index 100% rename from zerotierone/Makefile rename to zto/Makefile diff --git a/zerotierone/README.md b/zto/README.md similarity index 97% rename from zerotierone/README.md rename to zto/README.md index 49feac6..47bfc87 100644 --- a/zerotierone/README.md +++ b/zto/README.md @@ -1,7 +1,9 @@ ZeroTier - A Planetary Ethernet Switch ====== -ZeroTier is an advanced SDN Ethernet switch for planet Earth. It erases the LAN/WAN distinction and makes VPNs, tunnels, proxies, and other kludges arising from the inflexible nature of physical networks obsolete. Everything is encrypted end-to-end and traffic takes the most direct (peer to peer) path available. +ZeroTier is an enterprise Ethernet switch for planet Earth. + +It erases the LAN/WAN distinction and makes VPNs, tunnels, proxies, and other kludges arising from the inflexible nature of physical networks obsolete. Everything is encrypted end-to-end and traffic takes the most direct (peer to peer) path available. Visit [ZeroTier's site](https://www.zerotier.com/) for more information and [pre-built binary packages](https://www.zerotier.com/download.shtml). Apps for Android and iOS are available for free in the Google Play and Apple app stores. diff --git a/zto/RELEASE-NOTES.md b/zto/RELEASE-NOTES.md new file mode 100644 index 0000000..42a2aaa --- /dev/null +++ b/zto/RELEASE-NOTES.md @@ -0,0 +1,92 @@ +ZeroTier Release Notes +====== + +*As of 1.2.0 this will serve as a detailed changelog, which we've needed for a long time.* + +# 2017-03-13 -- Version 1.2.0 + +Version 1.2.0 is a major milestone release and introduces a large number of new capabilities to the ZeroTier core network hypervisor. It also includes some security tightening, major UI improvements for Windows and Macintosh platforms, and a number of bug fixes and platform issue workarounds. + +## Features in 1.2.0 + +### The ZeroTier Rules Engine + +The largest new feature in 1.2.0, and the product of many months of work, is our advanced network rules engine. With this release we achieve traffic control, security monitoring, and micro-segmentation capability on par with many enterprise SDN solutions designed for use in advanced data centers and corporate networks. + +Rules allow you to filter packets on your network and vector traffic to security observers (e.g. a node running Snort). Security observation can be performed in-band using REDIRECT or out of band using TEE, and for tha latter it can be done for headers only, for select traffic, or probabilistically to reduce overhead on large distributed networks. + +Tags and capabilites provide advanced methods for implementing fine grained permission structures and micro-segmentation schemes without bloating the size and complexity of your rules table. + +See our manual for more information. + +### Root Server Federation + +It's now possible to create your own root servers and add them to the root server pool on your nodes. This is done by creating what's called a "moon," which is a signed enumeration of root servers and their stable points on the network. Refer to the manual for more details on how to do this and how it works. + +Federated roots achieve a number of things: + + * You can deploy your own infrastructure to reduce dependency on ours. + * You can deploy them *inside your LAN* to ensure that network connectivity inside your facility still works if the Internet goes down. This is the first step toward making ZeroTier viable as an in-house SDN solution. + * Roots can be deployed inside national boundaries for countries with data residency laws or "great firewalls." (As of 1.2.0 there is still no way to force all traffic to use these roots, but that will be easy to do in a later version.) + * Last but not least this makes ZeroTier somewhat less centralized by eliminating any hard dependency on ZeroTier, Inc.'s infrastructure. + +Our roots will of course remain and continue to provide zero-configuration instant-on deployment, a secure global authority for identities, and free traffic relaying for those who can't establish peer to peer connections. + +### Local Configuration + +An element of our design philosophy is "features are bugs." This isn't an absolute dogma but more of a guiding principle. We try as hard as we can to avoid adding features, especially "knobs" that must be tweaked by a user. + +As of 1.2.0 we've decided that certain knobs are unavoidable, and so there is now a `local.conf` file that can be used to configure them. See the ZeroTier One documentation for these. They include: + + * Blacklisting interfaces you want to make sure ZeroTier doesn't use for network traffic, such as VPNs, slow links, or backplanes designated for only certain kinds of traffic. + * Turning uPnP/NAT-PMP on or off. + * Configuring software updates on Windows and Mac platforms. + * Defining trusted paths (the old trusted paths file is now deprecated) + * Setting the ZeroTier main port so it doesn't have to be changed on the command line, which is very inconvenient in many cases. + +### Improved In-Band Software Updates + +A good software update system for Windows and Mac clients has been a missing feature in previous versions. It does exist but we've been shy about using it so far due to its fragility in some environments. + +We've greatly improved this mechanism in 1.2.0. Not only does it now do a better job of actually invoking the update, but it also transfers updates in-band using the ZeroTier protocol. This means it can work in environments that do not allows http/https traffic or that force it through proxies. There's also now an update channel setting: `beta` or `release` (the default). + +As before software updates are authenticated in two ways: + + 1. ZeroTier's own signing key is used to sign all updates and this signature is checked prior to installation. Our signatures are done on an air-gapped machine. + + 2. Updates for Mac and Windows are signed using Apple and Microsoft (DigiCert) keys and will not install unless these signatures are also valid. + +Version 1.2.0's in-band mechanism effectively adds a third way: updates are fetched in-band from a designated ZeroTier node, thus authenticating the source using ZeroTier's built-in encryption and authentication mechanisms. + +Updates are now configurable via `local.conf`. There are three options: `disable`, `download`, and `apply`. The third is the default for official builds on Windows and Mac, making updates happen silently and automatically as they do for popular browsers like Chrome and Firefox. For managed enterprise deployments IT people could ship a local.conf that disables updates and instead push updates via their management capabilities. Updates are disabled on Linux and other Unix-type platforms as these get updates through package repositories. + +### Path Quality Monitoring (QoS and SD-WAN phase one) + +Version 1.2.0 is now aware of the link quality of direct paths with other 1.2.0 nodes. This information isn't used yet but is visible through the JSON API. (Quality always shows as 100% with pre-1.2.0 nodes.) + +Link quality monitoring is a precursor to intelligent multi-path and QoS support, which will in future versions bring us to feature parity with SD-WAN products like Cisco iWAN. + +"Connect all the things!" + +### Security Improvements + +Version 1.2.0 adds anti-DOS (denial of service) rate limits and other hardening for improved resiliency against a number of denial of service attack scenarios. + +It also adds a mechanism for instantaneous credential revocation. This can be used to revoke certificates of membership instantly to kick a node off a network (for private networks) and also to revoke capabilities and tags. The new controller sends revocations by default when a peer is de-authorized. + +Revocations propagate using a "rumor mill" peer to peer algorithm. This means that a controller need only successfully send a revocation to at least one member of a network with connections to other active members. At this point the revocation will flood through the network peer to peer very quickly. This helps make revocations more robust in the face of poor connectivity with the controller or attempts to incapacitate the controller with denial of service attacks, as well as making revocations faster on huge networks. + +### Windows and Macintosh UI Improvements (ZeroTier One) + +The Mac has a whole new UI built natively in Objective-C. It provides a pulldown similar in appearance and operation to the Mac WiFi task bar menu. The Windows UI has also been improved and now provides a task bar icon that can be right-clicked to manage networks. Both now expose managed route and IP permissions, allowing nodes to easily opt in to full tunnel operation if you have a router configured on your network. + +## Major Bug Fixes in 1.2.0 + + * **The Windows HyperV 100% CPU bug** + * This long-running problem turns out to have been an issue with Windows itself, but one we were triggering by placing invalid data into the Windows registry. Microsoft is aware of the issue but we've also fixed the triggering problem on our side. ZeroTier should now co-exist quite well with HyperV and should now be able to be bridged with a HyperV virtual switch. + * **Segmenation Faults on musl-libc based Linux Systems** + * Alpine Linux and some embedded Linux systems that use musl libc (a minimal libc) experienced segmentation faults. These were due to a smaller default stack size. A work-around that sets the stack size for new threads has been added. + * **Windows Firewall Blocks Local JSON API** + * On some Windows systems the firewall likes to block 127.0.0.1:9993 for mysterious reasons. This is now fixed in the installer via the addition of another firewall exemption rule. + * **UI Crash on Embedded Windows Due to Missing Fonts** + * The MSI installer now ships fonts and will install them if they are not present, so this should be fixed. diff --git a/zerotierone/controller/EmbeddedNetworkController.cpp b/zto/controller/EmbeddedNetworkController.cpp similarity index 98% rename from zerotierone/controller/EmbeddedNetworkController.cpp rename to zto/controller/EmbeddedNetworkController.cpp index b731db8..d2f40b1 100644 --- a/zerotierone/controller/EmbeddedNetworkController.cpp +++ b/zto/controller/EmbeddedNetworkController.cpp @@ -53,7 +53,7 @@ using json = nlohmann::json; #define ZT_NETCONF_CONTROLLER_API_VERSION 3 // Number of requests to remember in member history -#define ZT_NETCONF_DB_MEMBER_HISTORY_LENGTH 24 +#define ZT_NETCONF_DB_MEMBER_HISTORY_LENGTH 2 // Min duration between requests for an address/nwid combo to prevent floods #define ZT_NETCONF_MIN_REQUEST_PERIOD 1000 @@ -61,6 +61,9 @@ using json = nlohmann::json; // Nodes are considered active if they've queried in less than this long #define ZT_NETCONF_NODE_ACTIVE_THRESHOLD (ZT_NETWORK_AUTOCONF_DELAY * 2) +// Timeout for disk read cache (ms) +#define ZT_NETCONF_DB_CACHE_TTL 60000 + namespace ZeroTier { static json _renderRule(ZT_VirtualNetworkRule &rule) @@ -500,7 +503,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET( json network; { Mutex::Lock _l(_db_m); - network = _db.get("network",nwids,0); + network = _db.get("network",nwids,ZT_NETCONF_DB_CACHE_TTL); } if (!network.size()) return 404; @@ -515,7 +518,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET( json member; { Mutex::Lock _l(_db_m); - member = _db.get("network",nwids,"member",Address(address).toString(),0); + member = _db.get("network",nwids,"member",Address(address).toString(),ZT_NETCONF_DB_CACHE_TTL); } if (!member.size()) return 404; @@ -531,7 +534,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET( responseBody = "{"; std::string pfx(std::string("network/") + nwids + "member/"); - _db.filter(pfx,120000,[&responseBody](const std::string &n,const json &member) { + _db.filter(pfx,ZT_NETCONF_DB_CACHE_TTL,[&responseBody](const std::string &n,const json &member) { if (member.size() > 0) { responseBody.append((responseBody.length() == 1) ? "\"" : ",\""); responseBody.append(OSUtils::jsonString(member["id"],"")); @@ -639,7 +642,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST( json member; { Mutex::Lock _l(_db_m); - member = _db.get("network",nwids,"member",Address(address).toString(),0); + member = _db.get("network",nwids,"member",Address(address).toString(),ZT_NETCONF_DB_CACHE_TTL); } json origMember(member); // for detecting changes _initMember(member); @@ -822,7 +825,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST( uint64_t tryNwid = nwidPrefix | (nwidPostfix & 0xffffffULL); if ((tryNwid & 0xffffffULL) == 0ULL) tryNwid |= 1ULL; Utils::snprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)tryNwid); - if (_db.get("network",nwids,120000).size() <= 0) { + if (_db.get("network",nwids,ZT_NETCONF_DB_CACHE_TTL).size() <= 0) { nwid = tryNwid; break; } @@ -831,7 +834,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST( return 503; } - network = _db.get("network",nwids,0); + network = _db.get("network",nwids,ZT_NETCONF_DB_CACHE_TTL); } json origNetwork(network); // for detecting changes _initNetwork(network); @@ -1093,7 +1096,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE( json network; { Mutex::Lock _l(_db_m); - network = _db.get("network",nwids,0); + network = _db.get("network",nwids,ZT_NETCONF_DB_CACHE_TTL); } if (!network.size()) return 404; @@ -1104,7 +1107,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE( Mutex::Lock _l(_db_m); - json member = _db.get("network",nwids,"member",Address(address).toString(),0); + json member = _db.get("network",nwids,"member",Address(address).toString(),ZT_NETCONF_DB_CACHE_TTL); _db.erase("network",nwids,"member",Address(address).toString()); if (!member.size()) @@ -1244,8 +1247,8 @@ void EmbeddedNetworkController::_request( json member; { Mutex::Lock _l(_db_m); - network = _db.get("network",nwids,0); - member = _db.get("network",nwids,"member",identity.address().toString(),0); + network = _db.get("network",nwids,ZT_NETCONF_DB_CACHE_TTL); + member = _db.get("network",nwids,"member",identity.address().toString(),ZT_NETCONF_DB_CACHE_TTL); } if (!network.size()) { diff --git a/zerotierone/controller/EmbeddedNetworkController.hpp b/zto/controller/EmbeddedNetworkController.hpp similarity index 99% rename from zerotierone/controller/EmbeddedNetworkController.hpp rename to zto/controller/EmbeddedNetworkController.hpp index bca0956..a7277ac 100644 --- a/zerotierone/controller/EmbeddedNetworkController.hpp +++ b/zto/controller/EmbeddedNetworkController.hpp @@ -44,7 +44,7 @@ #include "JSONDB.hpp" // Number of background threads to start -- not actually started until needed -#define ZT_EMBEDDEDNETWORKCONTROLLER_BACKGROUND_THREAD_COUNT 2 +#define ZT_EMBEDDEDNETWORKCONTROLLER_BACKGROUND_THREAD_COUNT 4 // TTL for circuit tests #define ZT_EMBEDDEDNETWORKCONTROLLER_CIRCUIT_TEST_EXPIRATION 120000 diff --git a/zerotierone/controller/JSONDB.cpp b/zto/controller/JSONDB.cpp similarity index 100% rename from zerotierone/controller/JSONDB.cpp rename to zto/controller/JSONDB.cpp diff --git a/zerotierone/controller/JSONDB.hpp b/zto/controller/JSONDB.hpp similarity index 100% rename from zerotierone/controller/JSONDB.hpp rename to zto/controller/JSONDB.hpp diff --git a/zerotierone/controller/README.md b/zto/controller/README.md similarity index 100% rename from zerotierone/controller/README.md rename to zto/controller/README.md diff --git a/zerotierone/controller/migrate-sqlite/migrate.js b/zto/controller/migrate-sqlite/migrate.js similarity index 100% rename from zerotierone/controller/migrate-sqlite/migrate.js rename to zto/controller/migrate-sqlite/migrate.js diff --git a/zerotierone/controller/migrate-sqlite/package.json b/zto/controller/migrate-sqlite/package.json similarity index 100% rename from zerotierone/controller/migrate-sqlite/package.json rename to zto/controller/migrate-sqlite/package.json diff --git a/zerotierone/ext/README.md b/zto/ext/README.md similarity index 100% rename from zerotierone/ext/README.md rename to zto/ext/README.md diff --git a/zerotierone/ext/bin/tap-mac/tap.kext/Contents/Info.plist b/zto/ext/bin/tap-mac/tap.kext/Contents/Info.plist similarity index 100% rename from zerotierone/ext/bin/tap-mac/tap.kext/Contents/Info.plist rename to zto/ext/bin/tap-mac/tap.kext/Contents/Info.plist diff --git a/zerotierone/ext/bin/tap-mac/tap.kext/Contents/MacOS/tap b/zto/ext/bin/tap-mac/tap.kext/Contents/MacOS/tap similarity index 100% rename from zerotierone/ext/bin/tap-mac/tap.kext/Contents/MacOS/tap rename to zto/ext/bin/tap-mac/tap.kext/Contents/MacOS/tap diff --git a/zerotierone/ext/bin/tap-mac/tap.kext/Contents/_CodeSignature/CodeResources b/zto/ext/bin/tap-mac/tap.kext/Contents/_CodeSignature/CodeResources similarity index 100% rename from zerotierone/ext/bin/tap-mac/tap.kext/Contents/_CodeSignature/CodeResources rename to zto/ext/bin/tap-mac/tap.kext/Contents/_CodeSignature/CodeResources diff --git a/zerotierone/ext/bin/tap-windows-ndis6/x64/zttap300.cat b/zto/ext/bin/tap-windows-ndis6/x64/zttap300.cat similarity index 100% rename from zerotierone/ext/bin/tap-windows-ndis6/x64/zttap300.cat rename to zto/ext/bin/tap-windows-ndis6/x64/zttap300.cat diff --git a/zerotierone/ext/bin/tap-windows-ndis6/x64/zttap300.inf b/zto/ext/bin/tap-windows-ndis6/x64/zttap300.inf similarity index 100% rename from zerotierone/ext/bin/tap-windows-ndis6/x64/zttap300.inf rename to zto/ext/bin/tap-windows-ndis6/x64/zttap300.inf diff --git a/zerotierone/ext/bin/tap-windows-ndis6/x64/zttap300.sys b/zto/ext/bin/tap-windows-ndis6/x64/zttap300.sys similarity index 100% rename from zerotierone/ext/bin/tap-windows-ndis6/x64/zttap300.sys rename to zto/ext/bin/tap-windows-ndis6/x64/zttap300.sys diff --git a/zerotierone/ext/bin/tap-windows-ndis6/x86/zttap300.cat b/zto/ext/bin/tap-windows-ndis6/x86/zttap300.cat similarity index 100% rename from zerotierone/ext/bin/tap-windows-ndis6/x86/zttap300.cat rename to zto/ext/bin/tap-windows-ndis6/x86/zttap300.cat diff --git a/zerotierone/ext/bin/tap-windows-ndis6/x86/zttap300.inf b/zto/ext/bin/tap-windows-ndis6/x86/zttap300.inf similarity index 100% rename from zerotierone/ext/bin/tap-windows-ndis6/x86/zttap300.inf rename to zto/ext/bin/tap-windows-ndis6/x86/zttap300.inf diff --git a/zerotierone/ext/bin/tap-windows-ndis6/x86/zttap300.sys b/zto/ext/bin/tap-windows-ndis6/x86/zttap300.sys similarity index 100% rename from zerotierone/ext/bin/tap-windows-ndis6/x86/zttap300.sys rename to zto/ext/bin/tap-windows-ndis6/x86/zttap300.sys diff --git a/zerotierone/ext/http-parser/AUTHORS b/zto/ext/http-parser/AUTHORS similarity index 100% rename from zerotierone/ext/http-parser/AUTHORS rename to zto/ext/http-parser/AUTHORS diff --git a/zerotierone/ext/http-parser/LICENSE-MIT b/zto/ext/http-parser/LICENSE-MIT similarity index 100% rename from zerotierone/ext/http-parser/LICENSE-MIT rename to zto/ext/http-parser/LICENSE-MIT diff --git a/zerotierone/ext/http-parser/README.md b/zto/ext/http-parser/README.md similarity index 100% rename from zerotierone/ext/http-parser/README.md rename to zto/ext/http-parser/README.md diff --git a/zerotierone/ext/http-parser/http_parser.c b/zto/ext/http-parser/http_parser.c similarity index 100% rename from zerotierone/ext/http-parser/http_parser.c rename to zto/ext/http-parser/http_parser.c diff --git a/zerotierone/ext/http-parser/http_parser.h b/zto/ext/http-parser/http_parser.h similarity index 100% rename from zerotierone/ext/http-parser/http_parser.h rename to zto/ext/http-parser/http_parser.h diff --git a/zerotierone/ext/json/LICENSE.MIT b/zto/ext/json/LICENSE.MIT similarity index 100% rename from zerotierone/ext/json/LICENSE.MIT rename to zto/ext/json/LICENSE.MIT diff --git a/zerotierone/ext/json/README.md b/zto/ext/json/README.md similarity index 100% rename from zerotierone/ext/json/README.md rename to zto/ext/json/README.md diff --git a/zerotierone/ext/json/json.hpp b/zto/ext/json/json.hpp similarity index 100% rename from zerotierone/ext/json/json.hpp rename to zto/ext/json/json.hpp diff --git a/zerotierone/ext/libnatpmp/Changelog.txt b/zto/ext/libnatpmp/Changelog.txt similarity index 100% rename from zerotierone/ext/libnatpmp/Changelog.txt rename to zto/ext/libnatpmp/Changelog.txt diff --git a/zerotierone/ext/libnatpmp/JavaTest.java b/zto/ext/libnatpmp/JavaTest.java similarity index 100% rename from zerotierone/ext/libnatpmp/JavaTest.java rename to zto/ext/libnatpmp/JavaTest.java diff --git a/zerotierone/ext/libnatpmp/LICENSE b/zto/ext/libnatpmp/LICENSE similarity index 100% rename from zerotierone/ext/libnatpmp/LICENSE rename to zto/ext/libnatpmp/LICENSE diff --git a/zerotierone/ext/libnatpmp/Makefile b/zto/ext/libnatpmp/Makefile similarity index 100% rename from zerotierone/ext/libnatpmp/Makefile rename to zto/ext/libnatpmp/Makefile diff --git a/zerotierone/ext/libnatpmp/README b/zto/ext/libnatpmp/README similarity index 100% rename from zerotierone/ext/libnatpmp/README rename to zto/ext/libnatpmp/README diff --git a/zerotierone/ext/libnatpmp/build.bat b/zto/ext/libnatpmp/build.bat similarity index 100% rename from zerotierone/ext/libnatpmp/build.bat rename to zto/ext/libnatpmp/build.bat diff --git a/zerotierone/ext/libnatpmp/declspec.h b/zto/ext/libnatpmp/declspec.h similarity index 100% rename from zerotierone/ext/libnatpmp/declspec.h rename to zto/ext/libnatpmp/declspec.h diff --git a/zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/LibraryExtractor.java b/zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/LibraryExtractor.java similarity index 100% rename from zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/LibraryExtractor.java rename to zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/LibraryExtractor.java diff --git a/zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmp.java b/zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmp.java similarity index 100% rename from zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmp.java rename to zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmp.java diff --git a/zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmpResponse.java b/zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmpResponse.java similarity index 100% rename from zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmpResponse.java rename to zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/NatPmpResponse.java diff --git a/zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/URLUtils.java b/zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/URLUtils.java similarity index 100% rename from zerotierone/ext/libnatpmp/fr/free/miniupnp/libnatpmp/URLUtils.java rename to zto/ext/libnatpmp/fr/free/miniupnp/libnatpmp/URLUtils.java diff --git a/zerotierone/ext/libnatpmp/getgateway.c b/zto/ext/libnatpmp/getgateway.c similarity index 100% rename from zerotierone/ext/libnatpmp/getgateway.c rename to zto/ext/libnatpmp/getgateway.c diff --git a/zerotierone/ext/libnatpmp/getgateway.h b/zto/ext/libnatpmp/getgateway.h similarity index 100% rename from zerotierone/ext/libnatpmp/getgateway.h rename to zto/ext/libnatpmp/getgateway.h diff --git a/zerotierone/ext/libnatpmp/libnatpmpmodule.c b/zto/ext/libnatpmp/libnatpmpmodule.c similarity index 100% rename from zerotierone/ext/libnatpmp/libnatpmpmodule.c rename to zto/ext/libnatpmp/libnatpmpmodule.c diff --git a/zerotierone/ext/libnatpmp/msvc/libnatpmp.sln b/zto/ext/libnatpmp/msvc/libnatpmp.sln similarity index 100% rename from zerotierone/ext/libnatpmp/msvc/libnatpmp.sln rename to zto/ext/libnatpmp/msvc/libnatpmp.sln diff --git a/zerotierone/ext/libnatpmp/msvc/libnatpmp.vcproj b/zto/ext/libnatpmp/msvc/libnatpmp.vcproj similarity index 100% rename from zerotierone/ext/libnatpmp/msvc/libnatpmp.vcproj rename to zto/ext/libnatpmp/msvc/libnatpmp.vcproj diff --git a/zerotierone/ext/libnatpmp/msvc/natpmpc-static.vcproj b/zto/ext/libnatpmp/msvc/natpmpc-static.vcproj similarity index 100% rename from zerotierone/ext/libnatpmp/msvc/natpmpc-static.vcproj rename to zto/ext/libnatpmp/msvc/natpmpc-static.vcproj diff --git a/zerotierone/ext/libnatpmp/natpmp-jni.c b/zto/ext/libnatpmp/natpmp-jni.c similarity index 100% rename from zerotierone/ext/libnatpmp/natpmp-jni.c rename to zto/ext/libnatpmp/natpmp-jni.c diff --git a/zerotierone/ext/libnatpmp/natpmp.c b/zto/ext/libnatpmp/natpmp.c similarity index 100% rename from zerotierone/ext/libnatpmp/natpmp.c rename to zto/ext/libnatpmp/natpmp.c diff --git a/zerotierone/ext/libnatpmp/natpmp.def b/zto/ext/libnatpmp/natpmp.def similarity index 100% rename from zerotierone/ext/libnatpmp/natpmp.def rename to zto/ext/libnatpmp/natpmp.def diff --git a/zerotierone/ext/libnatpmp/natpmp.h b/zto/ext/libnatpmp/natpmp.h similarity index 100% rename from zerotierone/ext/libnatpmp/natpmp.h rename to zto/ext/libnatpmp/natpmp.h diff --git a/zerotierone/ext/libnatpmp/natpmpc.1 b/zto/ext/libnatpmp/natpmpc.1 similarity index 100% rename from zerotierone/ext/libnatpmp/natpmpc.1 rename to zto/ext/libnatpmp/natpmpc.1 diff --git a/zerotierone/ext/libnatpmp/natpmpc.c b/zto/ext/libnatpmp/natpmpc.c similarity index 100% rename from zerotierone/ext/libnatpmp/natpmpc.c rename to zto/ext/libnatpmp/natpmpc.c diff --git a/zerotierone/ext/libnatpmp/setup.py b/zto/ext/libnatpmp/setup.py similarity index 100% rename from zerotierone/ext/libnatpmp/setup.py rename to zto/ext/libnatpmp/setup.py diff --git a/zerotierone/ext/libnatpmp/setupmingw32.py b/zto/ext/libnatpmp/setupmingw32.py similarity index 100% rename from zerotierone/ext/libnatpmp/setupmingw32.py rename to zto/ext/libnatpmp/setupmingw32.py diff --git a/zerotierone/ext/libnatpmp/testgetgateway.c b/zto/ext/libnatpmp/testgetgateway.c similarity index 100% rename from zerotierone/ext/libnatpmp/testgetgateway.c rename to zto/ext/libnatpmp/testgetgateway.c diff --git a/zerotierone/ext/libnatpmp/wingettimeofday.c b/zto/ext/libnatpmp/wingettimeofday.c similarity index 100% rename from zerotierone/ext/libnatpmp/wingettimeofday.c rename to zto/ext/libnatpmp/wingettimeofday.c diff --git a/zerotierone/ext/libnatpmp/wingettimeofday.h b/zto/ext/libnatpmp/wingettimeofday.h similarity index 100% rename from zerotierone/ext/libnatpmp/wingettimeofday.h rename to zto/ext/libnatpmp/wingettimeofday.h diff --git a/zerotierone/ext/miniupnpc/Changelog.txt b/zto/ext/miniupnpc/Changelog.txt similarity index 100% rename from zerotierone/ext/miniupnpc/Changelog.txt rename to zto/ext/miniupnpc/Changelog.txt diff --git a/zerotierone/ext/miniupnpc/LICENSE b/zto/ext/miniupnpc/LICENSE similarity index 100% rename from zerotierone/ext/miniupnpc/LICENSE rename to zto/ext/miniupnpc/LICENSE diff --git a/zerotierone/ext/miniupnpc/MANIFEST.in b/zto/ext/miniupnpc/MANIFEST.in similarity index 100% rename from zerotierone/ext/miniupnpc/MANIFEST.in rename to zto/ext/miniupnpc/MANIFEST.in diff --git a/zerotierone/ext/miniupnpc/README b/zto/ext/miniupnpc/README similarity index 100% rename from zerotierone/ext/miniupnpc/README rename to zto/ext/miniupnpc/README diff --git a/zerotierone/ext/miniupnpc/VERSION b/zto/ext/miniupnpc/VERSION similarity index 100% rename from zerotierone/ext/miniupnpc/VERSION rename to zto/ext/miniupnpc/VERSION diff --git a/zerotierone/ext/miniupnpc/apiversions.txt b/zto/ext/miniupnpc/apiversions.txt similarity index 100% rename from zerotierone/ext/miniupnpc/apiversions.txt rename to zto/ext/miniupnpc/apiversions.txt diff --git a/zerotierone/ext/miniupnpc/codelength.h b/zto/ext/miniupnpc/codelength.h similarity index 100% rename from zerotierone/ext/miniupnpc/codelength.h rename to zto/ext/miniupnpc/codelength.h diff --git a/zerotierone/ext/miniupnpc/connecthostport.c b/zto/ext/miniupnpc/connecthostport.c similarity index 100% rename from zerotierone/ext/miniupnpc/connecthostport.c rename to zto/ext/miniupnpc/connecthostport.c diff --git a/zerotierone/ext/miniupnpc/connecthostport.h b/zto/ext/miniupnpc/connecthostport.h similarity index 100% rename from zerotierone/ext/miniupnpc/connecthostport.h rename to zto/ext/miniupnpc/connecthostport.h diff --git a/zerotierone/ext/miniupnpc/external-ip.sh b/zto/ext/miniupnpc/external-ip.sh similarity index 100% rename from zerotierone/ext/miniupnpc/external-ip.sh rename to zto/ext/miniupnpc/external-ip.sh diff --git a/zerotierone/ext/miniupnpc/igd_desc_parse.c b/zto/ext/miniupnpc/igd_desc_parse.c similarity index 100% rename from zerotierone/ext/miniupnpc/igd_desc_parse.c rename to zto/ext/miniupnpc/igd_desc_parse.c diff --git a/zerotierone/ext/miniupnpc/igd_desc_parse.h b/zto/ext/miniupnpc/igd_desc_parse.h similarity index 100% rename from zerotierone/ext/miniupnpc/igd_desc_parse.h rename to zto/ext/miniupnpc/igd_desc_parse.h diff --git a/zerotierone/ext/miniupnpc/listdevices.c b/zto/ext/miniupnpc/listdevices.c similarity index 100% rename from zerotierone/ext/miniupnpc/listdevices.c rename to zto/ext/miniupnpc/listdevices.c diff --git a/zerotierone/ext/miniupnpc/mingw32make.bat b/zto/ext/miniupnpc/mingw32make.bat similarity index 100% rename from zerotierone/ext/miniupnpc/mingw32make.bat rename to zto/ext/miniupnpc/mingw32make.bat diff --git a/zerotierone/ext/miniupnpc/minihttptestserver.c b/zto/ext/miniupnpc/minihttptestserver.c similarity index 100% rename from zerotierone/ext/miniupnpc/minihttptestserver.c rename to zto/ext/miniupnpc/minihttptestserver.c diff --git a/zerotierone/ext/miniupnpc/minisoap.c b/zto/ext/miniupnpc/minisoap.c similarity index 100% rename from zerotierone/ext/miniupnpc/minisoap.c rename to zto/ext/miniupnpc/minisoap.c diff --git a/zerotierone/ext/miniupnpc/minisoap.h b/zto/ext/miniupnpc/minisoap.h similarity index 100% rename from zerotierone/ext/miniupnpc/minisoap.h rename to zto/ext/miniupnpc/minisoap.h diff --git a/zerotierone/ext/miniupnpc/minissdpc.c b/zto/ext/miniupnpc/minissdpc.c similarity index 100% rename from zerotierone/ext/miniupnpc/minissdpc.c rename to zto/ext/miniupnpc/minissdpc.c diff --git a/zerotierone/ext/miniupnpc/minissdpc.h b/zto/ext/miniupnpc/minissdpc.h similarity index 100% rename from zerotierone/ext/miniupnpc/minissdpc.h rename to zto/ext/miniupnpc/minissdpc.h diff --git a/zerotierone/ext/miniupnpc/miniupnpc.c b/zto/ext/miniupnpc/miniupnpc.c similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpc.c rename to zto/ext/miniupnpc/miniupnpc.c diff --git a/zerotierone/ext/miniupnpc/miniupnpc.def b/zto/ext/miniupnpc/miniupnpc.def similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpc.def rename to zto/ext/miniupnpc/miniupnpc.def diff --git a/zerotierone/ext/miniupnpc/miniupnpc.h b/zto/ext/miniupnpc/miniupnpc.h similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpc.h rename to zto/ext/miniupnpc/miniupnpc.h diff --git a/zerotierone/ext/miniupnpc/miniupnpc_declspec.h b/zto/ext/miniupnpc/miniupnpc_declspec.h similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpc_declspec.h rename to zto/ext/miniupnpc/miniupnpc_declspec.h diff --git a/zerotierone/ext/miniupnpc/miniupnpcmodule.c b/zto/ext/miniupnpc/miniupnpcmodule.c similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpcmodule.c rename to zto/ext/miniupnpc/miniupnpcmodule.c diff --git a/zerotierone/ext/miniupnpc/miniupnpcstrings.h.in b/zto/ext/miniupnpc/miniupnpcstrings.h.in similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpcstrings.h.in rename to zto/ext/miniupnpc/miniupnpcstrings.h.in diff --git a/zerotierone/ext/miniupnpc/miniupnpctypes.h b/zto/ext/miniupnpc/miniupnpctypes.h similarity index 100% rename from zerotierone/ext/miniupnpc/miniupnpctypes.h rename to zto/ext/miniupnpc/miniupnpctypes.h diff --git a/zerotierone/ext/miniupnpc/miniwget.c b/zto/ext/miniupnpc/miniwget.c similarity index 100% rename from zerotierone/ext/miniupnpc/miniwget.c rename to zto/ext/miniupnpc/miniwget.c diff --git a/zerotierone/ext/miniupnpc/miniwget.h b/zto/ext/miniupnpc/miniwget.h similarity index 100% rename from zerotierone/ext/miniupnpc/miniwget.h rename to zto/ext/miniupnpc/miniwget.h diff --git a/zerotierone/ext/miniupnpc/minixml.c b/zto/ext/miniupnpc/minixml.c similarity index 100% rename from zerotierone/ext/miniupnpc/minixml.c rename to zto/ext/miniupnpc/minixml.c diff --git a/zerotierone/ext/miniupnpc/minixml.h b/zto/ext/miniupnpc/minixml.h similarity index 100% rename from zerotierone/ext/miniupnpc/minixml.h rename to zto/ext/miniupnpc/minixml.h diff --git a/zerotierone/ext/miniupnpc/minixmlvalid.c b/zto/ext/miniupnpc/minixmlvalid.c similarity index 100% rename from zerotierone/ext/miniupnpc/minixmlvalid.c rename to zto/ext/miniupnpc/minixmlvalid.c diff --git a/zerotierone/ext/miniupnpc/portlistingparse.c b/zto/ext/miniupnpc/portlistingparse.c similarity index 100% rename from zerotierone/ext/miniupnpc/portlistingparse.c rename to zto/ext/miniupnpc/portlistingparse.c diff --git a/zerotierone/ext/miniupnpc/portlistingparse.h b/zto/ext/miniupnpc/portlistingparse.h similarity index 100% rename from zerotierone/ext/miniupnpc/portlistingparse.h rename to zto/ext/miniupnpc/portlistingparse.h diff --git a/zerotierone/ext/miniupnpc/pymoduletest.py b/zto/ext/miniupnpc/pymoduletest.py similarity index 100% rename from zerotierone/ext/miniupnpc/pymoduletest.py rename to zto/ext/miniupnpc/pymoduletest.py diff --git a/zerotierone/ext/miniupnpc/receivedata.c b/zto/ext/miniupnpc/receivedata.c similarity index 100% rename from zerotierone/ext/miniupnpc/receivedata.c rename to zto/ext/miniupnpc/receivedata.c diff --git a/zerotierone/ext/miniupnpc/receivedata.h b/zto/ext/miniupnpc/receivedata.h similarity index 100% rename from zerotierone/ext/miniupnpc/receivedata.h rename to zto/ext/miniupnpc/receivedata.h diff --git a/zerotierone/ext/miniupnpc/setup.py b/zto/ext/miniupnpc/setup.py similarity index 100% rename from zerotierone/ext/miniupnpc/setup.py rename to zto/ext/miniupnpc/setup.py diff --git a/zerotierone/ext/miniupnpc/setupmingw32.py b/zto/ext/miniupnpc/setupmingw32.py similarity index 100% rename from zerotierone/ext/miniupnpc/setupmingw32.py rename to zto/ext/miniupnpc/setupmingw32.py diff --git a/zerotierone/ext/miniupnpc/testdesc/linksys_WAG200G_desc.values b/zto/ext/miniupnpc/testdesc/linksys_WAG200G_desc.values similarity index 100% rename from zerotierone/ext/miniupnpc/testdesc/linksys_WAG200G_desc.values rename to zto/ext/miniupnpc/testdesc/linksys_WAG200G_desc.values diff --git a/zerotierone/ext/miniupnpc/testdesc/linksys_WAG200G_desc.xml b/zto/ext/miniupnpc/testdesc/linksys_WAG200G_desc.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testdesc/linksys_WAG200G_desc.xml rename to zto/ext/miniupnpc/testdesc/linksys_WAG200G_desc.xml diff --git a/zerotierone/ext/miniupnpc/testdesc/new_LiveBox_desc.values b/zto/ext/miniupnpc/testdesc/new_LiveBox_desc.values similarity index 100% rename from zerotierone/ext/miniupnpc/testdesc/new_LiveBox_desc.values rename to zto/ext/miniupnpc/testdesc/new_LiveBox_desc.values diff --git a/zerotierone/ext/miniupnpc/testdesc/new_LiveBox_desc.xml b/zto/ext/miniupnpc/testdesc/new_LiveBox_desc.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testdesc/new_LiveBox_desc.xml rename to zto/ext/miniupnpc/testdesc/new_LiveBox_desc.xml diff --git a/zerotierone/ext/miniupnpc/testigddescparse.c b/zto/ext/miniupnpc/testigddescparse.c similarity index 100% rename from zerotierone/ext/miniupnpc/testigddescparse.c rename to zto/ext/miniupnpc/testigddescparse.c diff --git a/zerotierone/ext/miniupnpc/testminiwget.c b/zto/ext/miniupnpc/testminiwget.c similarity index 100% rename from zerotierone/ext/miniupnpc/testminiwget.c rename to zto/ext/miniupnpc/testminiwget.c diff --git a/zerotierone/ext/miniupnpc/testminiwget.sh b/zto/ext/miniupnpc/testminiwget.sh similarity index 100% rename from zerotierone/ext/miniupnpc/testminiwget.sh rename to zto/ext/miniupnpc/testminiwget.sh diff --git a/zerotierone/ext/miniupnpc/testminixml.c b/zto/ext/miniupnpc/testminixml.c similarity index 100% rename from zerotierone/ext/miniupnpc/testminixml.c rename to zto/ext/miniupnpc/testminixml.c diff --git a/zerotierone/ext/miniupnpc/testportlistingparse.c b/zto/ext/miniupnpc/testportlistingparse.c similarity index 100% rename from zerotierone/ext/miniupnpc/testportlistingparse.c rename to zto/ext/miniupnpc/testportlistingparse.c diff --git a/zerotierone/ext/miniupnpc/testreplyparse/DeletePortMapping.namevalue b/zto/ext/miniupnpc/testreplyparse/DeletePortMapping.namevalue similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/DeletePortMapping.namevalue rename to zto/ext/miniupnpc/testreplyparse/DeletePortMapping.namevalue diff --git a/zerotierone/ext/miniupnpc/testreplyparse/DeletePortMapping.xml b/zto/ext/miniupnpc/testreplyparse/DeletePortMapping.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/DeletePortMapping.xml rename to zto/ext/miniupnpc/testreplyparse/DeletePortMapping.xml diff --git a/zerotierone/ext/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue b/zto/ext/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue rename to zto/ext/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue diff --git a/zerotierone/ext/miniupnpc/testreplyparse/GetExternalIPAddress.xml b/zto/ext/miniupnpc/testreplyparse/GetExternalIPAddress.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/GetExternalIPAddress.xml rename to zto/ext/miniupnpc/testreplyparse/GetExternalIPAddress.xml diff --git a/zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue b/zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue rename to zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue diff --git a/zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml b/zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml rename to zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml diff --git a/zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue b/zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue rename to zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue diff --git a/zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml b/zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml rename to zto/ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml diff --git a/zerotierone/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue b/zto/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue rename to zto/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue diff --git a/zerotierone/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.xml b/zto/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.xml similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.xml rename to zto/ext/miniupnpc/testreplyparse/SetDefaultConnectionService.xml diff --git a/zerotierone/ext/miniupnpc/testreplyparse/readme.txt b/zto/ext/miniupnpc/testreplyparse/readme.txt similarity index 100% rename from zerotierone/ext/miniupnpc/testreplyparse/readme.txt rename to zto/ext/miniupnpc/testreplyparse/readme.txt diff --git a/zerotierone/ext/miniupnpc/testupnpigd.py b/zto/ext/miniupnpc/testupnpigd.py similarity index 100% rename from zerotierone/ext/miniupnpc/testupnpigd.py rename to zto/ext/miniupnpc/testupnpigd.py diff --git a/zerotierone/ext/miniupnpc/testupnpreplyparse.c b/zto/ext/miniupnpc/testupnpreplyparse.c similarity index 100% rename from zerotierone/ext/miniupnpc/testupnpreplyparse.c rename to zto/ext/miniupnpc/testupnpreplyparse.c diff --git a/zerotierone/ext/miniupnpc/testupnpreplyparse.sh b/zto/ext/miniupnpc/testupnpreplyparse.sh similarity index 100% rename from zerotierone/ext/miniupnpc/testupnpreplyparse.sh rename to zto/ext/miniupnpc/testupnpreplyparse.sh diff --git a/zerotierone/ext/miniupnpc/updateminiupnpcstrings.sh b/zto/ext/miniupnpc/updateminiupnpcstrings.sh similarity index 100% rename from zerotierone/ext/miniupnpc/updateminiupnpcstrings.sh rename to zto/ext/miniupnpc/updateminiupnpcstrings.sh diff --git a/zerotierone/ext/miniupnpc/upnpc.c b/zto/ext/miniupnpc/upnpc.c similarity index 100% rename from zerotierone/ext/miniupnpc/upnpc.c rename to zto/ext/miniupnpc/upnpc.c diff --git a/zerotierone/ext/miniupnpc/upnpcommands.c b/zto/ext/miniupnpc/upnpcommands.c similarity index 100% rename from zerotierone/ext/miniupnpc/upnpcommands.c rename to zto/ext/miniupnpc/upnpcommands.c diff --git a/zerotierone/ext/miniupnpc/upnpcommands.h b/zto/ext/miniupnpc/upnpcommands.h similarity index 100% rename from zerotierone/ext/miniupnpc/upnpcommands.h rename to zto/ext/miniupnpc/upnpcommands.h diff --git a/zerotierone/ext/miniupnpc/upnpdev.c b/zto/ext/miniupnpc/upnpdev.c similarity index 100% rename from zerotierone/ext/miniupnpc/upnpdev.c rename to zto/ext/miniupnpc/upnpdev.c diff --git a/zerotierone/ext/miniupnpc/upnpdev.h b/zto/ext/miniupnpc/upnpdev.h similarity index 100% rename from zerotierone/ext/miniupnpc/upnpdev.h rename to zto/ext/miniupnpc/upnpdev.h diff --git a/zerotierone/ext/miniupnpc/upnperrors.c b/zto/ext/miniupnpc/upnperrors.c similarity index 100% rename from zerotierone/ext/miniupnpc/upnperrors.c rename to zto/ext/miniupnpc/upnperrors.c diff --git a/zerotierone/ext/miniupnpc/upnperrors.h b/zto/ext/miniupnpc/upnperrors.h similarity index 100% rename from zerotierone/ext/miniupnpc/upnperrors.h rename to zto/ext/miniupnpc/upnperrors.h diff --git a/zerotierone/ext/miniupnpc/upnpreplyparse.c b/zto/ext/miniupnpc/upnpreplyparse.c similarity index 100% rename from zerotierone/ext/miniupnpc/upnpreplyparse.c rename to zto/ext/miniupnpc/upnpreplyparse.c diff --git a/zerotierone/ext/miniupnpc/upnpreplyparse.h b/zto/ext/miniupnpc/upnpreplyparse.h similarity index 100% rename from zerotierone/ext/miniupnpc/upnpreplyparse.h rename to zto/ext/miniupnpc/upnpreplyparse.h diff --git a/zerotierone/ext/miniupnpc/wingenminiupnpcstrings.c b/zto/ext/miniupnpc/wingenminiupnpcstrings.c similarity index 100% rename from zerotierone/ext/miniupnpc/wingenminiupnpcstrings.c rename to zto/ext/miniupnpc/wingenminiupnpcstrings.c diff --git a/zerotierone/ext/tap-mac/README.txt b/zto/ext/tap-mac/README.txt similarity index 100% rename from zerotierone/ext/tap-mac/README.txt rename to zto/ext/tap-mac/README.txt diff --git a/zerotierone/ext/tap-mac/tuntap/Makefile b/zto/ext/tap-mac/tuntap/Makefile similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/Makefile rename to zto/ext/tap-mac/tuntap/Makefile diff --git a/zerotierone/ext/tap-mac/tuntap/src/lock.cc b/zto/ext/tap-mac/tuntap/src/lock.cc similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/lock.cc rename to zto/ext/tap-mac/tuntap/src/lock.cc diff --git a/zerotierone/ext/tap-mac/tuntap/src/lock.h b/zto/ext/tap-mac/tuntap/src/lock.h similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/lock.h rename to zto/ext/tap-mac/tuntap/src/lock.h diff --git a/zerotierone/ext/tap-mac/tuntap/src/mem.cc b/zto/ext/tap-mac/tuntap/src/mem.cc similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/mem.cc rename to zto/ext/tap-mac/tuntap/src/mem.cc diff --git a/zerotierone/ext/tap-mac/tuntap/src/mem.h b/zto/ext/tap-mac/tuntap/src/mem.h similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/mem.h rename to zto/ext/tap-mac/tuntap/src/mem.h diff --git a/zerotierone/ext/tap-mac/tuntap/src/tap/Info.plist b/zto/ext/tap-mac/tuntap/src/tap/Info.plist similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tap/Info.plist rename to zto/ext/tap-mac/tuntap/src/tap/Info.plist diff --git a/zerotierone/ext/tap-mac/tuntap/src/tap/Makefile b/zto/ext/tap-mac/tuntap/src/tap/Makefile similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tap/Makefile rename to zto/ext/tap-mac/tuntap/src/tap/Makefile diff --git a/zerotierone/ext/tap-mac/tuntap/src/tap/kmod.cc b/zto/ext/tap-mac/tuntap/src/tap/kmod.cc similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tap/kmod.cc rename to zto/ext/tap-mac/tuntap/src/tap/kmod.cc diff --git a/zerotierone/ext/tap-mac/tuntap/src/tap/tap.cc b/zto/ext/tap-mac/tuntap/src/tap/tap.cc similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tap/tap.cc rename to zto/ext/tap-mac/tuntap/src/tap/tap.cc diff --git a/zerotierone/ext/tap-mac/tuntap/src/tap/tap.h b/zto/ext/tap-mac/tuntap/src/tap/tap.h similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tap/tap.h rename to zto/ext/tap-mac/tuntap/src/tap/tap.h diff --git a/zerotierone/ext/tap-mac/tuntap/src/tuntap.cc b/zto/ext/tap-mac/tuntap/src/tuntap.cc similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tuntap.cc rename to zto/ext/tap-mac/tuntap/src/tuntap.cc diff --git a/zerotierone/ext/tap-mac/tuntap/src/tuntap.h b/zto/ext/tap-mac/tuntap/src/tuntap.h similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tuntap.h rename to zto/ext/tap-mac/tuntap/src/tuntap.h diff --git a/zerotierone/ext/tap-mac/tuntap/src/tuntap_mgr.cc b/zto/ext/tap-mac/tuntap/src/tuntap_mgr.cc similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/tuntap_mgr.cc rename to zto/ext/tap-mac/tuntap/src/tuntap_mgr.cc diff --git a/zerotierone/ext/tap-mac/tuntap/src/util.h b/zto/ext/tap-mac/tuntap/src/util.h similarity index 100% rename from zerotierone/ext/tap-mac/tuntap/src/util.h rename to zto/ext/tap-mac/tuntap/src/util.h diff --git a/zerotierone/include/README.md b/zto/include/README.md similarity index 100% rename from zerotierone/include/README.md rename to zto/include/README.md diff --git a/zerotierone/include/ZeroTierOne.h b/zto/include/ZeroTierOne.h similarity index 99% rename from zerotierone/include/ZeroTierOne.h rename to zto/include/ZeroTierOne.h index 7a11334..98413a2 100644 --- a/zerotierone/include/ZeroTierOne.h +++ b/zto/include/ZeroTierOne.h @@ -74,7 +74,7 @@ extern "C" { * We use 2800, which leaves some room for other payload in other types of * messages such as multicast propagation or future support for bridging. */ -#define ZT_MAX_MTU 2000 +#define ZT_MAX_MTU 2800 /** * Maximum length of network short name diff --git a/zerotierone/make-bsd.mk b/zto/make-bsd.mk similarity index 100% rename from zerotierone/make-bsd.mk rename to zto/make-bsd.mk diff --git a/zerotierone/make-linux.mk b/zto/make-linux.mk similarity index 99% rename from zerotierone/make-linux.mk rename to zto/make-linux.mk index 68f865b..1bb6285 100644 --- a/zerotierone/make-linux.mk +++ b/zto/make-linux.mk @@ -185,10 +185,10 @@ uninstall: FORCE # These are just for convenience for building Linux packages -debian: distclean - debuild -I -i -us -uc +debian: FORCE + debuild -I -i -us -uc -nc -b -redhat: distclean +redhat: FORCE rpmbuild -ba zerotier-one.spec FORCE: diff --git a/zerotierone/make-mac.mk b/zto/make-mac.mk similarity index 99% rename from zerotierone/make-mac.mk rename to zto/make-mac.mk index 6c388a7..8ff1b77 100644 --- a/zerotierone/make-mac.mk +++ b/zto/make-mac.mk @@ -85,7 +85,7 @@ mac-dist-pkg: FORCE $(PRODUCTSIGN) --sign $(CODESIGN_INSTALLER_CERT) "ZeroTier One.pkg" "ZeroTier One Signed.pkg" if [ -f "ZeroTier One Signed.pkg" ]; then mv -f "ZeroTier One Signed.pkg" "ZeroTier One.pkg"; fi rm -f zt1_update_$(ZT_BUILD_PLATFORM)_$(ZT_BUILD_ARCHITECTURE)_* - cat ext/installfiles/mac-update/updater.tmpl.sh "ZeroTier One.pkg" >zt1_update_$(ZT_BUILD_PLATFORM)_$(ZT_BUILD_ARCHITECTURE)_$(ZT_VERSION_MAJOR).$(ZT_VERSION_MINOR).$(ZT_VERSION_REV)_$(ZT_VERSION_BUILD) + cat ext/installfiles/mac-update/updater.tmpl.sh "ZeroTier One.pkg" >zt1_update_$(ZT_BUILD_PLATFORM)_$(ZT_BUILD_ARCHITECTURE)_$(ZT_VERSION_MAJOR).$(ZT_VERSION_MINOR).$(ZT_VERSION_REV)_$(ZT_VERSION_BUILD).exe # For ZeroTier, Inc. to build official signed packages official: FORCE diff --git a/zerotierone/node/Address.hpp b/zto/node/Address.hpp similarity index 100% rename from zerotierone/node/Address.hpp rename to zto/node/Address.hpp diff --git a/zerotierone/node/Array.hpp b/zto/node/Array.hpp similarity index 100% rename from zerotierone/node/Array.hpp rename to zto/node/Array.hpp diff --git a/zerotierone/node/AtomicCounter.hpp b/zto/node/AtomicCounter.hpp similarity index 100% rename from zerotierone/node/AtomicCounter.hpp rename to zto/node/AtomicCounter.hpp diff --git a/zerotierone/node/Buffer.hpp b/zto/node/Buffer.hpp similarity index 100% rename from zerotierone/node/Buffer.hpp rename to zto/node/Buffer.hpp diff --git a/zerotierone/node/C25519.cpp b/zto/node/C25519.cpp similarity index 100% rename from zerotierone/node/C25519.cpp rename to zto/node/C25519.cpp diff --git a/zerotierone/node/C25519.hpp b/zto/node/C25519.hpp similarity index 100% rename from zerotierone/node/C25519.hpp rename to zto/node/C25519.hpp diff --git a/zerotierone/node/Capability.cpp b/zto/node/Capability.cpp similarity index 100% rename from zerotierone/node/Capability.cpp rename to zto/node/Capability.cpp diff --git a/zerotierone/node/Capability.hpp b/zto/node/Capability.hpp similarity index 98% rename from zerotierone/node/Capability.hpp rename to zto/node/Capability.hpp index 1ad6ea4..d070f2a 100644 --- a/zerotierone/node/Capability.hpp +++ b/zto/node/Capability.hpp @@ -52,6 +52,11 @@ class RuntimeEnvironment; * * Note that this is after evaluation of network scope rules and only if * network scope rules do not deliver an explicit match. + * + * Capabilities support a chain of custody. This is currently unused but + * in the future would allow the publication of capabilities that can be + * handed off between nodes. Limited transferrability of capabilities is + * a feature of true capability based security. */ class Capability { diff --git a/zerotierone/node/CertificateOfMembership.cpp b/zto/node/CertificateOfMembership.cpp similarity index 100% rename from zerotierone/node/CertificateOfMembership.cpp rename to zto/node/CertificateOfMembership.cpp diff --git a/zerotierone/node/CertificateOfMembership.hpp b/zto/node/CertificateOfMembership.hpp similarity index 100% rename from zerotierone/node/CertificateOfMembership.hpp rename to zto/node/CertificateOfMembership.hpp diff --git a/zerotierone/node/CertificateOfOwnership.cpp b/zto/node/CertificateOfOwnership.cpp similarity index 100% rename from zerotierone/node/CertificateOfOwnership.cpp rename to zto/node/CertificateOfOwnership.cpp diff --git a/zerotierone/node/CertificateOfOwnership.hpp b/zto/node/CertificateOfOwnership.hpp similarity index 100% rename from zerotierone/node/CertificateOfOwnership.hpp rename to zto/node/CertificateOfOwnership.hpp diff --git a/zerotierone/node/CertificateOfRepresentation.hpp b/zto/node/CertificateOfRepresentation.hpp similarity index 84% rename from zerotierone/node/CertificateOfRepresentation.hpp rename to zto/node/CertificateOfRepresentation.hpp index 7c239a9..02e961c 100644 --- a/zerotierone/node/CertificateOfRepresentation.hpp +++ b/zto/node/CertificateOfRepresentation.hpp @@ -32,6 +32,21 @@ namespace ZeroTier { +/** + * A signed enumeration of a node's roots (planet and moons) + * + * This is sent as part of HELLO and attests to which roots a node trusts + * to represent it on the network. Federated roots (moons) can send these + * further upstream to tell global roots which nodes they represent, making + * them reachable via federated roots if they are not reachable directly. + * + * As of 1.2.0 this is sent but not used. Right now nodes still always + * announce to planetary roots no matter what. In the future this can be + * used to implement even better fault tolerance for federation for the + * no roots are reachable case as well as a "privacy mode" where federated + * roots can shield nodes entirely and p2p connectivity behind them can + * be disabled. This will be desirable for a number of use cases. + */ class CertificateOfRepresentation { public: diff --git a/zerotierone/node/Cluster.cpp b/zto/node/Cluster.cpp similarity index 100% rename from zerotierone/node/Cluster.cpp rename to zto/node/Cluster.cpp diff --git a/zerotierone/node/Cluster.hpp b/zto/node/Cluster.hpp similarity index 100% rename from zerotierone/node/Cluster.hpp rename to zto/node/Cluster.hpp diff --git a/zerotierone/node/Constants.hpp b/zto/node/Constants.hpp similarity index 98% rename from zerotierone/node/Constants.hpp rename to zto/node/Constants.hpp index 3bda380..410a245 100644 --- a/zerotierone/node/Constants.hpp +++ b/zto/node/Constants.hpp @@ -202,7 +202,7 @@ /** * Maximum identity WHOIS retries (each attempt tries consulting a different peer) */ -#define ZT_MAX_WHOIS_RETRIES 3 +#define ZT_MAX_WHOIS_RETRIES 4 /** * Transmit queue entry timeout @@ -390,6 +390,11 @@ */ #define ZT_PEER_CREDEITIALS_CUTOFF_LIMIT 15 +/** + * WHOIS rate limit (we allow these to be pretty fast) + */ +#define ZT_PEER_WHOIS_RATE_LIMIT 100 + /** * General rate limit for other kinds of rate-limited packets (HELLO, credential request, etc.) both inbound and outbound */ diff --git a/zerotierone/node/Dictionary.hpp b/zto/node/Dictionary.hpp similarity index 100% rename from zerotierone/node/Dictionary.hpp rename to zto/node/Dictionary.hpp diff --git a/zerotierone/node/Hashtable.hpp b/zto/node/Hashtable.hpp similarity index 100% rename from zerotierone/node/Hashtable.hpp rename to zto/node/Hashtable.hpp diff --git a/zerotierone/node/Identity.cpp b/zto/node/Identity.cpp similarity index 100% rename from zerotierone/node/Identity.cpp rename to zto/node/Identity.cpp diff --git a/zerotierone/node/Identity.hpp b/zto/node/Identity.hpp similarity index 100% rename from zerotierone/node/Identity.hpp rename to zto/node/Identity.hpp diff --git a/zerotierone/node/IncomingPacket.cpp b/zto/node/IncomingPacket.cpp similarity index 99% rename from zerotierone/node/IncomingPacket.cpp rename to zto/node/IncomingPacket.cpp index 856538b..800985d 100644 --- a/zerotierone/node/IncomingPacket.cpp +++ b/zto/node/IncomingPacket.cpp @@ -320,7 +320,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR,const bool alreadyAut // Get moon IDs and timestamps if present if ((ptr + 2) <= size()) { - unsigned int numMoons = at(ptr); ptr += 2; + const unsigned int numMoons = at(ptr); ptr += 2; for(unsigned int i=0;i(at(ptr),at(ptr + 8))); @@ -552,7 +552,7 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr &p bool IncomingPacket::_doWHOIS(const RuntimeEnvironment *RR,const SharedPtr &peer) { try { - if (!peer->rateGateInboundWhoisRequest(RR->node->now())) { + if ((!RR->topology->amRoot())&&(!peer->rateGateInboundWhoisRequest(RR->node->now()))) { TRACE("dropped WHOIS from %s(%s): rate limit circuit breaker tripped",source().toString().c_str(),_path->address().toString().c_str()); return true; } diff --git a/zerotierone/node/IncomingPacket.hpp b/zto/node/IncomingPacket.hpp similarity index 100% rename from zerotierone/node/IncomingPacket.hpp rename to zto/node/IncomingPacket.hpp diff --git a/zerotierone/node/InetAddress.cpp b/zto/node/InetAddress.cpp similarity index 100% rename from zerotierone/node/InetAddress.cpp rename to zto/node/InetAddress.cpp diff --git a/zerotierone/node/InetAddress.hpp b/zto/node/InetAddress.hpp similarity index 100% rename from zerotierone/node/InetAddress.hpp rename to zto/node/InetAddress.hpp diff --git a/zerotierone/node/MAC.hpp b/zto/node/MAC.hpp similarity index 100% rename from zerotierone/node/MAC.hpp rename to zto/node/MAC.hpp diff --git a/zerotierone/node/Membership.cpp b/zto/node/Membership.cpp similarity index 98% rename from zerotierone/node/Membership.cpp rename to zto/node/Membership.cpp index a60b86b..3b2e3b1 100644 --- a/zerotierone/node/Membership.cpp +++ b/zto/node/Membership.cpp @@ -223,8 +223,7 @@ Membership::AddCredentialResult Membership::addCredential(const RuntimeEnvironme const uint64_t now = RR->node->now(); switch(rev.type()) { default: - //case Revocation::CREDENTIAL_TYPE_ALL: - return ( (_revokeCom(rev)||_revokeCap(rev,now)||_revokeTag(rev,now)||_revokeCoo(rev,now)) ? ADD_ACCEPTED_NEW : ADD_ACCEPTED_REDUNDANT ); + return ADD_REJECTED; case Revocation::CREDENTIAL_TYPE_COM: return (_revokeCom(rev) ? ADD_ACCEPTED_NEW : ADD_ACCEPTED_REDUNDANT); case Revocation::CREDENTIAL_TYPE_CAPABILITY: diff --git a/zerotierone/node/Membership.hpp b/zto/node/Membership.hpp similarity index 100% rename from zerotierone/node/Membership.hpp rename to zto/node/Membership.hpp diff --git a/zerotierone/node/MulticastGroup.hpp b/zto/node/MulticastGroup.hpp similarity index 100% rename from zerotierone/node/MulticastGroup.hpp rename to zto/node/MulticastGroup.hpp diff --git a/zerotierone/node/Multicaster.cpp b/zto/node/Multicaster.cpp similarity index 100% rename from zerotierone/node/Multicaster.cpp rename to zto/node/Multicaster.cpp diff --git a/zerotierone/node/Multicaster.hpp b/zto/node/Multicaster.hpp similarity index 100% rename from zerotierone/node/Multicaster.hpp rename to zto/node/Multicaster.hpp diff --git a/zerotierone/node/Mutex.hpp b/zto/node/Mutex.hpp similarity index 100% rename from zerotierone/node/Mutex.hpp rename to zto/node/Mutex.hpp diff --git a/zerotierone/node/Network.cpp b/zto/node/Network.cpp similarity index 100% rename from zerotierone/node/Network.cpp rename to zto/node/Network.cpp diff --git a/zerotierone/node/Network.hpp b/zto/node/Network.hpp similarity index 100% rename from zerotierone/node/Network.hpp rename to zto/node/Network.hpp diff --git a/zerotierone/node/NetworkConfig.cpp b/zto/node/NetworkConfig.cpp similarity index 100% rename from zerotierone/node/NetworkConfig.cpp rename to zto/node/NetworkConfig.cpp diff --git a/zerotierone/node/NetworkConfig.hpp b/zto/node/NetworkConfig.hpp similarity index 100% rename from zerotierone/node/NetworkConfig.hpp rename to zto/node/NetworkConfig.hpp diff --git a/zerotierone/node/NetworkController.hpp b/zto/node/NetworkController.hpp similarity index 100% rename from zerotierone/node/NetworkController.hpp rename to zto/node/NetworkController.hpp diff --git a/zerotierone/node/Node.cpp b/zto/node/Node.cpp similarity index 100% rename from zerotierone/node/Node.cpp rename to zto/node/Node.cpp diff --git a/zerotierone/node/Node.hpp b/zto/node/Node.hpp similarity index 100% rename from zerotierone/node/Node.hpp rename to zto/node/Node.hpp diff --git a/zerotierone/node/NonCopyable.hpp b/zto/node/NonCopyable.hpp similarity index 100% rename from zerotierone/node/NonCopyable.hpp rename to zto/node/NonCopyable.hpp diff --git a/zerotierone/node/OutboundMulticast.cpp b/zto/node/OutboundMulticast.cpp similarity index 100% rename from zerotierone/node/OutboundMulticast.cpp rename to zto/node/OutboundMulticast.cpp diff --git a/zerotierone/node/OutboundMulticast.hpp b/zto/node/OutboundMulticast.hpp similarity index 100% rename from zerotierone/node/OutboundMulticast.hpp rename to zto/node/OutboundMulticast.hpp diff --git a/zerotierone/node/Packet.cpp b/zto/node/Packet.cpp similarity index 99% rename from zerotierone/node/Packet.cpp rename to zto/node/Packet.cpp index 82a5d7e..c825ea9 100644 --- a/zerotierone/node/Packet.cpp +++ b/zto/node/Packet.cpp @@ -2025,16 +2025,12 @@ bool Packet::dearmor(const void *key) void Packet::cryptField(const void *key,unsigned int start,unsigned int len) { - unsigned char mangledKey[32]; - unsigned char macKey[32]; - _salsa20MangleKey((const unsigned char *)key,mangledKey); - mangledKey[0] ^= 0x7f; - mangledKey[1] ^= ((start >> 8) & 0xff); - mangledKey[2] ^= (start & 0xff); // slightly alter key for this use case as an added guard against key stream reuse - Salsa20 s20(mangledKey,256,field(ZT_PACKET_IDX_IV,8)); - s20.crypt12(ZERO_KEY,macKey,sizeof(macKey)); // discard the first 32 bytes of key stream (the ones use for MAC in armor()) as a precaution - unsigned char *const ptr = field(start,len); - s20.crypt12(ptr,ptr,len); + uint8_t *const data = reinterpret_cast(unsafeData()); + uint8_t iv[8]; + for(int i=0;i<8;++i) iv[i] = data[i]; + iv[7] &= 0xf8; // mask off least significant 3 bits of packet ID / IV since this is unset when this function gets called + Salsa20 s20(key,256,iv); + s20.crypt12(data + start,data + start,len); } bool Packet::compress() diff --git a/zerotierone/node/Packet.hpp b/zto/node/Packet.hpp similarity index 100% rename from zerotierone/node/Packet.hpp rename to zto/node/Packet.hpp diff --git a/zerotierone/node/Path.cpp b/zto/node/Path.cpp similarity index 100% rename from zerotierone/node/Path.cpp rename to zto/node/Path.cpp diff --git a/zerotierone/node/Path.hpp b/zto/node/Path.hpp similarity index 99% rename from zerotierone/node/Path.hpp rename to zto/node/Path.hpp index dd6455d..62f29c2 100644 --- a/zerotierone/node/Path.hpp +++ b/zto/node/Path.hpp @@ -156,7 +156,7 @@ public: const uint64_t fl = (_incomingLinkQualityFastLog = ((_incomingLinkQualityFastLog << 1) | (uint64_t)(prev == ((counter - 1) & 0x7)))); if (++_incomingLinkQualitySlowLogCounter >= 64) { _incomingLinkQualitySlowLogCounter = 0; - _incomingLinkQualitySlowLog[_incomingLinkQualitySlowLogPtr++ % sizeof(_incomingLinkQualitySlowLog)] = Utils::countBits(fl); + _incomingLinkQualitySlowLog[_incomingLinkQualitySlowLogPtr++ % sizeof(_incomingLinkQualitySlowLog)] = (uint8_t)Utils::countBits(fl); } } diff --git a/zerotierone/node/Peer.cpp b/zto/node/Peer.cpp similarity index 100% rename from zerotierone/node/Peer.cpp rename to zto/node/Peer.cpp diff --git a/zerotierone/node/Peer.hpp b/zto/node/Peer.hpp similarity index 99% rename from zerotierone/node/Peer.hpp rename to zto/node/Peer.hpp index 783f48b..72040b1 100644 --- a/zerotierone/node/Peer.hpp +++ b/zto/node/Peer.hpp @@ -370,7 +370,7 @@ public: */ inline bool rateGateInboundWhoisRequest(const uint64_t now) { - if ((now - _lastWhoisRequestReceived) >= ZT_PEER_GENERAL_RATE_LIMIT) { + if ((now - _lastWhoisRequestReceived) >= ZT_PEER_WHOIS_RATE_LIMIT) { _lastWhoisRequestReceived = now; return true; } diff --git a/zerotierone/node/Poly1305.cpp b/zto/node/Poly1305.cpp similarity index 100% rename from zerotierone/node/Poly1305.cpp rename to zto/node/Poly1305.cpp diff --git a/zerotierone/node/Poly1305.hpp b/zto/node/Poly1305.hpp similarity index 100% rename from zerotierone/node/Poly1305.hpp rename to zto/node/Poly1305.hpp diff --git a/zerotierone/node/README.md b/zto/node/README.md similarity index 100% rename from zerotierone/node/README.md rename to zto/node/README.md diff --git a/zerotierone/node/Revocation.cpp b/zto/node/Revocation.cpp similarity index 100% rename from zerotierone/node/Revocation.cpp rename to zto/node/Revocation.cpp diff --git a/zerotierone/node/Revocation.hpp b/zto/node/Revocation.hpp similarity index 91% rename from zerotierone/node/Revocation.hpp rename to zto/node/Revocation.hpp index 1697b52..93c5511 100644 --- a/zerotierone/node/Revocation.hpp +++ b/zto/node/Revocation.hpp @@ -47,9 +47,12 @@ class RuntimeEnvironment; class Revocation { public: + /** + * Credential type being revoked + */ enum CredentialType { - CREDENTIAL_TYPE_ALL = 0, + CREDENTIAL_TYPE_NULL = 0, CREDENTIAL_TYPE_COM = 1, // CertificateOfMembership CREDENTIAL_TYPE_CAPABILITY = 2, CREDENTIAL_TYPE_TAG = 3, @@ -61,6 +64,15 @@ public: memset(this,0,sizeof(Revocation)); } + /** + * @param i ID (arbitrary for revocations, currently random) + * @param nwid Network ID + * @param cid Credential ID being revoked (0 for all or for COMs, which lack IDs) + * @param thr Revocation time threshold before which credentials will be revoked + * @param fl Flags + * @param tgt Target node whose credential(s) are being revoked + * @param ct Credential type being revoked + */ Revocation(const uint64_t i,const uint64_t nwid,const uint64_t cid,const uint64_t thr,const uint64_t fl,const Address &tgt,const CredentialType ct) : _id(i), _networkId(nwid), diff --git a/zerotierone/node/RuntimeEnvironment.hpp b/zto/node/RuntimeEnvironment.hpp similarity index 100% rename from zerotierone/node/RuntimeEnvironment.hpp rename to zto/node/RuntimeEnvironment.hpp diff --git a/zerotierone/node/SHA512.cpp b/zto/node/SHA512.cpp similarity index 100% rename from zerotierone/node/SHA512.cpp rename to zto/node/SHA512.cpp diff --git a/zerotierone/node/SHA512.hpp b/zto/node/SHA512.hpp similarity index 100% rename from zerotierone/node/SHA512.hpp rename to zto/node/SHA512.hpp diff --git a/zerotierone/node/Salsa20.cpp b/zto/node/Salsa20.cpp similarity index 100% rename from zerotierone/node/Salsa20.cpp rename to zto/node/Salsa20.cpp diff --git a/zerotierone/node/Salsa20.hpp b/zto/node/Salsa20.hpp similarity index 100% rename from zerotierone/node/Salsa20.hpp rename to zto/node/Salsa20.hpp diff --git a/zerotierone/node/SelfAwareness.cpp b/zto/node/SelfAwareness.cpp similarity index 100% rename from zerotierone/node/SelfAwareness.cpp rename to zto/node/SelfAwareness.cpp diff --git a/zerotierone/node/SelfAwareness.hpp b/zto/node/SelfAwareness.hpp similarity index 100% rename from zerotierone/node/SelfAwareness.hpp rename to zto/node/SelfAwareness.hpp diff --git a/zerotierone/node/SharedPtr.hpp b/zto/node/SharedPtr.hpp similarity index 100% rename from zerotierone/node/SharedPtr.hpp rename to zto/node/SharedPtr.hpp diff --git a/zerotierone/node/Switch.cpp b/zto/node/Switch.cpp similarity index 99% rename from zerotierone/node/Switch.cpp rename to zto/node/Switch.cpp index 0392aec..85103aa 100644 --- a/zerotierone/node/Switch.cpp +++ b/zto/node/Switch.cpp @@ -688,9 +688,9 @@ unsigned long Switch::doTimerTasks(uint64_t now) _outstandingWhoisRequests.erase(*a); } else { r->lastSent = now; - r->peersConsulted[r->retries] = _sendWhoisRequest(*a,r->peersConsulted,r->retries); - ++r->retries; + r->peersConsulted[r->retries] = _sendWhoisRequest(*a,r->peersConsulted,(r->retries > 1) ? r->retries : 0); TRACE("WHOIS %s (retry %u)",a->toString().c_str(),r->retries); + ++r->retries; nextDelay = std::min(nextDelay,(unsigned long)ZT_WHOIS_RETRY_DELAY); } } else { diff --git a/zerotierone/node/Switch.hpp b/zto/node/Switch.hpp similarity index 100% rename from zerotierone/node/Switch.hpp rename to zto/node/Switch.hpp diff --git a/zerotierone/node/Tag.cpp b/zto/node/Tag.cpp similarity index 100% rename from zerotierone/node/Tag.cpp rename to zto/node/Tag.cpp diff --git a/zerotierone/node/Tag.hpp b/zto/node/Tag.hpp similarity index 100% rename from zerotierone/node/Tag.hpp rename to zto/node/Tag.hpp diff --git a/zerotierone/node/Topology.cpp b/zto/node/Topology.cpp similarity index 90% rename from zerotierone/node/Topology.cpp rename to zto/node/Topology.cpp index 5abc4df..21547cd 100644 --- a/zerotierone/node/Topology.cpp +++ b/zto/node/Topology.cpp @@ -159,61 +159,40 @@ void Topology::saveIdentity(const Identity &id) SharedPtr Topology::getUpstreamPeer(const Address *avoid,unsigned int avoidCount,bool strictAvoid) { const uint64_t now = RR->node->now(); + unsigned int bestQualityOverall = ~((unsigned int)0); + unsigned int bestQualityNotAvoid = ~((unsigned int)0); + const SharedPtr *bestOverall = (const SharedPtr *)0; + const SharedPtr *bestNotAvoid = (const SharedPtr *)0; + Mutex::Lock _l1(_peers_m); Mutex::Lock _l2(_upstreams_m); - if (_amRoot) { - /* If I am a root, pick another root that isn't mine and that - * has a numerically greater ID. This causes packets to roam - * around the top rather than bouncing between just two. */ - - for(unsigned long p=0;p<_upstreamAddresses.size();++p) { - if (_upstreamAddresses[p] == RR->identity.address()) { - for(unsigned long q=1;q<_upstreamAddresses.size();++q) { - const SharedPtr *const nextsn = _peers.get(_upstreamAddresses[(p + q) % _upstreamAddresses.size()]); - if ((nextsn)&&((*nextsn)->hasActiveDirectPath(now))) - return *nextsn; - } - break; - } - } - - } else { - /* Otherwise pick the bestest looking upstream */ - - unsigned int bestQualityOverall = ~((unsigned int)0); - unsigned int bestQualityNotAvoid = ~((unsigned int)0); - const SharedPtr *bestOverall = (const SharedPtr *)0; - const SharedPtr *bestNotAvoid = (const SharedPtr *)0; - - for(std::vector
::const_iterator a(_upstreamAddresses.begin());a!=_upstreamAddresses.end();++a) { - const SharedPtr *p = _peers.get(*a); - if (p) { - bool avoiding = false; - for(unsigned int i=0;iaddress()) { - avoiding = true; - break; - } - } - const unsigned int q = (*p)->relayQuality(now); - if (q <= bestQualityOverall) { - bestQualityOverall = q; - bestOverall = &(*p); - } - if ((!avoiding)&&(q <= bestQualityNotAvoid)) { - bestQualityNotAvoid = q; - bestNotAvoid = &(*p); + for(std::vector
::const_iterator a(_upstreamAddresses.begin());a!=_upstreamAddresses.end();++a) { + const SharedPtr *p = _peers.get(*a); + if (p) { + bool avoiding = false; + for(unsigned int i=0;iaddress()) { + avoiding = true; + break; } } + const unsigned int q = (*p)->relayQuality(now); + if (q <= bestQualityOverall) { + bestQualityOverall = q; + bestOverall = &(*p); + } + if ((!avoiding)&&(q <= bestQualityNotAvoid)) { + bestQualityNotAvoid = q; + bestNotAvoid = &(*p); + } } + } - if (bestNotAvoid) { - return *bestNotAvoid; - } else if ((!strictAvoid)&&(bestOverall)) { - return *bestOverall; - } - + if (bestNotAvoid) { + return *bestNotAvoid; + } else if ((!strictAvoid)&&(bestOverall)) { + return *bestOverall; } return SharedPtr(); diff --git a/zerotierone/node/Topology.hpp b/zto/node/Topology.hpp similarity index 100% rename from zerotierone/node/Topology.hpp rename to zto/node/Topology.hpp diff --git a/zerotierone/node/Utils.cpp b/zto/node/Utils.cpp similarity index 100% rename from zerotierone/node/Utils.cpp rename to zto/node/Utils.cpp diff --git a/zerotierone/node/Utils.hpp b/zto/node/Utils.hpp similarity index 100% rename from zerotierone/node/Utils.hpp rename to zto/node/Utils.hpp diff --git a/zerotierone/node/World.hpp b/zto/node/World.hpp similarity index 100% rename from zerotierone/node/World.hpp rename to zto/node/World.hpp diff --git a/zerotierone/objects.mk b/zto/objects.mk similarity index 96% rename from zerotierone/objects.mk rename to zto/objects.mk index 427024e..74efc33 100644 --- a/zerotierone/objects.mk +++ b/zto/objects.mk @@ -31,5 +31,4 @@ OBJS=\ osdep/Http.o \ osdep/OSUtils.o \ service/ClusterGeoIpService.o \ - service/ControlPlane.o \ service/SoftwareUpdater.o diff --git a/zerotierone/one.cpp b/zto/one.cpp similarity index 98% rename from zerotierone/one.cpp rename to zto/one.cpp index 8f116aa..f704f7e 100644 --- a/zerotierone/one.cpp +++ b/zto/one.cpp @@ -787,7 +787,7 @@ static int idtool(int argc,char **argv) mj["objtype"] = "world"; mj["worldType"] = "moon"; mj["updatesMustBeSignedBy"] = mj["signingKey"] = Utils::hex(kp.pub.data,(unsigned int)kp.pub.size()); - mj["updatesMustBeSignedBy_SECRET"] = Utils::hex(kp.priv.data,(unsigned int)kp.priv.size()); + mj["signingKey_SECRET"] = Utils::hex(kp.priv.data,(unsigned int)kp.priv.size()); mj["id"] = id.address().toString(); nlohmann::json seedj; seedj["identity"] = id.toString(false); @@ -825,8 +825,10 @@ static int idtool(int argc,char **argv) } C25519::Pair signingKey; - Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],""),signingKey.pub.data,(unsigned int)signingKey.pub.size()); - Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy_SECRET"],""),signingKey.priv.data,(unsigned int)signingKey.priv.size()); + C25519::Public updatesMustBeSignedBy; + Utils::unhex(OSUtils::jsonString(mj["signingKey"],""),signingKey.pub.data,(unsigned int)signingKey.pub.size()); + Utils::unhex(OSUtils::jsonString(mj["signingKey_SECRET"],""),signingKey.priv.data,(unsigned int)signingKey.priv.size()); + Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],""),updatesMustBeSignedBy.data,(unsigned int)updatesMustBeSignedBy.size()); std::vector roots; nlohmann::json &rootsj = mj["roots"]; @@ -848,11 +850,11 @@ static int idtool(int argc,char **argv) std::sort(roots.begin(),roots.end()); const uint64_t now = OSUtils::now(); - World w(World::make(t,id,now,signingKey.pub,roots,signingKey)); + World w(World::make(t,id,now,updatesMustBeSignedBy,roots,signingKey)); Buffer wbuf; w.serialize(wbuf); char fn[128]; - Utils::snprintf(fn,sizeof(fn),"%.16llx_%.16llx.moon",w.id(),now); + Utils::snprintf(fn,sizeof(fn),"%.16llx.moon",w.id()); OSUtils::writeFile(fn,wbuf.data(),wbuf.size()); printf("wrote %s (signed world with timestamp %llu)" ZT_EOL_S,fn,(unsigned long long)now); } diff --git a/zerotierone/osdep/Arp.cpp b/zto/osdep/Arp.cpp similarity index 100% rename from zerotierone/osdep/Arp.cpp rename to zto/osdep/Arp.cpp diff --git a/zerotierone/osdep/Arp.hpp b/zto/osdep/Arp.hpp similarity index 100% rename from zerotierone/osdep/Arp.hpp rename to zto/osdep/Arp.hpp diff --git a/zerotierone/osdep/BSDEthernetTap.cpp b/zto/osdep/BSDEthernetTap.cpp similarity index 100% rename from zerotierone/osdep/BSDEthernetTap.cpp rename to zto/osdep/BSDEthernetTap.cpp diff --git a/zerotierone/osdep/BSDEthernetTap.hpp b/zto/osdep/BSDEthernetTap.hpp similarity index 100% rename from zerotierone/osdep/BSDEthernetTap.hpp rename to zto/osdep/BSDEthernetTap.hpp diff --git a/zerotierone/osdep/Binder.hpp b/zto/osdep/Binder.hpp similarity index 100% rename from zerotierone/osdep/Binder.hpp rename to zto/osdep/Binder.hpp diff --git a/zerotierone/osdep/BlockingQueue.hpp b/zto/osdep/BlockingQueue.hpp similarity index 100% rename from zerotierone/osdep/BlockingQueue.hpp rename to zto/osdep/BlockingQueue.hpp diff --git a/zerotierone/osdep/Http.cpp b/zto/osdep/Http.cpp similarity index 100% rename from zerotierone/osdep/Http.cpp rename to zto/osdep/Http.cpp diff --git a/zerotierone/osdep/Http.hpp b/zto/osdep/Http.hpp similarity index 100% rename from zerotierone/osdep/Http.hpp rename to zto/osdep/Http.hpp diff --git a/zerotierone/osdep/LinuxEthernetTap.cpp b/zto/osdep/LinuxEthernetTap.cpp similarity index 98% rename from zerotierone/osdep/LinuxEthernetTap.cpp rename to zto/osdep/LinuxEthernetTap.cpp index 9d3773f..e7fe657 100644 --- a/zerotierone/osdep/LinuxEthernetTap.cpp +++ b/zto/osdep/LinuxEthernetTap.cpp @@ -220,6 +220,7 @@ static bool ___removeIp(const std::string &_dev,const InetAddress &ip) } } +#ifdef __SYNOLOGY__ bool LinuxEthernetTap::addIpSyn(std::vector ips) { // Here we fill out interface config (ifcfg-dev) to prevent it from being killed @@ -233,14 +234,14 @@ bool LinuxEthernetTap::addIpSyn(std::vector ips) setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1); // We must know if there is at least (one) of each protocol version so we // can properly enumerate address/netmask combinations in the ifcfg-dev file - for(int i=0; i 1 ? std::to_string(ip4) : ""; cfg_contents += "\nIPADDR"+numstr4+"="+ips[i].toIpString() @@ -256,7 +257,7 @@ bool LinuxEthernetTap::addIpSyn(std::vector ips) } OSUtils::writeFile(filepath.c_str(), cfg_contents.c_str(), cfg_contents.length()); // Finaly, add IPs - for(int i=0; i ips) } return true; } +#endif // __SYNOLOGY__ bool LinuxEthernetTap::addIp(const InetAddress &ip) { diff --git a/zerotierone/osdep/LinuxEthernetTap.hpp b/zto/osdep/LinuxEthernetTap.hpp similarity index 98% rename from zerotierone/osdep/LinuxEthernetTap.hpp rename to zto/osdep/LinuxEthernetTap.hpp index acdff9d..7dd7e01 100644 --- a/zerotierone/osdep/LinuxEthernetTap.hpp +++ b/zto/osdep/LinuxEthernetTap.hpp @@ -52,7 +52,9 @@ public: void setEnabled(bool en); bool enabled() const; bool addIp(const InetAddress &ip); +#ifdef __SYNOLOGY__ bool addIpSyn(std::vector ips); +#endif bool removeIp(const InetAddress &ip); std::vector ips() const; void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len); diff --git a/zerotierone/osdep/ManagedRoute.cpp b/zto/osdep/ManagedRoute.cpp similarity index 100% rename from zerotierone/osdep/ManagedRoute.cpp rename to zto/osdep/ManagedRoute.cpp diff --git a/zerotierone/osdep/ManagedRoute.hpp b/zto/osdep/ManagedRoute.hpp similarity index 100% rename from zerotierone/osdep/ManagedRoute.hpp rename to zto/osdep/ManagedRoute.hpp diff --git a/zerotierone/osdep/NeighborDiscovery.cpp b/zto/osdep/NeighborDiscovery.cpp similarity index 100% rename from zerotierone/osdep/NeighborDiscovery.cpp rename to zto/osdep/NeighborDiscovery.cpp diff --git a/zerotierone/osdep/NeighborDiscovery.hpp b/zto/osdep/NeighborDiscovery.hpp similarity index 100% rename from zerotierone/osdep/NeighborDiscovery.hpp rename to zto/osdep/NeighborDiscovery.hpp diff --git a/zerotierone/osdep/OSUtils.cpp b/zto/osdep/OSUtils.cpp similarity index 88% rename from zerotierone/osdep/OSUtils.cpp rename to zto/osdep/OSUtils.cpp index fc02109..6b95258 100644 --- a/zerotierone/osdep/OSUtils.cpp +++ b/zto/osdep/OSUtils.cpp @@ -145,6 +145,64 @@ std::map OSUtils::listDirectoryFull(const char *path) return r; } +long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan) +{ + long cleaned = 0; + +#ifdef __WINDOWS__ + HANDLE hFind; + WIN32_FIND_DATAA ffd; + LARGE_INTEGER date,adjust; + adjust.QuadPart = 11644473600000 * 10000; + char tmp[4096]; + if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) { + do { + if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)) { + date.HighPart = ffd.ftLastWriteTime.dwHighDateTime; + date.LowPart = ffd.ftLastWriteTime.dwLowDateTime; + if (date.QuadPart > 0) { + date.QuadPart -= adjust.QuadPart; + if (((date.QuadPart / 10000000) * 1000) < olderThan) { + Utils::snprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName); + if (DeleteFileA(tmp)) + ++cleaned; + } + } + } + } while (FindNextFileA(hFind,&ffd)); + FindClose(hFind); + } +#else + struct dirent de; + struct dirent *dptr; + struct stat st; + char tmp[4096]; + DIR *d = opendir(path); + if (!d) + return -1; + dptr = (struct dirent *)0; + for(;;) { + if (readdir_r(d,&de,&dptr)) + break; + if (dptr) { + if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type == DT_REG)) { + Utils::snprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name); + if (stat(tmp,&st) == 0) { + uint64_t mt = (uint64_t)(st.st_mtime); + if ((mt > 0)&&((mt * 1000) < olderThan)) { + if (unlink(tmp) == 0) + ++cleaned; + } + } + } + } else break; + } + closedir(d); +#endif + + return cleaned; +} + bool OSUtils::rmDashRf(const char *path) { #ifdef __WINDOWS__ @@ -369,7 +427,7 @@ std::string OSUtils::platformDefaultHomePath() } // Inline these massive JSON operations in one place only to reduce binary footprint and compile time -nlohmann::json OSUtils::jsonParse(const std::string &buf) { return nlohmann::json::parse(buf); } +nlohmann::json OSUtils::jsonParse(const std::string &buf) { return nlohmann::json::parse(buf.c_str()); } std::string OSUtils::jsonDump(const nlohmann::json &j) { return j.dump(1); } uint64_t OSUtils::jsonInt(const nlohmann::json &jv,const uint64_t dfl) diff --git a/zerotierone/osdep/OSUtils.hpp b/zto/osdep/OSUtils.hpp similarity index 95% rename from zerotierone/osdep/OSUtils.hpp rename to zto/osdep/OSUtils.hpp index 2fe0197..adf1488 100644 --- a/zerotierone/osdep/OSUtils.hpp +++ b/zto/osdep/OSUtils.hpp @@ -119,6 +119,16 @@ public: */ static std::map listDirectoryFull(const char *path); + /** + * Clean a directory of files whose last modified time is older than this + * + * This ignores directories, symbolic links, and other special files. + * + * @param olderThan Last modified older than timestamp (ms since epoch) + * @return Number of cleaned files or negative on fatal error + */ + static long cleanDirectory(const char *path,const uint64_t olderThan); + /** * Delete a directory and all its files and subdirectories recursively * diff --git a/zerotierone/osdep/OSXEthernetTap.cpp b/zto/osdep/OSXEthernetTap.cpp similarity index 100% rename from zerotierone/osdep/OSXEthernetTap.cpp rename to zto/osdep/OSXEthernetTap.cpp diff --git a/zerotierone/osdep/OSXEthernetTap.hpp b/zto/osdep/OSXEthernetTap.hpp similarity index 100% rename from zerotierone/osdep/OSXEthernetTap.hpp rename to zto/osdep/OSXEthernetTap.hpp diff --git a/zerotierone/osdep/Phy.hpp b/zto/osdep/Phy.hpp similarity index 99% rename from zerotierone/osdep/Phy.hpp rename to zto/osdep/Phy.hpp index 62dd079..5201cff 100644 --- a/zerotierone/osdep/Phy.hpp +++ b/zto/osdep/Phy.hpp @@ -917,7 +917,7 @@ public: } if ((FD_ISSET(sock,&wfds))&&(FD_ISSET(sock,&_writefds))) { try { - _handler->phyOnTcpWritable((PhySocket *)&(*s),&(s->uptr),false); + _handler->phyOnTcpWritable((PhySocket *)&(*s),&(s->uptr), false); } catch ( ... ) {} } } break; diff --git a/zerotierone/osdep/PortMapper.cpp b/zto/osdep/PortMapper.cpp similarity index 100% rename from zerotierone/osdep/PortMapper.cpp rename to zto/osdep/PortMapper.cpp diff --git a/zerotierone/osdep/PortMapper.hpp b/zto/osdep/PortMapper.hpp similarity index 100% rename from zerotierone/osdep/PortMapper.hpp rename to zto/osdep/PortMapper.hpp diff --git a/zerotierone/osdep/README.md b/zto/osdep/README.md similarity index 100% rename from zerotierone/osdep/README.md rename to zto/osdep/README.md diff --git a/zerotierone/osdep/Thread.hpp b/zto/osdep/Thread.hpp similarity index 100% rename from zerotierone/osdep/Thread.hpp rename to zto/osdep/Thread.hpp diff --git a/zerotierone/osdep/WindowsEthernetTap.cpp b/zto/osdep/WindowsEthernetTap.cpp similarity index 100% rename from zerotierone/osdep/WindowsEthernetTap.cpp rename to zto/osdep/WindowsEthernetTap.cpp diff --git a/zerotierone/osdep/WindowsEthernetTap.hpp b/zto/osdep/WindowsEthernetTap.hpp similarity index 100% rename from zerotierone/osdep/WindowsEthernetTap.hpp rename to zto/osdep/WindowsEthernetTap.hpp diff --git a/zerotierone/selftest.cpp b/zto/selftest.cpp similarity index 100% rename from zerotierone/selftest.cpp rename to zto/selftest.cpp diff --git a/zerotierone/service/ClusterDefinition.hpp b/zto/service/ClusterDefinition.hpp similarity index 100% rename from zerotierone/service/ClusterDefinition.hpp rename to zto/service/ClusterDefinition.hpp diff --git a/zerotierone/service/ClusterGeoIpService.cpp b/zto/service/ClusterGeoIpService.cpp similarity index 100% rename from zerotierone/service/ClusterGeoIpService.cpp rename to zto/service/ClusterGeoIpService.cpp diff --git a/zerotierone/service/ClusterGeoIpService.hpp b/zto/service/ClusterGeoIpService.hpp similarity index 100% rename from zerotierone/service/ClusterGeoIpService.hpp rename to zto/service/ClusterGeoIpService.hpp diff --git a/zerotierone/service/OneService.cpp b/zto/service/OneService.cpp similarity index 77% rename from zerotierone/service/OneService.cpp rename to zto/service/OneService.cpp index 486b836..29ef3a6 100644 --- a/zerotierone/service/OneService.cpp +++ b/zto/service/OneService.cpp @@ -38,6 +38,7 @@ #include "../node/InetAddress.hpp" #include "../node/MAC.hpp" #include "../node/Identity.hpp" +#include "../node/World.hpp" #include "../osdep/Phy.hpp" #include "../osdep/Thread.hpp" @@ -48,11 +49,24 @@ #include "../osdep/ManagedRoute.hpp" #include "OneService.hpp" -#include "ControlPlane.hpp" #include "ClusterGeoIpService.hpp" #include "ClusterDefinition.hpp" #include "SoftwareUpdater.hpp" +#ifdef __WINDOWS__ +#include +#include +#include +#include +#include +#else +#include +#include +#include +#include +#include +#endif + #ifdef ZT_USE_SYSTEM_HTTP_PARSER #include #else @@ -75,20 +89,6 @@ using json = nlohmann::json; #include "../controller/EmbeddedNetworkController.hpp" -#ifdef __WINDOWS__ -#include -#include -#include -#include -#include -#else -#include -#include -#include -#include -#include -#endif - // Include the right tap device driver for this platform -- add new platforms here #ifdef ZT_SDK @@ -119,7 +119,7 @@ namespace ZeroTier { typedef BSDEthernetTap EthernetTap; } namespace ZeroTier { typedef BSDEthernetTap EthernetTap; } #endif // __OpenBSD__ -#endif // ZT_SDK +#endif // ZT_SERVICE_NETCON // Sanity limits for HTTP #define ZT_MAX_HTTP_MESSAGE_SIZE (1024 * 1024 * 64) @@ -147,6 +147,9 @@ namespace ZeroTier { typedef BSDEthernetTap EthernetTap; } // How often to check for local interface addresses #define ZT_LOCAL_INTERFACE_CHECK_INTERVAL 60000 +// Clean files from iddb.d that are older than this (60 days) +#define ZT_IDDB_CLEANUP_AGE 5184000000ULL + namespace ZeroTier { namespace { @@ -170,6 +173,122 @@ static std::string _trimString(const std::string &s) return s.substr(start,end - start); } +static void _networkToJson(nlohmann::json &nj,const ZT_VirtualNetworkConfig *nc,const std::string &portDeviceName,const OneService::NetworkSettings &localSettings) +{ + char tmp[256]; + + const char *nstatus = "",*ntype = ""; + switch(nc->status) { + case ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION: nstatus = "REQUESTING_CONFIGURATION"; break; + case ZT_NETWORK_STATUS_OK: nstatus = "OK"; break; + case ZT_NETWORK_STATUS_ACCESS_DENIED: nstatus = "ACCESS_DENIED"; break; + case ZT_NETWORK_STATUS_NOT_FOUND: nstatus = "NOT_FOUND"; break; + case ZT_NETWORK_STATUS_PORT_ERROR: nstatus = "PORT_ERROR"; break; + case ZT_NETWORK_STATUS_CLIENT_TOO_OLD: nstatus = "CLIENT_TOO_OLD"; break; + } + switch(nc->type) { + case ZT_NETWORK_TYPE_PRIVATE: ntype = "PRIVATE"; break; + case ZT_NETWORK_TYPE_PUBLIC: ntype = "PUBLIC"; break; + } + + Utils::snprintf(tmp,sizeof(tmp),"%.16llx",nc->nwid); + nj["id"] = tmp; + nj["nwid"] = tmp; + Utils::snprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)((nc->mac >> 40) & 0xff),(unsigned int)((nc->mac >> 32) & 0xff),(unsigned int)((nc->mac >> 24) & 0xff),(unsigned int)((nc->mac >> 16) & 0xff),(unsigned int)((nc->mac >> 8) & 0xff),(unsigned int)(nc->mac & 0xff)); + nj["mac"] = tmp; + nj["name"] = nc->name; + nj["status"] = nstatus; + nj["type"] = ntype; + nj["mtu"] = nc->mtu; + nj["dhcp"] = (bool)(nc->dhcp != 0); + nj["bridge"] = (bool)(nc->bridge != 0); + nj["broadcastEnabled"] = (bool)(nc->broadcastEnabled != 0); + nj["portError"] = nc->portError; + nj["netconfRevision"] = nc->netconfRevision; + nj["portDeviceName"] = portDeviceName; + nj["allowManaged"] = localSettings.allowManaged; + nj["allowGlobal"] = localSettings.allowGlobal; + nj["allowDefault"] = localSettings.allowDefault; + + nlohmann::json aa = nlohmann::json::array(); + for(unsigned int i=0;iassignedAddressCount;++i) { + aa.push_back(reinterpret_cast(&(nc->assignedAddresses[i]))->toString()); + } + nj["assignedAddresses"] = aa; + + nlohmann::json ra = nlohmann::json::array(); + for(unsigned int i=0;irouteCount;++i) { + nlohmann::json rj; + rj["target"] = reinterpret_cast(&(nc->routes[i].target))->toString(); + if (nc->routes[i].via.ss_family == nc->routes[i].target.ss_family) + rj["via"] = reinterpret_cast(&(nc->routes[i].via))->toIpString(); + else rj["via"] = nlohmann::json(); + rj["flags"] = (int)nc->routes[i].flags; + rj["metric"] = (int)nc->routes[i].metric; + ra.push_back(rj); + } + nj["routes"] = ra; +} + +static void _peerToJson(nlohmann::json &pj,const ZT_Peer *peer) +{ + char tmp[256]; + + const char *prole = ""; + switch(peer->role) { + case ZT_PEER_ROLE_LEAF: prole = "LEAF"; break; + case ZT_PEER_ROLE_MOON: prole = "MOON"; break; + case ZT_PEER_ROLE_PLANET: prole = "PLANET"; break; + } + + Utils::snprintf(tmp,sizeof(tmp),"%.10llx",peer->address); + pj["address"] = tmp; + pj["versionMajor"] = peer->versionMajor; + pj["versionMinor"] = peer->versionMinor; + pj["versionRev"] = peer->versionRev; + Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d",peer->versionMajor,peer->versionMinor,peer->versionRev); + pj["version"] = tmp; + pj["latency"] = peer->latency; + pj["role"] = prole; + + nlohmann::json pa = nlohmann::json::array(); + for(unsigned int i=0;ipathCount;++i) { + nlohmann::json j; + j["address"] = reinterpret_cast(&(peer->paths[i].address))->toString(); + j["lastSend"] = peer->paths[i].lastSend; + j["lastReceive"] = peer->paths[i].lastReceive; + j["trustedPathId"] = peer->paths[i].trustedPathId; + j["linkQuality"] = (double)peer->paths[i].linkQuality / (double)ZT_PATH_LINK_QUALITY_MAX; + j["active"] = (bool)(peer->paths[i].expired == 0); + j["expired"] = (bool)(peer->paths[i].expired != 0); + j["preferred"] = (bool)(peer->paths[i].preferred != 0); + pa.push_back(j); + } + pj["paths"] = pa; +} + +static void _moonToJson(nlohmann::json &mj,const World &world) +{ + char tmp[64]; + Utils::snprintf(tmp,sizeof(tmp),"%.16llx",world.id()); + mj["id"] = tmp; + mj["timestamp"] = world.timestamp(); + mj["signature"] = Utils::hex(world.signature().data,(unsigned int)world.signature().size()); + mj["updatesMustBeSignedBy"] = Utils::hex(world.updatesMustBeSignedBy().data,(unsigned int)world.updatesMustBeSignedBy().size()); + nlohmann::json ra = nlohmann::json::array(); + for(std::vector::const_iterator r(world.roots().begin());r!=world.roots().end();++r) { + nlohmann::json rj; + rj["identity"] = r->identity.toString(false); + nlohmann::json eps = nlohmann::json::array(); + for(std::vector::const_iterator a(r->stableEndpoints.begin());a!=r->stableEndpoints.end();++a) + eps.push_back(a->toString()); + rj["stableEndpoints"] = eps; + ra.push_back(rj); + } + mj["roots"] = ra; + mj["waiting"] = false; +} + class OneServiceImpl; static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,void **nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf); @@ -261,6 +380,7 @@ public: // begin member variables -------------------------------------------------- const std::string _homePath; + std::string _authToken; EmbeddedNetworkController *_controller; Phy _phy; Node *_node; @@ -299,9 +419,6 @@ public: PhySocket *_v4TcpControlSocket; PhySocket *_v6TcpControlSocket; - // JSON API handler - ControlPlane *_controlPlane; - // Time we last received a packet from a global address uint64_t _lastDirectReceiveFromGlobal; #ifdef ZT_TCP_FALLBACK_RELAY @@ -371,7 +488,6 @@ public: ,_updater((SoftwareUpdater *)0) ,_updateAutoApply(false) ,_primaryPort(port) - ,_controlPlane((ControlPlane *)0) ,_lastDirectReceiveFromGlobal(0) #ifdef ZT_TCP_FALLBACK_RELAY ,_lastSendToGlobalV4(0) @@ -420,16 +536,15 @@ public: virtual ReasonForTermination run() { try { - std::string authToken; { - std::string authTokenPath(_homePath + ZT_PATH_SEPARATOR_S "authtoken.secret"); - if (!OSUtils::readFile(authTokenPath.c_str(),authToken)) { + const std::string authTokenPath(_homePath + ZT_PATH_SEPARATOR_S "authtoken.secret"); + if (!OSUtils::readFile(authTokenPath.c_str(),_authToken)) { unsigned char foo[24]; Utils::getSecureRandom(foo,sizeof(foo)); - authToken = ""; + _authToken = ""; for(unsigned int i=0;iaddAuthToken(authToken.c_str()); - _controlPlane->setController(_controller); - { // Load existing networks std::vector networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S "networks.d").c_str())); for(std::vector::iterator f(networksDotD.begin());f!=networksDotD.end();++f) { @@ -718,6 +829,7 @@ public: uint64_t lastBindRefresh = 0; uint64_t lastUpdateCheck = clockShouldBe; uint64_t lastLocalInterfaceAddressCheck = (clockShouldBe - ZT_LOCAL_INTERFACE_CHECK_INTERVAL) + 15000; // do this in 15s to give portmapper time to configure and other things time to settle + uint64_t lastCleanedIddb = 0; for(;;) { _run_m.lock(); if (!_run) { @@ -732,6 +844,12 @@ public: const uint64_t now = OSUtils::now(); + // Clean iddb.d on start and every 24 hours + if ((now - lastCleanedIddb) > 86400000) { + lastCleanedIddb = now; + OSUtils::cleanDirectory((_homePath + ZT_PATH_SEPARATOR_S "iddb.d").c_str(),now - ZT_IDDB_CLEANUP_AGE); + } + // Attempt to detect sleep/wake events by detecting delay overruns bool restarted = false; if ((now > clockShouldBe)&&((now - clockShouldBe) > 10000)) { @@ -831,8 +949,6 @@ public: _nets.clear(); } - delete _controlPlane; - _controlPlane = (ControlPlane *)0; delete _updater; _updater = (SoftwareUpdater *)0; delete _node; @@ -862,11 +978,6 @@ public: else return std::string(); } - virtual bool tcpFallbackActive() const - { - return (_tcpFallbackTunnel != (TcpConnection *)0); - } - virtual void terminate() { _run_m.lock(); @@ -943,16 +1054,411 @@ public: // Internal implementation methods ----------------------------------------- + inline unsigned int handleControlPlaneHttpRequest( + const InetAddress &fromAddress, + unsigned int httpMethod, + const std::string &path, + const std::map &headers, + const std::string &body, + std::string &responseBody, + std::string &responseContentType) + { + char tmp[256]; + unsigned int scode = 404; + json res; + std::vector ps(OSUtils::split(path.c_str(),"/","","")); + std::map urlArgs; + + /* Note: this is kind of restricted in what it'll take. It does not support + * URL encoding, and /'s in URL args will screw it up. But the only URL args + * it really uses in ?jsonp=funcionName, and otherwise it just takes simple + * paths to simply-named resources. */ + if (ps.size() > 0) { + std::size_t qpos = ps[ps.size() - 1].find('?'); + if (qpos != std::string::npos) { + std::string args(ps[ps.size() - 1].substr(qpos + 1)); + ps[ps.size() - 1] = ps[ps.size() - 1].substr(0,qpos); + std::vector asplit(OSUtils::split(args.c_str(),"&","","")); + for(std::vector::iterator a(asplit.begin());a!=asplit.end();++a) { + std::size_t eqpos = a->find('='); + if (eqpos == std::string::npos) + urlArgs[*a] = ""; + else urlArgs[a->substr(0,eqpos)] = a->substr(eqpos + 1); + } + } + } + + bool isAuth = false; + { + std::map::const_iterator ah(headers.find("x-zt1-auth")); + if ((ah != headers.end())&&(_authToken == ah->second)) { + isAuth = true; + } else { + ah = urlArgs.find("auth"); + if ((ah != urlArgs.end())&&(_authToken == ah->second)) + isAuth = true; + } + } + +#ifdef __SYNOLOGY__ + // Authenticate via Synology's built-in cgi script + if (!isAuth) { + /* + fprintf(stderr, "path = %s\n", path.c_str()); + fprintf(stderr, "headers.size=%d\n", headers.size()); + std::map::const_iterator it(headers.begin()); + while(it != headers.end()) { + fprintf(stderr,"header[%s] = %s\n", (it->first).c_str(), (it->second).c_str()); + it++; + } + */ + // parse out url args + int synotoken_pos = path.find("SynoToken"); + int argpos = path.find("?"); + if(synotoken_pos != std::string::npos && argpos != std::string::npos) { + std::string cookie = path.substr(argpos+1, synotoken_pos-(argpos+1)); + std::string synotoken = path.substr(synotoken_pos); + std::string cookie_val = cookie.substr(cookie.find("=")+1); + std::string synotoken_val = synotoken.substr(synotoken.find("=")+1); + // Set necessary env for auth script + std::map::const_iterator ah2(headers.find("x-forwarded-for")); + setenv("HTTP_COOKIE", cookie_val.c_str(), true); + setenv("HTTP_X_SYNO_TOKEN", synotoken_val.c_str(), true); + setenv("REMOTE_ADDR", ah2->second.c_str(),true); + //fprintf(stderr, "HTTP_COOKIE: %s\n",std::getenv ("HTTP_COOKIE")); + //fprintf(stderr, "HTTP_X_SYNO_TOKEN: %s\n",std::getenv ("HTTP_X_SYNO_TOKEN")); + //fprintf(stderr, "REMOTE_ADDR: %s\n",std::getenv ("REMOTE_ADDR")); + // check synology web auth + char user[256], buf[1024]; + FILE *fp = NULL; + bzero(user, 256); + fp = popen("/usr/syno/synoman/webman/modules/authenticate.cgi", "r"); + if(!fp) + isAuth = false; + else { + bzero(buf, sizeof(buf)); + fread(buf, 1024, 1, fp); + if(strlen(buf) > 0) { + snprintf(user, 256, "%s", buf); + isAuth = true; + } + } + pclose(fp); + } + } +#endif + + if (httpMethod == HTTP_GET) { + if (isAuth) { + if (ps[0] == "status") { + ZT_NodeStatus status; + _node->status(&status); + + Utils::snprintf(tmp,sizeof(tmp),"%.10llx",status.address); + res["address"] = tmp; + res["publicIdentity"] = status.publicIdentity; + res["online"] = (bool)(status.online != 0); + res["tcpFallbackActive"] = (_tcpFallbackTunnel != (TcpConnection *)0); + res["versionMajor"] = ZEROTIER_ONE_VERSION_MAJOR; + res["versionMinor"] = ZEROTIER_ONE_VERSION_MINOR; + res["versionRev"] = ZEROTIER_ONE_VERSION_REVISION; + res["versionBuild"] = ZEROTIER_ONE_VERSION_BUILD; + Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d",ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); + res["version"] = tmp; + res["clock"] = OSUtils::now(); + + { + Mutex::Lock _l(_localConfig_m); + res["config"] = _localConfig; + } + json &settings = res["config"]["settings"]; + settings["primaryPort"] = OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff; +#ifdef ZT_USE_MINIUPNPC + settings["portMappingEnabled"] = OSUtils::jsonBool(settings["portMappingEnabled"],true); +#else + settings["portMappingEnabled"] = false; // not supported in build +#endif + //settings["softwareUpdate"] = OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT); + //settings["softwareUpdateChannel"] = OSUtils::jsonString(settings["softwareUpdateChannel"],ZT_SOFTWARE_UPDATE_DEFAULT_CHANNEL); + + const World planet(_node->planet()); + res["planetWorldId"] = planet.id(); + res["planetWorldTimestamp"] = planet.timestamp(); + +#ifdef ZT_ENABLE_CLUSTER + json cj; + ZT_ClusterStatus cs; + _node->clusterStatus(&cs); + if (cs.clusterSize >= 1) { + json cja = json::array(); + for(unsigned int i=0;i moons(_node->moons()); + if (ps.size() == 1) { + // Return [array] of all moons + + res = json::array(); + for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) { + json mj; + _moonToJson(mj,*m); + res.push_back(mj); + } + + scode = 200; + } else { + // Return a single moon by ID + + const uint64_t id = Utils::hexStrToU64(ps[1].c_str()); + for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) { + if (m->id() == id) { + _moonToJson(res,*m); + scode = 200; + break; + } + } + + } + } else if (ps[0] == "network") { + ZT_VirtualNetworkList *nws = _node->networks(); + if (nws) { + if (ps.size() == 1) { + // Return [array] of all networks + + res = nlohmann::json::array(); + for(unsigned long i=0;inetworkCount;++i) { + OneService::NetworkSettings localSettings; + getNetworkSettings(nws->networks[i].nwid,localSettings); + nlohmann::json nj; + _networkToJson(nj,&(nws->networks[i]),portDeviceName(nws->networks[i].nwid),localSettings); + res.push_back(nj); + } + + scode = 200; + } else if (ps.size() == 2) { + // Return a single network by ID or 404 if not found + + const uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); + for(unsigned long i=0;inetworkCount;++i) { + if (nws->networks[i].nwid == wantnw) { + OneService::NetworkSettings localSettings; + getNetworkSettings(nws->networks[i].nwid,localSettings); + _networkToJson(res,&(nws->networks[i]),portDeviceName(nws->networks[i].nwid),localSettings); + scode = 200; + break; + } + } + + } else scode = 404; + _node->freeQueryResult((void *)nws); + } else scode = 500; + } else if (ps[0] == "peer") { + ZT_PeerList *pl = _node->peers(); + if (pl) { + if (ps.size() == 1) { + // Return [array] of all peers + + res = nlohmann::json::array(); + for(unsigned long i=0;ipeerCount;++i) { + nlohmann::json pj; + _peerToJson(pj,&(pl->peers[i])); + res.push_back(pj); + } + + scode = 200; + } else if (ps.size() == 2) { + // Return a single peer by ID or 404 if not found + + uint64_t wantp = Utils::hexStrToU64(ps[1].c_str()); + for(unsigned long i=0;ipeerCount;++i) { + if (pl->peers[i].address == wantp) { + _peerToJson(res,&(pl->peers[i])); + scode = 200; + break; + } + } + + } else scode = 404; + _node->freeQueryResult((void *)pl); + } else scode = 500; + } else { + if (_controller) { + scode = _controller->handleControlPlaneHttpGET(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); + } else scode = 404; + } + + } else scode = 401; // isAuth == false + } else if ((httpMethod == HTTP_POST)||(httpMethod == HTTP_PUT)) { + if (isAuth) { + + if (ps[0] == "moon") { + if (ps.size() == 2) { + + uint64_t seed = 0; + try { + json j(OSUtils::jsonParse(body)); + if (j.is_object()) { + seed = Utils::hexStrToU64(OSUtils::jsonString(j["seed"],"0").c_str()); + } + } catch ( ... ) { + // discard invalid JSON + } + + std::vector moons(_node->moons()); + const uint64_t id = Utils::hexStrToU64(ps[1].c_str()); + for(std::vector::const_iterator m(moons.begin());m!=moons.end();++m) { + if (m->id() == id) { + _moonToJson(res,*m); + scode = 200; + break; + } + } + + if ((scode != 200)&&(seed != 0)) { + char tmp[64]; + Utils::snprintf(tmp,sizeof(tmp),"%.16llx",id); + res["id"] = tmp; + res["roots"] = json::array(); + res["timestamp"] = 0; + res["signature"] = json(); + res["updatesMustBeSignedBy"] = json(); + res["waiting"] = true; + _node->orbit(id,seed); + scode = 200; + } + + } else scode = 404; + } else if (ps[0] == "network") { + if (ps.size() == 2) { + + uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); + _node->join(wantnw,(void *)0); // does nothing if we are a member + ZT_VirtualNetworkList *nws = _node->networks(); + if (nws) { + for(unsigned long i=0;inetworkCount;++i) { + if (nws->networks[i].nwid == wantnw) { + OneService::NetworkSettings localSettings; + getNetworkSettings(nws->networks[i].nwid,localSettings); + + try { + json j(OSUtils::jsonParse(body)); + if (j.is_object()) { + json &allowManaged = j["allowManaged"]; + if (allowManaged.is_boolean()) localSettings.allowManaged = (bool)allowManaged; + json &allowGlobal = j["allowGlobal"]; + if (allowGlobal.is_boolean()) localSettings.allowGlobal = (bool)allowGlobal; + json &allowDefault = j["allowDefault"]; + if (allowDefault.is_boolean()) localSettings.allowDefault = (bool)allowDefault; + } + } catch ( ... ) { + // discard invalid JSON + } + + setNetworkSettings(nws->networks[i].nwid,localSettings); + _networkToJson(res,&(nws->networks[i]),portDeviceName(nws->networks[i].nwid),localSettings); + + scode = 200; + break; + } + } + _node->freeQueryResult((void *)nws); + } else scode = 500; + + } else scode = 404; + } else { + if (_controller) + scode = _controller->handleControlPlaneHttpPOST(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); + else scode = 404; + } + + } else scode = 401; // isAuth == false + } else if (httpMethod == HTTP_DELETE) { + if (isAuth) { + + if (ps[0] == "moon") { + if (ps.size() == 2) { + _node->deorbit(Utils::hexStrToU64(ps[1].c_str())); + res["result"] = true; + scode = 200; + } // else 404 + } else if (ps[0] == "network") { + ZT_VirtualNetworkList *nws = _node->networks(); + if (nws) { + if (ps.size() == 2) { + uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); + for(unsigned long i=0;inetworkCount;++i) { + if (nws->networks[i].nwid == wantnw) { + _node->leave(wantnw,(void **)0); + res["result"] = true; + scode = 200; + break; + } + } + } // else 404 + _node->freeQueryResult((void *)nws); + } else scode = 500; + } else { + if (_controller) + scode = _controller->handleControlPlaneHttpDELETE(std::vector(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); + else scode = 404; + } + + } else scode = 401; // isAuth = false + } else { + scode = 400; + } + + if (responseBody.length() == 0) { + if ((res.is_object())||(res.is_array())) + responseBody = OSUtils::jsonDump(res); + else responseBody = "{}"; + responseContentType = "application/json"; + } + + // Wrap result in jsonp function call if the user included a jsonp= url argument. + // Also double-check isAuth since forbidding this without auth feels safer. + std::map::const_iterator jsonp(urlArgs.find("jsonp")); + if ((isAuth)&&(jsonp != urlArgs.end())&&(responseContentType == "application/json")) { + if (responseBody.length() > 0) + responseBody = jsonp->second + "(" + responseBody + ");"; + else responseBody = jsonp->second + "(null);"; + responseContentType = "application/javascript"; + } + + return scode; + } + // Must be called after _localConfig is read or modified void applyLocalConfig() { Mutex::Lock _l(_localConfig_m); + json lc(_localConfig); _v4Hints.clear(); _v6Hints.clear(); _v4Blacklists.clear(); _v6Blacklists.clear(); - json &virt = _localConfig["virtual"]; + json &virt = lc["virtual"]; if (virt.is_object()) { for(json::iterator v(virt.begin());v!=virt.end();++v) { const std::string nstr = v.key(); @@ -997,7 +1503,7 @@ public: _globalV4Blacklist.clear(); _globalV6Blacklist.clear(); - json &physical = _localConfig["physical"]; + json &physical = lc["physical"]; if (physical.is_object()) { for(json::iterator phy(physical.begin());phy!=physical.end();++phy) { const InetAddress net(OSUtils::jsonString(phy.key(),"")); @@ -1016,42 +1522,41 @@ public: _allowManagementFrom.clear(); _interfacePrefixBlacklist.clear(); - json &settings = _localConfig["settings"]; - if (settings.is_object()) { - _primaryPort = (unsigned int)OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff; - _portMappingEnabled = OSUtils::jsonBool(settings["portMappingEnabled"],true); + json &settings = lc["settings"]; + + _primaryPort = (unsigned int)OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff; + _portMappingEnabled = OSUtils::jsonBool(settings["portMappingEnabled"],true); /* - const std::string up(OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT)); - const bool udist = OSUtils::jsonBool(settings["softwareUpdateDist"],false); - if (((up == "apply")||(up == "download"))||(udist)) { - if (!_updater) - _updater = new SoftwareUpdater(*_node,_homePath); - _updateAutoApply = (up == "apply"); - _updater->setUpdateDistribution(udist); - _updater->setChannel(OSUtils::jsonString(settings["softwareUpdateChannel"],ZT_SOFTWARE_UPDATE_DEFAULT_CHANNEL)); - } else { - delete _updater; - _updater = (SoftwareUpdater *)0; - _updateAutoApply = false; - } + const std::string up(OSUtils::jsonString(settings["softwareUpdate"],ZT_SOFTWARE_UPDATE_DEFAULT)); + const bool udist = OSUtils::jsonBool(settings["softwareUpdateDist"],false); + if (((up == "apply")||(up == "download"))||(udist)) { + if (!_updater) + _updater = new SoftwareUpdater(*_node,_homePath); + _updateAutoApply = (up == "apply"); + _updater->setUpdateDistribution(udist); + _updater->setChannel(OSUtils::jsonString(settings["softwareUpdateChannel"],ZT_SOFTWARE_UPDATE_DEFAULT_CHANNEL)); + } else { + delete _updater; + _updater = (SoftwareUpdater *)0; + _updateAutoApply = false; + } */ - json &ignoreIfs = settings["interfacePrefixBlacklist"]; - if (ignoreIfs.is_array()) { - for(unsigned long i=0;i 0) - _interfacePrefixBlacklist.push_back(tmp); - } + json &ignoreIfs = settings["interfacePrefixBlacklist"]; + if (ignoreIfs.is_array()) { + for(unsigned long i=0;i 0) + _interfacePrefixBlacklist.push_back(tmp); } + } - json &amf = settings["allowManagementFrom"]; - if (amf.is_array()) { - for(unsigned long i=0;i callbacks ----------------------------------- + // ========================================================================= + // Handlers for Node and Phy<> callbacks + // ========================================================================= inline void phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *localAddr,const struct sockaddr *from,void *data,unsigned long len) { @@ -1812,9 +2319,7 @@ public: if (allow) { try { - if (_controlPlane) - scode = _controlPlane->handleRequest(tc->from,tc->parser.method,tc->url,tc->headers,tc->body,data,contentType); - else scode = 500; + scode = handleControlPlaneHttpRequest(tc->from,tc->parser.method,tc->url,tc->headers,tc->body,data,contentType); } catch (std::exception &exc) { fprintf(stderr,"WARNING: unexpected exception processing control HTTP request: %s" ZT_EOL_S,exc.what()); scode = 500; diff --git a/zerotierone/service/OneService.hpp b/zto/service/OneService.hpp similarity index 97% rename from zerotierone/service/OneService.hpp rename to zto/service/OneService.hpp index 6689932..37d8295 100644 --- a/zerotierone/service/OneService.hpp +++ b/zto/service/OneService.hpp @@ -23,7 +23,6 @@ #include #include "../node/InetAddress.hpp" - #include "../node/Node.hpp" // Include the right tap device driver for this platform -- add new platforms here @@ -140,11 +139,6 @@ public: */ virtual std::string portDeviceName(uint64_t nwid) const = 0; - /** - * @return True if TCP fallback is currently active - */ - virtual bool tcpFallbackActive() const = 0; - /** * Terminate background service (can be called from other threads) */ @@ -177,7 +171,7 @@ public: */ virtual Node * getNode() = 0; #endif - + /** * Get local settings for a network * diff --git a/zerotierone/service/README.md b/zto/service/README.md similarity index 100% rename from zerotierone/service/README.md rename to zto/service/README.md diff --git a/zerotierone/service/SoftwareUpdater.cpp b/zto/service/SoftwareUpdater.cpp similarity index 100% rename from zerotierone/service/SoftwareUpdater.cpp rename to zto/service/SoftwareUpdater.cpp diff --git a/zerotierone/service/SoftwareUpdater.hpp b/zto/service/SoftwareUpdater.hpp similarity index 88% rename from zerotierone/service/SoftwareUpdater.hpp rename to zto/service/SoftwareUpdater.hpp index e6e6b0c..8950782 100644 --- a/zerotierone/service/SoftwareUpdater.hpp +++ b/zto/service/SoftwareUpdater.hpp @@ -64,8 +64,7 @@ /** * How often (ms) do we check? */ -//#define ZT_SOFTWARE_UPDATE_CHECK_PERIOD (60 * 60 * 1000) -#define ZT_SOFTWARE_UPDATE_CHECK_PERIOD 5000 +#define ZT_SOFTWARE_UPDATE_CHECK_PERIOD (60 * 10 * 1000) /** * Default update channel @@ -82,21 +81,21 @@ */ #define ZT_SOFTWARE_UPDATE_BIN_FILENAME "latest-update.exe" -#define ZT_SOFTWARE_UPDATE_JSON_VERSION_MAJOR "versionMajor" -#define ZT_SOFTWARE_UPDATE_JSON_VERSION_MINOR "versionMinor" -#define ZT_SOFTWARE_UPDATE_JSON_VERSION_REVISION "versionRev" -#define ZT_SOFTWARE_UPDATE_JSON_VERSION_BUILD "versionBuild" +#define ZT_SOFTWARE_UPDATE_JSON_VERSION_MAJOR "vMajor" +#define ZT_SOFTWARE_UPDATE_JSON_VERSION_MINOR "vMinor" +#define ZT_SOFTWARE_UPDATE_JSON_VERSION_REVISION "vRev" +#define ZT_SOFTWARE_UPDATE_JSON_VERSION_BUILD "vBuild" #define ZT_SOFTWARE_UPDATE_JSON_PLATFORM "platform" #define ZT_SOFTWARE_UPDATE_JSON_ARCHITECTURE "arch" #define ZT_SOFTWARE_UPDATE_JSON_VENDOR "vendor" #define ZT_SOFTWARE_UPDATE_JSON_CHANNEL "channel" #define ZT_SOFTWARE_UPDATE_JSON_EXPECT_SIGNED_BY "expectedSigner" -#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_SIGNED_BY "updateSigner" -#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_SIGNATURE "updateSig" -#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_HASH "updateHash" -#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_SIZE "updateSize" -#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_EXEC_ARGS "updateExecArgs" -#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_URL "updateUrl" +#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_SIGNED_BY "signer" +#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_SIGNATURE "signature" +#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_HASH "hash" +#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_SIZE "size" +#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_EXEC_ARGS "execArgs" +#define ZT_SOFTWARE_UPDATE_JSON_UPDATE_URL "url" namespace ZeroTier { diff --git a/zerotierone/tcp-proxy/Makefile b/zto/tcp-proxy/Makefile similarity index 100% rename from zerotierone/tcp-proxy/Makefile rename to zto/tcp-proxy/Makefile diff --git a/zerotierone/tcp-proxy/README.md b/zto/tcp-proxy/README.md similarity index 100% rename from zerotierone/tcp-proxy/README.md rename to zto/tcp-proxy/README.md diff --git a/zerotierone/tcp-proxy/tcp-proxy.cpp b/zto/tcp-proxy/tcp-proxy.cpp similarity index 100% rename from zerotierone/tcp-proxy/tcp-proxy.cpp rename to zto/tcp-proxy/tcp-proxy.cpp diff --git a/zerotierone/version.h b/zto/version.h similarity index 93% rename from zerotierone/version.h rename to zto/version.h index 9f61666..b83cab0 100644 --- a/zerotierone/version.h +++ b/zto/version.h @@ -27,12 +27,12 @@ /** * Minor version */ -#define ZEROTIER_ONE_VERSION_MINOR 1 +#define ZEROTIER_ONE_VERSION_MINOR 2 /** * Revision */ -#define ZEROTIER_ONE_VERSION_REVISION 17 +#define ZEROTIER_ONE_VERSION_REVISION 0 /** * Build version diff --git a/zerotierone/windows/README.md b/zto/windows/README.md similarity index 100% rename from zerotierone/windows/README.md rename to zto/windows/README.md diff --git a/zerotierone/windows/TapDriver6/TapDriver6.vcxproj b/zto/windows/TapDriver6/TapDriver6.vcxproj similarity index 100% rename from zerotierone/windows/TapDriver6/TapDriver6.vcxproj rename to zto/windows/TapDriver6/TapDriver6.vcxproj diff --git a/zerotierone/windows/TapDriver6/TapDriver6.vcxproj.filters b/zto/windows/TapDriver6/TapDriver6.vcxproj.filters similarity index 100% rename from zerotierone/windows/TapDriver6/TapDriver6.vcxproj.filters rename to zto/windows/TapDriver6/TapDriver6.vcxproj.filters diff --git a/zerotierone/windows/TapDriver6/adapter.c b/zto/windows/TapDriver6/adapter.c similarity index 100% rename from zerotierone/windows/TapDriver6/adapter.c rename to zto/windows/TapDriver6/adapter.c diff --git a/zerotierone/windows/TapDriver6/adapter.h b/zto/windows/TapDriver6/adapter.h similarity index 100% rename from zerotierone/windows/TapDriver6/adapter.h rename to zto/windows/TapDriver6/adapter.h diff --git a/zerotierone/windows/TapDriver6/config.h b/zto/windows/TapDriver6/config.h similarity index 100% rename from zerotierone/windows/TapDriver6/config.h rename to zto/windows/TapDriver6/config.h diff --git a/zerotierone/windows/TapDriver6/constants.h b/zto/windows/TapDriver6/constants.h similarity index 100% rename from zerotierone/windows/TapDriver6/constants.h rename to zto/windows/TapDriver6/constants.h diff --git a/zerotierone/windows/TapDriver6/device.c b/zto/windows/TapDriver6/device.c similarity index 100% rename from zerotierone/windows/TapDriver6/device.c rename to zto/windows/TapDriver6/device.c diff --git a/zerotierone/windows/TapDriver6/device.h b/zto/windows/TapDriver6/device.h similarity index 100% rename from zerotierone/windows/TapDriver6/device.h rename to zto/windows/TapDriver6/device.h diff --git a/zerotierone/windows/TapDriver6/endian.h b/zto/windows/TapDriver6/endian.h similarity index 100% rename from zerotierone/windows/TapDriver6/endian.h rename to zto/windows/TapDriver6/endian.h diff --git a/zerotierone/windows/TapDriver6/error.c b/zto/windows/TapDriver6/error.c similarity index 100% rename from zerotierone/windows/TapDriver6/error.c rename to zto/windows/TapDriver6/error.c diff --git a/zerotierone/windows/TapDriver6/error.h b/zto/windows/TapDriver6/error.h similarity index 100% rename from zerotierone/windows/TapDriver6/error.h rename to zto/windows/TapDriver6/error.h diff --git a/zerotierone/windows/TapDriver6/hexdump.h b/zto/windows/TapDriver6/hexdump.h similarity index 100% rename from zerotierone/windows/TapDriver6/hexdump.h rename to zto/windows/TapDriver6/hexdump.h diff --git a/zerotierone/windows/TapDriver6/lock.h b/zto/windows/TapDriver6/lock.h similarity index 100% rename from zerotierone/windows/TapDriver6/lock.h rename to zto/windows/TapDriver6/lock.h diff --git a/zerotierone/windows/TapDriver6/macinfo.c b/zto/windows/TapDriver6/macinfo.c similarity index 100% rename from zerotierone/windows/TapDriver6/macinfo.c rename to zto/windows/TapDriver6/macinfo.c diff --git a/zerotierone/windows/TapDriver6/macinfo.h b/zto/windows/TapDriver6/macinfo.h similarity index 100% rename from zerotierone/windows/TapDriver6/macinfo.h rename to zto/windows/TapDriver6/macinfo.h diff --git a/zerotierone/windows/TapDriver6/mem.c b/zto/windows/TapDriver6/mem.c similarity index 100% rename from zerotierone/windows/TapDriver6/mem.c rename to zto/windows/TapDriver6/mem.c diff --git a/zerotierone/windows/TapDriver6/mem.h b/zto/windows/TapDriver6/mem.h similarity index 100% rename from zerotierone/windows/TapDriver6/mem.h rename to zto/windows/TapDriver6/mem.h diff --git a/zerotierone/windows/TapDriver6/oidrequest.c b/zto/windows/TapDriver6/oidrequest.c similarity index 100% rename from zerotierone/windows/TapDriver6/oidrequest.c rename to zto/windows/TapDriver6/oidrequest.c diff --git a/zerotierone/windows/TapDriver6/proto.h b/zto/windows/TapDriver6/proto.h similarity index 100% rename from zerotierone/windows/TapDriver6/proto.h rename to zto/windows/TapDriver6/proto.h diff --git a/zerotierone/windows/TapDriver6/prototypes.h b/zto/windows/TapDriver6/prototypes.h similarity index 100% rename from zerotierone/windows/TapDriver6/prototypes.h rename to zto/windows/TapDriver6/prototypes.h diff --git a/zerotierone/windows/TapDriver6/resource.h b/zto/windows/TapDriver6/resource.h similarity index 100% rename from zerotierone/windows/TapDriver6/resource.h rename to zto/windows/TapDriver6/resource.h diff --git a/zerotierone/windows/TapDriver6/resource.rc b/zto/windows/TapDriver6/resource.rc similarity index 100% rename from zerotierone/windows/TapDriver6/resource.rc rename to zto/windows/TapDriver6/resource.rc diff --git a/zerotierone/windows/TapDriver6/rxpath.c b/zto/windows/TapDriver6/rxpath.c similarity index 100% rename from zerotierone/windows/TapDriver6/rxpath.c rename to zto/windows/TapDriver6/rxpath.c diff --git a/zerotierone/windows/TapDriver6/tap-windows.h b/zto/windows/TapDriver6/tap-windows.h similarity index 100% rename from zerotierone/windows/TapDriver6/tap-windows.h rename to zto/windows/TapDriver6/tap-windows.h diff --git a/zerotierone/windows/TapDriver6/tap.h b/zto/windows/TapDriver6/tap.h similarity index 100% rename from zerotierone/windows/TapDriver6/tap.h rename to zto/windows/TapDriver6/tap.h diff --git a/zerotierone/windows/TapDriver6/tapdrvr.c b/zto/windows/TapDriver6/tapdrvr.c similarity index 100% rename from zerotierone/windows/TapDriver6/tapdrvr.c rename to zto/windows/TapDriver6/tapdrvr.c diff --git a/zerotierone/windows/TapDriver6/txpath.c b/zto/windows/TapDriver6/txpath.c similarity index 100% rename from zerotierone/windows/TapDriver6/txpath.c rename to zto/windows/TapDriver6/txpath.c diff --git a/zerotierone/windows/TapDriver6/types.h b/zto/windows/TapDriver6/types.h similarity index 100% rename from zerotierone/windows/TapDriver6/types.h rename to zto/windows/TapDriver6/types.h diff --git a/zerotierone/windows/TapDriver6/zttap300.inf b/zto/windows/TapDriver6/zttap300.inf similarity index 100% rename from zerotierone/windows/TapDriver6/zttap300.inf rename to zto/windows/TapDriver6/zttap300.inf diff --git a/zerotierone/windows/WinUI/APIHandler.cs b/zto/windows/WinUI/APIHandler.cs similarity index 94% rename from zerotierone/windows/WinUI/APIHandler.cs rename to zto/windows/WinUI/APIHandler.cs index a762fff..81c5b77 100644 --- a/zerotierone/windows/WinUI/APIHandler.cs +++ b/zto/windows/WinUI/APIHandler.cs @@ -230,16 +230,23 @@ namespace WinUI request.Method = "POST"; request.ContentType = "applicaiton/json"; request.Timeout = 10000; - - using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream())) - { - string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," + - "\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," + - "\"allowDefault\":" + (allowDefault ? "true" : "false") + "}"; - streamWriter.Write(json); - streamWriter.Flush(); - streamWriter.Close(); - } + try + { + using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream())) + { + string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," + + "\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," + + "\"allowDefault\":" + (allowDefault ? "true" : "false") + "}"; + streamWriter.Write(json); + streamWriter.Flush(); + streamWriter.Close(); + } + } + catch (System.Net.WebException) + { + MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); + return; + } try { diff --git a/zerotierone/windows/WinUI/AboutView.xaml b/zto/windows/WinUI/AboutView.xaml similarity index 100% rename from zerotierone/windows/WinUI/AboutView.xaml rename to zto/windows/WinUI/AboutView.xaml diff --git a/zerotierone/windows/WinUI/AboutView.xaml.cs b/zto/windows/WinUI/AboutView.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/AboutView.xaml.cs rename to zto/windows/WinUI/AboutView.xaml.cs diff --git a/zerotierone/windows/WinUI/App.config b/zto/windows/WinUI/App.config similarity index 100% rename from zerotierone/windows/WinUI/App.config rename to zto/windows/WinUI/App.config diff --git a/zerotierone/windows/WinUI/App.xaml b/zto/windows/WinUI/App.xaml similarity index 100% rename from zerotierone/windows/WinUI/App.xaml rename to zto/windows/WinUI/App.xaml diff --git a/zerotierone/windows/WinUI/App.xaml.cs b/zto/windows/WinUI/App.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/App.xaml.cs rename to zto/windows/WinUI/App.xaml.cs diff --git a/zerotierone/windows/WinUI/JoinNetworkView.xaml b/zto/windows/WinUI/JoinNetworkView.xaml similarity index 100% rename from zerotierone/windows/WinUI/JoinNetworkView.xaml rename to zto/windows/WinUI/JoinNetworkView.xaml diff --git a/zerotierone/windows/WinUI/JoinNetworkView.xaml.cs b/zto/windows/WinUI/JoinNetworkView.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/JoinNetworkView.xaml.cs rename to zto/windows/WinUI/JoinNetworkView.xaml.cs diff --git a/zerotierone/windows/WinUI/MainWindow.xaml.cs b/zto/windows/WinUI/MainWindow.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/MainWindow.xaml.cs rename to zto/windows/WinUI/MainWindow.xaml.cs diff --git a/zerotierone/windows/WinUI/NetworkInfoView.xaml b/zto/windows/WinUI/NetworkInfoView.xaml similarity index 100% rename from zerotierone/windows/WinUI/NetworkInfoView.xaml rename to zto/windows/WinUI/NetworkInfoView.xaml diff --git a/zerotierone/windows/WinUI/NetworkInfoView.xaml.cs b/zto/windows/WinUI/NetworkInfoView.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/NetworkInfoView.xaml.cs rename to zto/windows/WinUI/NetworkInfoView.xaml.cs diff --git a/zerotierone/windows/WinUI/NetworkListView.xaml b/zto/windows/WinUI/NetworkListView.xaml similarity index 100% rename from zerotierone/windows/WinUI/NetworkListView.xaml rename to zto/windows/WinUI/NetworkListView.xaml diff --git a/zerotierone/windows/WinUI/NetworkListView.xaml.cs b/zto/windows/WinUI/NetworkListView.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/NetworkListView.xaml.cs rename to zto/windows/WinUI/NetworkListView.xaml.cs diff --git a/zerotierone/windows/WinUI/NetworkMonitor.cs b/zto/windows/WinUI/NetworkMonitor.cs similarity index 98% rename from zerotierone/windows/WinUI/NetworkMonitor.cs rename to zto/windows/WinUI/NetworkMonitor.cs index 4877d34..c276079 100644 --- a/zerotierone/windows/WinUI/NetworkMonitor.cs +++ b/zto/windows/WinUI/NetworkMonitor.cs @@ -102,6 +102,11 @@ namespace WinUI private void apiNetworkCallback(List networks) { + if (networks == null) + { + return; + } + lock (_knownNetworks) { _knownNetworks = _knownNetworks.Union(networks, new NetworkEqualityComparer()).ToList(); diff --git a/zerotierone/windows/WinUI/NetworkRoute.cs b/zto/windows/WinUI/NetworkRoute.cs similarity index 100% rename from zerotierone/windows/WinUI/NetworkRoute.cs rename to zto/windows/WinUI/NetworkRoute.cs diff --git a/zerotierone/windows/WinUI/NetworksPage.xaml b/zto/windows/WinUI/NetworksPage.xaml similarity index 100% rename from zerotierone/windows/WinUI/NetworksPage.xaml rename to zto/windows/WinUI/NetworksPage.xaml diff --git a/zerotierone/windows/WinUI/NetworksPage.xaml.cs b/zto/windows/WinUI/NetworksPage.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/NetworksPage.xaml.cs rename to zto/windows/WinUI/NetworksPage.xaml.cs diff --git a/zerotierone/windows/WinUI/PeersPage.xaml b/zto/windows/WinUI/PeersPage.xaml similarity index 100% rename from zerotierone/windows/WinUI/PeersPage.xaml rename to zto/windows/WinUI/PeersPage.xaml diff --git a/zerotierone/windows/WinUI/PeersPage.xaml.cs b/zto/windows/WinUI/PeersPage.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/PeersPage.xaml.cs rename to zto/windows/WinUI/PeersPage.xaml.cs diff --git a/zerotierone/windows/WinUI/PreferencesView.xaml b/zto/windows/WinUI/PreferencesView.xaml similarity index 100% rename from zerotierone/windows/WinUI/PreferencesView.xaml rename to zto/windows/WinUI/PreferencesView.xaml diff --git a/zerotierone/windows/WinUI/PreferencesView.xaml.cs b/zto/windows/WinUI/PreferencesView.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/PreferencesView.xaml.cs rename to zto/windows/WinUI/PreferencesView.xaml.cs diff --git a/zerotierone/windows/WinUI/Properties/AssemblyInfo.cs b/zto/windows/WinUI/Properties/AssemblyInfo.cs similarity index 100% rename from zerotierone/windows/WinUI/Properties/AssemblyInfo.cs rename to zto/windows/WinUI/Properties/AssemblyInfo.cs diff --git a/zerotierone/windows/WinUI/Properties/Resources.Designer.cs b/zto/windows/WinUI/Properties/Resources.Designer.cs similarity index 100% rename from zerotierone/windows/WinUI/Properties/Resources.Designer.cs rename to zto/windows/WinUI/Properties/Resources.Designer.cs diff --git a/zerotierone/windows/WinUI/Properties/Resources.resx b/zto/windows/WinUI/Properties/Resources.resx similarity index 100% rename from zerotierone/windows/WinUI/Properties/Resources.resx rename to zto/windows/WinUI/Properties/Resources.resx diff --git a/zerotierone/windows/WinUI/Properties/Settings.Designer.cs b/zto/windows/WinUI/Properties/Settings.Designer.cs similarity index 100% rename from zerotierone/windows/WinUI/Properties/Settings.Designer.cs rename to zto/windows/WinUI/Properties/Settings.Designer.cs diff --git a/zerotierone/windows/WinUI/Properties/Settings.settings b/zto/windows/WinUI/Properties/Settings.settings similarity index 100% rename from zerotierone/windows/WinUI/Properties/Settings.settings rename to zto/windows/WinUI/Properties/Settings.settings diff --git a/zerotierone/windows/WinUI/Resources/ZeroTierIcon.ico b/zto/windows/WinUI/Resources/ZeroTierIcon.ico similarity index 100% rename from zerotierone/windows/WinUI/Resources/ZeroTierIcon.ico rename to zto/windows/WinUI/Resources/ZeroTierIcon.ico diff --git a/zerotierone/windows/WinUI/Simple Styles.xaml b/zto/windows/WinUI/Simple Styles.xaml similarity index 100% rename from zerotierone/windows/WinUI/Simple Styles.xaml rename to zto/windows/WinUI/Simple Styles.xaml diff --git a/zerotierone/windows/WinUI/Themes/Generic.xaml b/zto/windows/WinUI/Themes/Generic.xaml similarity index 100% rename from zerotierone/windows/WinUI/Themes/Generic.xaml rename to zto/windows/WinUI/Themes/Generic.xaml diff --git a/zerotierone/windows/WinUI/ToolbarItem.xaml b/zto/windows/WinUI/ToolbarItem.xaml similarity index 100% rename from zerotierone/windows/WinUI/ToolbarItem.xaml rename to zto/windows/WinUI/ToolbarItem.xaml diff --git a/zerotierone/windows/WinUI/ToolbarItem.xaml.cs b/zto/windows/WinUI/ToolbarItem.xaml.cs similarity index 100% rename from zerotierone/windows/WinUI/ToolbarItem.xaml.cs rename to zto/windows/WinUI/ToolbarItem.xaml.cs diff --git a/zerotierone/windows/WinUI/WinUI.csproj b/zto/windows/WinUI/WinUI.csproj similarity index 100% rename from zerotierone/windows/WinUI/WinUI.csproj rename to zto/windows/WinUI/WinUI.csproj diff --git a/zerotierone/windows/WinUI/ZeroTierIcon.ico b/zto/windows/WinUI/ZeroTierIcon.ico similarity index 100% rename from zerotierone/windows/WinUI/ZeroTierIcon.ico rename to zto/windows/WinUI/ZeroTierIcon.ico diff --git a/zerotierone/windows/WinUI/ZeroTierNetwork.cs b/zto/windows/WinUI/ZeroTierNetwork.cs similarity index 100% rename from zerotierone/windows/WinUI/ZeroTierNetwork.cs rename to zto/windows/WinUI/ZeroTierNetwork.cs diff --git a/zerotierone/windows/WinUI/ZeroTierPeer.cs b/zto/windows/WinUI/ZeroTierPeer.cs similarity index 100% rename from zerotierone/windows/WinUI/ZeroTierPeer.cs rename to zto/windows/WinUI/ZeroTierPeer.cs diff --git a/zerotierone/windows/WinUI/ZeroTierPeerPhysicalPath.cs b/zto/windows/WinUI/ZeroTierPeerPhysicalPath.cs similarity index 100% rename from zerotierone/windows/WinUI/ZeroTierPeerPhysicalPath.cs rename to zto/windows/WinUI/ZeroTierPeerPhysicalPath.cs diff --git a/zerotierone/windows/WinUI/ZeroTierStatus.cs b/zto/windows/WinUI/ZeroTierStatus.cs similarity index 100% rename from zerotierone/windows/WinUI/ZeroTierStatus.cs rename to zto/windows/WinUI/ZeroTierStatus.cs diff --git a/zerotierone/windows/WinUI/app.manifest b/zto/windows/WinUI/app.manifest similarity index 100% rename from zerotierone/windows/WinUI/app.manifest rename to zto/windows/WinUI/app.manifest diff --git a/zerotierone/windows/WinUI/packages.config b/zto/windows/WinUI/packages.config similarity index 100% rename from zerotierone/windows/WinUI/packages.config rename to zto/windows/WinUI/packages.config diff --git a/zerotierone/windows/ZeroTierOne.sln b/zto/windows/ZeroTierOne.sln similarity index 79% rename from zerotierone/windows/ZeroTierOne.sln rename to zto/windows/ZeroTierOne.sln index a136dd0..9baadd8 100644 --- a/zerotierone/windows/ZeroTierOne.sln +++ b/zto/windows/ZeroTierOne.sln @@ -20,57 +20,46 @@ Global CD_ROM|Mixed Platforms = CD_ROM|Mixed Platforms CD_ROM|Win32 = CD_ROM|Win32 CD_ROM|x64 = CD_ROM|x64 - CD_ROM|x86 = CD_ROM|x86 Debug|Any CPU = Debug|Any CPU Debug|Mixed Platforms = Debug|Mixed Platforms Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 DVD-5|Any CPU = DVD-5|Any CPU DVD-5|Mixed Platforms = DVD-5|Mixed Platforms DVD-5|Win32 = DVD-5|Win32 DVD-5|x64 = DVD-5|x64 - DVD-5|x86 = DVD-5|x86 Release|Any CPU = Release|Any CPU Release|Mixed Platforms = Release|Mixed Platforms Release|Win32 = Release|Win32 Release|x64 = Release|x64 - Release|x86 = Release|x86 SingleImage|Any CPU = SingleImage|Any CPU SingleImage|Mixed Platforms = SingleImage|Mixed Platforms SingleImage|Win32 = SingleImage|Win32 SingleImage|x64 = SingleImage|x64 - SingleImage|x86 = SingleImage|x86 Vista Debug|Any CPU = Vista Debug|Any CPU Vista Debug|Mixed Platforms = Vista Debug|Mixed Platforms Vista Debug|Win32 = Vista Debug|Win32 Vista Debug|x64 = Vista Debug|x64 - Vista Debug|x86 = Vista Debug|x86 Vista Release|Any CPU = Vista Release|Any CPU Vista Release|Mixed Platforms = Vista Release|Mixed Platforms Vista Release|Win32 = Vista Release|Win32 Vista Release|x64 = Vista Release|x64 - Vista Release|x86 = Vista Release|x86 Win7 Debug|Any CPU = Win7 Debug|Any CPU Win7 Debug|Mixed Platforms = Win7 Debug|Mixed Platforms Win7 Debug|Win32 = Win7 Debug|Win32 Win7 Debug|x64 = Win7 Debug|x64 - Win7 Debug|x86 = Win7 Debug|x86 Win7 Release|Any CPU = Win7 Release|Any CPU Win7 Release|Mixed Platforms = Win7 Release|Mixed Platforms Win7 Release|Win32 = Win7 Release|Win32 Win7 Release|x64 = Win7 Release|x64 - Win7 Release|x86 = Win7 Release|x86 Win8 Debug|Any CPU = Win8 Debug|Any CPU Win8 Debug|Mixed Platforms = Win8 Debug|Mixed Platforms Win8 Debug|Win32 = Win8 Debug|Win32 Win8 Debug|x64 = Win8 Debug|x64 - Win8 Debug|x86 = Win8 Debug|x86 Win8 Release|Any CPU = Win8 Release|Any CPU Win8 Release|Mixed Platforms = Win8 Release|Mixed Platforms Win8 Release|Win32 = Win8 Release|Win32 Win8 Release|x64 = Win8 Release|x64 - Win8 Release|x86 = Win8 Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|Any CPU.ActiveCfg = Release|Win32 @@ -83,9 +72,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|x64.ActiveCfg = Release|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|x64.Build.0 = Release|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|x64.Deploy.0 = Release|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.CD_ROM|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|Any CPU.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|Mixed Platforms.Build.0 = Debug|Win32 @@ -95,9 +81,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|Win32.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|x64.ActiveCfg = Debug|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|x64.Build.0 = Debug|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Debug|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|Any CPU.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|Mixed Platforms.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|Mixed Platforms.Build.0 = Debug|Win32 @@ -108,9 +91,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|x64.ActiveCfg = Debug|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|x64.Build.0 = Debug|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|x64.Deploy.0 = Debug|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.DVD-5|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|Any CPU.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|Mixed Platforms.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|Mixed Platforms.Build.0 = Release|Win32 @@ -119,9 +99,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|Win32.Build.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|Win32.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|x64.ActiveCfg = Release|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|x86.ActiveCfg = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|x86.Build.0 = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Release|x86.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|Any CPU.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|Mixed Platforms.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|Mixed Platforms.Build.0 = Release|Win32 @@ -132,9 +109,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|x64.ActiveCfg = Release|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|x64.Build.0 = Release|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|x64.Deploy.0 = Release|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.SingleImage|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|Any CPU.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|Mixed Platforms.Build.0 = Debug|Win32 @@ -143,9 +117,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|Win32.Build.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|Win32.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|x64.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Debug|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|Any CPU.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|Mixed Platforms.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|Mixed Platforms.Build.0 = Release|Win32 @@ -154,9 +125,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|Win32.Build.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|Win32.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|x64.ActiveCfg = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|x86.ActiveCfg = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|x86.Build.0 = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Vista Release|x86.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Any CPU.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Mixed Platforms.Build.0 = Debug|Win32 @@ -166,9 +134,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Win32.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x64.ActiveCfg = Debug|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x64.Build.0 = Debug|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|Any CPU.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|Mixed Platforms.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|Mixed Platforms.Build.0 = Release|Win32 @@ -178,9 +143,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|Win32.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x64.ActiveCfg = Release|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x64.Build.0 = Release|x64 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x86.ActiveCfg = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x86.Build.0 = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x86.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|Any CPU.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|Mixed Platforms.Build.0 = Debug|Win32 @@ -189,9 +151,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|Win32.Build.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|Win32.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|x64.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|x86.ActiveCfg = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|x86.Build.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Debug|x86.Deploy.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|Any CPU.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|Mixed Platforms.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|Mixed Platforms.Build.0 = Release|Win32 @@ -200,9 +159,6 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|Win32.Build.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|Win32.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x64.ActiveCfg = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x86.ActiveCfg = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x86.Build.0 = Release|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win8 Release|x86.Deploy.0 = Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Any CPU.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Mixed Platforms.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|Mixed Platforms.Build.0 = Win8 Release|Win32 @@ -213,9 +169,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x64.ActiveCfg = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x64.Build.0 = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x64.Deploy.0 = Win8 Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x86.ActiveCfg = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x86.Build.0 = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.CD_ROM|x86.Deploy.0 = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Any CPU.ActiveCfg = Win7 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Mixed Platforms.ActiveCfg = Win7 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|Mixed Platforms.Build.0 = Win7 Debug|Win32 @@ -226,9 +179,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x64.ActiveCfg = Win7 Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x64.Build.0 = Win7 Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x64.Deploy.0 = Win7 Debug|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x86.ActiveCfg = Win7 Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x86.Build.0 = Win7 Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Debug|x86.Deploy.0 = Win7 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Any CPU.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Mixed Platforms.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|Mixed Platforms.Build.0 = Win8 Release|Win32 @@ -239,9 +189,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x64.ActiveCfg = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x64.Build.0 = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x64.Deploy.0 = Win8 Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x86.ActiveCfg = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x86.Build.0 = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.DVD-5|x86.Deploy.0 = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Any CPU.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Mixed Platforms.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|Mixed Platforms.Build.0 = Win8 Release|Win32 @@ -252,9 +199,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x64.ActiveCfg = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x64.Build.0 = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x64.Deploy.0 = Win8 Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x86.ActiveCfg = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x86.Build.0 = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Release|x86.Deploy.0 = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Any CPU.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Mixed Platforms.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|Mixed Platforms.Build.0 = Win8 Release|Win32 @@ -265,9 +209,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x64.ActiveCfg = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x64.Build.0 = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x64.Deploy.0 = Win8 Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x86.ActiveCfg = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x86.Build.0 = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.SingleImage|x86.Deploy.0 = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Any CPU.ActiveCfg = Vista Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Mixed Platforms.ActiveCfg = Vista Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|Mixed Platforms.Build.0 = Vista Debug|Win32 @@ -278,9 +219,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x64.ActiveCfg = Vista Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x64.Build.0 = Vista Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x64.Deploy.0 = Vista Debug|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x86.ActiveCfg = Vista Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x86.Build.0 = Vista Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Debug|x86.Deploy.0 = Vista Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Any CPU.ActiveCfg = Vista Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Mixed Platforms.ActiveCfg = Vista Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|Mixed Platforms.Build.0 = Vista Release|Win32 @@ -291,9 +229,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x64.ActiveCfg = Vista Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x64.Build.0 = Vista Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x64.Deploy.0 = Vista Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x86.ActiveCfg = Vista Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x86.Build.0 = Vista Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Vista Release|x86.Deploy.0 = Vista Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Any CPU.ActiveCfg = Win7 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Mixed Platforms.ActiveCfg = Win7 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|Mixed Platforms.Build.0 = Win7 Debug|Win32 @@ -304,9 +239,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x86.ActiveCfg = Win7 Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x86.Build.0 = Win7 Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Debug|x86.Deploy.0 = Win7 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Any CPU.ActiveCfg = Win7 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Mixed Platforms.ActiveCfg = Win7 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|Mixed Platforms.Build.0 = Win7 Release|Win32 @@ -317,9 +249,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x64.Build.0 = Win7 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x86.ActiveCfg = Win7 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x86.Build.0 = Win7 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win7 Release|x86.Deploy.0 = Win7 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Any CPU.ActiveCfg = Win8 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Mixed Platforms.ActiveCfg = Win8 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|Mixed Platforms.Build.0 = Win8 Debug|Win32 @@ -330,9 +259,6 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x86.ActiveCfg = Win8 Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x86.Build.0 = Win8 Debug|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Debug|x86.Deploy.0 = Win8 Debug|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Any CPU.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Mixed Platforms.ActiveCfg = Win8 Release|Win32 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|Mixed Platforms.Build.0 = Win8 Release|Win32 @@ -343,58 +269,48 @@ Global {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x64.Build.0 = Win8 Release|x64 {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x86.ActiveCfg = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x86.Build.0 = Win8 Release|Win32 - {43BA7584-D4DB-4F7C-90FC-E2B18A68A213}.Win8 Release|x86.Deploy.0 = Win8 Release|Win32 {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|Mixed Platforms.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|Mixed Platforms.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|x64.ActiveCfg = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.CD_ROM|x86.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|Any CPU.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|Win32.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|x64.ActiveCfg = Debug|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Debug|x86.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|Any CPU.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|Mixed Platforms.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|Mixed Platforms.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|Win32.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|x64.ActiveCfg = Debug|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.DVD-5|x86.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|Mixed Platforms.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|x64.ActiveCfg = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Release|x86.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|Mixed Platforms.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|Mixed Platforms.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|x64.ActiveCfg = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.SingleImage|x86.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|Any CPU.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|Any CPU.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|Mixed Platforms.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|Win32.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|x64.ActiveCfg = Debug|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Debug|x86.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|Mixed Platforms.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|Mixed Platforms.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|x64.ActiveCfg = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Vista Release|x86.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|Any CPU.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|Any CPU.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -402,8 +318,6 @@ Global {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|Win32.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x64.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x64.Build.0 = Debug|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x86.ActiveCfg = Debug|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x86.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -411,22 +325,18 @@ Global {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x64.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x64.Build.0 = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x86.ActiveCfg = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x86.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Any CPU.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Any CPU.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Mixed Platforms.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Win32.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|x64.ActiveCfg = Debug|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|x86.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|Mixed Platforms.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|Mixed Platforms.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|x64.ActiveCfg = Release|Any CPU - {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Release|x86.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|Any CPU.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -435,8 +345,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|Win32.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|x64.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|x64.Build.0 = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|x86.ActiveCfg = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.CD_ROM|x86.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -445,8 +353,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|Win32.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|x64.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|x64.Build.0 = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|x86.ActiveCfg = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Debug|x86.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|Any CPU.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -455,8 +361,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|Win32.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|x64.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|x64.Build.0 = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|x86.ActiveCfg = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.DVD-5|x86.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|Any CPU.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -465,8 +369,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|Win32.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|x64.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|x64.Build.0 = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|x86.ActiveCfg = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Release|x86.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|Any CPU.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -475,8 +377,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|Win32.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|x64.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|x64.Build.0 = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|x86.ActiveCfg = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.SingleImage|x86.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|Any CPU.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -485,8 +385,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|Win32.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|x64.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|x64.Build.0 = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|x86.ActiveCfg = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Debug|x86.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|Any CPU.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|Any CPU.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -495,8 +393,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|Win32.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|x64.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|x64.Build.0 = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|x86.ActiveCfg = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Vista Release|x86.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|Any CPU.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -505,8 +401,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|Win32.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|x64.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|x64.Build.0 = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|x86.ActiveCfg = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Debug|x86.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|Any CPU.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|Any CPU.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -515,8 +409,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|Win32.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|x64.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|x64.Build.0 = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|x86.ActiveCfg = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win7 Release|x86.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|Any CPU.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -525,8 +417,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|Win32.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|x64.ActiveCfg = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|x64.Build.0 = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|x86.ActiveCfg = Debug|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Debug|x86.Build.0 = Debug|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|Any CPU.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|Any CPU.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -535,8 +425,6 @@ Global {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|Win32.Build.0 = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|x64.ActiveCfg = Release|Any CPU {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|x64.Build.0 = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|x86.ActiveCfg = Release|Any CPU - {6D27214A-087B-4484-B898-AD2A13FA3B9E}.Win8 Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/zerotierone/windows/copyutil/App.config b/zto/windows/copyutil/App.config similarity index 100% rename from zerotierone/windows/copyutil/App.config rename to zto/windows/copyutil/App.config diff --git a/zerotierone/windows/copyutil/Program.cs b/zto/windows/copyutil/Program.cs similarity index 100% rename from zerotierone/windows/copyutil/Program.cs rename to zto/windows/copyutil/Program.cs diff --git a/zerotierone/windows/copyutil/Properties/AssemblyInfo.cs b/zto/windows/copyutil/Properties/AssemblyInfo.cs similarity index 100% rename from zerotierone/windows/copyutil/Properties/AssemblyInfo.cs rename to zto/windows/copyutil/Properties/AssemblyInfo.cs diff --git a/zerotierone/windows/copyutil/copyutil.csproj b/zto/windows/copyutil/copyutil.csproj similarity index 100% rename from zerotierone/windows/copyutil/copyutil.csproj rename to zto/windows/copyutil/copyutil.csproj diff --git a/zerotierone/windows/packages/.gitignore b/zto/windows/packages/.gitignore similarity index 100% rename from zerotierone/windows/packages/.gitignore rename to zto/windows/packages/.gitignore diff --git a/zerotierone/windows/packages/repositories.config b/zto/windows/packages/repositories.config similarity index 100% rename from zerotierone/windows/packages/repositories.config rename to zto/windows/packages/repositories.config diff --git a/zerotierone/zerotier-one.spec b/zto/zerotier-one.spec similarity index 69% rename from zerotierone/zerotier-one.spec rename to zto/zerotier-one.spec index 5c01e5b..0a3b045 100644 --- a/zerotierone/zerotier-one.spec +++ b/zto/zerotier-one.spec @@ -1,18 +1,16 @@ Name: zerotier-one -Version: 1.1.14 -Release: 0.1%{?dist} +Version: 1.2.0 +Release: 1%{?dist} Summary: ZeroTier One network virtualization service License: GPLv3 URL: https://www.zerotier.com -Source0: %{name}-%{version}.tar.gz %if 0%{?rhel} >= 7 BuildRequires: systemd %endif %if 0%{?fedora} >= 21 -BuildRequires: libnatpmp-devel BuildRequires: systemd %endif @@ -20,6 +18,7 @@ Requires: iproute %if 0%{?rhel} >= 7 Requires: systemd +Requires(pre): /usr/sbin/useradd, /usr/bin/getent %endif %if 0%{?rhel} <= 6 @@ -27,15 +26,8 @@ Requires: chkconfig %endif %if 0%{?fedora} >= 21 -Requires: libnatpmp Requires: systemd -%endif - -Provides: bundled(http-parser) = 2.7.0 -Provides: bundled(miniupnpc) = 2.0.20161216 - -%if 0%{?rhel} >= 6 -Provides: bundled(libnatpmp) = 20131126 +Requires(pre): /usr/sbin/useradd, /usr/bin/getent %endif %description @@ -51,33 +43,43 @@ like conventional VPNs or VLANs. It can run on native systems, VMs, or containers (Docker, OpenVZ, etc.). %prep -rm -rf * -ln -s %{getenv:PWD} %{name}-%{version} -tar --exclude=%{name}-%{version}/.git --exclude=%{name}-%{version}/%{name}-%{version} -czf %{_sourcedir}/%{name}-%{version}.tar.gz %{name}-%{version}/* -rm -f %{name}-%{version} -cp -a %{getenv:PWD}/* . +#rm -rf * +#ln -s %{getenv:PWD} %{name}-%{version} +#tar --exclude=%{name}-%{version}/.git --exclude=%{name}-%{version}/%{name}-%{version} -czf %{_sourcedir}/%{name}-%{version}.tar.gz %{name}-%{version}/* +#rm -f %{name}-%{version} +#cp -a %{getenv:PWD}/* . %build -%if 0%{?rhel} <= 7 -make CFLAGS="`echo %{optflags} | sed s/stack-protector-strong/stack-protector/`" CXXFLAGS="`echo %{optflags} | sed s/stack-protector-strong/stack-protector/`" ZT_USE_MINIUPNPC=1 %{?_smp_mflags} one manpages selftest -%else -make CFLAGS="%{optflags}" CXXFLAGS="%{optflags}" ZT_USE_MINIUPNPC=1 %{?_smp_mflags} one manpages selftest +#%if 0%{?rhel} <= 7 +#make CFLAGS="`echo %{optflags} | sed s/stack-protector-strong/stack-protector/`" CXXFLAGS="`echo %{optflags} | sed s/stack-protector-strong/stack-protector/`" ZT_USE_MINIUPNPC=1 %{?_smp_mflags} one manpages selftest +#%else +#make CFLAGS="%{optflags}" CXXFLAGS="%{optflags}" ZT_USE_MINIUPNPC=1 %{?_smp_mflags} one manpages selftest +#%endif + +%pre +%if 0%{?rhel} >= 7 +/usr/bin/getent passwd zerotier-one || /usr/sbin/useradd -r -d /var/lib/zerotier-one -s /sbin/nologin zerotier-one +%endif +%if 0%{?fedora} >= 21 +/usr/bin/getent passwd zerotier-one || /usr/sbin/useradd -r -d /var/lib/zerotier-one -s /sbin/nologin zerotier-one %endif %install rm -rf $RPM_BUILD_ROOT +pushd %{getenv:PWD} make install DESTDIR=$RPM_BUILD_ROOT +popd %if 0%{?rhel} >= 7 mkdir -p $RPM_BUILD_ROOT%{_unitdir} -cp debian/zerotier-one.service $RPM_BUILD_ROOT%{_unitdir}/%{name}.service +cp %{getenv:PWD}/debian/zerotier-one.service $RPM_BUILD_ROOT%{_unitdir}/%{name}.service %endif %if 0%{?fedora} >= 21 mkdir -p $RPM_BUILD_ROOT%{_unitdir} -cp debian/zerotier-one.service $RPM_BUILD_ROOT%{_unitdir}/%{name}.service +cp ${getenv:PWD}/debian/zerotier-one.service $RPM_BUILD_ROOT%{_unitdir}/%{name}.service %endif %if 0%{?rhel} <= 6 mkdir -p $RPM_BUILD_ROOT/etc/init.d -cp ext/installfiles/linux/zerotier-one.init.rhel6 $RPM_BUILD_ROOT/etc/init.d/zerotier-one +cp %{getenv:PWD}/ext/installfiles/linux/zerotier-one.init.rhel6 $RPM_BUILD_ROOT/etc/init.d/zerotier-one chmod 0755 $RPM_BUILD_ROOT/etc/init.d/zerotier-one %endif