This removes the necessity for libevent.
switch (type) {
case REQ_STOP:
- event_loopexit(NULL);
+ abort();
return control_ok(c, REQ_STOP);
case REQ_DUMP_NODES:
end does not reply in time, we consider them dead
and close the connection.
*/
-static void timeout_handler(int fd, short events, void *event) {
+static void timeout_handler(void *arg) {
+ event_t *event = arg;
splay_node_t *node, *next;
connection_t *c;
time_t now = time(NULL);
if(rand() % 3 == 0) {
logger(LOG_ERR, "Shutting down, check configuration of all nodes for duplicate Names!");
- event_loopexit(NULL);
+ abort();
return;
}
contradicting_del_edge = 0;
}
- event_add(event, &(struct timeval){pingtimeout, 0});
+ event->time = now + pingtimeout;
+ event_add(event);
}
void handle_meta_connection_data(void *data) {
static void sigterm_handler(int signal, short events, void *data) {
logger(LOG_NOTICE, "Got %s signal", strsignal(signal));
- event_loopexit(NULL);
+ exit(0);
}
static void sighup_handler(int signal, short events, void *data) {
if(!read_server_config()) {
logger(LOG_ERR, "Unable to reread configuration file, exitting.");
- event_loopexit(NULL);
+ abort();
return EINVAL;
}
c = node->data;
if(c->outgoing && !c->node) {
- if(timeout_initialized(&c->outgoing->ev))
- event_del(&c->outgoing->ev);
+ event_del(&c->outgoing->ev);
if(c->status.connecting)
close(c->socket);
c->outgoing->timeout = 0;
*/
int main_loop(void) {
struct event timeout_event;
- struct event sighup_event;
- struct event sigterm_event;
- struct event sigquit_event;
- timeout_set(&timeout_event, timeout_handler, &timeout_event);
- event_add(&timeout_event, &(struct timeval){pingtimeout, 0});
+ timeout_event.time = time(NULL) + pingtimeout;
+ timeout_event.handler = timeout_handler;
+ timeout_event.data = &timeout_event;
+
+ event_add(&timeout_event);
#ifdef SIGHUP
- signal_set(&sighup_event, SIGHUP, sighup_handler, NULL);
- signal_add(&sighup_event, NULL);
+ signal(SIGHUP, sighup_handler);
#endif
#ifdef SIGTERM
- signal_set(&sigterm_event, SIGTERM, sigterm_handler, NULL);
- signal_add(&sigterm_event, NULL);
+ signal(SIGTERM, sigterm_handler);
#endif
#ifdef SIGQUIT
- signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL);
- signal_add(&sigquit_event, NULL);
+ signal(SIGQUIT, sigterm_handler);
#endif
- if(event_loop(0) < 0) {
- logger(LOG_ERR, "Error while waiting for input: %s", strerror(errno));
- return 1;
+ while(true) {
+ sleep(1);
+ struct event *event;
+ while((event = get_expired_event())) {
+ event->handler(event->data);
+ }
}
- signal_del(&sighup_event);
- signal_del(&sigterm_event);
- signal_del(&sigquit_event);
event_del(&timeout_event);
return 0;
#ifndef __TINC_NET_H__
#define __TINC_NET_H__
+#include "event.h"
#include "ipv6.h"
#include "cipher.h"
#include "digest.h"
// mtuprobes == 32: send 1 burst, sleep pingtimeout second
// mtuprobes == 33: no response from other side, restart PMTU discovery process
-static void send_mtu_probe_handler(int fd, short events, void *data) {
+static void send_mtu_probe_handler(void *data) {
node_t *n = data;
vpn_packet_t packet;
int len, i;
}
end:
- event_add(&n->mtuevent, &(struct timeval){timeout, 0});
+ n->mtuevent.time = time(NULL) + timeout;
+ event_add(&n->mtuevent);
}
void send_mtu_probe(node_t *n) {
- if(!timeout_initialized(&n->mtuevent))
- timeout_set(&n->mtuevent, send_mtu_probe_handler, n);
- send_mtu_probe_handler(0, 0, n);
+ event_del(&n->mtuevent);
+ n->mtuevent.handler = send_mtu_probe_handler;
+ n->mtuevent.data = n;
+ send_mtu_probe_handler(n);
}
void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
static struct event keyexpire_event;
-static void keyexpire_handler(int fd, short events, void *data) {
+static void keyexpire_handler(void *data) {
regenerate_key();
}
void regenerate_key() {
- if(timeout_initialized(&keyexpire_event)) {
- ifdebug(STATUS) logger(LOG_INFO, "Expiring symmetric keys");
- event_del(&keyexpire_event);
- send_key_changed(broadcast, myself);
- } else {
- timeout_set(&keyexpire_event, keyexpire_handler, NULL);
- }
-
- event_add(&keyexpire_event, &(struct timeval){keylifetime, 0});
+ ifdebug(STATUS) logger(LOG_INFO, "Expiring symmetric keys");
+ event_del(&keyexpire_event);
+ send_key_changed(broadcast, myself);
+ keyexpire_event.time = time(NULL) + keylifetime;
+ keyexpire_event.handler = keyexpire_handler;
+ event_add(&keyexpire_event);
}
/*
if(!setup_device())
return false;
- if(device_fd >= 0) {
- event_set(&device_ev, device_fd, EV_READ|EV_PERSIST, handle_device_data, NULL);
-
- if (event_add(&device_ev, NULL) < 0) {
- logger(LOG_ERR, "event_add failed: %s", strerror(errno));
- close_device();
- return false;
- }
- }
-
/* Run tinc-up script to further initialize the tap interface */
xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
xasprintf(&envp[1], "DEVICE=%s", device ? : "");
return nfd;
} /* int setup_vpn_in_socket */
-static void retry_outgoing_handler(int fd, short events, void *data) {
+static void retry_outgoing_handler(void *data) {
setup_outgoing_connection(data);
}
if(outgoing->timeout > maxtimeout)
outgoing->timeout = maxtimeout;
- timeout_set(&outgoing->ev, retry_outgoing_handler, outgoing);
- event_add(&outgoing->ev, &(struct timeval){outgoing->timeout, 0});
+ outgoing->ev.handler = retry_outgoing_handler;
+ outgoing->ev.time = time(NULL) + outgoing->timeout;
+ event_add(&outgoing->ev);
ifdebug(CONNECTIONS) logger(LOG_NOTICE,
"Trying to re-establish outgoing connection in %d seconds",
#include "cipher.h"
#include "connection.h"
#include "digest.h"
+#include "event.h"
#include "list.h"
#include "subnet.h"
return ERROR_CALL_NOT_IMPLEMENTED;
}
- event_loopexit(NULL);
+ abort();
status.dwWaitHint = 30000;
status.dwCurrentState = SERVICE_STOP_PENDING;
SetServiceStatus(statushandle, &status);
new->request = xstrdup(request);
new->firstseen = time(NULL);
splay_insert(past_request_tree, new);
- event_add(&past_request_event, &(struct timeval){10, 0});
+ past_request_event.time = time(NULL) + 10;
+ event_add(&past_request_event);
return false;
}
}
-void age_past_requests(int fd, short events, void *data) {
+void age_past_requests(void *data) {
splay_node_t *node, *next;
past_request_t *p;
int left = 0, deleted = 0;
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Aging past requests: deleted %d, left %d",
deleted, left);
- if(left)
- event_add(&past_request_event, &(struct timeval){10, 0});
+ if(left) {
+ past_request_event.time = time(NULL) + 10;
+ event_add(&past_request_event);
+ }
}
void init_requests(void) {
past_request_tree = splay_alloc_tree((splay_compare_t) past_request_compare, (splay_action_t) free_past_request);
- timeout_set(&past_request_event, age_past_requests, NULL);
+ past_request_event.handler = age_past_requests;
}
void exit_requests(void) {
memcpy(&packet->data[6], &tmp, sizeof tmp);
}
-static void age_subnets(int fd, short events, void *data) {
+static void age_subnets(void *data) {
subnet_t *s;
connection_t *c;
splay_node_t *node, *next, *node2;
}
}
- if(left)
- event_add(&age_subnets_event, &(struct timeval){10, 0});
+ if(left) {
+ age_subnets_event.time = time(NULL) + 10;
+ event_add(&age_subnets_event);
+ }
}
static void learn_mac(mac_t *address) {
send_add_subnet(c, subnet);
}
- if(!timeout_initialized(&age_subnets_event))
- timeout_set(&age_subnets_event, age_subnets, NULL);
- event_add(&age_subnets_event, &(struct timeval){10, 0});
+ age_subnets_event.handler = age_subnets;
+ age_subnets_event.time = time(NULL) + 10;
+ event_add(&age_subnets_event);
} else {
if(subnet->expires)
subnet->expires = time(NULL) + macexpire;
openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
- if(!event_init()) {
- logger(LOG_ERR, "Error initializing libevent!");
- return 1;
- }
-
g_argv = argv;
+ init_events();
init_configuration(&config_tree);
/* Slllluuuuuuurrrrp! */
crypto_exit();
exit_configuration(&config_tree);
+ exit_events();
free_names();
return status;