X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=0bec2f8aaf831c2cfd663f36fb7c0f97a7155633;hb=c1aaccb26739c0c513c9443dce57560349141687;hp=2d4c2e1f2beb1c218eebd5343be2f6aa75cb8644;hpb=be83b0af60449c7b35d17d97f2e6dc12f611e831;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 2d4c2e1f..0bec2f8a 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -37,6 +37,7 @@ #include "ed25519/sha512.h" #include "discovery.h" #include "devtools.h" +#include "graph.h" #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 @@ -1527,8 +1528,9 @@ bool meshlink_start(meshlink_handle_t *mesh) { pthread_cond_wait(&mesh->cond, &mesh->mutex); mesh->threadstarted = true; - mesh->self->last_reachable = time(NULL); - mesh->self->status.dirty = true; + + // Ensure we are considered reachable + graph(mesh); pthread_mutex_unlock(&mesh->mutex); return true; @@ -1543,11 +1545,6 @@ void meshlink_stop(meshlink_handle_t *mesh) { pthread_mutex_lock(&mesh->mutex); logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n"); - if(mesh->self) { - mesh->self->last_unreachable = time(NULL); - mesh->self->status.dirty = true; - } - // Shut down the main thread event_loop_stop(&mesh->loop); @@ -1587,6 +1584,11 @@ void meshlink_stop(meshlink_handle_t *mesh) { exit_outgoings(mesh); + // Ensure we are considered unreachable + if(mesh->nodes) { + graph(mesh); + } + // Try to write out any changed node config files, ignore errors at this point. if(mesh->nodes) { for splay_each(node_t, n, mesh->nodes) { @@ -2153,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; @@ -2973,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. */ @@ -3044,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); }