]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Don't add duplicates to the list of recently seen addresses.
[meshlink] / src / meshlink.c
index 88a4c31991a9a340e32edde80523b6686b62b354..69ab8f244ef1e715e171b2b13fd8ff521fb27dab 100644 (file)
@@ -868,6 +868,18 @@ static void add_local_addresses(meshlink_handle_t *mesh) {
 }
 
 static bool meshlink_setup(meshlink_handle_t *mesh) {
+       if(!config_destroy(mesh->confbase, "new")) {
+               logger(mesh, MESHLINK_ERROR, "Could not delete configuration in %s/new: %s\n", mesh->confbase, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
+               return false;
+       }
+
+       if(!config_destroy(mesh->confbase, "old")) {
+               logger(mesh, MESHLINK_ERROR, "Could not delete configuration in %s/old: %s\n", mesh->confbase, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
+               return false;
+       }
+
        if(!config_init(mesh, "current")) {
                logger(mesh, MESHLINK_ERROR, "Could not set up configuration in %s/current: %s\n", mesh->confbase, strerror(errno));
                meshlink_errno = MESHLINK_ESTORAGE;
@@ -1683,7 +1695,6 @@ bool meshlink_destroy(const char *confbase) {
 
        fclose(lockfile);
 
-       /* TODO: do we need to remove confbase? Potential race condition? */
        if(!sync_path(confbase)) {
                logger(NULL, MESHLINK_ERROR, "Cannot sync directory %s: %s\n", confbase, strerror(errno));
                meshlink_errno = MESHLINK_ESTORAGE;
@@ -3109,11 +3120,11 @@ void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const
        pthread_mutex_lock(&mesh->mutex);
 
        node_t *n = (node_t *)node;
-       memmove(n->recent + 1, n->recent, (MAX_RECENT - 1) * sizeof(*n->recent));
-       memcpy(n->recent, addr, SALEN(*addr));
 
-       if(!node_write_config(mesh, n)) {
-               logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name);
+       if(node_add_recent_address(mesh, n, (sockaddr_t *)addr)) {
+               if(!node_write_config(mesh, n)) {
+                       logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name);
+               }
        }
 
        pthread_mutex_unlock(&mesh->mutex);