diff --git a/README.md b/README.md index b817e01..f91ccc9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -## **ZeroTier SDK**: Embed ZeroTier directly into your app +## **libzt**: Embed ZeroTier directly into your app - + -**ZeroTier** makes it easy to securely connect devices, servers, cloud VMs, containers, and apps everywhere and manage them at scale. Now, with the SDK you can bake this ability directly into your application or service using your preferred language. We provide a BSD socket-like API to make the integration simple. +**ZeroTier** makes it easy to securely connect devices, servers, cloud VMs, containers, and apps everywhere and manage them at scale. Now, with *libzt* you can bake this ability directly into your app or service using your preferred language or framework. We provide a BSD socket-like API to make the integration simple.
@@ -13,6 +13,8 @@ Pre-Built Binaries Here: [zerotier.com/download.shtml](https://zerotier.com/down ### Example ``` +#include "libzt.h" + char *str = "welcome to the machine"; char *nwid = "c7cd7c9e1b0f52a2"; @@ -35,20 +37,16 @@ All build targets will output to `build/`. ### Static Library - - `make static_lib SDK_IPV4=1` + - `make static_lib` ### iOS App Framework - - `make ios_app_framework SDK_IPV4=1` + - `make ios_app_framework` ### macOS App Framework - - `make macos_app_framework SDK_IPV4=1` + - `make macos_app_framework` *** -## IP version flags - - `SDK_IPV4=1` - - `SDK_IPV6=1` - ## Using Language Bindings - `SDK_LANG_JNI=1`: Enable JNI bindings for Java (produces a shared library) - `SDK_LANG_CSHARP=1` diff --git a/artwork/ztapp100.png b/artwork/ztapp100.png new file mode 100644 index 0000000..7d32378 Binary files /dev/null and b/artwork/ztapp100.png differ diff --git a/examples/cpp/simple.cpp b/examples/cpp/simple.cpp index 22f577e..82148b8 100644 --- a/examples/cpp/simple.cpp +++ b/examples/cpp/simple.cpp @@ -10,7 +10,7 @@ #include #include -#include "ZeroTierSDK.h" +#include "libzt.h" int main() { @@ -121,7 +121,6 @@ int main() // End Socket API calls - // Get the ipv4 address assigned for this network char addr_str[ZT_MAX_IPADDR_LEN]; zts_get_ipv4_address(nwid, addr_str, ZT_MAX_IPADDR_LEN); @@ -132,53 +131,10 @@ int main() printf("peer_count = %lu\n", zts_get_peer_count()); - - while(1) - { + while(1) { sleep(1); } - - // --- - - /* - - "Tap Multiplexer" - - socket() [BEFORE JOIN]: take requests for new sockets - - Create them, and store them in a temporary holding space until we find out where we should assign them - - - connect(): - - Search SocketTaps for tap with a relevant route - - None? -> ENETUNREACH - - Found? - - Assign previously-held socket to this tap - - Attempt connection - - - bind(): - - bind on all Interfaces? - - - Join Semantics - - Create : SocketTap - - Create : rpc.d/nwid unix domain socket (if intercept mode?) - - Create : Stack Interface - - Provide : IPs to Interface - - - /--- int0: 10. 9.0.0 - stack ---- int1: 172.27.0.0 - \--- int2: ? - */ - - // zts_join("other_network"); // 10.9.0.0 - // zts_join("whatever"); // 172.27.0.0 - - //zts_socket(AF, STREAM, 0); - //zts_connect("10.9.9.5"); - - - // --- - // Stop service, delete tap interfaces, and network stack zts_stop(); return 0; diff --git a/include/ZeroTierSDK.h b/include/libzt.h similarity index 100% rename from include/ZeroTierSDK.h rename to include/libzt.h diff --git a/make-bsd.mk b/make-bsd.mk index 6e32c54..4b784bb 100644 --- a/make-bsd.mk +++ b/make-bsd.mk @@ -137,12 +137,12 @@ CXXFLAGS+=-DSDK_IPV6 STACK_DRIVER_FILES:=src/picoTCP.cpp TAP_FILES:=src/SocketTap.cpp \ - src/ZeroTierSDK.cpp \ + src/libzt.cpp \ src/Utilities.cpp SDK_OBJS+= SocketTap.o \ picoTCP.o \ - ZeroTierSDK.o \ + libzt.o \ Utilities.o PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \ diff --git a/make-linux.mk b/make-linux.mk index 050b4c5..8fd0b3b 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -137,12 +137,12 @@ CXXFLAGS+=-DSDK_IPV6 STACK_DRIVER_FILES:=src/picoTCP.cpp TAP_FILES:=src/SocketTap.cpp \ - src/ZeroTierSDK.cpp \ + src/libzt.cpp \ src/Utilities.cpp SDK_OBJS+= SocketTap.o \ picoTCP.o \ - ZeroTierSDK.o \ + libzt.o \ Utilities.o PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \ diff --git a/make-mac.mk b/make-mac.mk index f47481c..c12c61f 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -136,12 +136,12 @@ CXXFLAGS+=-DSDK_IPV6 STACK_DRIVER_FILES:=src/picoTCP.cpp TAP_FILES:=src/SocketTap.cpp \ - src/ZeroTierSDK.cpp \ + src/libzt.cpp \ src/Utilities.cpp SDK_OBJS+= SocketTap.o \ picoTCP.o \ - ZeroTierSDK.o \ + libzt.o \ Utilities.o PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \ diff --git a/src/Connection.hpp b/src/Connection.hpp index 395795f..ab0452c 100644 --- a/src/Connection.hpp +++ b/src/Connection.hpp @@ -37,7 +37,7 @@ #include "Phy.hpp" // SDK -#include "ZeroTierSDK.h" +#include "libzt.h" #include "SocketTap.hpp" //#include "RingBuffer.hpp" @@ -72,7 +72,7 @@ namespace ZeroTier { std::queue _AcceptedConnections; SocketTap *tap; // Reference to SocketTap - int state; // See ZeroTierSDK.h for (ZT_SOCK_STATE_*) + int state; // See libzt.h for (ZT_SOCK_STATE_*) // timestamp for closure event std::time_t closure_ts; diff --git a/src/SocketTap.cpp b/src/SocketTap.cpp index 152fbd2..9d96cdd 100644 --- a/src/SocketTap.cpp +++ b/src/SocketTap.cpp @@ -37,7 +37,7 @@ // SDK #include "SocketTap.hpp" -#include "ZeroTierSDK.h" +#include "libzt.h" #include "picoTCP.hpp" // ZT diff --git a/src/SocketTap.hpp b/src/SocketTap.hpp index 7f3542e..df87f39 100644 --- a/src/SocketTap.hpp +++ b/src/SocketTap.hpp @@ -43,7 +43,7 @@ #include "Thread.hpp" #include "Phy.hpp" -#include "ZeroTierSDK.h" +#include "libzt.h" #include "picoTCP.hpp" #include "Connection.hpp" @@ -181,7 +181,7 @@ namespace ZeroTier { /* * Timestamp of last run of housekeeping - * SEE: ZT_HOUSEKEEPING_INTERVAL in ZeroTierSDK.h + * SEE: ZT_HOUSEKEEPING_INTERVAL in libzt.h */ std::time_t last_housekeeping_ts; diff --git a/src/Utilities.cpp b/src/Utilities.cpp index 49db98e..fc8fe21 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -42,53 +42,3 @@ void zt_dump_stacktrace(int sig) { exit(1); } */ - -/* -char *beautify_pico_error(int err) -{ - switch(err){ - PICO_ERR_NOERR = 0, - PICO_ERR_EPERM = 1, - PICO_ERR_ENOENT = 2, - - PICO_ERR_EINTR = 4, - PICO_ERR_EIO = 5, - PICO_ERR_ENXIO = 6, - - PICO_ERR_EAGAIN = 11, - PICO_ERR_ENOMEM = 12, - PICO_ERR_EACCESS = 13, - PICO_ERR_EFAULT = 14, - - PICO_ERR_EBUSY = 16, - PICO_ERR_EEXIST = 17, - - PICO_ERR_EINVAL = 22, - - PICO_ERR_ENONET = 64, - - PICO_ERR_EPROTO = 71, - - PICO_ERR_ENOPROTOOPT = 92, - PICO_ERR_EPROTONOSUPPORT = 93, - - PICO_ERR_EOPNOTSUPP = 95, - PICO_ERR_EADDRINUSE = 98, - PICO_ERR_EADDRNOTAVAIL = 99, - PICO_ERR_ENETDOWN = 100, - PICO_ERR_ENETUNREACH = 101, - - PICO_ERR_ECONNRESET = 104, - - PICO_ERR_EISCONN = 106, - PICO_ERR_ENOTCONN = 107, - PICO_ERR_ESHUTDOWN = 108, - - PICO_ERR_ETIMEDOUT = 110, - PICO_ERR_ECONNREFUSED = 111, - PICO_ERR_EHOSTDOWN = 112, - PICO_ERR_EHOSTUNREACH = 113, - } - return err_text; -} -*/ \ No newline at end of file diff --git a/src/ZeroTierSDK.cpp b/src/libzt.cpp similarity index 99% rename from src/ZeroTierSDK.cpp rename to src/libzt.cpp index 85a33c2..5b55ad3 100644 --- a/src/ZeroTierSDK.cpp +++ b/src/libzt.cpp @@ -49,7 +49,7 @@ // SDK #include "SocketTap.hpp" -#include "ZeroTierSDK.h" +#include "libzt.h" #ifdef __cplusplus extern "C" { @@ -434,7 +434,7 @@ int zts_connect(ZT_CONNECT_SIG) { if(fd < 0) { errno = EBADF; DEBUG_ERROR("EBADF"); - err = -1; + return -1; } if(!zt1Service) { DEBUG_ERROR("Service not started. Call zts_start(path) first"); diff --git a/src/picoTCP.cpp b/src/picoTCP.cpp index 0d2c5aa..248ee90 100644 --- a/src/picoTCP.cpp +++ b/src/picoTCP.cpp @@ -38,7 +38,7 @@ #include "pico_ipv6.h" // SDK -#include "ZeroTierSDK.h" +#include "libzt.h" #include "Utilities.hpp" #include "SocketTap.hpp" #include "picoTCP.hpp" @@ -692,4 +692,55 @@ namespace ZeroTier { } return err; } + + int beautify_pico_error(int err) + { + return 0; + /* + switch(err){ + PICO_ERR_NOERR = 0, + PICO_ERR_EPERM = 1, + PICO_ERR_ENOENT = 2, + + PICO_ERR_EINTR = 4, + PICO_ERR_EIO = 5, + PICO_ERR_ENXIO = 6, + + PICO_ERR_EAGAIN = 11, + PICO_ERR_ENOMEM = 12, + PICO_ERR_EACCESS = 13, + PICO_ERR_EFAULT = 14, + + PICO_ERR_EBUSY = 16, + PICO_ERR_EEXIST = 17, + + PICO_ERR_EINVAL = 22, + + PICO_ERR_ENONET = 64, + + PICO_ERR_EPROTO = 71, + + PICO_ERR_ENOPROTOOPT = 92, + PICO_ERR_EPROTONOSUPPORT = 93, + + PICO_ERR_EOPNOTSUPP = 95, + PICO_ERR_EADDRINUSE = 98, + PICO_ERR_EADDRNOTAVAIL = 99, + PICO_ERR_ENETDOWN = 100, + PICO_ERR_ENETUNREACH = 101, + + PICO_ERR_ECONNRESET = 104, + + PICO_ERR_EISCONN = 106, + PICO_ERR_ENOTCONN = 107, + PICO_ERR_ESHUTDOWN = 108, + + PICO_ERR_ETIMEDOUT = 110, + PICO_ERR_ECONNREFUSED = 111, + PICO_ERR_EHOSTDOWN = 112, + PICO_ERR_EHOSTUNREACH = 113, + } + return err_text; + */ + } } diff --git a/src/picoTCP.hpp b/src/picoTCP.hpp index 4132e4e..d4a09f1 100644 --- a/src/picoTCP.hpp +++ b/src/picoTCP.hpp @@ -40,7 +40,7 @@ #include "SocketTap.hpp" /****************************************************************************/ -/* PicoTCP API Signatures (See ZeroTierSDK.h for the API an app should use) */ +/* PicoTCP API Signatures (See libzt.h for the API an app should use) */ /****************************************************************************/ #define PICO_IPV4_TO_STRING_SIG char *ipbuf, const uint32_t ip diff --git a/test/selftest.cpp b/test/selftest.cpp index 0e97ea9..093ec95 100644 --- a/test/selftest.cpp +++ b/test/selftest.cpp @@ -45,7 +45,7 @@ #include #include -#include "ZeroTierSDK.h" +#include "libzt.h" #define PASSED 0 #define FAILED -1 diff --git a/test/ztproxy.cpp b/test/ztproxy.cpp index 00ba2c2..d6c933a 100644 --- a/test/ztproxy.cpp +++ b/test/ztproxy.cpp @@ -24,9 +24,6 @@ * of your own application. */ -#include "ztproxy.hpp" -#include "ZeroTierSDK.h" - #include #include #include @@ -49,6 +46,9 @@ #include #include +#include "ztproxy.hpp" +#include "libzt.h" + namespace ZeroTier { typedef void PhySocket; @@ -242,7 +242,7 @@ namespace ZeroTier { void ZTProxy::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from) { - DEBUG_INFO("phyOnTcpAccept, sockL=%d, sockN=%d", sockL, sockN); + DEBUG_INFO("phyOnTcpAccept, sockL=%p, sockN=%p", sockL, sockN); TcpConnection *conn; // try to recycle TcpConnection objects instead of allocating new ones if(cqueue.size()) { @@ -292,13 +292,13 @@ namespace ZeroTier { } void ZTProxy::phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked) { - DEBUG_INFO("phyOnUnixWritable, sock=%d", sock); + DEBUG_INFO("phyOnUnixWritable, sock=%p", sock); exit(0); } void ZTProxy::phyOnTcpClose(PhySocket *sock,void **uptr) { - DEBUG_INFO("phyOnTcpClose, sock=%d", sock); + DEBUG_INFO("phyOnTcpClose, sock=%p", sock); TcpConnection *conn = cmap[sock]; if(conn)