struct event outev; /* events on this metadata connection */
time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */
- time_t last_flushed_time; /* last time buffer was empty. Only meaningful if outbuflen > 0 */
avl_tree_t *config_tree; /* Pointer to configuration tree belonging to him */
} connection_t;
c->name, c->hostname);
if(!c->outbuflen) {
- c->last_flushed_time = now;
if(event_add(&c->outev, NULL) < 0) {
logger(LOG_EMERG, _("event_add failed: %s"), strerror(errno));
abort();
return false;
}
- c->last_ping_time = now;
+ c->last_ping_time = time(NULL);
return true;
}
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);
- }
- }
}
}
signal_set(&sigalrm_event, SIGALRM, sigalrm_handler, NULL);
signal_add(&sigalrm_event, NULL);
- 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);
}
}
extern bool do_prune;
extern bool do_purge;
extern char *myport;
-extern time_t now;
extern EVP_CIPHER_CTX packet_ctx;
/* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
inpkt = outpkt;
}
- if(n->connection)
- n->connection->last_ping_time = now;
-
if(!inpkt->data[12] && !inpkt->data[13])
mtu_probe_h(n, inpkt);
else
{
cp();
- now = time(NULL);
-
init_connections();
init_subnets();
init_nodes();
configure_tcp(c);
- c->last_ping_time = now;
+ c->last_ping_time = time(NULL);
c->status.connecting = false;
send_id(c);
}
c->outgoing = outgoing;
- c->last_ping_time = now;
+ c->last_ping_time = time(NULL);
connection_add(c);
c->address = sa;
c->hostname = sockaddr2hostname(&sa);
c->socket = fd;
- c->last_ping_time = now;
+ c->last_ping_time = time(NULL);
ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname);
} else {
new = xmalloc(sizeof(*new));
new->request = xstrdup(request);
- new->firstseen = now;
+ new->firstseen = time(NULL);
avl_insert(past_request_tree, new);
event_add(&past_request_event, &(struct timeval){10, 0});
return false;
avl_node_t *node, *next;
past_request_t *p;
int left = 0, deleted = 0;
+ time_t now = time(NULL);
cp();
cp();
c->status.pinged = true;
- c->last_ping_time = now;
+ c->last_ping_time = time(NULL);
return send_request(c, "%d", PING);
}
static bool ratelimit(int frequency) {
static time_t lasttime = 0;
static int count = 0;
+ time_t now = time(NULL);
if(lasttime == now) {
if(++count > frequency)
connection_t *c;
avl_node_t *node, *next, *node2;
bool left = false;
+ time_t now = time(NULL);
cp();
subnet = new_subnet();
subnet->type = SUBNET_MAC;
- subnet->expires = now + macexpire;
+ subnet->expires = time(NULL) + macexpire;
subnet->net.mac.address = *address;
subnet_add(myself, subnet);
if(!timeout_initialized(&age_subnets_event))
timeout_set(&age_subnets_event, age_subnets, NULL);
event_add(&age_subnets_event, &(struct timeval){10, 0});
+ } else {
+ if(subnet->expires)
+ subnet->expires = time(NULL) + macexpire;
}
-
- if(subnet->expires)
- subnet->expires = now + macexpire;
}
static void route_mac(node_t *source, vpn_packet_t *packet)