From c1aaccb26739c0c513c9443dce57560349141687 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 3 Feb 2020 16:11:36 +0100 Subject: [PATCH] Fix reachability queries for blacklisted nodes. --- src/graph.c | 25 +++++++++++++++---------- src/meshlink.c | 7 ++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/graph.c b/src/graph.c index e6212116..431a72a5 100644 --- a/src/graph.c +++ b/src/graph.c @@ -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? */ diff --git a/src/meshlink.c b/src/meshlink.c index 2309d775..0bec2f8a 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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); } -- 2.39.2