diff --git a/examples/python/example.py b/examples/python/example.py index 5a4a759..7e0de34 100644 --- a/examples/python/example.py +++ b/examples/python/example.py @@ -1,7 +1,6 @@ import time, sys import libzt -from prototype import * # Where identity files are stored keyPath = "." @@ -114,7 +113,7 @@ print('Joined network') if (mode == 'server'): print("Starting server...") try: - serv = zerotier.socket(libzt.ZTS_AF_INET6, libzt.ZTS_SOCK_STREAM, 0) + serv = libzt.zerotier.socket(libzt.ZTS_AF_INET, libzt.ZTS_SOCK_STREAM, 0) serv.bind(('::', serverPort)) serv.listen(5) while True: @@ -144,7 +143,7 @@ if (mode == 'server'): if (mode == 'client'): print("Starting client...") try: - client = zerotier.socket(libzt.ZTS_AF_INET6, libzt.ZTS_SOCK_STREAM, 0) + client = libzt.zerotier.socket(libzt.ZTS_AF_INET, libzt.ZTS_SOCK_STREAM, 0) print("connecting...") client.connect((remoteIP, serverPort)) print("send...") diff --git a/pkg/pypi/MANIFEST.in b/pkg/pypi/MANIFEST.in new file mode 100644 index 0000000..f57e51f --- /dev/null +++ b/pkg/pypi/MANIFEST.in @@ -0,0 +1,3 @@ +README.rst +setup.cfg +setup.py diff --git a/pkg/pypi/README.md b/pkg/pypi/README.md new file mode 100644 index 0000000..5a9f0d9 --- /dev/null +++ b/pkg/pypi/README.md @@ -0,0 +1,13 @@ +# PyPI Package ([pypi/libzt](https://pypi.python.org/pypi/libzt)) + +``` +pip install libzt +``` + +### Example usage + +- See [examples/python](../../examples/python) + +### Implementation Details + +- See [src/bindings/python](../../src/bindings/python) diff --git a/pkg/pypi/README.rst b/pkg/pypi/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/pkg/pypi/build.sh b/pkg/pypi/build.sh new file mode 100755 index 0000000..df8527e --- /dev/null +++ b/pkg/pypi/build.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +PYBIN=python3 +#PYBIN=/opt/python/cp39-cp39/bin/python3 + +# Build the extension module +ext() +{ + # Symbolic link to source tree so that sdist structure makes sense + ln -s ../../ native + # Copy language bindings into module directory + cp -f native/src/bindings/python/*.py libzt/ + cp -f native/LICENSE.txt LICENSE + #mkdir -p build/temp.macosx-11-x86_64-3.9 + #mkdir -p build/temp.linux-x86_64-3.8 + # Build C libraries (and then) C++ extension + $PYBIN setup.py build_clib --verbose build_ext -i --verbose +} + +# Build a wheel +wheel() +{ + ext + $PYBIN setup.py bdist_wheel +} + +clean() +{ + find . -name '*.so' -type f -delete + find . -name '*.pyc' -type f -delete + find . -name '__pycache__' -type d -delete + rm -rf libzt/prototype.py + rm -rf libzt/libzt.py + rm -rf src ext build dist native + rm -rf libzt.egg-info + rm -rf LICENSE +} + +manylinux() +{ + CONTAINER="quay.io/pypa/manylinux_2_24_aarch64" + docker pull ${CONTAINER} + docker run --rm -it --entrypoint bash -v $(pwd)/../../:/media/libzt ${CONTAINER} +} + +"$@" \ No newline at end of file diff --git a/pkg/pypi/libzt/__init__.py b/pkg/pypi/libzt/__init__.py new file mode 100644 index 0000000..3b8b2fe --- /dev/null +++ b/pkg/pypi/libzt/__init__.py @@ -0,0 +1,4 @@ +__version__ = "1.3.3" + +from .libzt import * +from .prototype import ztsocket, zerotier \ No newline at end of file diff --git a/pkg/pypi/setup.cfg b/pkg/pypi/setup.cfg new file mode 100644 index 0000000..447a470 --- /dev/null +++ b/pkg/pypi/setup.cfg @@ -0,0 +1,4 @@ +[metadata] +version = attr: libzt.__version__ +description-file = README.rst +license_files = LICENSE \ No newline at end of file diff --git a/pkg/pypi/setup.py b/pkg/pypi/setup.py new file mode 100644 index 0000000..33155dc --- /dev/null +++ b/pkg/pypi/setup.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python + +from setuptools import setup, Extension, Command, Distribution +import glob +import os + +class BinaryDistribution(Distribution): + def is_pure(self): + return False + +cpp_glob = [] +c_glob = [] + +# Windows +if os.name == 'nt': + print('TODO') + #extra_compile_args=['/std:c++14', '-DNOMINMAX=1', '-DZT_SDK', '-DSDK'], + #extra_link_args=['/LIBPATH:.', 'WS2_32.Lib', 'ShLwApi.Lib', 'iphlpapi.Lib','lwip.lib'], + +# Everything else +else: + cpp_glob.extend(list(glob.glob('native/src/bindings/python/*.cpp'))) + cpp_glob.extend(list(glob.glob('native/src/*.cpp'))) + cpp_glob.extend(list(glob.glob('native/ext/ZeroTierOne/node/*.cpp'))) + cpp_glob.extend(list(glob.glob('native/ext/ZeroTierOne/osdep/OSUtils.cpp'))) + cpp_glob.extend(list(glob.glob('native/ext/ZeroTierOne/osdep/PortMapper.cpp'))) + cpp_glob.extend(list(glob.glob('native/ext/ZeroTierOne/osdep/ManagedRoute.cpp'))) + + my_include_dirs=['native/include', + 'native/src', + 'native/src/bindings/python', + 'native/ext/concurrentqueue', + 'native/ext/lwip/src/include', + 'native/ext/lwip-contrib/ports/unix/port/include', + 'native/ext/ZeroTierOne/include', + 'native/ext/ZeroTierOne/node', + 'native/ext/ZeroTierOne/service', + 'native/ext/ZeroTierOne/osdep', + 'native/ext/ZeroTierOne/controller'] + + libzt_module = Extension('libzt._libzt', + extra_compile_args=['-std=c++11', '-DZTS_ENABLE_PYTHON=1', '-DZT_SDK'], + sources=cpp_glob, include_dirs=my_include_dirs) + + # Separate C library, this is needed since C++ compiler flags are applied + # to everything in the extension module regardless of type. + + # libnatpmp + c_glob.extend(list(glob.glob('native/ext/ZeroTierOne/ext/libnatpmp/natpmp.c'))) + c_glob.extend(list(glob.glob('native/ext/ZeroTierOne/ext/libnatpmp/wingettimeofday.c'))) + c_glob.extend(list(glob.glob('native/ext/ZeroTierOne/ext/libnatpmp/getgateway.c'))) + # miniupnpc + c_glob.extend(list(glob.glob('native/ext/miniupnpc/*.c'))) + # lwip + c_glob.extend(list(glob.glob('native/ext/lwip/src/netif/*.c'))) + c_glob.extend(list(glob.glob('native/ext/lwip/src/api/*.c'))) + c_glob.extend(list(glob.glob('native/ext/lwip/src/core/*.c'))) + c_glob.extend(list(glob.glob('native/ext/lwip/src/core/ipv4/*.c'))) + c_glob.extend(list(glob.glob('native/ext/lwip/src/core/ipv6/*.c'))) + c_glob.extend(list(glob.glob('native/ext/lwip/src/netif/*.c'))) + c_glob.extend(list(glob.glob('native/ext/lwip-contrib/ports/unix/port/sys_arch.c'))) + +cstuff = ('cstuff', {'sources': + c_glob, 'include_dirs': my_include_dirs}) + +setup( + name = 'libzt', + version = '1.3.3', + description = 'ZeroTier', + long_description = 'Encrypted P2P communication between apps and services', + author = 'ZeroTier, Inc.', + author_email = 'joseph.henry@zerotier.com', + url = 'https://github.com/zerotier/libzt', + license='BUSL 1.1', + download_url = 'https://github.com/zerotier/libzt/archive/1.3.3.tar.gz', + keywords = 'zerotier sdwan sdn virtual network socket p2p peer-to-peer', + py_modules = ['libzt'], + packages = ['libzt'], + classifiers = ['Development Status :: 3 - Alpha', + 'Topic :: Internet', + 'Topic :: System :: Networking', + 'Topic :: Security :: Cryptography', + 'Operating System :: OS Independent', + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'Intended Audience :: Science/Research', + 'Intended Audience :: System Administrators', + 'Intended Audience :: Telecommunications Industry', + 'Intended Audience :: End Users/Desktop', + 'License :: Free for non-commercial use', + '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' + ], + distclass=BinaryDistribution, + libraries=[cstuff], + ext_modules = [libzt_module], + python_requires='>=3.0', +) \ No newline at end of file