aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-08-31 09:51:55 -0700
committerGarrett D'Amore <garrett@damore.org>2018-08-31 09:51:55 -0700
commit2426984f20a8363e52fef5cd69221da05c0b1756 (patch)
tree259aaec2d304707003a343a0ad9a6b45f8d2fcd5
parent0cc96c69b3fce09a9c4a8d467d17cfbda76bc02f (diff)
downloadnng-2426984f20a8363e52fef5cd69221da05c0b1756.tar.gz
nng-2426984f20a8363e52fef5cd69221da05c0b1756.tar.bz2
nng-2426984f20a8363e52fef5cd69221da05c0b1756.zip
fixes #690 Zerotier listener LOCADDR property wanted
While here we separate out the dialer and listener options, so that options for tuning connection are only available for listeners.
-rw-r--r--src/transport/zerotier/zerotier.c99
-rw-r--r--tests/zt.c18
2 files changed, 108 insertions, 9 deletions
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index 95fedc0d..ff732236 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -2892,6 +2892,22 @@ zt_ep_get_conn_tries(void *arg, void *data, size_t *szp, nni_opt_type t)
}
static int
+zt_ep_get_locaddr(void *arg, void *data, size_t *szp, nni_opt_type t)
+{
+ zt_ep * ep = arg;
+ nng_sockaddr sa;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.s_zt.sa_family = NNG_AF_ZT;
+ nni_mtx_lock(&zt_lk);
+ sa.s_zt.sa_nwid = ep->ze_nwid;
+ sa.s_zt.sa_nodeid = ep->ze_laddr >> zt_port_shift;
+ sa.s_zt.sa_port = ep->ze_laddr & zt_port_mask;
+ nni_mtx_unlock(&zt_lk);
+ return (nni_copyout_sockaddr(&sa, data, szp, t));
+}
+
+static int
zt_pipe_get_locaddr(void *arg, void *data, size_t *szp, nni_opt_type t)
{
zt_pipe * p = arg;
@@ -2973,7 +2989,7 @@ static nni_tran_pipe_ops zt_pipe_ops = {
.p_options = zt_pipe_options,
};
-static nni_tran_option zt_ep_options[] = {
+static nni_tran_option zt_dialer_options[] = {
{
.o_name = NNG_OPT_RECVMAXSZ,
.o_type = NNI_TYPE_SIZE,
@@ -3059,12 +3075,89 @@ static nni_tran_option zt_ep_options[] = {
},
};
+static nni_tran_option zt_listener_options[] = {
+ {
+ .o_name = NNG_OPT_RECVMAXSZ,
+ .o_type = NNI_TYPE_SIZE,
+ .o_get = zt_ep_get_recvmaxsz,
+ .o_set = zt_ep_set_recvmaxsz,
+ .o_chk = zt_ep_chk_recvmaxsz,
+ },
+ {
+ .o_name = NNG_OPT_URL,
+ .o_type = NNI_TYPE_STRING,
+ .o_get = zt_ep_get_url,
+ },
+ {
+ .o_name = NNG_OPT_ZT_HOME,
+ .o_type = NNI_TYPE_STRING,
+ .o_get = zt_ep_get_home,
+ .o_set = zt_ep_set_home,
+ .o_chk = zt_ep_chk_string,
+ },
+ {
+ .o_name = NNG_OPT_ZT_NODE,
+ .o_type = NNI_TYPE_UINT64,
+ .o_get = zt_ep_get_node,
+ },
+ {
+ .o_name = NNG_OPT_ZT_NWID,
+ .o_type = NNI_TYPE_UINT64,
+ .o_get = zt_ep_get_nwid,
+ },
+ {
+ .o_name = NNG_OPT_ZT_NETWORK_STATUS,
+ .o_type = NNI_TYPE_INT32, // enumeration really
+ .o_get = zt_ep_get_nw_status,
+ },
+ {
+ .o_name = NNG_OPT_ZT_NETWORK_NAME,
+ .o_type = NNI_TYPE_STRING,
+ .o_get = zt_ep_get_nw_name,
+ },
+ {
+ .o_name = NNG_OPT_ZT_PING_TIME,
+ .o_type = NNI_TYPE_DURATION,
+ .o_get = zt_ep_get_ping_time,
+ .o_set = zt_ep_set_ping_time,
+ .o_chk = zt_ep_chk_time,
+ },
+ {
+ .o_name = NNG_OPT_ZT_PING_TRIES,
+ .o_type = NNI_TYPE_INT32,
+ .o_get = zt_ep_get_ping_tries,
+ .o_set = zt_ep_set_ping_tries,
+ .o_chk = zt_ep_chk_tries,
+ },
+ {
+ .o_name = NNG_OPT_ZT_ORBIT,
+ .o_type = NNI_TYPE_UINT64, // use opaque for two
+ .o_set = zt_ep_set_orbit,
+ .o_chk = zt_ep_chk_orbit,
+ },
+ {
+ .o_name = NNG_OPT_ZT_DEORBIT,
+ .o_type = NNI_TYPE_UINT64,
+ .o_set = zt_ep_set_deorbit,
+ .o_chk = zt_ep_chk_deorbit,
+ },
+ {
+ .o_name = NNG_OPT_LOCADDR,
+ .o_type = NNI_TYPE_SOCKADDR,
+ .o_get = zt_ep_get_locaddr,
+ },
+ // terminate list
+ {
+ .o_name = NULL,
+ },
+};
+
static nni_tran_dialer_ops zt_dialer_ops = {
.d_init = zt_dialer_init,
.d_fini = zt_ep_fini,
.d_connect = zt_ep_connect,
.d_close = zt_ep_close,
- .d_options = zt_ep_options,
+ .d_options = zt_dialer_options,
};
static nni_tran_listener_ops zt_listener_ops = {
@@ -3073,7 +3166,7 @@ static nni_tran_listener_ops zt_listener_ops = {
.l_bind = zt_ep_bind,
.l_accept = zt_ep_accept,
.l_close = zt_ep_close,
- .l_options = zt_ep_options,
+ .l_options = zt_listener_options,
};
// This is the ZeroTier transport linkage, and should be the
diff --git a/tests/zt.c b/tests/zt.c
index 237cc01a..bc11d3ac 100644
--- a/tests/zt.c
+++ b/tests/zt.c
@@ -21,6 +21,7 @@
// This network is an open network setup exclusively for nng testing.
// Do not attach to it in production.
#define NWID "a09acf02337b057b"
+#define NWID_NUM 0xa09acf02337b057bull
// This network is a closed network, which nothing can join. We use it for
// testing permission denied.
@@ -53,7 +54,7 @@ check_props(nng_msg *msg)
So(la.s_family == NNG_AF_ZT);
So(la.s_zt.sa_port == (trantest_port - 1));
- So(la.s_zt.sa_nwid == 0xa09acf02337b057bull);
+ So(la.s_zt.sa_nwid == NWID_NUM);
So(la.s_zt.sa_nodeid != 0);
});
@@ -65,7 +66,7 @@ check_props(nng_msg *msg)
So(nng_pipe_getopt_sockaddr(p, NNG_OPT_REMADDR, &ra) == 0);
So(ra.s_family == NNG_AF_ZT);
So(ra.s_zt.sa_port != 0);
- So(ra.s_zt.sa_nwid == 0xa09acf02337b057bull);
+ So(ra.s_zt.sa_nwid == NWID_NUM);
So(nng_pipe_getopt_uint64(p, NNG_OPT_ZT_NODE, &mynode) == 0);
So(mynode != 0);
@@ -124,7 +125,6 @@ check_props(nng_msg *msg)
}
TestMain("ZeroTier Transport", {
-
char path1[NNG_MAXADDRLEN] = "/tmp/zt_server";
char path2[NNG_MAXADDRLEN] = "/tmp/zt_client";
unsigned port;
@@ -150,7 +150,6 @@ TestMain("ZeroTier Transport", {
So(nng_listener_create(&l, s, addr) == 0);
Convey("And it can be started...", {
-
mkdir(path1, 0700);
So(nng_listener_setopt(l, NNG_OPT_ZT_HOME, path1,
@@ -158,6 +157,15 @@ TestMain("ZeroTier Transport", {
So(nng_listener_start(l, 0) == 0);
+ Convey("It has the right local address", {
+ nng_sockaddr sa;
+ So(nng_listener_getopt_sockaddr(
+ l, NNG_OPT_LOCADDR, &sa) == 0);
+ So(sa.s_zt.sa_family == NNG_AF_ZT);
+ So(sa.s_zt.sa_nwid == NWID_NUM);
+ So(sa.s_zt.sa_port == port);
+ So(sa.s_zt.sa_nodeid != 0);
+ });
Convey("And we can orbit a moon", {
uint64_t ids[2];
// Provided by Janjaap...
@@ -166,7 +174,6 @@ TestMain("ZeroTier Transport", {
So(nng_listener_setopt(l, NNG_OPT_ZT_ORBIT,
ids, sizeof(ids)) == 0);
-
});
Convey("And we can deorbit anything", {
uint64_t id;
@@ -284,5 +291,4 @@ TestMain("ZeroTier Transport", {
nng_listener_close(l_test);
trantest_test_extended(fmt, check_props);
-
})