aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-10-19 15:16:25 -0700
committerGarrett D'Amore <garrett@damore.org>2017-10-19 17:56:49 -0700
commit4e668fdd5b5da0d46f97d835249dbe5f0ea319a7 (patch)
tree0aaad8a672024b3a510763150b167320be6f1f5b /src/transport
parentd7e39a2423212a31c5ef62dcb0b7a5b4bf9f34df (diff)
downloadnng-4e668fdd5b5da0d46f97d835249dbe5f0ea319a7.tar.gz
nng-4e668fdd5b5da0d46f97d835249dbe5f0ea319a7.tar.bz2
nng-4e668fdd5b5da0d46f97d835249dbe5f0ea319a7.zip
fixes #84 Consider using msec for durations
There is now a public nng_duration type. We have also updated the zerotier work to work with the signed int64_t's that the latst ZeroTier dev branch is using.
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/tcp/tcp.c6
-rw-r--r--src/transport/zerotier/zerotier.c49
-rw-r--r--src/transport/zerotier/zerotier.h2
3 files changed, 27 insertions, 30 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 2e0b023a..5ed90ca4 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -800,16 +800,16 @@ nni_tcp_ep_setopt_linger(void *arg, const void *v, size_t sz)
{
nni_tcp_ep *ep = arg;
if (ep == NULL) {
- return (nni_chkopt_usec(v, sz));
+ return (nni_chkopt_ms(v, sz));
}
- return (nni_setopt_usec(&ep->linger, v, sz));
+ return (nni_setopt_ms(&ep->linger, v, sz));
}
static int
nni_tcp_ep_getopt_linger(void *arg, void *v, size_t *szp)
{
nni_tcp_ep *ep = arg;
- return (nni_getopt_usec(ep->linger, v, szp));
+ return (nni_getopt_ms(ep->linger, v, szp));
}
static nni_tran_pipe_option nni_tcp_pipe_options[] = {
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index e306c85a..607c353c 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -91,14 +91,14 @@ static const uint32_t zt_port_shift = 24;
// These are compile time tunables for now.
enum zt_tunables {
zt_listenq = 128, // backlog queue length
- zt_listen_expire = 60000000, // maximum time in backlog
+ zt_listen_expire = 60000, // maximum time in backlog (msec)
zt_rcv_bufsize = ZT_MAX_PHYSMTU, // max UDP recv
zt_conn_attempts = 12, // connection attempts (default)
- zt_conn_interval = 5000000, // between attempts (usec)
+ zt_conn_interval = 5000, // between attempts (msec)
zt_udp_sendq = 16, // outgoing UDP queue length
zt_recvq = 2, // max pending recv (per pipe)
- zt_recv_stale = 1000000, // frags older than are stale
- zt_ping_time = 60000000, // keepalive time (usec)
+ zt_recv_stale = 1000, // frags older than are stale (msec)
+ zt_ping_time = 60000, // keepalive time (msec)
zt_ping_count = 5, // keepalive attempts
};
@@ -292,22 +292,22 @@ static void zt_virtual_recv(ZT_Node *, void *, void *, uint64_t, void **,
uint64_t, uint64_t, unsigned int, unsigned int, const void *,
unsigned int);
-static uint64_t
+static int64_t
zt_now(void)
{
// We return msec
- return (nni_clock() / 1000);
+ return ((int64_t) nni_clock());
}
static void
zt_bgthr(void *arg)
{
zt_node *ztn = arg;
- nni_time now;
+ int64_t now;
nni_mtx_lock(&zt_lk);
for (;;) {
- now = nni_clock();
+ now = zt_now();
if (ztn->zn_closed) {
break;
@@ -318,18 +318,21 @@ zt_bgthr(void *arg)
continue;
}
- now /= 1000; // usec -> msec
+ ztn->zn_bgtime = 0;
ZT_Node_processBackgroundTasks(ztn->zn_znode, NULL, now, &now);
- ztn->zn_bgtime = now * 1000; // usec
+ ztn->zn_bgtime = now;
}
nni_mtx_unlock(&zt_lk);
}
static void
-zt_node_resched(zt_node *ztn, uint64_t msec)
+zt_node_resched(zt_node *ztn, int64_t msec)
{
- ztn->zn_bgtime = msec * 1000; // convert to usec
+ if (msec > ztn->zn_bgtime && ztn->zn_bgtime != 0) {
+ return;
+ }
+ ztn->zn_bgtime = msec;
nni_cv_wake1(&ztn->zn_bgcv);
}
@@ -341,7 +344,7 @@ zt_node_rcv4_cb(void *arg)
struct sockaddr_storage sa;
struct sockaddr_in * sin;
nng_sockaddr_in * nsin;
- uint64_t now;
+ int64_t now;
if (nni_aio_result(aio) != 0) {
// Outside of memory exhaustion, we can't really think
@@ -392,7 +395,7 @@ zt_node_rcv6_cb(void *arg)
struct sockaddr_storage sa;
struct sockaddr_in6 * sin6;
struct nng_sockaddr_in6 *nsin6;
- uint64_t now;
+ int64_t now;
if (nni_aio_result(aio) != 0) {
// Outside of memory exhaustion, we can't really think
@@ -558,7 +561,7 @@ zt_send(zt_node *ztn, uint64_t nwid, uint8_t op, uint64_t raddr,
{
uint64_t srcmac = zt_node_to_mac(laddr >> 24, nwid);
uint64_t dstmac = zt_node_to_mac(raddr >> 24, nwid);
- uint64_t now = zt_now();
+ int64_t now = zt_now();
NNI_ASSERT(len >= zt_size_headers);
data[zt_offset_op] = op;
@@ -569,13 +572,6 @@ zt_send(zt_node *ztn, uint64_t nwid, uint8_t op, uint64_t raddr,
ZT_PUT24(data + zt_offset_dst_port, raddr & zt_port_mask);
ZT_PUT24(data + zt_offset_src_port, laddr & zt_port_mask);
- // If we are looping back, bypass ZT.
- if (srcmac == dstmac) {
- zt_virtual_recv(ztn->zn_znode, ztn, NULL, nwid, NULL, srcmac,
- dstmac, zt_ethertype, 0, data, len);
- return;
- }
-
(void) ZT_Node_processVirtualNetworkFrame(ztn->zn_znode, NULL, now,
nwid, srcmac, dstmac, zt_ethertype, 0, data, len, &now);
@@ -1877,6 +1873,8 @@ zt_pipe_dorecv(zt_pipe *p)
msg = fl->fl_msg;
fl->fl_msg = NULL;
NNI_ASSERT(msg != NULL);
+
+ p->zp_user_rxaio = NULL;
nni_aio_finish_msg(aio, msg);
zt_fraglist_clear(fl);
return;
@@ -2375,7 +2373,6 @@ zt_ep_doaccept(zt_ep *ep)
continue;
}
p->zp_peer = creq.cr_proto;
-
zt_pipe_send_conn_ack(p);
nni_aio_finish_pipe(aio, p);
}
@@ -2645,16 +2642,16 @@ zt_ep_setopt_ping_time(void *arg, const void *data, size_t sz)
{
zt_ep *ep = arg;
if (ep == NULL) {
- return (nni_chkopt_usec(data, sz));
+ return (nni_chkopt_ms(data, sz));
}
- return (nni_setopt_usec(&ep->ze_ping_time, data, sz));
+ return (nni_setopt_ms(&ep->ze_ping_time, data, sz));
}
static int
zt_ep_getopt_ping_time(void *arg, void *data, size_t *szp)
{
zt_ep *ep = arg;
- return (nni_getopt_usec(ep->ze_ping_time, data, szp));
+ return (nni_getopt_ms(ep->ze_ping_time, data, szp));
}
static int
diff --git a/src/transport/zerotier/zerotier.h b/src/transport/zerotier/zerotier.h
index 1b3ee8b6..4f10f9be 100644
--- a/src/transport/zerotier/zerotier.h
+++ b/src/transport/zerotier/zerotier.h
@@ -81,7 +81,7 @@
// is sent. This will be done up to ping-count times. If no traffic from
// the remote peer is seen after all ping requests are sent, then the peer
// is assumed to be dead or offline, and the session is closed. The
-// NNG_OPT_ZT_PING_TIME is a duration (usec, stored as an nng_duration, and
+// NNG_OPT_ZT_PING_TIME is a duration (msec, stored as an nng_duration, and
// NNG_OPT_ZT_PING_COUNT is an integer.) This ping process can be disabled
// by setting either ping-time or ping-count to zero.
#define NNG_OPT_ZT_PING_TIME "zt:ping-time"