Remove global variable "now".
This commit is contained in:
parent
7e1117197c
commit
ddc6a81a85
10 changed files with 18 additions and 38 deletions
|
@ -104,7 +104,6 @@ typedef struct connection_t {
|
|||
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;
|
||||
|
|
|
@ -45,7 +45,6 @@ bool send_meta(connection_t *c, const char *buffer, int length)
|
|||
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();
|
||||
|
@ -239,7 +238,7 @@ bool receive_meta(connection_t *c)
|
|||
return false;
|
||||
}
|
||||
|
||||
c->last_ping_time = now;
|
||||
c->last_ping_time = time(NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
25
src/net.c
25
src/net.c
|
@ -41,8 +41,6 @@
|
|||
|
||||
volatile bool running = false;
|
||||
|
||||
time_t now = 0;
|
||||
|
||||
/* Purge edges and subnets of unreachable nodes. Use carefully. */
|
||||
|
||||
static void purge(void)
|
||||
|
@ -208,6 +206,7 @@ static void check_dead_connections(void)
|
|||
{
|
||||
avl_node_t *node, *next;
|
||||
connection_t *c;
|
||||
time_t now = time(NULL);
|
||||
|
||||
cp();
|
||||
|
||||
|
@ -243,16 +242,6 @@ static void check_dead_connections(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,16 +426,13 @@ int main_loop(void)
|
|||
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;
|
||||
|
||||
|
@ -463,7 +449,6 @@ int main_loop(void)
|
|||
}
|
||||
|
||||
r = event_loop(EVLOOP_ONCE);
|
||||
now = time(NULL);
|
||||
if(r < 0) {
|
||||
logger(LOG_ERR, _("Error while waiting for input: %s"),
|
||||
strerror(errno));
|
||||
|
@ -477,9 +462,9 @@ int main_loop(void)
|
|||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,6 @@ extern int keylifetime;
|
|||
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 */
|
||||
|
|
|
@ -263,9 +263,6 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
|
|||
inpkt = outpkt;
|
||||
}
|
||||
|
||||
if(n->connection)
|
||||
n->connection->last_ping_time = now;
|
||||
|
||||
if(!inpkt->data[12] && !inpkt->data[13])
|
||||
mtu_probe_h(n, inpkt);
|
||||
else
|
||||
|
|
|
@ -580,8 +580,6 @@ bool setup_network_connections(void)
|
|||
{
|
||||
cp();
|
||||
|
||||
now = time(NULL);
|
||||
|
||||
init_connections();
|
||||
init_subnets();
|
||||
init_nodes();
|
||||
|
|
|
@ -261,7 +261,7 @@ void finish_connecting(connection_t *c)
|
|||
|
||||
configure_tcp(c);
|
||||
|
||||
c->last_ping_time = now;
|
||||
c->last_ping_time = time(NULL);
|
||||
c->status.connecting = false;
|
||||
|
||||
send_id(c);
|
||||
|
@ -391,7 +391,7 @@ void setup_outgoing_connection(outgoing_t *outgoing)
|
|||
}
|
||||
|
||||
c->outgoing = outgoing;
|
||||
c->last_ping_time = now;
|
||||
c->last_ping_time = time(NULL);
|
||||
|
||||
connection_add(c);
|
||||
|
||||
|
@ -437,7 +437,7 @@ void handle_new_meta_connection(int sock, short events, void *data)
|
|||
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);
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ bool seen_request(char *request)
|
|||
} 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;
|
||||
|
@ -223,6 +223,7 @@ void age_past_requests(int fd, short events, void *data)
|
|||
avl_node_t *node, *next;
|
||||
past_request_t *p;
|
||||
int left = 0, deleted = 0;
|
||||
time_t now = time(NULL);
|
||||
|
||||
cp();
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ bool send_ping(connection_t *c)
|
|||
cp();
|
||||
|
||||
c->status.pinged = true;
|
||||
c->last_ping_time = now;
|
||||
c->last_ping_time = time(NULL);
|
||||
|
||||
return send_request(c, "%d", PING);
|
||||
}
|
||||
|
|
10
src/route.c
10
src/route.c
|
@ -77,6 +77,7 @@ static uint16_t inet_checksum(void *data, int len, uint16_t prevsum)
|
|||
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)
|
||||
|
@ -103,6 +104,7 @@ static void age_subnets(int fd, short events, void *data)
|
|||
connection_t *c;
|
||||
avl_node_t *node, *next, *node2;
|
||||
bool left = false;
|
||||
time_t now = time(NULL);
|
||||
|
||||
cp();
|
||||
|
||||
|
@ -152,7 +154,7 @@ static void learn_mac(mac_t *address)
|
|||
|
||||
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);
|
||||
|
||||
|
@ -167,10 +169,10 @@ static void learn_mac(mac_t *address)
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue