volatile bool running = false;
-time_t now = 0;
-
/* Purge edges and subnets of unreachable nodes. Use carefully. */
static void purge(void)
{
avl_node_t *node, *next;
connection_t *c;
+ time_t now = time(NULL);
cp();
}
}
}
-
- if(c->outbuflen > 0 && c->last_flushed_time + pingtimeout < now) {
- if(c->status.active) {
- ifdebug(CONNECTIONS) logger(LOG_INFO,
- _("%s (%s) could not flush for %ld seconds (%d bytes remaining)"),
- c->name, c->hostname, now - c->last_flushed_time, c->outbuflen);
- c->status.timeout = true;
- terminate_connection(c, true);
- }
- }
}
}
}
}
-static void keyexpire_handler(int fd, short events, void *event) {
- ifdebug(STATUS) logger(LOG_INFO, _("Regenerating symmetric key"));
-
- RAND_pseudo_bytes((unsigned char *)myself->key, myself->keylength);
- if(myself->cipher)
- EVP_DecryptInit_ex(&packet_ctx, myself->cipher, NULL, (unsigned char *)myself->key, (unsigned char *)myself->key + myself->cipher->key_len);
- send_key_changed(broadcast, myself);
-
- event_add(event, &(struct timeval){keylifetime, 0});
-}
-
/*
this is where it all happens...
*/
struct event sigusr2_event;
struct event sigwinch_event;
struct event sigalrm_event;
- struct event keyexpire_event;
cp();
signal_add(&sigwinch_event, NULL);
signal_set(&sigalrm_event, SIGALRM, sigalrm_handler, NULL);
signal_add(&sigalrm_event, NULL);
- timeout_set(&keyexpire_event, keyexpire_handler, &keyexpire_event);
- event_add(&keyexpire_event, &(struct timeval){keylifetime, 0});
- last_ping_check = now;
+ last_ping_check = time(NULL);
- srand(now);
+ srand(time(NULL));
running = true;
while(running) {
- now = time(NULL);
-
- // tv.tv_sec = 1 + (rand() & 7); /* Approx. 5 seconds, randomized to prevent global synchronisation effects */
tv.tv_sec = 1;
tv.tv_usec = 0;
}
r = event_loop(EVLOOP_ONCE);
- now = time(NULL);
if(r < 0) {
logger(LOG_ERR, _("Error while waiting for input: %s"),
strerror(errno));
/* Let's check if everybody is still alive */
- if(last_ping_check + pingtimeout < now) {
+ if(last_ping_check + pingtimeout < time(NULL)) {
check_dead_connections();
- last_ping_check = now;
+ last_ping_check = time(NULL);
}
}
signal_del(&sigusr2_event);
signal_del(&sigwinch_event);
signal_del(&sigalrm_event);
- event_del(&keyexpire_event);
return 0;
}