Update build process, Go glue builds now.

This commit is contained in:
Adam Ierymenko 2019-09-20 15:00:53 -07:00
parent ed2024285d
commit e0ddbc2f28
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
7 changed files with 70 additions and 153 deletions

View file

@ -1,5 +1,3 @@
# CMake build script for ZeroTier One
cmake_minimum_required (VERSION 3.8) cmake_minimum_required (VERSION 3.8)
if(${CMAKE_VERSION} VERSION_LESS 3.15) if(${CMAKE_VERSION} VERSION_LESS 3.15)
@ -13,17 +11,11 @@ if(WIN32)
set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE) set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
endif(WIN32) endif(WIN32)
# set(ZEROTIER_ONE_VERSION_MAJOR 2 CACHE INTERNAL "")
# ZeroTier One Version Config set(ZEROTIER_ONE_VERSION_MINOR 0 CACHE INTERNAL "")
#
set(ZEROTIER_ONE_VERSION_MAJOR 1 CACHE INTERNAL "")
set(ZEROTIER_ONE_VERSION_MINOR 9 CACHE INTERNAL "")
set(ZEROTIER_ONE_VERSION_REVISION 0 CACHE INTERNAL "") set(ZEROTIER_ONE_VERSION_REVISION 0 CACHE INTERNAL "")
set(ZEROTIER_ONE_VERSION_BUILD 0 CACHE INTERNAL "") set(ZEROTIER_ONE_VERSION_BUILD 0 CACHE INTERNAL "")
#
# Set a default build type if none was specified
#
set(default_build_type "Release") set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git") if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug") set(default_build_type "Debug")
@ -59,8 +51,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DZT_TRACE) add_definitions(-DZT_TRACE)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug") endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
project(zerotier-one project(zerotier
DESCRIPTION "ZeroTier One" DESCRIPTION "ZeroTier Network Hypervisor"
LANGUAGES CXX C) LANGUAGES CXX C)
if(WIN32) if(WIN32)
@ -141,20 +133,20 @@ endif()
add_subdirectory(node) add_subdirectory(node)
add_subdirectory(controller) add_subdirectory(controller)
add_subdirectory(osdep) add_subdirectory(osdep)
#add_subdirectory(service)
add_subdirectory(root) add_subdirectory(root)
add_subdirectory(go/native)
if(WIN32) #if(WIN32)
add_subdirectory("windows/WinUI") # add_subdirectory("windows/WinUI")
add_subdirectory("windows/copyutil") # add_subdirectory("windows/copyutil")
add_definitions(-DNOMINMAX) # add_definitions(-DNOMINMAX)
endif(WIN32) #endif(WIN32)
set(libs set(
# zt_service
zt_osdep zt_osdep
zt_core zt_core
zt_controller zt_controller
zt_go_native
) )
configure_file( configure_file(
@ -162,40 +154,47 @@ configure_file(
${CMAKE_BINARY_DIR}/version.h ${CMAKE_BINARY_DIR}/version.h
) )
set(src #set(src
one.cpp # one.cpp
"ext/http-parser/http_parser.c" # "ext/http-parser/http_parser.c"
) #)
set(headers #set(headers
"ext/http-parser/http_parser.h" # "ext/http-parser/http_parser.h"
) #)
if(WIN32) if(WIN32)
set(libs ${libs} wsock32 ws2_32 rpcrt4 iphlpapi) set(libs ${libs} wsock32 ws2_32 rpcrt4 iphlpapi)
set(src
${src}
"windows/ZeroTierOne/ServiceBase.cpp"
"windows/ZeroTierOne/ServiceInstaller.cpp"
"windows/ZeroTierOne/ZeroTierOneService.cpp"
"windows/ZeroTierOne/ZeroTierOne.rc"
)
set(headers
${headers}
"windows/ZeroTierOne/ServiceBase.h"
"windows/ZeroTierOne/ServiceInstaller.h"
"windows/ZeroTierOne/ZeroTierOneService.h"
)
else(WIN32) else(WIN32)
set(libs ${libs} pthread resolv) set(libs ${libs} pthread)
endif(WIN32) endif(WIN32)
if(BUILD_CENTRAL_CONTROLLER) #if(WIN32)
set(libs ${libs} rabbitmq-static ${PostgreSQL_LIBRARIES}) # set(libs ${libs} wsock32 ws2_32 rpcrt4 iphlpapi)
endif(BUILD_CENTRAL_CONTROLLER) # set(src
# ${src}
# "windows/ZeroTierOne/ServiceBase.cpp"
# "windows/ZeroTierOne/ServiceInstaller.cpp"
# "windows/ZeroTierOne/ZeroTierOneService.cpp"
# "windows/ZeroTierOne/ZeroTierOne.rc"
# )
# set(headers
# ${headers}
# "windows/ZeroTierOne/ServiceBase.h"
# "windows/ZeroTierOne/ServiceInstaller.h"
# "windows/ZeroTierOne/ZeroTierOneService.h"
# )
#else(WIN32)
# set(libs ${libs} pthread resolv)
#endif(WIN32)
add_executable(${PROJECT_NAME} ${src} ${headers}) #if(BUILD_CENTRAL_CONTROLLER)
target_link_libraries(${PROJECT_NAME} ${libs}) # set(libs ${libs} rabbitmq-static ${PostgreSQL_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) #endif(BUILD_CENTRAL_CONTROLLER)
#add_executable(${PROJECT_NAME} ${src} ${headers})
#target_link_libraries(${PROJECT_NAME} ${libs})
#target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
add_executable(zerotier-selftest selftest.cpp) add_executable(zerotier-selftest selftest.cpp)
target_link_libraries(zerotier-selftest ${libs}) target_link_libraries(zerotier-selftest ${libs} zt_core zt_osdep)
target_compile_features(zerotier-selftest PUBLIC cxx_std_11)

View file

@ -124,6 +124,7 @@ static int ZT_GoNode_VirtualNetworkConfigFunction(
if (cfg) if (cfg)
ev.data.nconf.conf = *cfg; ev.data.nconf.conf = *cfg;
reinterpret_cast<ZT_GoNode *>(uptr)->eq.post(ev); reinterpret_cast<ZT_GoNode *>(uptr)->eq.post(ev);
return 0;
} }
static void ZT_GoNode_VirtualNetworkFrameFunction( static void ZT_GoNode_VirtualNetworkFrameFunction(
@ -218,7 +219,7 @@ static ZT_ALWAYS_INLINE void doUdpSend(ZT_SOCKET sock,const struct sockaddr_stor
} }
} }
static void ZT_GoNode_WirePacketSendFunction( static int ZT_GoNode_WirePacketSendFunction(
ZT_Node *node, ZT_Node *node,
void *uptr, void *uptr,
void *tptr, void *tptr,
@ -242,6 +243,7 @@ static void ZT_GoNode_WirePacketSendFunction(
} }
} }
} }
return 0;
} }
static int ZT_GoNode_PathCheckFunction( static int ZT_GoNode_PathCheckFunction(
@ -291,14 +293,15 @@ extern "C" ZT_GoNode *ZT_GoNode_new(
{ {
try { try {
struct ZT_Node_Callbacks cb; struct ZT_Node_Callbacks cb;
cb.virtualNetworkConfigFunction = &ZT_GoNode_VirtualNetworkConfigFunction;
cb.virtualNetworkFrameFunction = &ZT_GoNode_VirtualNetworkFrameFunction;
cb.eventCallback = &ZT_GoNode_EventCallback;
cb.statePutFunction = &ZT_GoNode_StatePutFunction; cb.statePutFunction = &ZT_GoNode_StatePutFunction;
cb.stateGetFunction = &ZT_GoNode_StateGetFunction; cb.stateGetFunction = &ZT_GoNode_StateGetFunction;
cb.wirePacketSendFunction = &ZT_GoNode_WirePacketSendFunction;
cb.virtualNetworkFrameFunction = &ZT_GoNode_VirtualNetworkFrameFunction;
cb.virtualNetworkConfigFunction = &ZT_GoNode_VirtualNetworkConfigFunction;
cb.eventCallback = &ZT_GoNode_EventCallback;
cb.dnsResolver = &ZT_GoNode_DNSResolver;
cb.pathCheckFunction = &ZT_GoNode_PathCheckFunction; cb.pathCheckFunction = &ZT_GoNode_PathCheckFunction;
cb.pathLookupFunction = &ZT_GoNode_PathLookupFunction; cb.pathLookupFunction = &ZT_GoNode_PathLookupFunction;
cb.dnsResolver = &ZT_GoNode_DNSResolver;
ZT_GoNode_Impl *gn = new ZT_GoNode_Impl; ZT_GoNode_Impl *gn = new ZT_GoNode_Impl;
const int64_t now = OSUtils::now(); const int64_t now = OSUtils::now();
@ -334,17 +337,14 @@ extern "C" void ZT_GoNode_delete(ZT_GoNode *gn)
sd.type = ZT_GONODE_EVENT_SHUTDOWN; sd.type = ZT_GONODE_EVENT_SHUTDOWN;
gn->eq.post(sd); gn->eq.post(sd);
std::vector<std::thread> th;
gn->threads_l.lock(); gn->threads_l.lock();
for(auto t=gn->threads.begin();t!=gn->threads.end();++t) { for(auto t=gn->threads.begin();t!=gn->threads.end();++t) {
t->second.run = false; t->second.run = false;
shutdown(t->first,SHUT_RDWR); shutdown(t->first,SHUT_RDWR);
close(t->first); close(t->first);
th.emplace_back(t->second.thr); t->second.thr.join();
} }
gn->threads_l.unlock(); gn->threads_l.unlock();
for(auto t=th.begin();t!=th.end();++t)
t->join();
gn->taps_l.lock(); gn->taps_l.lock();
for(auto t=gn->taps.begin();t!=gn->taps.end();++t) for(auto t=gn->taps.begin();t!=gn->taps.end();++t)
@ -518,9 +518,10 @@ extern "C" int ZT_GoNode_phyStopListen(ZT_GoNode *gn,const char *dev,const char
} else ++t; } else ++t;
} }
} }
return 0;
} }
extern "C" int ZT_GoNode_waitForEvent(ZT_GoNode *gn,ZT_GoNodeEvent *ev) extern "C" void ZT_GoNode_waitForEvent(ZT_GoNode *gn,ZT_GoNodeEvent *ev)
{ {
gn->eq.get(*ev); gn->eq.get(*ev);
} }

View file

@ -45,7 +45,7 @@ struct ZT_GoNodeEvent_Impl
{ {
#ifdef __cplusplus #ifdef __cplusplus
inline ZT_GoNodeEvent_Impl() { memset(reinterpret_cast<void *>(this),0,sizeof(ZT_GoNodeEvent_Impl)); } inline ZT_GoNodeEvent_Impl() { memset(reinterpret_cast<void *>(this),0,sizeof(ZT_GoNodeEvent_Impl)); }
inline ZT_GoNodeEvent_Impl(const ZT_GoNodeEvent &ev) { memcpy(reinterpret_cast<void *>(this),reinterpret_cast<const void *>(&ev),sizeof(ZT_GoNodeEvent_Impl)); } inline ZT_GoNodeEvent_Impl(const ZT_GoNodeEvent_Impl &ev) { memcpy(reinterpret_cast<void *>(this),reinterpret_cast<const void *>(&ev),sizeof(ZT_GoNodeEvent_Impl)); }
inline ZT_GoNodeEvent_Impl &operator=(const ZT_GoNodeEvent_Impl &ev) { memcpy(reinterpret_cast<void *>(this),reinterpret_cast<const void *>(&ev),sizeof(ZT_GoNodeEvent_Impl)); return *this; } inline ZT_GoNodeEvent_Impl &operator=(const ZT_GoNodeEvent_Impl &ev) { memcpy(reinterpret_cast<void *>(this),reinterpret_cast<const void *>(&ev),sizeof(ZT_GoNodeEvent_Impl)); return *this; }
#endif #endif
@ -106,7 +106,7 @@ int ZT_GoNode_phyStartListen(ZT_GoNode *gn,const char *dev,const char *ip,const
/* Close all listener threads for a given local IP and port */ /* Close all listener threads for a given local IP and port */
int ZT_GoNode_phyStopListen(ZT_GoNode *gn,const char *dev,const char *ip,const int port); int ZT_GoNode_phyStopListen(ZT_GoNode *gn,const char *dev,const char *ip,const int port);
int ZT_GoNode_waitForEvent(ZT_GoNode *gn,ZT_GoNodeEvent *ev); void ZT_GoNode_waitForEvent(ZT_GoNode *gn,ZT_GoNodeEvent *ev);
ZT_GoTap *ZT_GoNode_join(ZT_GoNode *gn,uint64_t nwid); ZT_GoTap *ZT_GoNode_join(ZT_GoNode *gn,uint64_t nwid);

View file

@ -14,10 +14,10 @@
package ztnode package ztnode
//#cgo CFLAGS: -O3 //#cgo CFLAGS: -O3
//#cgo LDFLAGS: ${SRCDIR}/../../../build/node/libzt_core.a -lc++ //#cgo LDFLAGS: ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/go/native/libzt_go_native.a -lc++
//#define ZT_CGO 1 //#define ZT_CGO 1
//#include <stdint.h> //#include <stdint.h>
//#include "../../../include/ZeroTierCore.h" //#include "../../native/GoGlue.h"
//#if __has_include("../../../version.h") //#if __has_include("../../../version.h")
//#include "../../../version.h" //#include "../../../version.h"
//#else //#else
@ -27,6 +27,7 @@ package ztnode
//#define ZEROTIER_ONE_VERSION_BUILD 255 //#define ZEROTIER_ONE_VERSION_BUILD 255
//#endif //#endif
import "C" import "C"
import "sync"
const ( const (
// CoreVersionMajor is the major version of the ZeroTier core // CoreVersionMajor is the major version of the ZeroTier core
@ -44,5 +45,11 @@ const (
// Node is an instance of a ZeroTier node // Node is an instance of a ZeroTier node
type Node struct { type Node struct {
node *C.ZT_Node gn *C.ZT_GoNode
zn *C.ZT_Node
} }
var (
nodesByUserPtr map[uintptr]*Node
nodesByUserPtrLock sync.Mutex
)

View file

@ -30,15 +30,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <dirent.h> #include <dirent.h>
#include <netdb.h>
#include <arpa/nameser.h>
#include <resolv.h>
#ifndef C_IN
#define C_IN ns_c_in
#endif
#ifndef T_TXT
#define T_TXT ns_t_txt
#endif
#endif #endif
#ifdef __WINDOWS__ #ifdef __WINDOWS__
@ -300,54 +291,6 @@ int64_t OSUtils::getFileSize(const char *path)
return -1; return -1;
} }
std::vector<std::string> OSUtils::resolveTxt(const char *host)
{
static std::atomic_bool libresolvInitialized(false);
if (!libresolvInitialized.exchange(true))
res_init();
std::vector<std::string> results;
uint8_t answer[32768];
char name[1024];
int alen = res_search(host,C_IN,T_TXT,answer,sizeof(answer));
if ((alen > 12)&&(alen < sizeof(answer))) {
uint8_t *pptr = answer + 12;
uint8_t *const end = answer + alen;
int explen = dn_expand(answer,end,pptr,name,sizeof(name));
if (explen > 0) {
pptr += explen;
if ((pptr + 2) >= end) return results;
unsigned int rtype = ((unsigned int)pptr[0] << 8) | (unsigned int)pptr[1];
if (rtype == T_TXT) {
pptr += 4;
if (pptr >= end) return results;
while (pptr < end) {
explen = dn_expand(answer,end,pptr,name,sizeof(name));
if (explen > 0) {
pptr += explen;
if ((pptr + 2) >= end) return results;
rtype = ((unsigned int)pptr[0] << 8) | (unsigned int)pptr[1];
pptr += 10;
if (pptr >= end) return results;
unsigned int elen = *(pptr++);
if (elen) {
if ((pptr + elen) > end) return results;
if (rtype == T_TXT)
results.push_back(std::string((const char *)pptr,elen));
pptr += elen;
}
} else {
return results;
}
}
}
}
}
return results;
}
bool OSUtils::readFile(const char *path,std::string &buf) bool OSUtils::readFile(const char *path,std::string &buf)
{ {
char tmp[16384]; char tmp[16384];

View file

@ -185,14 +185,6 @@ public:
*/ */
static int64_t getFileSize(const char *path); static int64_t getFileSize(const char *path);
/**
* Get full DNS TXT results
*
* @param name DNS FQDN
* @return TXT record result(s) or empty on error or not found
*/
static std::vector<std::string> resolveTxt(const char *name);
/** /**
* @return Current time in milliseconds since epoch * @return Current time in milliseconds since epoch
*/ */

View file

@ -620,31 +620,6 @@ static int testIdentity()
} }
} }
/*
try {
std::cout << "[identity] Testing Locator and DNS TXT encoding... "; std::cout.flush();
uint8_t dnsPub[ZT_ECC384_PUBLIC_KEY_SIZE],dnsPriv[ZT_ECC384_PRIVATE_KEY_SIZE];
ECC384GenerateKey(dnsPub,dnsPriv);
std::unique_ptr<Locator> l(new Locator());
std::unique_ptr<Identity> ti(new Identity());
ti->generate(Identity::C25519);
l->add(InetAddress("127.0.0.1/9993"));
l->add(InetAddress("cafe:babe:face:dbad:deca:f::1/9993"));
l->finish(*ti,OSUtils::now());
l->sign(*ti);
auto tr = l->makeTxtRecords(dnsPub,dnsPriv);
std::unique_ptr<Locator> l2(new Locator());
if (!l2->decodeTxtRecords(tr.begin(),tr.end())) {
std::cout << "FAILED (decode TXT records returned false)" ZT_EOL_S;
return -1;
}
std::cout << "OK" ZT_EOL_S;
} catch (int e) {
std::cout << "FAILED (threw integer exception " << e << ")" ZT_EOL_S;
return -1;
}
*/
return 0; return 0;
} }