]> git.meshlink.io Git - meshlink/commitdiff
Avoid unnecessary calls to time().
authorGuus Sliepen <guus@meshlink.io>
Sun, 4 Aug 2019 10:22:52 +0000 (12:22 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 4 Aug 2019 10:23:08 +0000 (12:23 +0200)
We already have the current time from the event loop.

src/conf.c
src/net.c
src/protocol_auth.c

index a9e3e4d6f0d2171fb893fe87515df8d78ab4a391..e0d3595041c2807d7393e912ff935b8584f0751c 100644 (file)
@@ -735,7 +735,7 @@ bool invitation_read(meshlink_handle_t *mesh, const char *conf_subdir, const cha
                return false;
        }
 
-       if(time(NULL) > st.st_mtime + mesh->invitation_timeout) {
+       if(mesh->loop.now.tv_sec > st.st_mtime + mesh->invitation_timeout) {
                logger(mesh, MESHLINK_ERROR, "Peer tried to use an outdated invitation file %s\n", name);
                fclose(f);
                unlink(used_path);
index ddfd2cf09aa828abc5a861742e60172e33b8fddb..1df0be0030b257f800ed23e12d9c89e757e0a175 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -393,7 +393,6 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                logger(mesh, MESHLINK_DEBUG, "* min_connects = %d", min_connects);
                logger(mesh, MESHLINK_DEBUG, "* max_connects = %d", max_connects);
 
-
                // find the best one for initial connect
 
                if(cur_connects < min_connects) {
@@ -402,7 +401,7 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                        for splay_each(node_t, n, mesh->nodes) {
                                logger(mesh, MESHLINK_DEBUG, "* %s->devclass = %d", n->name, n->devclass);
 
-                               if(n != mesh->self && n->devclass <= mesh->devclass && !n->connection && !n->status.blacklisted && (n->last_connect_try == 0 || (time(NULL) - n->last_connect_try) > retry_timeout)) {
+                               if(n != mesh->self && n->devclass <= mesh->devclass && !n->connection && !n->status.blacklisted && (n->last_connect_try == 0 || (mesh->loop.now.tv_sec - n->last_connect_try) > retry_timeout)) {
                                        splay_insert(nodes, n);
                                }
                        }
@@ -436,7 +435,7 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                                        splay_tree_t *nodes = splay_alloc_tree(node_compare_lsc_desc, NULL);
 
                                        for splay_each(node_t, n, mesh->nodes) {
-                                               if(n != mesh->self && n->devclass == devclass && !n->connection && !n->status.blacklisted && (n->last_connect_try == 0 || (time(NULL) - n->last_connect_try) > retry_timeout)) {
+                                               if(n != mesh->self && n->devclass == devclass && !n->connection && !n->status.blacklisted && (n->last_connect_try == 0 || (mesh->loop.now.tv_sec - n->last_connect_try) > retry_timeout)) {
                                                        splay_insert(nodes, n);
                                                }
                                        }
@@ -467,7 +466,7 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                        splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_lsc_desc, NULL);
 
                        for splay_each(node_t, n, mesh->nodes) {
-                               if(n != mesh->self && n->devclass <= mesh->devclass && !n->status.reachable && !n->status.blacklisted && (n->last_connect_try == 0 || (time(NULL) - n->last_connect_try) > retry_timeout)) {
+                               if(n != mesh->self && n->devclass <= mesh->devclass && !n->status.reachable && !n->status.blacklisted && (n->last_connect_try == 0 || (mesh->loop.now.tv_sec - n->last_connect_try) > retry_timeout)) {
                                        splay_insert(nodes, n);
                                }
                        }
@@ -486,7 +485,7 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                // perform connect
 
                if(connect_to && !connect_to->connection) {
-                       connect_to->last_connect_try = time(NULL);
+                       connect_to->last_connect_try = mesh->loop.now.tv_sec;
                        logger(mesh, MESHLINK_DEBUG, "Autoconnect trying to connect to %s", connect_to->name);
 
                        /* check if there is already a connection attempt to this node */
index e9aa0c51ddb4370bf4ba4135c92224e434e5845b..c7d6882984e8239f7f30345fa54bb04aae2a7ebd 100644 (file)
@@ -432,7 +432,7 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        n->devclass = devclass;
        n->status.dirty = true;
 
-       n->last_successfull_connection = time(NULL);
+       n->last_successfull_connection = mesh->loop.now.tv_sec;
 
        n->connection = c;
        c->node = n;