]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Clear reachability times in imported host config files.
[meshlink] / src / meshlink.c
index 2309d77521865147a0f584701df518bd635c12a4..a93bdd674ac32579adc39ddf337645599f0bd913 100644 (file)
@@ -668,6 +668,10 @@ static bool finalize_join(meshlink_handle_t *mesh, const void *buf, uint16_t len
                        }
                }
 
+               /* Clear the reachability times, since we ourself have never seen these nodes yet */
+               n->last_reachable = 0;
+               n->last_unreachable = 0;
+
                if(!node_write_config(mesh, n)) {
                        free_node(n);
                        return false;
@@ -720,7 +724,7 @@ static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint
                return finalize_join(mesh, msg, len);
 
        case 1:
-               logger(mesh, MESHLINK_DEBUG, "Invitation succesfully accepted.\n");
+               logger(mesh, MESHLINK_DEBUG, "Invitation successfully accepted.\n");
                shutdown(mesh->sock, SHUT_RDWR);
                mesh->success = true;
                break;
@@ -2155,7 +2159,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;
@@ -2428,7 +2432,7 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c
        }
 
        // Ensure no other nodes know about this name
-       if(meshlink_get_node(mesh, name)) {
+       if(lookup_node(mesh, name)) {
                logger(mesh, MESHLINK_ERROR, "A node with name %s is already known!\n", name);
                meshlink_errno = MESHLINK_EEXIST;
                pthread_mutex_unlock(&mesh->mutex);
@@ -2454,7 +2458,7 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c
        // If we changed our own host config file, write it out now
        if(mesh->self->status.dirty) {
                if(!node_write_config(mesh, mesh->self)) {
-                       logger(mesh, MESHLINK_ERROR, "Could not write our own host conifg file!\n");
+                       logger(mesh, MESHLINK_ERROR, "Could not write our own host config file!\n");
                        pthread_mutex_unlock(&mesh->mutex);
                        return NULL;
                }
@@ -2919,7 +2923,11 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) {
                        break;
                }
 
-               if(!config_write(mesh, "current", n->name, &config, mesh->config_key)) {
+               /* Clear the reachability times, since we ourself have never seen these nodes yet */
+               n->last_reachable = 0;
+               n->last_unreachable = 0;
+
+               if(!node_write_config(mesh, n)) {
                        free_node(n);
                        return false;
                }
@@ -2975,6 +2983,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 +3058,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);
        }