summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-10 12:53:37 -0800
committerGarrett D'Amore <garrett@damore.org>2018-03-10 12:53:37 -0800
commit3ad3e050704de2ca343848a46dd913b3b84bc287 (patch)
tree2b2c4b34a7229dbe8845d850b9898bf577665e0a
parent6f2ced1d6c3bfd4a4fcbc29701beb42348782a53 (diff)
downloadnng-3ad3e050704de2ca343848a46dd913b3b84bc287.tar.gz
nng-3ad3e050704de2ca343848a46dd913b3b84bc287.tar.bz2
nng-3ad3e050704de2ca343848a46dd913b3b84bc287.zip
fixes #276 decouple NNG and zerotier definitions
-rw-r--r--docs/man/nng_zerotier.adoc56
-rw-r--r--src/transport/zerotier/zerotier.c35
-rw-r--r--src/transport/zerotier/zerotier.h15
-rw-r--r--tests/zt.c6
4 files changed, 64 insertions, 48 deletions
diff --git a/docs/man/nng_zerotier.adoc b/docs/man/nng_zerotier.adoc
index a36f20de..06f89566 100644
--- a/docs/man/nng_zerotier.adoc
+++ b/docs/man/nng_zerotier.adoc
@@ -115,6 +115,36 @@ below.
It is possible for a single application to join multiple networks
using the same node, or using separate nodes.
+=== Network Status
+
+A ZeroTier node can be in one of the following states, which
+can be obtained with the `NNG_OPT_ZT_NETWORK_STATUS` option:
+
+`NNG_ZT_STATUS_UP`::
+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 (`NNG_OPT_ZT_NETWORK_NAME`) is available.
+
+`NNG_ZT_STATUS_CONFIG`::
+The ZeroTier node is still configuring, network services are not available.
+
+`NNG_ZT_STATUS_DENIED`::
+The node does not have permission to join the ZeroTier network.
+
+`NNG_ZT_STATUS_NOTFOUND`::
+The ZeroTier network is not found.
+
+`NNG_ZT_STATUS_ERROR`::
+Some other ZeroTier error has occurred; the network is not available.
+
+`NNG_ZT_STATUS_OBSOLETE`::
+The node is running obsolete software; the network is not available.
+
+`NNG_ZT_STATUS_UNKNOWN`::
+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.
+
=== Transport Options
The following transport options are available:
@@ -148,31 +178,7 @@ in this fashion.
`NNG_OPT_ZT_NETWORK_STATUS`::
This is a read-only integer, representing the ZeroTier network status.
- Valid values for this are:
-+
-[cols="3,5"]
-|===
-
-| `nng_zt_network_status_configuring`
-| The ZeroTier node is still configuring, network services are not available.
-
-| `nng_zt_network_status_ok`
-| The ZeroTier network is up.
-
-| `nng_zt_network_status_denied`
-| The node does not have permission to join the ZeroTier network.
-
-| `nng_zt_network_status_notfound`
-| The ZeroTier network is not found.
-
-| `nng_zt_network_status_error`
-| Some other ZeroTier error has occurred; the network is not available.
-
-| `nng_zt_network_status_obsolete`
-| The node is running obsolete software; the network is not available.
-
-|===
-
+ See <<Network Status>> for an explanation of this option.
`NNG_OPT_ZT_NETWORK_NAME`::
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index 254684b7..01c290db 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -18,17 +18,6 @@
#include <ZeroTierOne.h>
-// These values are supplied to help folks checking status. They are the
-// return values from zt_opt_status. It's important that the status values
-// here match what the underlying ZeroTier core gives us.
-int nng_zt_network_status_configuring =
- ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION;
-int nng_zt_network_status_ok = ZT_NETWORK_STATUS_OK;
-int nng_zt_network_status_denied = ZT_NETWORK_STATUS_ACCESS_DENIED;
-int nng_zt_network_status_notfound = ZT_NETWORK_STATUS_NOT_FOUND;
-int nng_zt_network_status_error = ZT_NETWORK_STATUS_PORT_ERROR;
-int nng_zt_network_status_obsolete = ZT_NETWORK_STATUS_CLIENT_TOO_OLD;
-
// ZeroTier Transport. This sits on the ZeroTier L2 network, which itself
// is implemented on top of UDP. This requires the 3rd party
// libzerotiercore library (which is GPLv3!) and platform specific UDP
@@ -1949,7 +1938,29 @@ zt_getopt_network_status(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp)
nni_mtx_unlock(&zt_lk);
return (NNG_ECLOSED);
}
- status = vcfg->status;
+ switch (vcfg->status) {
+ case ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION:
+ status = NNG_ZT_STATUS_CONFIG;
+ break;
+ case ZT_NETWORK_STATUS_OK:
+ status = NNG_ZT_STATUS_UP;
+ break;
+ case ZT_NETWORK_STATUS_ACCESS_DENIED:
+ status = NNG_ZT_STATUS_DENIED;
+ break;
+ case ZT_NETWORK_STATUS_NOT_FOUND:
+ status = NNG_ZT_STATUS_NOTFOUND;
+ break;
+ case ZT_NETWORK_STATUS_PORT_ERROR:
+ status = NNG_ZT_STATUS_ERROR;
+ break;
+ case ZT_NETWORK_STATUS_CLIENT_TOO_OLD:
+ status = NNG_ZT_STATUS_OBSOLETE;
+ break;
+ default:
+ status = NNG_ZT_STATUS_UNKNOWN;
+ break;
+ }
ZT_Node_freeQueryResult(ztn->zn_znode, vcfg);
nni_mtx_unlock(&zt_lk);
diff --git a/src/transport/zerotier/zerotier.h b/src/transport/zerotier/zerotier.h
index a191b106..3ba84879 100644
--- a/src/transport/zerotier/zerotier.h
+++ b/src/transport/zerotier/zerotier.h
@@ -121,12 +121,15 @@
// return values from zt_opt_status. We avoid hard coding them as defines,
// to keep applications from baking in values that may change if the
// underlying ZeroTier transport changes.
-NNG_DECL int nng_zt_network_status_configuring;
-NNG_DECL int nng_zt_network_status_ok;
-NNG_DECL int nng_zt_network_status_denied;
-NNG_DECL int nng_zt_network_status_notfound;
-NNG_DECL int nng_zt_network_status_error;
-NNG_DECL int nng_zt_network_status_obsolete;
+enum nng_zt_status {
+ NNG_ZT_STATUS_UP,
+ NNG_ZT_STATUS_CONFIG,
+ NNG_ZT_STATUS_DENIED,
+ NNG_ZT_STATUS_NOTFOUND,
+ NNG_ZT_STATUS_ERROR,
+ NNG_ZT_STATUS_OBSOLETE,
+ NNG_ZT_STATUS_UNKNOWN,
+};
NNG_DECL int nng_zt_register(void);
diff --git a/tests/zt.c b/tests/zt.c
index 4009588a..1952ef1b 100644
--- a/tests/zt.c
+++ b/tests/zt.c
@@ -39,10 +39,6 @@ mkdir(const char *path, int mode)
#include <unistd.h>
#endif // WIN32
-#ifndef NNG_TRANSPORT_ZEROTIER
-#define nng_zt_network_status_ok 0
-#endif
-
static int
check_props(nng_msg *msg)
{
@@ -94,7 +90,7 @@ check_props(nng_msg *msg)
z = sizeof(s);
s = 0;
So(nng_pipe_getopt(p, NNG_OPT_ZT_NETWORK_STATUS, &s, &z) == 0);
- So(s == nng_zt_network_status_ok);
+ So(s == NNG_ZT_STATUS_UP);
});
Convey("Ping properties work", {