]> git.meshlink.io Git - meshlink/commitdiff
Remove global variable "now".
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 18 May 2007 09:34:06 +0000 (09:34 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 18 May 2007 09:34:06 +0000 (09:34 +0000)
src/connection.h
src/meta.c
src/net.c
src/net.h
src/net_packet.c
src/net_setup.c
src/net_socket.c
src/protocol.c
src/protocol_misc.c
src/route.c

index 495c38e159680de85c90650209649b76006f0b12..92cd23b4f08028992a57ed2dcc23da6f12a8d40d 100644 (file)
@@ -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;
index 3e750451aad071163876e0cd5469de398758e392..b7546267189a40c23e4ef72116c4ee5bffaec8e5 100644 (file)
@@ -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;
 }
index df5fae77ccb2009cd450ccea483df6bd6bf5514e..9681a7bbdd1bfcc3686f4c5b010b20603c502a33 100644 (file)
--- a/src/net.c
+++ b/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);
                }
        }
 
index 28ec2eeb90c589c0ee559c52bbef503de75c42cc..943b7e61097f8f20b7d7260054d6524acad79d1e 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -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 */
index 596b9d53c7ce4201b6fd4c269047e361999763a9..61465a25df46735d3ac8bb6cbf00f3962a2e9f67 100644 (file)
@@ -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
index 814d698f8ef3834da433ebf0f46bbeb29fb1aa38..22a956151f03a520e49f10ffbe6d7af9e068f61d 100644 (file)
@@ -580,8 +580,6 @@ bool setup_network_connections(void)
 {
        cp();
 
-       now = time(NULL);
-
        init_connections();
        init_subnets();
        init_nodes();
index bba0d97dababb118cd3dabd20e7f83a650e3cbc3..287d68887fde45ecaa6e4d9b4aa1b6beed054861 100644 (file)
@@ -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);
 
index 93f27514bcac73c4a685282334509647cd97a23e..6ad9740fc1301003ca6aceae82b759a8e2b50d80 100644 (file)
@@ -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();
 
index 52e97e5448193f9260a86d605e80e4996cebd89b..ca1dc315993884a0aa30a4138c2ea805c961c288 100644 (file)
@@ -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);
 }
index 32afa0d6e8f819ff624a6665e384cd118030eb6f..5ccf9bd0c9c2e840e91ae4a7944d54bc30df879b 100644 (file)
@@ -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)