X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnode.c;h=9281178b582351057d69d7827b11e57cb3e608ff;hb=ce8775000ab38229a78ecf3dc26bab008ca0f332;hp=75f01e30b9a8c2f67ba94d3ad65c80b44eb0ce48;hpb=c4afc481541bff4db7f57c81796b7a5f61cdb1b5;p=meshlink diff --git a/src/node.c b/src/node.c index 75f01e30..9281178b 100644 --- a/src/node.c +++ b/src/node.c @@ -1,6 +1,6 @@ /* node.c -- node tree management - Copyright (C) 2001-2009 Guus Sliepen , + Copyright (C) 2001-2011 Guus Sliepen , 2001-2005 Ivo Timmermans This program is free software; you can redistribute it and/or modify @@ -20,6 +20,7 @@ #include "system.h" +#include "control_common.h" #include "splay_tree.h" #include "logger.h" #include "net.h" @@ -61,6 +62,7 @@ void exit_nodes(void) { node_t *new_node(void) { node_t *n = xmalloc_and_zero(sizeof *n); + if(replaywin) n->late = xmalloc_and_zero(replaywin); n->subnet_tree = new_subnet_tree(); n->edge_tree = new_edge_tree(); n->mtu = MTU; @@ -91,6 +93,9 @@ void free_node(node_t *n) { if(n->name) free(n->name); + if(n->late) + free(n->late); + free(n); } @@ -137,6 +142,11 @@ node_t *lookup_node_udp(const sockaddr_t *sa) { } void update_node_udp(node_t *n, const sockaddr_t *sa) { + if(n == myself) { + logger(LOG_WARNING, "Trying to update UDP address of myself!\n"); + return; + } + splay_delete(node_udp_tree, n); if(n->hostname) @@ -154,19 +164,18 @@ void update_node_udp(node_t *n, const sockaddr_t *sa) { } } -int dump_nodes(struct evbuffer *out) { +bool dump_nodes(connection_t *c) { splay_node_t *node; node_t *n; for(node = node_tree->head; node; node = node->next) { n = node->data; - if(evbuffer_add_printf(out, " %s at %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d)\n", + send_request(c, "%d %d %s at %s cipher %d digest %d maclength %zd compression %d options %x status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d)", CONTROL, REQ_DUMP_NODES, n->name, n->hostname, cipher_get_nid(&n->outcipher), digest_get_nid(&n->outdigest), digest_length(&n->outdigest), n->outcompression, n->options, bitfield_to_int(&n->status, sizeof n->status), n->nexthop ? n->nexthop->name : "-", - n->via ? n->via->name : "-", n->distance, n->mtu, n->minmtu, n->maxmtu) == -1) - return errno; + n->via ? n->via->name : "-", n->distance, n->mtu, n->minmtu, n->maxmtu); } - return 0; + return send_request(c, "%d %d", CONTROL, REQ_DUMP_NODES); }