- free(n->hostname);
- n->hostname = sockaddr2hostname(&n->address);
- logger(mesh, MESHLINK_DEBUG, "UDP address of %s set to %s", n->name, n->hostname);
+
+ node_add_recent_address(mesh, n, sa);
+
+ if(mesh->log_level <= MESHLINK_DEBUG) {
+ char *hostname = sockaddr2hostname(&n->address);
+ logger(mesh, MESHLINK_DEBUG, "UDP address of %s set to %s", n->name, hostname);
+ free(hostname);
+ }
+ }
+}
+
+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;
+ }