'\" t
.\"     Title: nng_zerotier
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.23
.\"      Date: 2025-02-02
.\"    Manual: NNG Reference Manual
.\"    Source: \ \&
.\"  Language: English
.\"
.TH "NNG_ZEROTIER" "7" "2025-02-02" "\ \&" "NNG Reference Manual"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
nng_zerotier \- ZeroTier transport
.SH "SYNOPSIS"
.sp
.if n .RS 4
.nf
.fam C
#include <nng/transport/zerotier/zerotier.h>

int nng_zt_register(void);
.fam
.fi
.if n .RE
.SH "DESCRIPTION"
.sp

The \fIzt\fP transport provides communication support for
\fINNG\fP applications over a \c
.URL "http://www.zerotier.com" "ZeroTier" ""
network,
using a Virtual Layer 2 packet facility.
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Important
.ps -1
.br
.sp
This transport is experimental.
To utilize it at present, the library must be built with support, and linked
against a suitable \f(CRlibzerotiercore\fP library.
Further information about building with this support are in the build
documentation included with the distribution.
.sp .5v
.RE
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Important
.ps -1
.br
.sp
The \f(CRlibzerotiercore\fP library at present is covered under different
license terms than the rest of \fINNG\fP.  Please be careful to review
and adhere to the licensing terms.
.sp .5v
.RE
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Important
.ps -1
.br
.sp
The ZeroTier transport can take a long time to establish an
initial connection \(em up to even a minute in extreme cases, while the network
topology is configured.  Consequently, this transport is not recommended
for use cases involving short\-lived programs, but is better for long\-running
programs such as background daemons or agents.
.sp .5v
.RE
.sp
While ZeroTier makes use of the host\(cqs IP stack (and UDP in particular),
this transport does not use or require an IP stack on the virtual
network; thereby mitigating any considerations about IP address management.
.sp
This service uses Ethernet type 901 to transport packets.  Network rules
must permit this Ethernet type to pass in order to have a functional
network.
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Note
.ps -1
.br
.sp
This document assumes that the reader is familiar with ZeroTier
concepts and administration.
.sp .5v
.RE
.SS "Registration"
.sp
Depending upon how the library was built, it may be necessary to
register the transport by calling
\f(CRnng_zt_register()\fP.
This function
returns zero on success, or an nng error value if the transport
cannot be initialized for any reason.
.SS "URI Format"
.sp

This transport uses URIs using the scheme \f(CRzt://\fP, followed by a node
number (ten hexadecimal digits) followed by a \f(CR.\fP delimited, and then
a network address (sixteen hexadecimal digits), followed by a colon (\f(CR:\fP)
and service or port number (decimal value,
up to 24\-bits).
For example, the URI \f(CRzt://fedcba9876.0123456789abdef:999\fP indicates
that node fedcba9876 on network 0123456789abcdef is listening on port 999.
.sp
The special value \f(CR*\fP can be used in lieu of a node number to represent
the node\(cqs own node number.
.sp
Listeners may use port 0 to indicate that a suitable port
number be selected automatically.
Applications using this must determine the selected port number using the
\f(CRnng_listener_getopt()\fP function.
.SS "Socket Address"
.sp
When using an \f(CRnng_sockaddr\fP structure,
the actual structure is of type
\f(CRnng_sockaddr_zt\fP.
.SS "Node Presence"
.sp
By default this transport creates an "ephemeral" node, and used the
same ephemeral node for any additional endpoints created.
As this node is ephemeral, the keys associated with it and all associated data
are located in memory and are discarded upon application termination.
If a persistent node is desired, please see the \f(CRNNG_OPT_ZT_HOME\fP option.
.sp
It is possible for a single application to join multiple networks
using the same node, or using separate nodes.
.SS "Network Status"
.sp

A ZeroTier node can be in one of the following states, which can be obtained
with the \f(CRNNG_OPT_ZT_NETWORK_STATUS\fP option:
.sp
\f(CRNNG_ZT_STATUS_UP\fP
.RS 4
The ZeroTier network is up.
This is the only state where it is possible to communicate with peers,
and the only state where the network name (\f(CRNNG_OPT_ZT_NETWORK_NAME\fP)
is available.
.RE
.sp
\f(CRNNG_ZT_STATUS_CONFIG\fP
.RS 4
The ZeroTier node is still configuring, network services are not available.
.RE
.sp
\f(CRNNG_ZT_STATUS_DENIED\fP
.RS 4
The node does not have permission to join the ZeroTier network.
.RE
.sp
\f(CRNNG_ZT_STATUS_NOTFOUND\fP
.RS 4
The ZeroTier network is not found.
.RE
.sp
\f(CRNNG_ZT_STATUS_ERROR\fP
.RS 4
Some other ZeroTier error has occurred; the network is not available.
.RE
.sp
\f(CRNNG_ZT_STATUS_OBSOLETE\fP
.RS 4
The node is running obsolete software; the network is not available.
.RE
.sp
\f(CRNNG_ZT_STATUS_UNKNOWN\fP
.RS 4
The network is in an unknown state. This should not happen, as it
indicates that the ZeroTier software is reporting an unexpected status.
The network is most likely not available.
.RE
.SS "Transport Options"
.sp
The following transport options are available:
.sp
\f(CRNNG_OPT_ZT_HOME\fP
.RS 4
(string) This option represents the home directory, where the transport
can store (and reuse) persistent state, such as key materials, node
identity, and federation membership.
This option must be set before the ZeroTier transport is first used.
If this value is empty, then an ephemeral ZeroTier node is created,
and no persistent state is used.
The default is to use an ephemeral node.
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Note
.ps -1
.br
.sp
If this option is set to different values on different sockets,
dialers, or listeners, then separate nodes will be created.
It is perfectly valid for an application to have multiple node identities
in this fashion.
.sp .5v
.RE
.RE
.sp
\f(CRNNG_OPT_ZT_NWID\fP
.RS 4
(\f(CRuint64_t\fP) The 64\-bit ZeroTier network number (native byte order).
.RE
.sp
\f(CRNNG_OPT_ZT_NODE\fP
.RS 4
(\f(CRuint64_t\fP) The ZeroTier  40\-bit node address (native byte order).
.RE
.sp
\f(CRNNG_OPT_ZT_NETWORK_STATUS\fP
.RS 4

(\f(CRint\fP) The ZeroTier network status.
See Network Status for an explanation of this option.
.RE
.sp
\f(CRNNG_OPT_ZT_NETWORK_NAME\fP
.RS 4

(string) The name of the network
as established by the ZeroTier network administrator.
.RE
.sp
\f(CRNNG_OPT_ZT_CONN_TIME\fP
.RS 4
(\f(CRnng_duration\fP)
The time to wait between sending connection attempts,
only used with dialers.
The default is 500 msec.
.RE
.sp
\f(CRNNG_OPT_ZT_CONN_TRIES\fP
.RS 4
(\f(CRint\fP) The maximum number of attempts to try to establish a connection
before reporting a timeout, and is only used with dialers.
The default is 240, which results in a 2 minute timeout if
\f(CRNNG_OPT_ZT_CONN_TIME\fP is at its default of 500.
If the value is set to 0, then connection attempts will keep retrying forever.
.RE
.sp
\f(CRNNG_OPT_ZT_PING_TIME\fP
.RS 4
(\f(CRnng_duration\fP) If no traffic has been received from
the ZeroTier peer after this
period of time, then a ping message is sent to check if the peer
is still alive.
.RE
.sp
\f(CRNNG_OPT_ZT_PING_TRIES\fP
.RS 4
(\f(CRint\fP) If this number of consecutive ping requests are sent to the
peer with no response (and no other intervening traffic), then the
peer is assumed to be dead and the connection is closed.
.RE
.sp
\f(CRNNG_OPT_ZT_MTU\fP
.RS 4
(\f(CRsize_t\fP) The ZeroTier virtual network MTU (read\-only) as configured
on the network; this is the Virtual Layer 2 MTU.  The headers used by
this transport and the protocols consume some of this for each message
sent over the network.  (The transport uses 20\-bytes of this, and each
protocol may consume additional space, typically not more than 16\-bytes.)
.RE
.sp
\f(CRNNG_OPT_ZT_ORBIT\fP
.RS 4
(\f(CRuint64_t[2]\fP) Write\-only array of two \f(CRuint64_t\fP values,
indicating the ID of a ZeroTier <em>moon</em>, and the node ID of the root server
for that moon.  (The ID may be zero if the moon ID is the same as its
root server ID, which is conventional.)
.RE
.sp
\f(CRNNG_OPT_ZT_DEORBIT\fP
.RS 4
(\f(CRuint64_t\fP) Write\-only option indicating the moon ID to deorbit.
If the node is not already orbiting the moon, then this has no effect.
.RE
.SH "SEE ALSO"
.sp
nng_sockaddr_zt(5),
nng(7)