From: Guus Sliepen Date: Tue, 3 Sep 2002 20:43:26 +0000 (+0000) Subject: Drop graph and edge stuff. Use new node stuff instead. X-Git-Tag: release-1.0pre8~39 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=d134c4542d4e890e1c1007f32b866742319853c5;p=tinc Drop graph and edge stuff. Use new node stuff instead. --- diff --git a/src/Makefile.am b/src/Makefile.am index aadeae29..cc1cdc30 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,17 +1,17 @@ ## Produce this file with automake to get Makefile.in -# $Id: Makefile.am,v 1.4.4.25 2002/08/24 12:11:40 guus Exp $ +# $Id: Makefile.am,v 1.4.4.26 2002/09/03 20:43:24 guus Exp $ sbin_PROGRAMS = tincd EXTRA_DIST = linux/device.c freebsd/device.c openbsd/device.c solaris/device.c netbsd/device.c darwin/device.c cygwin/device.c -tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c meta.c net.c net_packet.c net_setup.c \ - net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c \ +tincd_SOURCES = conf.c connection.c device.c event.c meta.c net.c net_packet.c net_setup.c \ + net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_node.c protocol_misc.c \ protocol_key.c protocol_subnet.c route.c subnet.c tincd.c INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib -noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h meta.h net.h netutl.h node.h process.h \ +noinst_HEADERS = conf.h connection.h device.h event.h meta.h net.h netutl.h node.h process.h \ protocol.h route.h subnet.h LIBS = @LIBS@ diff --git a/src/connection.h b/src/connection.h index 5f8b970a..fdc87d74 100644 --- a/src/connection.h +++ b/src/connection.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connection.h,v 1.1.2.27 2002/06/21 10:11:12 guus Exp $ + $Id: connection.h,v 1.1.2.28 2002/09/03 20:43:24 guus Exp $ */ #ifndef __TINC_CONNECTION_H__ @@ -44,7 +44,6 @@ #include "conf.h" #include "node.h" -#include "edge.h" #define OPTION_INDIRECT 0x0001 #define OPTION_TCPONLY 0x0002 @@ -66,18 +65,19 @@ typedef struct connection_t { char *name; /* name he claims to have */ sockaddr_t address; /* his real (internet) ip */ + sockaddr_t myaddress; /* our own address as seen by him */ + char *hostname; /* the hostname of its real ip */ int protocol_version; /* used protocol */ int socket; /* socket used for this connection */ long int options; /* options for this connection */ struct connection_status_t status; /* status info */ - int estimated_weight; /* estimation for the weight of the edge for this connection */ + int estimated_weight; /* estimation for the weight for this connection */ struct timeval start; /* time this connection was started, used for above estimation */ struct outgoing_t *outgoing; /* used to keep track of outgoing connections */ struct node_t *node; /* node associated with the other end */ - struct edge_t *edge; /* edge associated with this connection */ RSA *rsa_key; /* his public/private key */ const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */ diff --git a/src/net.c b/src/net.c index 2a072d80..ca70886f 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.174 2002/06/21 10:11:12 guus Exp $ + $Id: net.c,v 1.35.4.175 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -65,7 +65,6 @@ #include "process.h" #include "protocol.h" #include "subnet.h" -#include "graph.h" #include "process.h" #include "route.h" #include "device.h" @@ -83,13 +82,12 @@ int sigalrm = 0; time_t now = 0; -/* Purge edges and subnets of unreachable nodes. Use carefully. */ +/* Purge subnets of unreachable nodes. Use carefully. */ void purge(void) { - avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext, *cnode; + avl_node_t *nnode, *nnext, *snode, *snext, *cnode; node_t *n; - edge_t *e; subnet_t *s; connection_t *c; cp @@ -121,21 +119,6 @@ cp subnet_del(n, s); } - for(enode = n->edge_tree->head; enode; enode = enext) - { - enext = enode->next; - e = (edge_t *)enode->data; - - for(cnode = connection_tree->head; cnode; cnode = cnode->next) - { - c = (connection_t *)cnode->data; - if(c->status.active) - send_del_edge(c, e); - } - - edge_del(e); - } - node_del(n); } } @@ -182,14 +165,15 @@ cp /* Terminate a connection: - Close the socket - - Remove associated edge and tell other connections about it if report = 1 + - Tell other connections about it if report = 1 - Check if we need to retry making an outgoing connection - Deactivate the host */ void terminate_connection(connection_t *c, int report) { - avl_node_t *node; + avl_node_t *node, *node2; connection_t *other; + node_t *n; cp if(c->status.remove) return; @@ -202,30 +186,31 @@ cp c->status.active = 0; if(c->node) - c->node->connection = NULL; - - if(c->socket) - close(c->socket); - - if(c->edge) { - if(report) + if(report && c->node->connection) { for(node = connection_tree->head; node; node = node->next) { other = (connection_t *)node->data; - if(other->status.active && other != c) - send_del_edge(other, c->edge); + if(other == c) + continue; + for(node2 = node_tree->head; node2; node2 = node2->next) + { + n = (node_t *)node2->data; + if(n->nexthop == c->node) + { + send_del_node(other, n); + n->status.reachable = 0; + } + } } } - - edge_del(c->edge); - - /* Run MST and SSSP algorithms */ - - graph(); + c->node->connection = NULL; } + if(c->socket) + close(c->socket); + /* Check if this was our outgoing connection */ if(c->outgoing) @@ -246,14 +231,13 @@ cp */ void check_dead_connections(void) { - avl_node_t *node, *next; + avl_node_t *node; connection_t *c; cp - for(node = connection_tree->head; node; node = next) + for(node = connection_tree->head; node; node = node->next) { - next = node->next; c = (connection_t *)node->data; - if(c->last_ping_time + pingtimeout < now) + if(c->last_ping_time + pingtimeout < now && !c->status.remove) { if(c->status.active) { diff --git a/src/net_packet.c b/src/net_packet.c index 25f1d28e..bd1e4e21 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_packet.c,v 1.1.2.17 2002/06/21 10:11:12 guus Exp $ + $Id: net_packet.c,v 1.1.2.18 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -70,7 +70,6 @@ #include "process.h" #include "protocol.h" #include "subnet.h" -#include "graph.h" #include "process.h" #include "route.h" #include "device.h" @@ -332,7 +331,7 @@ cp return; } - via = (n->via == myself)?n->nexthop:n->via; + via = (n->options & OPTION_INDIRECT)?n->nexthop:n; if(via != n && debug_lvl >= DEBUG_TRAFFIC) syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"), diff --git a/src/net_setup.c b/src/net_setup.c index 2884c50a..edbcbf54 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_setup.c,v 1.1.2.21 2002/07/10 11:27:06 guus Exp $ + $Id: net_setup.c,v 1.1.2.22 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -67,7 +67,6 @@ #include "process.h" #include "protocol.h" #include "subnet.h" -#include "graph.h" #include "process.h" #include "route.h" #include "device.h" @@ -464,8 +463,6 @@ cp myself->status.reachable = 1; node_add(myself); - graph(); - cp /* Open sockets */ @@ -531,7 +528,6 @@ cp init_connections(); init_subnets(); init_nodes(); - init_edges(); init_events(); init_requests(); @@ -597,7 +593,6 @@ cp exit_requests(); exit_events(); - exit_edges(); exit_subnets(); exit_nodes(); exit_connections(); diff --git a/src/net_socket.c b/src/net_socket.c index f1628cdd..e0cec2c8 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_socket.c,v 1.1.2.16 2002/06/21 10:11:12 guus Exp $ + $Id: net_socket.c,v 1.1.2.17 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -63,7 +63,6 @@ #include "process.h" #include "protocol.h" #include "subnet.h" -#include "graph.h" #include "process.h" #include "route.h" #include "device.h" @@ -147,7 +146,7 @@ cp return -1; } - if(listen(nfd, 3)) + if(listen(nfd, 0)) { close(nfd); syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno)); diff --git a/src/node.c b/src/node.c index 591f4ed5..adc3a74d 100644 --- a/src/node.c +++ b/src/node.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: node.c,v 1.1.2.13 2002/06/21 10:11:13 guus Exp $ + $Id: node.c,v 1.1.2.14 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -77,7 +77,6 @@ node_t *new_node(void) node_t *n = (node_t *)xmalloc_and_zero(sizeof(*n)); cp n->subnet_tree = new_subnet_tree(); - n->edge_tree = new_edge_tree(); n->queue = list_alloc((list_action_t)free); cp return n; @@ -96,8 +95,6 @@ cp free(n->key); if(n->subnet_tree) free_subnet_tree(n->subnet_tree); - if(n->edge_tree) - free_edge_tree(n->edge_tree); free(n); cp } @@ -113,7 +110,6 @@ cp void node_del(node_t *n) { avl_node_t *node, *next; - edge_t *e; subnet_t *s; cp for(node = n->subnet_tree->head; node; node = next) @@ -122,13 +118,6 @@ cp s = (subnet_t *)node->data; subnet_del(n, s); } - - for(node = n->edge_tree->head; node; node = next) - { - next = node->next; - e = (edge_t *)node->data; - edge_del(e); - } cp avl_delete(node_tree, n); avl_delete(node_udp_tree, n); @@ -163,9 +152,9 @@ cp 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"), + syslog(LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s distance %d"), 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:"-"); + n->status, n->nexthop?n->nexthop->name:"-", n->distance); } syslog(LOG_DEBUG, _("End of nodes.")); diff --git a/src/node.h b/src/node.h index f80075f5..174a4c1e 100644 --- a/src/node.h +++ b/src/node.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: node.h,v 1.1.2.16 2002/06/21 10:11:13 guus Exp $ + $Id: node.h,v 1.1.2.17 2002/09/03 20:43:25 guus Exp $ */ #ifndef __TINC_NODE_H__ @@ -51,6 +51,8 @@ typedef struct node_t { struct node_status_t status; + int distance; /* Distance from us to that node */ + const EVP_CIPHER *cipher; /* Cipher type for UDP packets */ char *key; /* Cipher key and iv */ int keylength; /* Cipher key and iv length*/ @@ -67,8 +69,6 @@ typedef struct node_t { avl_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */ - avl_tree_t *edge_tree; /* Edges with this node as one of the endpoints */ - struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */ uint32_t sent_seqno; /* Sequence number last sent to this node */ diff --git a/src/process.c b/src/process.c index 8e701b2e..d53d5f06 100644 --- a/src/process.c +++ b/src/process.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.c,v 1.1.2.42 2002/07/10 11:27:06 guus Exp $ + $Id: process.c,v 1.1.2.43 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -399,7 +399,6 @@ sigusr2_handler(int a) { dump_device_stats(); dump_nodes(); - dump_edges(); dump_subnets(); } diff --git a/src/protocol.c b/src/protocol.c index 60273539..76c252f6 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28.4.129 2002/06/21 10:11:13 guus Exp $ + $Id: protocol.c,v 1.28.4.130 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -226,7 +226,7 @@ int (*request_handlers[])(connection_t*) = { status_h, error_h, termreq_h, ping_h, pong_h, add_subnet_h, del_subnet_h, - add_edge_h, del_edge_h, + add_node_h, del_node_h, key_changed_h, req_key_h, ans_key_h, tcppacket_h, }; @@ -238,7 +238,7 @@ char (*request_name[]) = { "STATUS", "ERROR", "TERMREQ", "PING", "PONG", "ADD_SUBNET", "DEL_SUBNET", - "ADD_EDGE", "DEL_EDGE", + "ADD_NODE", "DEL_NODE", "KEY_CHANGED", "REQ_KEY", "ANS_KEY", "PACKET", }; diff --git a/src/protocol.h b/src/protocol.h index 1ed4bebe..dea2e9f0 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.h,v 1.5.4.30 2002/06/21 10:11:13 guus Exp $ + $Id: protocol.h,v 1.5.4.31 2002/09/03 20:43:25 guus Exp $ */ #ifndef __TINC_PROTOCOL_H__ @@ -31,7 +31,7 @@ incompatible version have different protocols. */ -#define PROT_CURRENT 14 +#define PROT_CURRENT 15 /* Request numbers */ @@ -40,9 +40,8 @@ enum { ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK, STATUS, ERROR, TERMREQ, PING, PONG, -// ADD_NODE, DEL_NODE, ADD_SUBNET, DEL_SUBNET, - ADD_EDGE, DEL_EDGE, + ADD_NODE, DEL_NODE, KEY_CHANGED, REQ_KEY, ANS_KEY, PACKET, LAST /* Guardian for the highest request number */ @@ -81,12 +80,10 @@ extern int send_error(connection_t *, int, char *); extern int send_termreq(connection_t *); extern int send_ping(connection_t *); extern int send_pong(connection_t *); -// extern int send_add_node(connection_t *, node_t *); -// extern int send_del_node(connection_t *, node_t *); extern int send_add_subnet(connection_t *, subnet_t *); extern int send_del_subnet(connection_t *, subnet_t *); -extern int send_add_edge(connection_t *, edge_t *); -extern int send_del_edge(connection_t *, edge_t *); +extern int send_add_node(connection_t *, node_t *); +extern int send_del_node(connection_t *, node_t *); extern int send_key_changed(connection_t *, node_t *); extern int send_req_key(connection_t *, node_t *, node_t *); extern int send_ans_key(connection_t *, node_t *, node_t *); @@ -106,12 +103,10 @@ extern int error_h(connection_t *); extern int termreq_h(connection_t *); extern int ping_h(connection_t *); extern int pong_h(connection_t *); -// extern int add_node_h(connection_t *); -// extern int del_node_h(connection_t *); extern int add_subnet_h(connection_t *); extern int del_subnet_h(connection_t *); -extern int add_edge_h(connection_t *); -extern int del_edge_h(connection_t *); +extern int add_node_h(connection_t *); +extern int del_node_h(connection_t *); extern int key_changed_h(connection_t *); extern int req_key_h(connection_t *); extern int ans_key_h(connection_t *); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index c7c57329..b2ffaff9 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_auth.c,v 1.1.4.9 2002/06/21 10:11:13 guus Exp $ + $Id: protocol_auth.c,v 1.1.4.10 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -48,8 +48,6 @@ #include "meta.h" #include "connection.h" #include "node.h" -#include "edge.h" -#include "graph.h" #include "system.h" @@ -462,7 +460,7 @@ cp int send_ack(connection_t *c) { /* ACK message contains rest of the information the other end needs - to create node_t and edge_t structures. */ + to create node_t structures. */ int x; char *address, *port; @@ -473,7 +471,7 @@ cp gettimeofday(&now, NULL); c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000; sockaddr2str(&c->address, &address, &port); - x = send_request(c, "%d %s %s %d %lx", ACK, myport, address, c->estimated_weight, c->options); + x = send_request(c, "%d %s %s %lx", ACK, myport, address, c->options); free(address); free(port); cp @@ -485,13 +483,16 @@ void send_everything(connection_t *c) avl_node_t *node, *node2; node_t *n; subnet_t *s; - edge_t *e; + connection_t *other; - /* Send all known subnets */ + /* Send all known nodes and subnets */ for(node = node_tree->head; node; node = node->next) { n = (node_t *)node->data; + + if(n != c->node && n != myself) + send_add_node(c, n); for(node2 = n->subnet_tree->head; node2; node2 = node2->next) { @@ -500,16 +501,14 @@ void send_everything(connection_t *c) } } - /* Send all known edges */ - - for(node = edge_tree->head; node; node = node->next) + /* Inform others of this new node */ + + for(node = connection_tree->head; node; node = node->next) { - e = (edge_t *)node->data; - - if(e == c->edge) - continue; - - send_add_edge(c, e); + other = (connection_t *)node->data; + + if(other->status.active && other != c) + send_add_node(other, c->node); } } @@ -518,13 +517,11 @@ int ack_h(connection_t *c) char myaddress[MAX_STRING_SIZE]; char hisport[MAX_STRING_SIZE]; char *hisaddress, *dummy; - int weight; long int options; node_t *n; - connection_t *other; avl_node_t *node; cp - if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %d %lx", hisport, myaddress, &weight, &options) != 4) + if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %lx", hisport, myaddress, &options) != 3) { syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname); return -1; @@ -549,30 +546,26 @@ cp syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->name, n->hostname); terminate_connection(n->connection, 0); } - - /* FIXME: check if information in existing node matches that of the other end of this connection */ } - n->connection = c; c->node = n; c->options |= options; - - /* Create an edge_t for this connection */ - - c->edge = new_edge(); -cp - c->edge->from.node = myself; - c->edge->from.udpaddress = str2sockaddr(myaddress, myport); - c->edge->to.node = n; + c->myaddress = str2sockaddr(myaddress, myport); + + n->connection = c; sockaddr2str(&c->address, &hisaddress, &dummy); - c->edge->to.udpaddress = str2sockaddr(hisaddress, hisport); - free(hisaddress); - free(dummy); - c->edge->weight = (weight + c->estimated_weight) / 2; - c->edge->connection = c; - c->edge->options = c->options; -cp - edge_add(c->edge); + node = avl_unlink(node_udp_tree, n); + n->address = str2sockaddr(hisaddress, hisport); + avl_insert_node(node_udp_tree, node); + if(n->hostname) + free(n->hostname); + n->hostname = sockaddr2hostname(&n->address); + n->options = c->options; + n->distance = 1; + n->via = n->nexthop = n; + n->status.reachable = 1; + n->status.validkey = 0; + n->status.waitingforkey = 0; /* Activate this connection */ @@ -583,23 +576,9 @@ cp syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname); cp - /* Send him everything we know */ + /* Send him everything we know and tell the others about him */ send_everything(c); - - /* Notify others of this connection */ - - for(node = connection_tree->head; node; node = node->next) - { - other = (connection_t *)node->data; - - if(other->status.active && other != c) - send_add_edge(other, c->edge); - } - - /* Run MST and SSSP algorithms */ - - graph(); cp return 0; } diff --git a/src/protocol_key.c b/src/protocol_key.c index 3d711f90..90df50f2 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_key.c,v 1.1.4.7 2002/06/21 10:11:19 guus Exp $ + $Id: protocol_key.c,v 1.1.4.8 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -40,7 +40,6 @@ #include "meta.h" #include "connection.h" #include "node.h" -#include "edge.h" #include "system.h" @@ -96,7 +95,6 @@ cp n->status.validkey = 0; n->status.waitingforkey = 0; - n->sent_seqno = 0; /* Tell the others */ @@ -153,7 +151,7 @@ cp if(to == myself) /* Yes, send our own key back */ { mykeyused = 1; - from->received_seqno = 0; + from->sent_seqno = 0; send_ans_key(c, myself, from); } else @@ -235,7 +233,8 @@ cp from->status.validkey = 1; from->status.waitingforkey = 0; - + from->received_seqno = 0; + /* Check and lookup cipher and digest algorithms */ if(cipher) diff --git a/src/protocol_node.c b/src/protocol_node.c index 3d0355fd..7808ab41 100644 --- a/src/protocol_node.c +++ b/src/protocol_node.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_node.c,v 1.1.4.1 2002/09/02 22:40:42 guus Exp $ + $Id: protocol_node.c,v 1.1.4.2 2002/09/03 20:43:25 guus Exp $ */ #include "config.h" @@ -48,10 +48,13 @@ int send_add_node(connection_t *c, node_t *n) int x; char *address, *port; cp + if(!n->status.reachable) + return 0; + sockaddr2str(&n->address, &address, &port); x = send_request(c, "%d %s %s %s %lx %d", ADD_NODE, n->name, address, port, - n->options, n->distance + 1); + n->options, n->distance + 1); // Alternatively, use n->distance + c->estimated_weight free(address); free(port); cp @@ -84,6 +87,11 @@ cp return -1; } + /* This node is indirect if it's nexthop is as well */ + + if(c->node->options & OPTION_INDIRECT) + options |= OPTION_INDIRECT; + /* Lookup nodes */ n = lookup_node(name); @@ -97,20 +105,27 @@ cp n->hostname = sockaddr2hostname(&n->address); n->options = options; n->distance = distance; - n->nexthop = c->node; + n->via = n->nexthop = c->node; + n->status.reachable = 1; node_add(n); } else { // If this ADD_NODE is closer or more direct, use it instead of the old one. - if((n->options & OPTION_INDIRECT) && !(options & OPTION_INDIRECT) || n->distance > distance) + if(((n->options & OPTION_INDIRECT) && !(options & OPTION_INDIRECT)) || n->distance > distance) { - free(n->hostname); + avl_node_t *node = avl_unlink(node_udp_tree, n); n->address = str2sockaddr(address, port); + avl_insert_node(node_udp_tree, node); + if(n->hostname) + free(n->hostname); n->hostname = sockaddr2hostname(&n->address); n->options = options; n->distance = distance; - n->nexthop = c->node; + n->via = n->nexthop = c->node; + n->status.reachable = 1; + n->status.validkey = 0; + n->status.waitingforkey = 0; } else // Otherwise, just ignore it. @@ -185,11 +200,10 @@ cp send_del_node(other, n); } - /* Delete the node */ + /* "Delete" the node */ - node_del(n); - - exit: + n->status.reachable = 0; + n->status.validkey = 0; cp return 0; } diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index d6ca43df..e5103079 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_subnet.c,v 1.1.4.4 2002/06/21 10:11:19 guus Exp $ + $Id: protocol_subnet.c,v 1.1.4.5 2002/09/03 20:43:26 guus Exp $ */ #include "config.h" @@ -40,8 +40,6 @@ #include "meta.h" #include "connection.h" #include "node.h" -#include "edge.h" -#include "graph.h" #include "system.h"