From 54f39e9eb073883f433710ff683ea0aa212e0215 Mon Sep 17 00:00:00 2001 From: Logan oos Even <46396513+Logan007@users.noreply.github.com> Date: Thu, 17 Jun 2021 22:16:45 +0545 Subject: [PATCH] fixed supernode's detetcion of orderly remote tcp connection closure (#713) --- src/sn_utils.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/sn_utils.c b/src/sn_utils.c index fd12fd5..1828f09 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -2265,10 +2265,11 @@ int run_sn_loop (n2n_sn_t *sss, int *keep_running) { conn->buffer + conn->position, conn->expected - conn->position, 0 /*flags*/, (struct sockaddr *)&sender_sock, (socklen_t *)&i); - if((bread <= 0) && (errno)) { - traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno)); + if(bread <= 0) { + traceEvent(TRACE_INFO, "run_sn_loop closes tcp connection to '%s'", sock_to_cstr(sockbuf, (n2n_sock_t*)&sender_sock)); + traceEvent(TRACE_DEBUG, "recvfrom() returns %d and sees errno %d (%s)", bread, errno, strerror(errno)); #ifdef WIN32 - traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); + traceEvent(TRACE_DEBUG, "WSAGetLastError(): %u", WSAGetLastError()); #endif close_tcp_connection(sss, conn); continue; @@ -2280,7 +2281,8 @@ int run_sn_loop (n2n_sn_t *sss, int *keep_running) { // the prepended length has been read, preparing for the packet conn->expected += be16toh(*(uint16_t*)(conn->buffer)); if(conn->expected > N2N_SN_PKTBUF_SIZE) { - traceEvent(TRACE_ERROR, "too many bytes in tcp packet expected"); + traceEvent(TRACE_INFO, "run_sn_loop closes tcp connection to '%s'", sock_to_cstr(sockbuf, (n2n_sock_t*)&sender_sock)); + traceEvent(TRACE_DEBUG, "too many bytes in tcp packet expected"); close_tcp_connection(sss, conn); continue; } @@ -2322,8 +2324,8 @@ int run_sn_loop (n2n_sn_t *sss, int *keep_running) { conn->expected = sizeof(uint16_t); conn->position = 0; HASH_ADD_INT(sss->tcp_connections, socket_fd, conn); - traceEvent(TRACE_DEBUG, "run_sn_loop accepted incoming TCP connection from %s", - sock_to_cstr(sockbuf, (n2n_sock_t*)&sender_sock)); + traceEvent(TRACE_INFO, "run_sn_loop accepted incoming TCP connection from %s", + sock_to_cstr(sockbuf, (n2n_sock_t*)&sender_sock)); } } } else { @@ -2357,9 +2359,9 @@ int run_sn_loop (n2n_sn_t *sss, int *keep_running) { if(((now - before) < wait_time.tv_sec) && (*keep_running)){ // this is no real timeout, something went wrong with one of the tcp connections (probably) // close them all, edges will re-open if they detect closure + traceEvent(TRACE_DEBUG, "falsly claimed timeout, assuming issue with tcp connection, closing them all"); HASH_ITER(hh, sss->tcp_connections, conn, tmp_conn) close_tcp_connection(sss, conn); - traceEvent(TRACE_DEBUG, "falsly claimed timeout, assuming issue with tcp connection, closing them all"); } else traceEvent(TRACE_DEBUG, "timeout"); }