README updates, misc filename changes, debug trace fixes, introduction of libzt moniker
This commit is contained in:
18
README.md
18
README.md
@@ -1,8 +1,8 @@
|
|||||||
## **ZeroTier SDK**: Embed ZeroTier directly into your app
|
## **libzt**: Embed ZeroTier directly into your app
|
||||||
|
|
||||||
<a href="https://www.zerotier.com"><img src="https://github.com/zerotier/ZeroTierOne/raw/master/artwork/AppIcon_87x87.png" align="left" hspace="20" vspace="6"></a>
|
<a href="https://www.zerotier.com"><img src="https://github.com/zerotier/ZeroTierOne/raw/master/artwork/ztapp100.png" align="left" hspace="20" vspace="6"></a>
|
||||||
|
|
||||||
**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.
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@ Pre-Built Binaries Here: [zerotier.com/download.shtml](https://zerotier.com/down
|
|||||||
### Example
|
### Example
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#include "libzt.h"
|
||||||
|
|
||||||
char *str = "welcome to the machine";
|
char *str = "welcome to the machine";
|
||||||
char *nwid = "c7cd7c9e1b0f52a2";
|
char *nwid = "c7cd7c9e1b0f52a2";
|
||||||
|
|
||||||
@@ -35,20 +37,16 @@ All build targets will output to `build/`.
|
|||||||
|
|
||||||
### Static Library
|
### Static Library
|
||||||
|
|
||||||
- `make static_lib SDK_IPV4=1`
|
- `make static_lib`
|
||||||
|
|
||||||
### iOS App Framework
|
### iOS App Framework
|
||||||
- `make ios_app_framework SDK_IPV4=1`
|
- `make ios_app_framework`
|
||||||
|
|
||||||
### macOS 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
|
## Using Language Bindings
|
||||||
- `SDK_LANG_JNI=1`: Enable JNI bindings for Java (produces a shared library)
|
- `SDK_LANG_JNI=1`: Enable JNI bindings for Java (produces a shared library)
|
||||||
- `SDK_LANG_CSHARP=1`
|
- `SDK_LANG_CSHARP=1`
|
||||||
|
|||||||
BIN
artwork/ztapp100.png
Normal file
BIN
artwork/ztapp100.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
@@ -10,7 +10,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -121,7 +121,6 @@ int main()
|
|||||||
|
|
||||||
// End Socket API calls
|
// End Socket API calls
|
||||||
|
|
||||||
|
|
||||||
// Get the ipv4 address assigned for this network
|
// Get the ipv4 address assigned for this network
|
||||||
char addr_str[ZT_MAX_IPADDR_LEN];
|
char addr_str[ZT_MAX_IPADDR_LEN];
|
||||||
zts_get_ipv4_address(nwid, 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());
|
printf("peer_count = %lu\n", zts_get_peer_count());
|
||||||
|
|
||||||
|
while(1) {
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
sleep(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
|
// Stop service, delete tap interfaces, and network stack
|
||||||
zts_stop();
|
zts_stop();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -137,12 +137,12 @@ CXXFLAGS+=-DSDK_IPV6
|
|||||||
|
|
||||||
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
||||||
TAP_FILES:=src/SocketTap.cpp \
|
TAP_FILES:=src/SocketTap.cpp \
|
||||||
src/ZeroTierSDK.cpp \
|
src/libzt.cpp \
|
||||||
src/Utilities.cpp
|
src/Utilities.cpp
|
||||||
|
|
||||||
SDK_OBJS+= SocketTap.o \
|
SDK_OBJS+= SocketTap.o \
|
||||||
picoTCP.o \
|
picoTCP.o \
|
||||||
ZeroTierSDK.o \
|
libzt.o \
|
||||||
Utilities.o
|
Utilities.o
|
||||||
|
|
||||||
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
|
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
|
||||||
|
|||||||
@@ -137,12 +137,12 @@ CXXFLAGS+=-DSDK_IPV6
|
|||||||
|
|
||||||
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
||||||
TAP_FILES:=src/SocketTap.cpp \
|
TAP_FILES:=src/SocketTap.cpp \
|
||||||
src/ZeroTierSDK.cpp \
|
src/libzt.cpp \
|
||||||
src/Utilities.cpp
|
src/Utilities.cpp
|
||||||
|
|
||||||
SDK_OBJS+= SocketTap.o \
|
SDK_OBJS+= SocketTap.o \
|
||||||
picoTCP.o \
|
picoTCP.o \
|
||||||
ZeroTierSDK.o \
|
libzt.o \
|
||||||
Utilities.o
|
Utilities.o
|
||||||
|
|
||||||
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
|
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
|
||||||
|
|||||||
@@ -136,12 +136,12 @@ CXXFLAGS+=-DSDK_IPV6
|
|||||||
|
|
||||||
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
||||||
TAP_FILES:=src/SocketTap.cpp \
|
TAP_FILES:=src/SocketTap.cpp \
|
||||||
src/ZeroTierSDK.cpp \
|
src/libzt.cpp \
|
||||||
src/Utilities.cpp
|
src/Utilities.cpp
|
||||||
|
|
||||||
SDK_OBJS+= SocketTap.o \
|
SDK_OBJS+= SocketTap.o \
|
||||||
picoTCP.o \
|
picoTCP.o \
|
||||||
ZeroTierSDK.o \
|
libzt.o \
|
||||||
Utilities.o
|
Utilities.o
|
||||||
|
|
||||||
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
|
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#include "Phy.hpp"
|
#include "Phy.hpp"
|
||||||
|
|
||||||
// SDK
|
// SDK
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
#include "SocketTap.hpp"
|
#include "SocketTap.hpp"
|
||||||
//#include "RingBuffer.hpp"
|
//#include "RingBuffer.hpp"
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ namespace ZeroTier {
|
|||||||
|
|
||||||
std::queue<Connection*> _AcceptedConnections;
|
std::queue<Connection*> _AcceptedConnections;
|
||||||
SocketTap *tap; // Reference to SocketTap
|
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
|
// timestamp for closure event
|
||||||
std::time_t closure_ts;
|
std::time_t closure_ts;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
// SDK
|
// SDK
|
||||||
#include "SocketTap.hpp"
|
#include "SocketTap.hpp"
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
#include "picoTCP.hpp"
|
#include "picoTCP.hpp"
|
||||||
|
|
||||||
// ZT
|
// ZT
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
#include "Thread.hpp"
|
#include "Thread.hpp"
|
||||||
#include "Phy.hpp"
|
#include "Phy.hpp"
|
||||||
|
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
#include "picoTCP.hpp"
|
#include "picoTCP.hpp"
|
||||||
#include "Connection.hpp"
|
#include "Connection.hpp"
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ namespace ZeroTier {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Timestamp of last run of housekeeping
|
* 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;
|
std::time_t last_housekeeping_ts;
|
||||||
|
|
||||||
|
|||||||
@@ -42,53 +42,3 @@ void zt_dump_stacktrace(int sig) {
|
|||||||
exit(1);
|
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;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
// SDK
|
// SDK
|
||||||
#include "SocketTap.hpp"
|
#include "SocketTap.hpp"
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -434,7 +434,7 @@ int zts_connect(ZT_CONNECT_SIG) {
|
|||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
DEBUG_ERROR("EBADF");
|
DEBUG_ERROR("EBADF");
|
||||||
err = -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(!zt1Service) {
|
if(!zt1Service) {
|
||||||
DEBUG_ERROR("Service not started. Call zts_start(path) first");
|
DEBUG_ERROR("Service not started. Call zts_start(path) first");
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
#include "pico_ipv6.h"
|
#include "pico_ipv6.h"
|
||||||
|
|
||||||
// SDK
|
// SDK
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
#include "Utilities.hpp"
|
#include "Utilities.hpp"
|
||||||
#include "SocketTap.hpp"
|
#include "SocketTap.hpp"
|
||||||
#include "picoTCP.hpp"
|
#include "picoTCP.hpp"
|
||||||
@@ -692,4 +692,55 @@ namespace ZeroTier {
|
|||||||
}
|
}
|
||||||
return err;
|
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;
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
#include "SocketTap.hpp"
|
#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
|
#define PICO_IPV4_TO_STRING_SIG char *ipbuf, const uint32_t ip
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "ZeroTierSDK.h"
|
#include "libzt.h"
|
||||||
|
|
||||||
#define PASSED 0
|
#define PASSED 0
|
||||||
#define FAILED -1
|
#define FAILED -1
|
||||||
|
|||||||
@@ -24,9 +24,6 @@
|
|||||||
* of your own application.
|
* of your own application.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ztproxy.hpp"
|
|
||||||
#include "ZeroTierSDK.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -49,6 +46,9 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "ztproxy.hpp"
|
||||||
|
#include "libzt.h"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
typedef void PhySocket;
|
typedef void PhySocket;
|
||||||
@@ -242,7 +242,7 @@ namespace ZeroTier {
|
|||||||
|
|
||||||
void ZTProxy::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from)
|
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;
|
TcpConnection *conn;
|
||||||
// try to recycle TcpConnection objects instead of allocating new ones
|
// try to recycle TcpConnection objects instead of allocating new ones
|
||||||
if(cqueue.size()) {
|
if(cqueue.size()) {
|
||||||
@@ -292,13 +292,13 @@ namespace ZeroTier {
|
|||||||
}
|
}
|
||||||
void ZTProxy::phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked)
|
void ZTProxy::phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked)
|
||||||
{
|
{
|
||||||
DEBUG_INFO("phyOnUnixWritable, sock=%d", sock);
|
DEBUG_INFO("phyOnUnixWritable, sock=%p", sock);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZTProxy::phyOnTcpClose(PhySocket *sock,void **uptr)
|
void ZTProxy::phyOnTcpClose(PhySocket *sock,void **uptr)
|
||||||
{
|
{
|
||||||
DEBUG_INFO("phyOnTcpClose, sock=%d", sock);
|
DEBUG_INFO("phyOnTcpClose, sock=%p", sock);
|
||||||
|
|
||||||
TcpConnection *conn = cmap[sock];
|
TcpConnection *conn = cmap[sock];
|
||||||
if(conn)
|
if(conn)
|
||||||
|
|||||||
Reference in New Issue
Block a user