In most cases we can use the cached time.
for splay_each(node_t, n, node_tree) {
if(n->status.visited != n->status.reachable) {
n->status.reachable = !n->status.reachable;
- n->last_state_change = time(NULL);
+ n->last_state_change = now.tv_sec;
if(n->status.reachable) {
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Node %s (%s) became reachable",
free(fname);
}
- last_config_check = time(NULL);
+ last_config_check = now.tv_sec;
return 0;
}
logger(DEBUG_TRAFFIC, LOG_INFO, "No valid key known yet for %s (%s)", n->name, n->hostname);
if(!n->status.waitingforkey)
send_req_key(n);
- else if(n->last_req_key + 10 < time(NULL)) {
+ else if(n->last_req_key + 10 < now.tv_sec) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "No key from %s after 10 seconds, restarting SPTPS", n->name);
sptps_stop(&n->sptps);
n->status.waitingforkey = false;
myself->nexthop = myself;
myself->via = myself;
myself->status.reachable = true;
- myself->last_state_change = time(NULL);
+ myself->last_state_change = now.tv_sec;
myself->status.sptps = experimental;
node_add(myself);
return false;
}
- last_config_check = time(NULL);
+ last_config_check = now.tv_sec;
return true;
}
void finish_connecting(connection_t *c) {
logger(DEBUG_CONNECTIONS, LOG_INFO, "Connected to %s (%s)", c->name, c->hostname);
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now.tv_sec;
c->status.connecting = false;
send_id(c);
c->outdigest = myself->connection->outdigest;
c->outmaclength = myself->connection->outmaclength;
c->outcompression = myself->connection->outcompression;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now.tv_sec;
connection_add(c);
c->address = sa;
c->hostname = sockaddr2hostname(&sa);
c->socket = fd;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now.tv_sec;
logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection from %s", c->hostname);
c->address = sa;
c->hostname = xstrdup("localhost port unix");
c->socket = fd;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now.tv_sec;
logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection from %s", c->hostname);
} else {
new = xmalloc(sizeof *new);
new->request = xstrdup(request);
- new->firstseen = time(NULL);
+ new->firstseen = now.tv_sec;
splay_insert(past_request_tree, new);
timeout_add(&past_request_timeout, age_past_requests, NULL, &(struct timeval){10, rand() % 100000});
return false;
if(name[0] == '^' && !strcmp(name + 1, controlcookie)) {
c->status.control = true;
c->allow_request = CONTROL;
- c->last_ping_time = time(NULL) + 3600;
+ c->last_ping_time = now.tv_sec + 3600;
free(c->name);
c->name = xstrdup("<control>");
sptps_stop(&to->sptps);
to->status.validkey = false;
to->status.waitingforkey = true;
- to->last_req_key = time(NULL);
+ to->last_req_key = now.tv_sec;
to->incompression = myself->incompression;
return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record);
}
sptps_stop(&from->sptps);
from->status.validkey = false;
from->status.waitingforkey = true;
- from->last_req_key = time(NULL);
+ from->last_req_key = now.tv_sec;
sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record);
sptps_receive_data(&from->sptps, buf, len);
return true;
bool send_ping(connection_t *c) {
c->status.pinged = true;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now.tv_sec;
return send_request(c, "%d", PING);
}
subnet = new_subnet();
subnet->type = SUBNET_MAC;
- subnet->expires = time(NULL) + macexpire;
+ subnet->expires = now.tv_sec + macexpire;
subnet->net.mac.address = *address;
subnet->weight = 10;
subnet_add(myself, subnet);
timeout_add(&age_subnets_timeout, age_subnets, NULL, &(struct timeval){10, rand() % 100000});
} else {
if(subnet->expires)
- subnet->expires = time(NULL) + macexpire;
+ subnet->expires = now.tv_sec + macexpire;
}
}
/* Slllluuuuuuurrrrp! */
- srand(time(NULL));
+ gettimeofday(&now, NULL);
+ srand(now.tv_sec + now.tv_usec);
crypto_init();
if(!read_server_config())