X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=69ab8f244ef1e715e171b2b13fd8ff521fb27dab;hb=703197ca7614963ba9b831967352b6c90379af48;hp=88a4c31991a9a340e32edde80523b6686b62b354;hpb=42cef01039177f3c762001439c8fb6bbdcd6e159;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 88a4c319..69ab8f24 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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);