]> git.meshlink.io Git - meshlink/commitdiff
Fix reachability queries for blacklisted nodes.
authorGuus Sliepen <guus@meshlink.io>
Mon, 3 Feb 2020 15:11:36 +0000 (16:11 +0100)
committerGuus Sliepen <guus@meshlink.io>
Mon, 3 Feb 2020 15:11:36 +0000 (16:11 +0100)
src/graph.c
src/meshlink.c

index e6212116528a64d17bb0b03d5e209ace106158fe..431a72a559f068d34fa0a61002e26602b884950e 100644 (file)
@@ -173,17 +173,22 @@ static void check_reachability(meshlink_handle_t *mesh) {
                        n->status.reachable = !n->status.reachable;
                        n->status.dirty = true;
 
-                       if(n->status.reachable) {
-                               logger(mesh, MESHLINK_DEBUG, "Node %s became reachable", n->name);
-                               bool first_time_reachable = !n->last_reachable;
-                               n->last_reachable = mesh->loop.now.tv_sec;
-
-                               if(first_time_reachable) {
-                                       node_write_config(mesh, n);
+                       if(!n->status.blacklisted) {
+                               if(n->status.reachable) {
+                                       logger(mesh, MESHLINK_DEBUG, "Node %s became reachable", n->name);
+                                       bool first_time_reachable = !n->last_reachable;
+                                       n->last_reachable = mesh->loop.now.tv_sec;
+
+                                       if(first_time_reachable) {
+                                               if(!node_write_config(mesh, n)) {
+                                                       logger(mesh, MESHLINK_WARNING, "Could not write host config file for node %s!\n", n->name);
+
+                                               }
+                                       }
+                               } else {
+                                       logger(mesh, MESHLINK_DEBUG, "Node %s became unreachable", n->name);
+                                       n->last_unreachable = mesh->loop.now.tv_sec;
                                }
-                       } else {
-                               logger(mesh, MESHLINK_DEBUG, "Node %s became unreachable", n->name);
-                               n->last_unreachable = mesh->loop.now.tv_sec;
                        }
 
                        /* TODO: only clear status.validkey if node is unreachable? */
index 2309d77521865147a0f584701df518bd635c12a4..0bec2f8aaf831c2cfd663f36fb7c0f97a7155633 100644 (file)
@@ -2155,7 +2155,7 @@ bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct meshlin
        bool reachable;
 
        pthread_mutex_lock(&mesh->mutex);
-       reachable = n->status.reachable;
+       reachable = n->status.reachable && !n->status.blacklisted;
 
        if(last_reachable) {
                *last_reachable = n->last_reachable;
@@ -2975,6 +2975,10 @@ static bool blacklist(meshlink_handle_t *mesh, node_t *n) {
        n->mtuprobes = 0;
        n->status.udp_confirmed = false;
 
+       if(n->status.reachable) {
+               n->last_unreachable = mesh->loop.now.tv_sec;
+       }
+
        /* Graph updates will suppress status updates for blacklisted nodes, so we need to
         * manually call the status callback if necessary.
         */
@@ -3046,6 +3050,7 @@ static bool whitelist(meshlink_handle_t *mesh, node_t *n) {
        n->status.blacklisted = false;
 
        if(n->status.reachable) {
+               n->last_reachable = mesh->loop.now.tv_sec;
                update_node_status(mesh, n);
        }