-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 port %hd options %ld status %04x"),
- n->name, n->hostname, n->port, n->options,
- n->status);
- }
-
- syslog(LOG_DEBUG, _("End of nodes."));
-cp
+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;
+ }
+
+ hash_insert(mesh->node_udp_cache, &n->address, NULL);
+
+ if(sa) {
+ n->address = *sa;
+ n->sock = 0;
+
+ for(int i = 0; i < mesh->listen_sockets; i++) {
+ if(mesh->listen_socket[i].sa.sa.sa_family == sa->sa.sa_family) {
+ n->sock = i;
+ break;
+ }
+ }
+
+ hash_insert(mesh->node_udp_cache, sa, n);
+
+ meshlink_hint_address(mesh, (meshlink_node_t *)n, &sa->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);
+ }
+ }