merged with guus/1.1

This commit is contained in:
thorkill 2016-05-23 21:17:42 +02:00
commit f922b1c1e1
2 changed files with 35 additions and 19 deletions

View file

@ -148,7 +148,7 @@ static void timeout_handler(void *data) {
bool close_all_connections = false; bool close_all_connections = false;
/* /*
timeout_hanlder will start after 30 seconds from start of tincd timeout_handler will start after 30 seconds from start of tincd
hold information about the elapsed time since last time the handler hold information about the elapsed time since last time the handler
has been run has been run
*/ */
@ -176,6 +176,7 @@ static void timeout_handler(void *data) {
last_periodic_run_time = now; last_periodic_run_time = now;
for list_each(connection_t, c, connection_list) { for list_each(connection_t, c, connection_list) {
// control connections (eg. tinc ctl) do not have any timeout
if(c->status.control) if(c->status.control)
continue; continue;
@ -185,26 +186,34 @@ static void timeout_handler(void *data) {
continue; continue;
} }
if(c->last_ping_time.tv_sec + pingtimeout <= now.tv_sec) { // Bail out early if we haven't reached the ping timeout for this node yet
if(c->edge) { if(c->last_ping_time + pingtimeout > now.tv_sec)
try_tx(c->node, false); continue;
if(c->status.pinged) {
logger(DEBUG_CONNECTIONS, LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)now.tv_sec - c->last_ping_time.tv_sec); // timeout during connection establishing
} else if(c->last_ping_time.tv_sec + pinginterval <= now.tv_sec) { if(!c->edge) {
send_ping(c); if(c->status.connecting)
continue; logger(DEBUG_CONNECTIONS, LOG_WARNING, "Timeout while connecting to %s (%s)", c->name, c->hostname);
} else { else
continue; logger(DEBUG_CONNECTIONS, LOG_WARNING, "Timeout from %s (%s) during authentication", c->name, c->hostname);
}
} else {
if(c->status.connecting)
logger(DEBUG_CONNECTIONS, LOG_WARNING, "Timeout while connecting to %s (%s)", c->name, c->hostname);
else
logger(DEBUG_CONNECTIONS, LOG_WARNING, "Timeout from %s (%s) during authentication", c->name, c->hostname);
}
terminate_connection(c, c->edge); terminate_connection(c, c->edge);
continue;
} }
// helps in UDP holepunching
try_tx(c->node, false);
// timeout during ping
if(c->status.pinged) {
logger(DEBUG_CONNECTIONS, LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)now.tv_sec - c->last_ping_time);
terminate_connection(c, c->edge);
continue;
}
// check whether we need to send a new ping
if(c->last_ping_time + pinginterval <= now.tv_sec)
send_ping(c);
} }
timeout_set(data, &(struct timeval){1, rand() % 100000}); timeout_set(data, &(struct timeval){1, rand() % 100000});

View file

@ -717,6 +717,13 @@ bool connect_tincd(bool verbose) {
} }
fclose(f); fclose(f);
if ((pid == 0) || (kill(pid, 0) && (errno == ESRCH))) {
fprintf(stderr, "Could not find tincd running at pid %d\n", pid);
/* clean up the stale socket and pid file */
unlink(pidfilename);
unlink(unixsocketname);
return false;
}
#ifndef HAVE_MINGW #ifndef HAVE_MINGW
struct sockaddr_un sa; struct sockaddr_un sa;
@ -1390,7 +1397,7 @@ static int cmd_pid(int argc, char *argv[]) {
return 1; return 1;
} }
if(!connect_tincd(true) && !pid) if(!connect_tincd(true) || !pid)
return 1; return 1;
printf("%d\n", pid); printf("%d\n", pid);