}
}
+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;
if(last_ping_check + pingtimeout < now) {
check_dead_connections();
last_ping_check = now;
-
- /* Should we regenerate our key? */
-
- if(keyexpires < now) {
- 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);
- keyexpires = now + keylifetime;
- }
}
}
signal_del(&sigusr2_event);
signal_del(&sigwinch_event);
signal_del(&sigalrm_event);
+ event_del(&keyexpire_event);
return 0;
}