-void dump_nodes(void)
-{
- avl_node_t *node;
- node_t *n;
-cp
- syslog(LOG_DEBUG, _("Nodes:"));
-
- for(node = node_tree->head; node; node = node->next)
- {
- n = (node_t *)node->data;
- syslog(LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s"),
- n->name, n->hostname, n->cipher?n->cipher->nid:0, n->digest?n->digest->type:0, n->maclength, n->compression, n->options,
- n->status, n->nexthop?n->nexthop->name:"-", n->via?n->via->name:"-");
- }
-
- syslog(LOG_DEBUG, _("End of nodes."));
-cp
+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;