This commit is contained in:
joseph.henry
2018-01-30 10:56:30 -08:00
44 changed files with 6698 additions and 189 deletions

View File

@@ -10,7 +10,7 @@ A library version of [ZeroTier](https://github.com/zerotier/ZeroTierOne), **libz
[![irc](https://img.shields.io/badge/IRC-%23zerotier%20on%20freenode-orange.svg)](https://webchat.freenode.net/?channels=zerotier) [![irc](https://img.shields.io/badge/IRC-%23zerotier%20on%20freenode-orange.svg)](https://webchat.freenode.net/?channels=zerotier)
- Pre-Built binaries will soon be placed here: [zerotier.com/download.shtml](https://zerotier.com/download.shtml?pk_campaign=github_libzt) - Pre-Built binaries: [zerotier.com/download.shtml](https://zerotier.com/download.shtml?pk_campaign=github_libzt)
- Windows DLL (x64) can be found here: [libzt_win_x64_1.1.5.zip](https://download.zerotier.com/dist/libzt_win_x64_1.1.5.zip) - Windows DLL (x64) can be found here: [libzt_win_x64_1.1.5.zip](https://download.zerotier.com/dist/libzt_win_x64_1.1.5.zip)
- Bindings for popular languages like [Scala](examples/bindings/scala), [Swift](examples/bindings/swift), [Java](examples/bindings/java), [Python](examples/bindings/python), etc. can be found [here](examples/bindings) - Bindings for popular languages like [Scala](examples/bindings/scala), [Swift](examples/bindings/swift), [Java](examples/bindings/java), [Python](examples/bindings/python), etc. can be found [here](examples/bindings)
@@ -68,10 +68,10 @@ We recommend using [CMake](https://cmake.org/) for its extensive cross-platform
git submodule init git submodule init
git submodule update git submodule update
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=DEBUG cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=DEBUG
cmake --build -build cmake --build build
``` ```
Builds are placed in `bin` and `bin\lib`. Change `CMAKE_BUILD_TYPE` to `RELEASE` for a smaller and optmized build. Use `libzt.a` or `libzt.dylib` in your application. They are placed in `bin\lib`. Change `CMAKE_BUILD_TYPE` to `RELEASE` for a smaller and optmized build.
### Install ### Install
@@ -89,8 +89,8 @@ Builds are placed in `bin` and `bin\lib`. Change `CMAKE_BUILD_TYPE` to `RELEASE`
Please make pull requests against the `dev` branch. The `master` branch is release, and `edge` is for unstable and work in progress changes and is not likely to work. Please make pull requests against the `dev` branch. The `master` branch is release, and `edge` is for unstable and work in progress changes and is not likely to work.
### Commercial License ### Commercial License
- To be released from GPLv3, contact us directly via `contact@zerotier.com` to discuss commercial licensing. - If you want a commercial license to use libzt in your product contact us directly via `contact@zerotier.com`.
### Adding a custom network stack ### Adding a custom network stack
- If you wish to use something other than lwIP or picoTCP, you can easily add your own API function calls in `src/libzt.cpp` or `src/VirtualSocket.cpp` depending on whether your stack's API exposes a POSIX-socket API or a raw API, respectively. - If you wish to use something other than lwIP or picoTCP, you can easily add your own API function calls in `src/libzt.cpp` or `src/VirtualSocket.cpp` depending on whether your stack's API exposes a POSIX-socket API or a raw API, respectively.

View File

@@ -1,4 +1,4 @@
## libzt Python examples libzt wrapper and PyPI package
*** ***
Coming soon See [libzt/packages/pypi](../../../packages/pypi)

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,3 +0,0 @@
# file GENERATED by distutils, do NOT edit
setup.cfg
setup.py

View File

@@ -1,96 +0,0 @@
# libzt
*Embed ZeroTier directly into your app*
***
<a href="https://www.zerotier.com/?pk_campaign=github_libzt"><img src="https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/artwork/ZeroTierIcon.png" width="128" height="128" align="left" hspace="20" vspace="9"></a>
A library version of [ZeroTier](https://github.com/zerotier/ZeroTierOne), **libzt** makes it easy to securely connect devices, servers, cloud VMs, containers, and apps everywhere and manage them at scale. Now you can bake this ability directly into your app or service using your preferred language. We provide a POSIX-like socket API supporting `SOCK_STREAM`, `SOCK_DGRAM`, and `SOCK_RAW` to make the integration simple. There's no need for system-wide virtual interfaces. This connection is exclusive to your app and fully encrypted via the [Salsa20](https://en.wikipedia.org/wiki/Salsa20) cipher. For a more in-depth discussion on the technical side of ZeroTier, check out our [Manual](https://www.zerotier.com/manual.shtml?pk_campaign=github_libzt)
<hr>
[![irc](https://img.shields.io/badge/IRC-%23zerotier%20on%20freenode-orange.svg)](https://webchat.freenode.net/?channels=zerotier)
- Pre-Built binaries will soon be placed here: [zerotier.com/download.shtml](https://zerotier.com/download.shtml?pk_campaign=github_libzt)
- Windows DLL (x64) can be found here: [libzt_win_x64_1.1.5.zip](https://download.zerotier.com/dist/libzt_win_x64_1.1.5.zip)
- Bindings for popular languages like [Scala](examples/bindings/scala), [Swift](examples/bindings/swift), [Java](examples/bindings/java), [Python](examples/bindings/python), etc. can be found [here](examples/bindings)
***
### C++ Example
```
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "libzt.h"
int main()
{
char *str = "welcome to the machine";
char *ip = "10.8.8.42"; // remote address
int port = 8080; // remote port
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(ip);
addr.sin_port = htons(port);
zts_startjoin("path", 0xc7cd7c981b0f52a2); // config path, nwid
int fd, err = 0;
if ((fd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("error creating socket\n");
}
if ((err = zts_connect(fd, (const struct sockaddr *)&addr, sizeof(addr))) < 0) {
printf("error connecting to remote host\n");
}
if ((err = zts_write(fd, str, strlen(str))) < 0) {
printf("error writing to socket\n");
}
if ((err = zts_close(fd)) < 0) {
printf("error closing socket\n");
}
zts_stop();
return 0;
}
```
For an example using only the [Virtual Layer 2](https://www.zerotier.com/manual.shtml#2_2?pk_campaign=github_libzt), see [test/layer2.cpp](test/layer2.cpp)
***
### Build
We recommend using [CMake](https://cmake.org/) for its extensive cross-platform build support.
```
git submodule init
git submodule update
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=DEBUG
cmake --build -build
```
Builds are placed in `bin` and `bin\lib`. Change `CMAKE_BUILD_TYPE` to `RELEASE` for a smaller and optmized build.
### Install
- Install: `make install`
- Uninstall: `xargs rm < install_manifest.txt`
***
### Testing and Debugging
- See [TESTING.md](TESTING.md)
### Contributing
Please make pull requests against the `dev` branch. The `master` branch is release, and `edge` is for unstable and work in progress changes and is not likely to work.
### Commercial License
- To be released from GPLv3, contact us directly via `contact@zerotier.com` to discuss commercial licensing.
### Adding a custom network stack
- If you wish to use something other than lwIP or picoTCP, you can easily add your own API function calls in `src/libzt.cpp` or `src/VirtualSocket.cpp` depending on whether your stack's API exposes a POSIX-socket API or a raw API, respectively.

View File

@@ -1,2 +0,0 @@
[metadata]
description-file = README.md

View File

@@ -1,13 +0,0 @@
from distutils.core import setup
setup(
name = 'libzt',
packages = ['libzt'],
version = '1.1.5',
description = 'Library version of ZeroTier',
author = 'Joseph Henry',
author_email = 'joseph@zerotier.com',
url = 'https://github.com/zerotier/libzt',
download_url = 'https://github.com/zerotier/libzt/archive/1.1.5.tar.gz',
keywords = ['virtual', 'network', 'socket', 'lwip', 'network stack'],
classifiers = [],
)

View File

@@ -1,3 +0,0 @@
#!/bin/bash
python setup.py sdist upload -r pypitest
# python setup.py register -r pypi

10
packages/pypi/MANIFEST.in Normal file
View File

@@ -0,0 +1,10 @@
# file GENERATED by distutils, do NOT edit
README.rst
setup.cfg
setup.py
recursive-include data *.c
recursive-include data *.cpp
recursive-include data *.h
recursive-include data *.hpp
include libhttp.a
include liblwip.a

38
packages/pypi/README.md Normal file
View File

@@ -0,0 +1,38 @@
## libzt PyPI Package
[pypi/libzt](https://pypi.python.org/pypi/libzt)
***
## Getting started
`pip3 install libzt`
```
import libzt
import time
print('joining virtual network...')
libzt.zts_startjoin('whatev_config', 0x123456789ABCDEF1)
print('fd = ' + str(libzt.zts_socket(1,2,3)))
print('looping forever, ping me')
while True:
time.sleep(1)
```
## Building the Package
Package is specified in [setup.py](setup.py). *Note: A new version must be specified in `setup.py` for every new upload of a package*
Get necessary tools
`pip3 install wheel twine`
*Note: As there appears to be no way to differentiate C and C++ code (and thus pass correct build args to each type) in a setuptools script we must separately build the `lwip` and `http_parser` libraries, copy them here, and then build the binary. See the top-level [README.md](../../README.md) for instructions on how to do that*
Build the binary distribution wheel:
`python3 setup.py bdist_wheel`
Upload to PyPI
`twine upload dist/*`

8
packages/pypi/README.rst Normal file
View File

@@ -0,0 +1,8 @@
# libzt
*Embed ZeroTier directly into your app*
***
A library version of [ZeroTier](https://github.com/zerotier/ZeroTierOne), **libzt** makes it easy to securely connect devices, servers, cloud VMs, containers, and apps everywhere and manage them at scale. Now you can bake this ability directly into your app or service using your preferred language. We provide a POSIX-like socket API supporting `SOCK_STREAM`, `SOCK_DGRAM`, and `SOCK_RAW` to make the integration simple. There's no need for system-wide virtual interfaces. This connection is exclusive to your app and fully encrypted via the [Salsa20](https://en.wikipedia.org/wiki/Salsa20) cipher. For a more in-depth discussion on the technical side of ZeroTier, check out our [Manual](https://www.zerotier.com/manual.shtml?pk_campaign=github_libzt)
### Commercial License
- To be released from GPLv3, contact us directly via `contact@zerotier.com` for commercial licensing.

138
packages/pypi/libzt.i Normal file
View File

@@ -0,0 +1,138 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 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 <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
%module libzt
%include "stdint.i"
%{
#define SWIG_FILE_WITH_INIT
#include "data/libzt/include/libzt.h"
%}
int zts_start(const char *path, bool blocking);
int zts_startjoin(const char *path, const uint64_t nwid);
void zts_stop();
int zts_core_running();
int zts_stack_running();
int zts_ready();
int zts_join(const uint64_t nwid);
int zts_leave(const uint64_t nwid);
void zts_get_path(char *homePath, const size_t len);
uint64_t zts_get_node_id();
uint64_t zts_get_node_id_from_file(const char *filepath);
int zts_has_address(const uint64_t nwid);
int zts_get_num_assigned_addresses(const uint64_t nwid);
int zts_get_address_at_index(
const uint64_t nwid, const int index, struct sockaddr_storage *addr);
int zts_get_address(
const uint64_t nwid, struct sockaddr_storage *addr, const int address_family);
void zts_get_6plane_addr(
struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId);
void zts_get_rfc4193_addr(
struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId);
unsigned long zts_get_peer_count();
int zts_get_peer_address(char *peer, const uint64_t nodeId);
void zts_allow_http_control(bool allowed);
int zts_socket(int socket_family, int socket_type, int protocol);
int zts_connect(int fd, const struct sockaddr *addr, socklen_t addrlen);
int zts_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
int zts_listen(int fd, int backlog);
int zts_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
int zts_setsockopt(
int fd, int level, int optname, const void *optval, socklen_t optlen);
int zts_getsockopt(
int fd, int level, int optname, void *optval, socklen_t *optlen);
int zts_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen);
int zts_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen);
int zts_gethostname(char *name, size_t len);
int zts_sethostname(const char *name, size_t len);
struct hostent *zts_gethostbyname(const char *name);
int zts_close(int fd);
int zts_select(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int zts_fcntl(int fd, int cmd, int flags);
int zts_ioctl(int fd, unsigned long request, void *argp);
ssize_t zts_send(int fd, const void *buf, size_t len, int flags);
ssize_t zts_sendto(
int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen);
ssize_t zts_sendmsg(int fd, const struct msghdr *msg, int flags);
ssize_t zts_recv(int fd, void *buf, size_t len, int flags);
ssize_t zts_recvfrom(
int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen);
ssize_t zts_recvmsg(int fd, struct msghdr *msg,int flags);
int zts_read(int fd, void *buf, size_t len);
int zts_write(int fd, const void *buf, size_t len);
int zts_shutdown(int fd, int how);
int zts_add_dns_nameserver(struct sockaddr *addr);
int zts_del_dns_nameserver(struct sockaddr *addr);

View File

@@ -0,0 +1,288 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.12
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_libzt')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_libzt')
_libzt = swig_import_helper()
del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_libzt', [dirname(__file__)])
except ImportError:
import _libzt
return _libzt
try:
_mod = imp.load_module('_libzt', fp, pathname, description)
finally:
if fp is not None:
fp.close()
return _mod
_libzt = swig_import_helper()
del swig_import_helper
else:
import _libzt
del _swig_python_version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
try:
import builtins as __builtin__
except ImportError:
import __builtin__
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
if _newclass:
object.__setattr__(self, name, value)
else:
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr(self, class_type, name):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except __builtin__.Exception:
class _object:
pass
_newclass = 0
def zts_start(path, blocking):
return _libzt.zts_start(path, blocking)
zts_start = _libzt.zts_start
def zts_startjoin(path, nwid):
return _libzt.zts_startjoin(path, nwid)
zts_startjoin = _libzt.zts_startjoin
def zts_stop():
return _libzt.zts_stop()
zts_stop = _libzt.zts_stop
def zts_core_running():
return _libzt.zts_core_running()
zts_core_running = _libzt.zts_core_running
def zts_stack_running():
return _libzt.zts_stack_running()
zts_stack_running = _libzt.zts_stack_running
def zts_ready():
return _libzt.zts_ready()
zts_ready = _libzt.zts_ready
def zts_join(nwid):
return _libzt.zts_join(nwid)
zts_join = _libzt.zts_join
def zts_leave(nwid):
return _libzt.zts_leave(nwid)
zts_leave = _libzt.zts_leave
def zts_get_path(homePath, len):
return _libzt.zts_get_path(homePath, len)
zts_get_path = _libzt.zts_get_path
def zts_get_node_id():
return _libzt.zts_get_node_id()
zts_get_node_id = _libzt.zts_get_node_id
def zts_get_node_id_from_file(filepath):
return _libzt.zts_get_node_id_from_file(filepath)
zts_get_node_id_from_file = _libzt.zts_get_node_id_from_file
def zts_has_address(nwid):
return _libzt.zts_has_address(nwid)
zts_has_address = _libzt.zts_has_address
def zts_get_num_assigned_addresses(nwid):
return _libzt.zts_get_num_assigned_addresses(nwid)
zts_get_num_assigned_addresses = _libzt.zts_get_num_assigned_addresses
def zts_get_address_at_index(nwid, index, addr):
return _libzt.zts_get_address_at_index(nwid, index, addr)
zts_get_address_at_index = _libzt.zts_get_address_at_index
def zts_get_address(nwid, addr, address_family):
return _libzt.zts_get_address(nwid, addr, address_family)
zts_get_address = _libzt.zts_get_address
def zts_get_6plane_addr(addr, nwid, nodeId):
return _libzt.zts_get_6plane_addr(addr, nwid, nodeId)
zts_get_6plane_addr = _libzt.zts_get_6plane_addr
def zts_get_rfc4193_addr(addr, nwid, nodeId):
return _libzt.zts_get_rfc4193_addr(addr, nwid, nodeId)
zts_get_rfc4193_addr = _libzt.zts_get_rfc4193_addr
def zts_get_peer_count():
return _libzt.zts_get_peer_count()
zts_get_peer_count = _libzt.zts_get_peer_count
def zts_get_peer_address(peer, nodeId):
return _libzt.zts_get_peer_address(peer, nodeId)
zts_get_peer_address = _libzt.zts_get_peer_address
def zts_allow_http_control(allowed):
return _libzt.zts_allow_http_control(allowed)
zts_allow_http_control = _libzt.zts_allow_http_control
def zts_socket(socket_family, socket_type, protocol):
return _libzt.zts_socket(socket_family, socket_type, protocol)
zts_socket = _libzt.zts_socket
def zts_connect(fd, addr, addrlen):
return _libzt.zts_connect(fd, addr, addrlen)
zts_connect = _libzt.zts_connect
def zts_bind(fd, addr, addrlen):
return _libzt.zts_bind(fd, addr, addrlen)
zts_bind = _libzt.zts_bind
def zts_listen(fd, backlog):
return _libzt.zts_listen(fd, backlog)
zts_listen = _libzt.zts_listen
def zts_accept(fd, addr, addrlen):
return _libzt.zts_accept(fd, addr, addrlen)
zts_accept = _libzt.zts_accept
def zts_setsockopt(fd, level, optname, optval, optlen):
return _libzt.zts_setsockopt(fd, level, optname, optval, optlen)
zts_setsockopt = _libzt.zts_setsockopt
def zts_getsockopt(fd, level, optname, optval, optlen):
return _libzt.zts_getsockopt(fd, level, optname, optval, optlen)
zts_getsockopt = _libzt.zts_getsockopt
def zts_getsockname(fd, addr, addrlen):
return _libzt.zts_getsockname(fd, addr, addrlen)
zts_getsockname = _libzt.zts_getsockname
def zts_getpeername(fd, addr, addrlen):
return _libzt.zts_getpeername(fd, addr, addrlen)
zts_getpeername = _libzt.zts_getpeername
def zts_gethostname(name, len):
return _libzt.zts_gethostname(name, len)
zts_gethostname = _libzt.zts_gethostname
def zts_sethostname(name, len):
return _libzt.zts_sethostname(name, len)
zts_sethostname = _libzt.zts_sethostname
def zts_gethostbyname(name):
return _libzt.zts_gethostbyname(name)
zts_gethostbyname = _libzt.zts_gethostbyname
def zts_close(fd):
return _libzt.zts_close(fd)
zts_close = _libzt.zts_close
def zts_select(nfds, readfds, writefds, exceptfds, timeout):
return _libzt.zts_select(nfds, readfds, writefds, exceptfds, timeout)
zts_select = _libzt.zts_select
def zts_fcntl(fd, cmd, flags):
return _libzt.zts_fcntl(fd, cmd, flags)
zts_fcntl = _libzt.zts_fcntl
def zts_ioctl(fd, request, argp):
return _libzt.zts_ioctl(fd, request, argp)
zts_ioctl = _libzt.zts_ioctl
def zts_send(fd, buf, len, flags):
return _libzt.zts_send(fd, buf, len, flags)
zts_send = _libzt.zts_send
def zts_sendto(fd, buf, len, flags, addr, addrlen):
return _libzt.zts_sendto(fd, buf, len, flags, addr, addrlen)
zts_sendto = _libzt.zts_sendto
def zts_sendmsg(fd, msg, flags):
return _libzt.zts_sendmsg(fd, msg, flags)
zts_sendmsg = _libzt.zts_sendmsg
def zts_recv(fd, buf, len, flags):
return _libzt.zts_recv(fd, buf, len, flags)
zts_recv = _libzt.zts_recv
def zts_recvfrom(fd, buf, len, flags, addr, addrlen):
return _libzt.zts_recvfrom(fd, buf, len, flags, addr, addrlen)
zts_recvfrom = _libzt.zts_recvfrom
def zts_recvmsg(fd, msg, flags):
return _libzt.zts_recvmsg(fd, msg, flags)
zts_recvmsg = _libzt.zts_recvmsg
def zts_read(fd, buf, len):
return _libzt.zts_read(fd, buf, len)
zts_read = _libzt.zts_read
def zts_write(fd, buf, len):
return _libzt.zts_write(fd, buf, len)
zts_write = _libzt.zts_write
def zts_shutdown(fd, how):
return _libzt.zts_shutdown(fd, how)
zts_shutdown = _libzt.zts_shutdown
def zts_add_dns_nameserver(addr):
return _libzt.zts_add_dns_nameserver(addr)
zts_add_dns_nameserver = _libzt.zts_add_dns_nameserver
def zts_del_dns_nameserver(addr):
return _libzt.zts_del_dns_nameserver(addr)
zts_del_dns_nameserver = _libzt.zts_del_dns_nameserver
# This file is compatible with both classic and new-style classes.

6025
packages/pypi/libzt_wrap.cxx Normal file

File diff suppressed because it is too large Load Diff

15
packages/pypi/prepare.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Move sources into top-level subdirectory so MANIFEST.in can include it in the source distribution
mkdir -p data/libzt
mkdir -p data/zto
# libzt
cp -r ../../src data/libzt/src
cp -r ../../include data/libzt/include
cp -r ../../ext data/libzt/ext
# ZeroTier
cp -r ../../zto/ data/zto

2
packages/pypi/setup.cfg Normal file
View File

@@ -0,0 +1,2 @@
[metadata]
description-file = README.rst

96
packages/pypi/setup.py Normal file
View File

@@ -0,0 +1,96 @@
#!/usr/bin/env python
from setuptools import setup, Extension, Command, Distribution
import glob
class BinaryDistribution(Distribution):
def is_pure(self):
return False
source_list = ['libzt_wrap.cxx']
source_list.extend(list(glob.glob('data/libzt/src/*.cpp')))
source_list.extend(list(glob.glob('data/zto/node/*.cpp')))
source_list.extend(list(glob.glob('data/zto/osdep/*.cpp')))
source_list.extend(list(glob.glob('data/zto/service/*.cpp')))
source_list.extend(list(glob.glob('data/zto/controller/*.cpp')))
#http_parser_source_list = ['libzt_wrap.cxx']
#http_parser_source_list.extend(list(glob.glob('../../zto/ext/http-parser/*.c')))
#lwip_source_list = ['libzt_wrap.cxx']
#lwip_source_list.extend(list(glob.glob('../../ext/lwip/src/core/*.c')))
#lwip_source_list.extend(list(glob.glob('../../ext/lwip/src/core/ipv4/*.c')))
#lwip_source_list.extend(list(glob.glob('../../ext/lwip/src/core/ipv6/*.c')))
source_list = list(set(source_list)-set(
['data/zto/osdep/LinuxEthernetTap.cpp','data/zto/osdep/BSDEthernetTap.cpp','data/zto/osdep/OSXEthernetTap.cpp', 'data/zto/osdep/WindowsEthernetTap.cpp']))
#lwip_module = Extension('lwip',
# extra_compile_args=['-DZT_SDK'],
# extra_link_args=[],
# sources=lwip_source_list,
# include_dirs=['../include',
# '../../include',
# '../../ext/lwip/src/include',
# '../../ext/lwip-contrib/ports/unix/include',]
# )
#http_parser_module = Extension('http_parser',
# extra_compile_args=[],
# extra_link_args=[],
# sources=http_parser_source_list,
# )
libzt_module = Extension('libzt',
extra_compile_args=['-std=c++11', '-DZT_SDK', '-DZT_SOFTWARE_UPDATE_DEFAULT=\"disable\"'],
extra_link_args=['-L.','-llwip','-lhttp'],
sources=source_list,
include_dirs=['data/libzt/include',
'data/libzt/ext/lwip/src/include',
'data/libzt/ext/lwip-contrib/ports/unix/include',
'data/zto/include',
'data/zto/node',
'data/zto/service',
'data/zto/osdep',
'data/zto/controller']
)
setup(
include_package_data=True,
distclass=BinaryDistribution,
ext_modules = [libzt_module],
py_modules = ['libzt'],
name = 'libzt',
packages = ['libzt'],
version = '1.1.5a19',
description = 'ZeroTier, in library form.',
long_description = 'Encrypted P2P networks between your applications',
author = 'ZeroTier, Inc.',
author_email = 'joseph@zerotier.com',
url = 'https://github.com/zerotier/libzt',
license='GPLv3',
download_url = 'https://github.com/zerotier/libzt/archive/1.1.5.tar.gz',
keywords = 'zerotier sdwan sdn virtual network socket p2p peer-to-peer',
classifiers = ['Development Status :: 3 - Alpha',
'Environment :: MacOS X',
'Environment :: Win32 (MS Windows)',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'Intended Audience :: System Administrators',
'Intended Audience :: Telecommunications Industry',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'License :: Free for non-commercial use',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: iOS',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: BSD',
'Operating System :: Unix',
'Programming Language :: C++',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Internet',
'Topic :: Security :: Cryptography',
'Topic :: System :: Networking'
],
)

10
packages/pypi/test.py Normal file
View File

@@ -0,0 +1,10 @@
import libzt
import time
print('joining virtual network...')
libzt.zts_startjoin('whatev_config', 0x1234567890ABCDEF)
print('fd = ' + str(libzt.zts_socket(1,2,3)))
print('looping forever, ping me')
while True:
time.sleep(1)

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,28 +1,28 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* -- * --
* *
* You can be released from the requirements of the license by purchasing * You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you * a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links * develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code * directly against ZeroTier software without disclosing the source code
* of your own application. * of your own application.
*/ */
/** /**
* @file * @file

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -39,6 +39,7 @@
#include "OneService.hpp" #include "OneService.hpp"
#include "InetAddress.hpp" #include "InetAddress.hpp"
#include "OSUtils.hpp" #include "OSUtils.hpp"
#include "Mutex.hpp"
std::vector<void*> vtaps; std::vector<void*> vtaps;
ZeroTier::Mutex _vtaps_lock; ZeroTier::Mutex _vtaps_lock;

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* /*
* ZeroTier SDK - Network Virtualization Everywhere * ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -142,13 +142,13 @@
inline unsigned int gettid() inline unsigned int gettid()
{ {
#ifdef _WIN32 #ifdef _WIN32
return GetCurrentThreadId(); return GetCurrentThreadId();
#elif defined(__unix__) #elif defined(__unix__)
return static_cast<unsigned int>(::syscall(__NR_gettid)); return static_cast<unsigned int>(::syscall(__NR_gettid));
#elif defined(__APPLE__) #elif defined(__APPLE__)
uint64_t tid64; uint64_t tid64;
pthread_threadid_np(NULL, &tid64); pthread_threadid_np(NULL, &tid64);
return static_cast<unsigned int>(tid64); return static_cast<unsigned int>(tid64);
#endif #endif
} }
@@ -381,7 +381,7 @@ void wait_until_everyone_is_ready(struct sockaddr *local_addr, struct sockaddr *
struct sockaddr_in client; struct sockaddr_in client;
socklen_t client_addrlen = sizeof(sockaddr_in); socklen_t client_addrlen = sizeof(sockaddr_in);
if ((accepted_fd = ACCEPT(listen_fd, (struct sockaddr *)&client, &client_addrlen)) < 0) { if ((accepted_fd = ACCEPT(listen_fd, (struct sockaddr *)&client, &client_addrlen)) < 0) {
DEBUG_TEST("errno = %d", errno); //DEBUG_TEST("errno = %d", errno);
} }
else { else {
DEBUG_TEST("connected"); DEBUG_TEST("connected");
@@ -390,11 +390,9 @@ void wait_until_everyone_is_ready(struct sockaddr *local_addr, struct sockaddr *
} }
sleep(1); sleep(1);
} }
DEBUG_TEST("closing");
CLOSE(listen_fd); CLOSE(listen_fd);
CLOSE(conn_fd); CLOSE(conn_fd);
CLOSE(accepted_fd); CLOSE(accepted_fd);
DEBUG_TEST("returning");
} }
@@ -2886,7 +2884,7 @@ for (int i=0; i<num_repeats; i++)
long int selftest_start_time = get_now_ts(); long int selftest_start_time = get_now_ts();
subtest_expected_duration = 20; // initial value, wait for other instance to come online subtest_expected_duration = 20; // initial value, wait for other instance to come online
#endif #endif
/*
// UDP 4 client/server // UDP 4 client/server
ipv = 4; ipv = 4;
@@ -3059,12 +3057,9 @@ for (int i=0; i<num_repeats; i++)
} }
RECORD_RESULTS(passed, details, &results); RECORD_RESULTS(passed, details, &results);
port++; port++;
*/
// IPV6 // IPV6
/*
// UDP 6 client/server // UDP 6 client/server
ipv = 6; ipv = 6;
@@ -3172,7 +3167,7 @@ for (int i=0; i<num_repeats; i++)
} }
RECORD_RESULTS(passed, details, &results); RECORD_RESULTS(passed, details, &results);
port++; port++;
*/
// TCP 6 sustained transfer // TCP 6 sustained transfer
ipv = 6; ipv = 6;