From 8a20acfa34e1eedf34254354b8a219bd8fbca2ed Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 7 Mar 2018 17:06:16 -0800 Subject: fixes #269 nngcat unreliable with ZeroTier transport This does a few things. First it closes a case where a dropped message could prevent subsequent connection attempts from getting through. Second, it changes the rate at which we retry, and the timeout, to be a lot more aggressive when attempting to establish a connection. We retry every 500 ms, for up to 2 minutes, before giving up. This gives a lot more resilience in the face of message loss that is typical of ZeroTier in some environments when first establishing communication. Third, makes the values for the connection attempts *tunable*, so that applications can adjust for different deployment scenarios. Fourth, it includes the ability to get the UDP socket name. This was needed during some debug, and may be useful for a real UDP transport later, so we're keeping it. Finally, we added documentation for the above items. --- src/platform/posix/posix_udp.c | 15 +++++++++++++++ src/platform/windows/win_udp.c | 14 ++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'src/platform') diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index 61546667..8a402acc 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -306,4 +306,19 @@ nni_plat_udp_send(nni_plat_udp *udp, nni_aio *aio) nni_mtx_unlock(&udp->udp_mtx); } +int +nni_plat_udp_sockname(nni_plat_udp *udp, nni_sockaddr *sa) +{ + struct sockaddr_storage ss; + socklen_t sz; + int rv; + + sz = sizeof(ss); + if ((rv = getsockname(udp->udp_fd, (struct sockaddr *) &ss, &sz)) < + 0) { + return (nni_plat_errno(errno)); + } + return (nni_posix_sockaddr2nn(sa, &ss)); +} + #endif // NNG_PLATFORM_POSIX diff --git a/src/platform/windows/win_udp.c b/src/platform/windows/win_udp.c index 81aa2c06..ba6b400c 100644 --- a/src/platform/windows/win_udp.c +++ b/src/platform/windows/win_udp.c @@ -289,6 +289,20 @@ nni_win_udp_finish_tx(nni_win_event *evt, nni_aio *aio) nni_aio_finish(aio, rv, cnt); } +int +nni_plat_udp_sockname(nni_plat_udp *udp, nni_sockaddr *sa) +{ + SOCKADDR_STORAGE ss; + int sz; + int rv; + + sz = sizeof(ss); + if ((rv = getsockname(udp->s, (SOCKADDR *) &ss, &sz)) < 0) { + return (nni_win_error(GetLastError())); + } + return (nni_win_sockaddr2nn(sa, &ss)); +} + int nni_win_udp_sysinit(void) { -- cgit v1.2.3-70-g09d2