- if(c->last_ping_time + pingtimeout <= now) {
- if(c->status.active) {
- 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 - c->last_ping_time);
- } else if(c->last_ping_time + pinginterval <= now) {
- send_ping(c);
- continue;
- } else {
- continue;
- }
- } 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->status.active);
+ if(close_all_connections) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Forcing connection close after sleep time %s (%s)", c->name, c->hostname);
+ terminate_connection(c, c->edge);
+ continue;
+ }
+
+ // Bail out early if we haven't reached the ping timeout for this node yet
+ if(c->last_ping_time + pingtimeout > now.tv_sec)
+ continue;
+
+ // timeout during connection establishing
+ if(!c->edge) {
+ 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);
+ 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;