This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Sean Reifschneider 7dbf42d899 Attempt to fix zts_recv for Python.
There were a few I'm attempting to fix in zts_py_recv():

Was allocating a static buffer of 4096, but taking whatever
length the user passed in.  This change allocates a PyBytes
object of the size the user requests.

Was converting to a string without giving a size.  Which probably
led to the UnicodeDecodeError I was seeing below, trying to
decode a character beyond the received bytes.  Would also lead
to problems reading binary data that included embedded NULs.
Used the number of bytes received as the size of the returned data.

Variable "err" was being used, changed that to "bytes_read" as
that's what lwip_recv() returns, with <0 bytes read indicating
error.

Read data was being returned as a Unicode string, leading to this
response when I tried talking to my SSH server:

    UnicodeDecodeError: 'utf-8' codec can't decode
    byte 0xa1 in position 42: invalid start byte

My ssh banner is 40 bytes long, so I think position 42 was outside
the received buffer.  Changed it to a PyBytes response as is
normal for network data.  This code was cribbed from the Python
socketmodule

This was producing this error, as it was still returning the tuple:

    SystemError: <built-in function zts_py_recv> returned a
    result with an error set

This indicates that the UnicodeDecodeError had set an exception,
but a tuple was being returned instead of NULL.

In the case of a lwip_recv() error, the error response was not
being sent back to the wrapper code.  Instead, a "return NULL;"
was done.  I changed this case to return the tuple (err, None)
to the wrapper.

NOTE: this code built using "./build.sh host-python release", but
there was some sort of build problem I didn't understand which
produced a _libzt.so that I couldn't import, due to:

    ImportError: dynamic module does not define module export
    function (PyInit__libzt)

So I don't have a way to test these changes.
2021-03-16 15:52:55 -06:00
2021-03-12 21:24:26 -08:00
2021-03-16 15:52:55 -06:00
2021-02-16 00:24:38 -08:00
2019-05-07 12:22:58 -07:00
2020-12-20 18:40:17 -07:00
2021-01-23 11:58:06 -08:00
2021-03-02 01:53:03 -08:00
2021-03-10 11:20:00 -08:00

ZeroTier SDK

zts_socket()

Peer-to-peer and cross-platform encrypted connections built right into your app or service. No drivers, no root, and no host configuration.


Examples | API Documentation | Community | Report a Bug

@zerotier r/zerotier

latest libzt version Last Commit Build Status (master branch)

Language/Platform Installation Version Example
C/C++ Build from source version C/C++
Objective-C See examples/objective-c version Objective-C
C# Install-Package ZeroTier.Sockets C#
Python pip install libzt Python
Rust Coming very soon version Rust
Swift See examples/swift version Swift
Java ./build.sh host-jar Java
Node.js See examples/nodejs Node.js
Linux Build from source version C/C++
macOS brew install libzt C/C++, Objective-C
iOS / iPadOS ./build.sh ios-framework Objective-C, Swift
Android ./build.sh android-aar Java

#include "ZeroTierSockets.h"

int main()
{
    zts_start(...)
    zts_join(networkId);
    zts_socket(ZTS_AF_INET, ZTS_SOCK_STREAM, 0);
    zts_connect(...);
    ...
}

Build from source

git submodule update --init

This project uses CMake as a build system generator. The scripts build.* simplify building and packaging for various targets. There are many targets and configurations not mentioned here.

Platform Build instructions Notes
Linux ./build.sh host "release" build.sh
macOS ./build.sh host "release" build.sh
Windows . .\build.ps1; Build-Host -BuildType "Release" build.ps1, Requires PowerShell

Using the host keyword will automatically detect the current machine type and build standard libzt for use in C/C++ (no additional language bindings.) See ./build.sh list for additional target options.

Example output:

~/libzt/dist/macos-x64-host-release
├── bin
│   ├── client
│   ├── server
│   └── ...
└── lib
    ├── libzt.a
    └── libzt.dylib

Important directories:

Directory Purpose
dist Contains finished targets (libraries, binaries, packages, etc.)
cache Contains build system caches that can safely be deleted after use.
pkg Contains project, script and spec files to generate packages.

Self-hosting (Optional)

We provide ways for your app or enterprise to function indepenently from any of our services if desired.

While we do operate a global network of redundant root servers, network controllers and an admin API/UI called Central, some use-cases require full control over the infrastructure and we try to make it as easy as possible to set up your own controllers and root servers: See here to learn more about how to set up your own network controller, and here to learn more about setting up your own roots.

Help

Licensing

ZeroTier and the ZeroTier SDK (libzt and libztcore) are licensed under the BSL version 1.1. ZeroTier is free to use internally in businesses and academic institutions and for non-commercial purposes. Certain types of commercial use such as building closed-source apps and devices based on ZeroTier or offering ZeroTier network controllers and network management as a SaaS service require a commercial license. A small amount of third party code is also included in ZeroTier and is not subject to our BSL license. See AUTHORS.md for a list of third party code, where it is included, and the licenses that apply to it. All of the third party code in ZeroTier is liberally licensed (MIT, BSD, Apache, public domain, etc.). If you want a commercial license to use the ZeroTier SDK in your product contact us directly via contact@zerotier.com

Description
No description provided
Readme 17 MiB
Languages
C++ 58%
C 21.6%
C# 5.8%
Java 5%
Rust 3.3%
Other 6.3%