X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnode.c;h=977b98b60b000d7375da10627545731b8393d87b;hb=d9164d1d24e4100e14b269f170ac5266463f2028;hp=5f5d235cf4d28e35929754b38576080ac8fc8836;hpb=8538d6c661a083774e5b54163eaf5cdbcadcda6d;p=meshlink diff --git a/src/node.c b/src/node.c index 5f5d235c..977b98b6 100644 --- a/src/node.c +++ b/src/node.c @@ -76,10 +76,6 @@ void free_node(node_t *n) { ecdsa_free(n->ecdsa); sptps_stop(&n->sptps); - if(n->mtutimeout.cb) { - abort(); - } - free(n->name); free(n->canonical_address); @@ -92,7 +88,7 @@ void node_add(meshlink_handle_t *mesh, node_t *n) { } void node_del(meshlink_handle_t *mesh, node_t *n) { - timeout_del(&mesh->loop, &n->mtutimeout); + timeout_del(&mesh->loop, &n->udp_ping_timeout); for splay_each(edge_t, e, n->edge_tree) { edge_del(mesh, e); @@ -116,7 +112,6 @@ node_t *lookup_node_udp(meshlink_handle_t *mesh, const sockaddr_t *sa) { void update_node_udp(meshlink_handle_t *mesh, node_t *n, const sockaddr_t *sa) { if(n == mesh->self) { - logger(mesh, MESHLINK_WARNING, "Trying to update UDP address of mesh->self!"); return; } @@ -135,7 +130,7 @@ void update_node_udp(meshlink_handle_t *mesh, node_t *n, const sockaddr_t *sa) { hash_insert(mesh->node_udp_cache, sa, n); - meshlink_hint_address(mesh, (meshlink_node_t *)n, &sa->sa); + node_add_recent_address(mesh, n, sa); if(mesh->log_level <= MESHLINK_DEBUG) { char *hostname = sockaddr2hostname(&n->address); @@ -144,3 +139,32 @@ void update_node_udp(meshlink_handle_t *mesh, node_t *n, const sockaddr_t *sa) { } } } + +bool node_add_recent_address(meshlink_handle_t *mesh, node_t *n, const sockaddr_t *sa) { + (void)mesh; + bool found = false; + int i; + + /* Check if we already know this address */ + for(i = 0; i < MAX_RECENT && n->recent[i].sa.sa_family; i++) { + if(!sockaddrcmp(&n->recent[i], sa)) { + found = true; + break; + } + } + + if(found && i == 0) { + /* It's already the most recent address, nothing to do. */ + return false; + } + + if(i >= MAX_RECENT) { + i = MAX_RECENT - 1; + } + + memmove(n->recent + 1, n->recent, i * sizeof(*n->recent)); + memcpy(n->recent, sa, SALEN(sa->sa)); + + n->status.dirty = true; + return !found; +}