diff --git a/README.md b/README.md index d642620..8e9ddcb 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(ip); addr.sin_port = hton(port); -zts_simple_start(path, nwid); +zts_startjoin(path, nwid); int fd, err = 0; if ((fd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) { diff --git a/examples/node/binding.cc b/examples/node/binding.cc index b5ab3c8..dd1e129 100644 --- a/examples/node/binding.cc +++ b/examples/node/binding.cc @@ -9,7 +9,7 @@ struct ZT { } static void simpleStart(const char *path, const char *nwid) { - zts_simple_start(path, nwid); + zts_startjoin(path, nwid); } static void stop() { diff --git a/examples/visual_studio_cpp/libztHelloWorld/libztHelloWorld/libztHelloWorld.cpp b/examples/visual_studio_cpp/libztHelloWorld/libztHelloWorld/libztHelloWorld.cpp index c102231..d824cc0 100644 --- a/examples/visual_studio_cpp/libztHelloWorld/libztHelloWorld/libztHelloWorld.cpp +++ b/examples/visual_studio_cpp/libztHelloWorld/libztHelloWorld/libztHelloWorld.cpp @@ -11,7 +11,7 @@ int main() { printf("waiting for libzt to come online...\n"); - zts_simple_start("dlldir", "17d709436c2c5367"); + zts_startjoin("dlldir", "17d709436c2c5367"); printf("started. now performing a socket call\n"); int fd = zts_socket(AF_INET, SOCK_STREAM, 0); printf("fd=%d\n", fd); diff --git a/examples/ztproxy/ztproxy.cpp b/examples/ztproxy/ztproxy.cpp index 26d4f44..6aa5218 100644 --- a/examples/ztproxy/ztproxy.cpp +++ b/examples/ztproxy/ztproxy.cpp @@ -376,7 +376,7 @@ int main(int argc, char **argv) // Start ZeroTier Node // Join Network which contains resources we need to proxy DEBUG_INFO("waiting for libzt to come online"); - zts_simple_start(path.c_str(), nwid.c_str()); + zts_startjoin(path.c_str(), nwid.c_str()); ZeroTier::ZTProxy *proxy = new ZeroTier::ZTProxy(proxy_listen_port, nwid, path, internal_addr, internal_port, dns_nameserver); diff --git a/include/ZT1Service.h b/include/ZT1Service.h index a55c088..cf489b8 100644 --- a/include/ZT1Service.h +++ b/include/ZT1Service.h @@ -213,7 +213,7 @@ int zts_start(const char *path); * @param nwid A 16-digit hexidecimal virtual network ID * @return Returns 0 on success, -1 on failure */ -int zts_simple_start(const char *path, const char *nwid); +int zts_startjoin(const char *path, const char *nwid); /** * @brief Stops libzt (ZeroTier core services, stack drivers, stack threads, etc) diff --git a/include/libzt.h b/include/libzt.h index 34aab82..995fd8b 100644 --- a/include/libzt.h +++ b/include/libzt.h @@ -104,7 +104,7 @@ ZT_SOCKET_API int ZTCALL zts_start(const char *path); * @param nwid A 16-digit hexidecimal network identifier (e.g. Earth: `8056c2e21c000001`) * @return 0 if successful; or 1 if failed */ -ZT_SOCKET_API int ZTCALL zts_simple_start(const char *path, const char *nwid); +ZT_SOCKET_API int ZTCALL zts_startjoin(const char *path, const char *nwid); /** * @brief Stops the ZeroTier core service and disconnects from all virtual networks @@ -117,7 +117,7 @@ ZT_SOCKET_API void ZTCALL zts_stop(); /** * @brief Joins a virtual network * - * @usage Called after zts_start() or zts_simple_start() + * @usage Called after zts_start() or zts_startjoin() * @param nwid the 16-digit hexidecimal network identifier * @return */ diff --git a/src/ZT1Service.cpp b/src/ZT1Service.cpp index 2e71e45..5fbb920 100644 --- a/src/ZT1Service.cpp +++ b/src/ZT1Service.cpp @@ -163,7 +163,9 @@ ZeroTier::VirtualTap *getAnyTap() return vtap; } -int zts_get_device_id_from_file(const char *filepath, char *devID) { +int zts_get_device_id_from_file(const char *filepath, char *devID) +{ + DEBUG_EXTRA(); std::string fname("identity.public"); std::string fpath(filepath); if (ZeroTier::OSUtils::fileExists((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),false)) { @@ -178,7 +180,7 @@ int zts_get_device_id_from_file(const char *filepath, char *devID) { // Starts a ZeroTier service in the background void *zts_start_service(void *thread_id) { - DEBUG_INFO("homeDir=%s", ZeroTier::homeDir.c_str()); + DEBUG_INFO("path=%s", ZeroTier::homeDir.c_str()); // Where network .conf files will be stored ZeroTier::netDir = ZeroTier::homeDir + "/networks.d"; ZeroTier::zt1Service = (ZeroTier::OneService *)0; @@ -250,6 +252,7 @@ void *zts_start_service(void *thread_id) void disableTaps() { + DEBUG_EXTRA(); ZeroTier::_vtaps_lock.lock(); for (size_t i=0; igivenHomePath() + "/networks.d/" + nwid + ".conf"; if (ZeroTier::OSUtils::mkdir(ZeroTier::netDir) == false) { @@ -361,7 +373,9 @@ void zts_join(const char * nwid) { } } -void zts_join_soft(const char * filepath, const char * nwid) { +void zts_join_soft(const char * filepath, const char * nwid) +{ + DEBUG_EXTRA(); std::string net_dir = std::string(filepath) + "/networks.d/"; std::string confFile = net_dir + std::string(nwid) + ".conf"; if (ZeroTier::OSUtils::mkdir(net_dir) == false) { @@ -376,23 +390,30 @@ void zts_join_soft(const char * filepath, const char * nwid) { } } -void zts_leave(const char * nwid) { +void zts_leave(const char * nwid) +{ + DEBUG_EXTRA(); if (ZeroTier::zt1Service) { ZeroTier::zt1Service->leave(nwid); } } -void zts_leave_soft(const char * filepath, const char * nwid) { +void zts_leave_soft(const char * filepath, const char * nwid) +{ + DEBUG_EXTRA(); std::string net_dir = std::string(filepath) + "/networks.d/"; ZeroTier::OSUtils::rm((net_dir + nwid + ".conf").c_str()); } -int zts_running() { +int zts_running() +{ + DEBUG_EXTRA(); return ZeroTier::zt1Service == NULL ? false : ZeroTier::zt1Service->isRunning(); } int zts_start(const char *path) { + DEBUG_EXTRA(); if (ZeroTier::zt1Service) { return 0; // already initialized, ok } @@ -406,8 +427,9 @@ int zts_start(const char *path) return pthread_create(&service_thread, NULL, zts_start_service, NULL); } -int zts_simple_start(const char *path, const char *nwid) +int zts_startjoin(const char *path, const char *nwid) { + DEBUG_EXTRA(); ZT_NodeStatus status; int err = zts_start(path); while (zts_running() == false || ZeroTier::zt1Service->getNode() == NULL) { @@ -437,7 +459,9 @@ int zts_simple_start(const char *path, const char *nwid) return err; } -void zts_stop() { +void zts_stop() +{ + DEBUG_EXTRA(); if (ZeroTier::zt1Service) { ZeroTier::zt1Service->terminate(); disableTaps(); @@ -447,7 +471,9 @@ void zts_stop() { #endif } -void zts_get_homepath(char *homePath, size_t len) { +void zts_get_homepath(char *homePath, size_t len) +{ + DEBUG_EXTRA(); if (ZeroTier::homeDir.length()) { memset(homePath, 0, len); size_t buf_len = len < ZeroTier::homeDir.length() ? len : ZeroTier::homeDir.length(); @@ -455,7 +481,9 @@ void zts_get_homepath(char *homePath, size_t len) { } } -int zts_get_device_id(char *devID) { +int zts_get_device_id(char *devID) +{ + DEBUG_EXTRA(); if (ZeroTier::zt1Service) { char id[ZTO_ID_LEN]; sprintf(id, "%lx",ZeroTier::zt1Service->getNode()->address()); @@ -476,7 +504,9 @@ int zts_get_device_id(char *devID) { return -1; } -unsigned long zts_get_peer_count() { +unsigned long zts_get_peer_count() +{ + DEBUG_EXTRA(); if (ZeroTier::zt1Service) { return ZeroTier::zt1Service->getNode()->peers()->peerCount; } @@ -485,7 +515,9 @@ unsigned long zts_get_peer_count() { } } -int zts_get_peer_address(char *peer, const char *devID) { +int zts_get_peer_address(char *peer, const char *devID) +{ + DEBUG_EXTRA(); if (ZeroTier::zt1Service) { ZT_PeerList *pl = ZeroTier::zt1Service->getNode()->peers(); // uint64_t addr; @@ -501,12 +533,11 @@ int zts_get_peer_address(char *peer, const char *devID) { void zts_allow_http_control(bool allowed) { + DEBUG_EXTRA(); // TODO } - - #if defined(SDK_JNI) namespace ZeroTier { diff --git a/test/alice/README.md b/test/alice/README.md new file mode 100644 index 0000000..f8b6c65 --- /dev/null +++ b/test/alice/README.md @@ -0,0 +1 @@ +**alice's** identity files and keys go here \ No newline at end of file diff --git a/test/bob/README.md b/test/bob/README.md new file mode 100644 index 0000000..4b32d98 --- /dev/null +++ b/test/bob/README.md @@ -0,0 +1 @@ +**bob's** identity files and keys go here \ No newline at end of file diff --git a/test/carol/README.md b/test/carol/README.md new file mode 100644 index 0000000..e742c6a --- /dev/null +++ b/test/carol/README.md @@ -0,0 +1 @@ +**carol's** identity files and keys go here \ No newline at end of file diff --git a/test/carol/e5cd7a9e1c0fd272.conf b/test/carol/e5cd7a9e1c0fd272.conf new file mode 100644 index 0000000..249fd55 --- /dev/null +++ b/test/carol/e5cd7a9e1c0fd272.conf @@ -0,0 +1,16 @@ +v=7 +nwid=e5cd7a9e1c0fd272 +ts=15cd93097cf +ctmd=6ddd00 +r=4c +id=611fc8b606 +f=6 +ml=20 +t=0 +n=OPNET +mtu=af0 +C=\0\0\0\0\0\0\0\0\0\0\0\\0\0\0\0\0\0m\0\0\0\0\0\0\0\0zr\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aȶz!²urxDqIY^#5,HzЅIt, NFK 6VOWדa6[z[BCFXw\0\0 +RT=\n \0\0\0\0\0\0\0\0 +I=zraȶ\0X\n 4\0\n 4\0 +R=\0\0\0\0 \ No newline at end of file diff --git a/test/client.cpp b/test/client.cpp index a8a8ae4..f85c921 100644 --- a/test/client.cpp +++ b/test/client.cpp @@ -36,7 +36,7 @@ int main(int argc, char **argv) // --- BEGIN DEBUG_TEST("Waiting for libzt to come online...\n"); - zts_simple_start(path.c_str(), nwid.c_str()); + zts_startjoin(path.c_str(), nwid.c_str()); char device_id[11]; zts_get_device_id(device_id); DEBUG_TEST("I am %s", device_id); diff --git a/test/layer2.cpp b/test/layer2.cpp index 05aa695..42b6d1c 100644 --- a/test/layer2.cpp +++ b/test/layer2.cpp @@ -44,7 +44,7 @@ int main(int argc , char *argv[]) // initialize library printf("Starting libzt...\n"); - zts_simple_start(argv[1], argv[2]); + zts_startjoin(argv[1], argv[2]); char device_id[11]; zts_get_device_id(device_id); fprintf(stderr, "Complete. I am %s\n", device_id); diff --git a/test/selftest.cpp b/test/selftest.cpp index 111a716..cc1592d 100644 --- a/test/selftest.cpp +++ b/test/selftest.cpp @@ -1759,7 +1759,84 @@ void tcp_perf_rx_echo_4(TCP_UNIT_TEST_SIG_4) } +int ZT_control_semantics_test(bool *passed) +{ + // TODO: Each discrete operation should be tested in random order among every other discrete operation for a sustained period + /* + std::vector *zts_get_network_routes(char *nwid); + int zts_get_device_id_from_file(const char *filepath, char *devID); + void *zts_start_service(void *thread_id); + void disableTaps(); + void zts_get_ipv4_address(const char *nwid, char *addrstr, const size_t addrlen); + void zts_get_ipv6_address(const char *nwid, char *addrstr, const size_t addrlen); + int zts_has_ipv4_address(const char *nwid); + int zts_has_ipv6_address(const char *nwid); + int zts_has_address(const char *nwid); + void zts_get_6plane_addr(char *addr, const char *nwid, const char *devID); + void zts_get_rfc4193_addr(char *addr, const char *nwid, const char *devID); + void zts_join(const char * nwid); + void zts_leave(const char * nwid); + int zts_running(); + int zts_start(const char *path); + int zts_start(const char *path, const char *nwid); + void zts_stop(); + void zts_get_homepath(char *homePath, size_t len); + int zts_get_device_id(char *devID); + unsigned long zts_get_peer_count(); + int zts_get_peer_address(char *peer, const char *devID); + */ + + int n_times = 5; + char *nwid = "17d709436c2c5367"; + char *path = "fake_path"; +/* + // Perform operations on ZeroTier before calling zts_start(). Doing this makes absolutely no sense but could happen + zts_stop(); + zts_join(nwid); + zts_leave(nwid); + + DEBUG_TEST("---\n"); + sleep(1); + + // Perform operations on ZeroTier immediately upon startup, try to catch it with its pants down + // Ideally, the service wrapper should perform necessary checks to prevent any sort of issue + zts_start(path); + zts_join(nwid); + zts_leave(nwid); + zts_stop(); + + DEBUG_TEST("---\n"); + sleep(1); +*/ + zts_start(path); + zts_join(nwid); + zts_leave(nwid); + zts_stop(); + + DEBUG_TEST("---\n"); + sleep(1); +/* + // start the ZeroTier service many times + for (int i=0; i