Drop graph and edge stuff. Use new node stuff instead.

This commit is contained in:
Guus Sliepen 2002-09-03 20:43:26 +00:00
parent 856de4c5fe
commit d134c4542d
15 changed files with 116 additions and 166 deletions

View file

@ -1,17 +1,17 @@
## Produce this file with automake to get Makefile.in ## 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 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 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 \ 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_edge.c protocol_misc.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 protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib 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 protocol.h route.h subnet.h
LIBS = @LIBS@ LIBS = @LIBS@

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__ #ifndef __TINC_CONNECTION_H__
@ -44,7 +44,6 @@
#include "conf.h" #include "conf.h"
#include "node.h" #include "node.h"
#include "edge.h"
#define OPTION_INDIRECT 0x0001 #define OPTION_INDIRECT 0x0001
#define OPTION_TCPONLY 0x0002 #define OPTION_TCPONLY 0x0002
@ -66,18 +65,19 @@ typedef struct connection_t {
char *name; /* name he claims to have */ char *name; /* name he claims to have */
sockaddr_t address; /* his real (internet) ip */ 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 */ char *hostname; /* the hostname of its real ip */
int protocol_version; /* used protocol */ int protocol_version; /* used protocol */
int socket; /* socket used for this connection */ int socket; /* socket used for this connection */
long int options; /* options for this connection */ long int options; /* options for this connection */
struct connection_status_t status; /* status info */ 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 timeval start; /* time this connection was started, used for above estimation */
struct outgoing_t *outgoing; /* used to keep track of outgoing connections */ struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
struct node_t *node; /* node associated with the other end */ 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 */ RSA *rsa_key; /* his public/private key */
const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */ const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -65,7 +65,6 @@
#include "process.h" #include "process.h"
#include "protocol.h" #include "protocol.h"
#include "subnet.h" #include "subnet.h"
#include "graph.h"
#include "process.h" #include "process.h"
#include "route.h" #include "route.h"
#include "device.h" #include "device.h"
@ -83,13 +82,12 @@ int sigalrm = 0;
time_t now = 0; time_t now = 0;
/* Purge edges and subnets of unreachable nodes. Use carefully. */ /* Purge subnets of unreachable nodes. Use carefully. */
void purge(void) void purge(void)
{ {
avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext, *cnode; avl_node_t *nnode, *nnext, *snode, *snext, *cnode;
node_t *n; node_t *n;
edge_t *e;
subnet_t *s; subnet_t *s;
connection_t *c; connection_t *c;
cp cp
@ -121,21 +119,6 @@ cp
subnet_del(n, s); 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); node_del(n);
} }
} }
@ -182,14 +165,15 @@ cp
/* /*
Terminate a connection: Terminate a connection:
- Close the socket - 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 - Check if we need to retry making an outgoing connection
- Deactivate the host - Deactivate the host
*/ */
void terminate_connection(connection_t *c, int report) void terminate_connection(connection_t *c, int report)
{ {
avl_node_t *node; avl_node_t *node, *node2;
connection_t *other; connection_t *other;
node_t *n;
cp cp
if(c->status.remove) if(c->status.remove)
return; return;
@ -202,30 +186,31 @@ cp
c->status.active = 0; c->status.active = 0;
if(c->node) 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) for(node = connection_tree->head; node; node = node->next)
{ {
other = (connection_t *)node->data; other = (connection_t *)node->data;
if(other->status.active && other != c) if(other == c)
send_del_edge(other, c->edge); 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;
}
}
} }
} }
c->node->connection = NULL;
edge_del(c->edge);
/* Run MST and SSSP algorithms */
graph();
} }
if(c->socket)
close(c->socket);
/* Check if this was our outgoing connection */ /* Check if this was our outgoing connection */
if(c->outgoing) if(c->outgoing)
@ -246,14 +231,13 @@ cp
*/ */
void check_dead_connections(void) void check_dead_connections(void)
{ {
avl_node_t *node, *next; avl_node_t *node;
connection_t *c; connection_t *c;
cp 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; 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) if(c->status.active)
{ {

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -70,7 +70,6 @@
#include "process.h" #include "process.h"
#include "protocol.h" #include "protocol.h"
#include "subnet.h" #include "subnet.h"
#include "graph.h"
#include "process.h" #include "process.h"
#include "route.h" #include "route.h"
#include "device.h" #include "device.h"
@ -332,7 +331,7 @@ cp
return; return;
} }
via = (n->via == myself)?n->nexthop:n->via; via = (n->options & OPTION_INDIRECT)?n->nexthop:n;
if(via != n && debug_lvl >= DEBUG_TRAFFIC) if(via != n && debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"), syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"),

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -67,7 +67,6 @@
#include "process.h" #include "process.h"
#include "protocol.h" #include "protocol.h"
#include "subnet.h" #include "subnet.h"
#include "graph.h"
#include "process.h" #include "process.h"
#include "route.h" #include "route.h"
#include "device.h" #include "device.h"
@ -464,8 +463,6 @@ cp
myself->status.reachable = 1; myself->status.reachable = 1;
node_add(myself); node_add(myself);
graph();
cp cp
/* Open sockets */ /* Open sockets */
@ -531,7 +528,6 @@ cp
init_connections(); init_connections();
init_subnets(); init_subnets();
init_nodes(); init_nodes();
init_edges();
init_events(); init_events();
init_requests(); init_requests();
@ -597,7 +593,6 @@ cp
exit_requests(); exit_requests();
exit_events(); exit_events();
exit_edges();
exit_subnets(); exit_subnets();
exit_nodes(); exit_nodes();
exit_connections(); exit_connections();

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -63,7 +63,6 @@
#include "process.h" #include "process.h"
#include "protocol.h" #include "protocol.h"
#include "subnet.h" #include "subnet.h"
#include "graph.h"
#include "process.h" #include "process.h"
#include "route.h" #include "route.h"
#include "device.h" #include "device.h"
@ -147,7 +146,7 @@ cp
return -1; return -1;
} }
if(listen(nfd, 3)) if(listen(nfd, 0))
{ {
close(nfd); close(nfd);
syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno)); syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno));

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -77,7 +77,6 @@ node_t *new_node(void)
node_t *n = (node_t *)xmalloc_and_zero(sizeof(*n)); node_t *n = (node_t *)xmalloc_and_zero(sizeof(*n));
cp cp
n->subnet_tree = new_subnet_tree(); n->subnet_tree = new_subnet_tree();
n->edge_tree = new_edge_tree();
n->queue = list_alloc((list_action_t)free); n->queue = list_alloc((list_action_t)free);
cp cp
return n; return n;
@ -96,8 +95,6 @@ cp
free(n->key); free(n->key);
if(n->subnet_tree) if(n->subnet_tree)
free_subnet_tree(n->subnet_tree); free_subnet_tree(n->subnet_tree);
if(n->edge_tree)
free_edge_tree(n->edge_tree);
free(n); free(n);
cp cp
} }
@ -113,7 +110,6 @@ cp
void node_del(node_t *n) void node_del(node_t *n)
{ {
avl_node_t *node, *next; avl_node_t *node, *next;
edge_t *e;
subnet_t *s; subnet_t *s;
cp cp
for(node = n->subnet_tree->head; node; node = next) for(node = n->subnet_tree->head; node; node = next)
@ -122,13 +118,6 @@ cp
s = (subnet_t *)node->data; s = (subnet_t *)node->data;
subnet_del(n, s); 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 cp
avl_delete(node_tree, n); avl_delete(node_tree, n);
avl_delete(node_udp_tree, n); avl_delete(node_udp_tree, n);
@ -163,9 +152,9 @@ cp
for(node = node_tree->head; node; node = node->next) for(node = node_tree->head; node; node = node->next)
{ {
n = (node_t *)node->data; 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->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.")); syslog(LOG_DEBUG, _("End of nodes."));

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__ #ifndef __TINC_NODE_H__
@ -51,6 +51,8 @@ typedef struct node_t {
struct node_status_t status; struct node_status_t status;
int distance; /* Distance from us to that node */
const EVP_CIPHER *cipher; /* Cipher type for UDP packets */ const EVP_CIPHER *cipher; /* Cipher type for UDP packets */
char *key; /* Cipher key and iv */ char *key; /* Cipher key and iv */
int keylength; /* Cipher key and iv length*/ 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 *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) */ 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 */ uint32_t sent_seqno; /* Sequence number last sent to this node */

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -399,7 +399,6 @@ sigusr2_handler(int a)
{ {
dump_device_stats(); dump_device_stats();
dump_nodes(); dump_nodes();
dump_edges();
dump_subnets(); dump_subnets();
} }

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -226,7 +226,7 @@ int (*request_handlers[])(connection_t*) = {
status_h, error_h, termreq_h, status_h, error_h, termreq_h,
ping_h, pong_h, ping_h, pong_h,
add_subnet_h, del_subnet_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, key_changed_h, req_key_h, ans_key_h,
tcppacket_h, tcppacket_h,
}; };
@ -238,7 +238,7 @@ char (*request_name[]) = {
"STATUS", "ERROR", "TERMREQ", "STATUS", "ERROR", "TERMREQ",
"PING", "PONG", "PING", "PONG",
"ADD_SUBNET", "DEL_SUBNET", "ADD_SUBNET", "DEL_SUBNET",
"ADD_EDGE", "DEL_EDGE", "ADD_NODE", "DEL_NODE",
"KEY_CHANGED", "REQ_KEY", "ANS_KEY", "KEY_CHANGED", "REQ_KEY", "ANS_KEY",
"PACKET", "PACKET",
}; };

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__ #ifndef __TINC_PROTOCOL_H__
@ -31,7 +31,7 @@
incompatible version have different protocols. incompatible version have different protocols.
*/ */
#define PROT_CURRENT 14 #define PROT_CURRENT 15
/* Request numbers */ /* Request numbers */
@ -40,9 +40,8 @@ enum {
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK, ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
STATUS, ERROR, TERMREQ, STATUS, ERROR, TERMREQ,
PING, PONG, PING, PONG,
// ADD_NODE, DEL_NODE,
ADD_SUBNET, DEL_SUBNET, ADD_SUBNET, DEL_SUBNET,
ADD_EDGE, DEL_EDGE, ADD_NODE, DEL_NODE,
KEY_CHANGED, REQ_KEY, ANS_KEY, KEY_CHANGED, REQ_KEY, ANS_KEY,
PACKET, PACKET,
LAST /* Guardian for the highest request number */ 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_termreq(connection_t *);
extern int send_ping(connection_t *); extern int send_ping(connection_t *);
extern int send_pong(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_add_subnet(connection_t *, subnet_t *);
extern int send_del_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_add_node(connection_t *, node_t *);
extern int send_del_edge(connection_t *, edge_t *); extern int send_del_node(connection_t *, node_t *);
extern int send_key_changed(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_req_key(connection_t *, node_t *, node_t *);
extern int send_ans_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 termreq_h(connection_t *);
extern int ping_h(connection_t *); extern int ping_h(connection_t *);
extern int pong_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 add_subnet_h(connection_t *);
extern int del_subnet_h(connection_t *); extern int del_subnet_h(connection_t *);
extern int add_edge_h(connection_t *); extern int add_node_h(connection_t *);
extern int del_edge_h(connection_t *); extern int del_node_h(connection_t *);
extern int key_changed_h(connection_t *); extern int key_changed_h(connection_t *);
extern int req_key_h(connection_t *); extern int req_key_h(connection_t *);
extern int ans_key_h(connection_t *); extern int ans_key_h(connection_t *);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -48,8 +48,6 @@
#include "meta.h" #include "meta.h"
#include "connection.h" #include "connection.h"
#include "node.h" #include "node.h"
#include "edge.h"
#include "graph.h"
#include "system.h" #include "system.h"
@ -462,7 +460,7 @@ cp
int send_ack(connection_t *c) int send_ack(connection_t *c)
{ {
/* ACK message contains rest of the information the other end needs /* 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; int x;
char *address, *port; char *address, *port;
@ -473,7 +471,7 @@ cp
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000; c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000;
sockaddr2str(&c->address, &address, &port); 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(address);
free(port); free(port);
cp cp
@ -485,13 +483,16 @@ void send_everything(connection_t *c)
avl_node_t *node, *node2; avl_node_t *node, *node2;
node_t *n; node_t *n;
subnet_t *s; 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) for(node = node_tree->head; node; node = node->next)
{ {
n = (node_t *)node->data; 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) for(node2 = n->subnet_tree->head; node2; node2 = node2->next)
{ {
@ -500,16 +501,14 @@ void send_everything(connection_t *c)
} }
} }
/* Send all known edges */ /* Inform others of this new node */
for(node = edge_tree->head; node; node = node->next) for(node = connection_tree->head; node; node = node->next)
{ {
e = (edge_t *)node->data; other = (connection_t *)node->data;
if(e == c->edge) if(other->status.active && other != c)
continue; send_add_node(other, c->node);
send_add_edge(c, e);
} }
} }
@ -518,13 +517,11 @@ int ack_h(connection_t *c)
char myaddress[MAX_STRING_SIZE]; char myaddress[MAX_STRING_SIZE];
char hisport[MAX_STRING_SIZE]; char hisport[MAX_STRING_SIZE];
char *hisaddress, *dummy; char *hisaddress, *dummy;
int weight;
long int options; long int options;
node_t *n; node_t *n;
connection_t *other;
avl_node_t *node; avl_node_t *node;
cp 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); syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname);
return -1; return -1;
@ -549,30 +546,26 @@ cp
syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->name, n->hostname); syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->name, n->hostname);
terminate_connection(n->connection, 0); 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->node = n;
c->options |= options; c->options |= options;
c->myaddress = str2sockaddr(myaddress, myport);
/* Create an edge_t for this connection */
n->connection = c;
c->edge = new_edge();
cp
c->edge->from.node = myself;
c->edge->from.udpaddress = str2sockaddr(myaddress, myport);
c->edge->to.node = n;
sockaddr2str(&c->address, &hisaddress, &dummy); sockaddr2str(&c->address, &hisaddress, &dummy);
c->edge->to.udpaddress = str2sockaddr(hisaddress, hisport); node = avl_unlink(node_udp_tree, n);
free(hisaddress); n->address = str2sockaddr(hisaddress, hisport);
free(dummy); avl_insert_node(node_udp_tree, node);
c->edge->weight = (weight + c->estimated_weight) / 2; if(n->hostname)
c->edge->connection = c; free(n->hostname);
c->edge->options = c->options; n->hostname = sockaddr2hostname(&n->address);
cp n->options = c->options;
edge_add(c->edge); n->distance = 1;
n->via = n->nexthop = n;
n->status.reachable = 1;
n->status.validkey = 0;
n->status.waitingforkey = 0;
/* Activate this connection */ /* Activate this connection */
@ -583,23 +576,9 @@ cp
syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname); syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname);
cp cp
/* Send him everything we know */ /* Send him everything we know and tell the others about him */
send_everything(c); 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 cp
return 0; return 0;
} }

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -40,7 +40,6 @@
#include "meta.h" #include "meta.h"
#include "connection.h" #include "connection.h"
#include "node.h" #include "node.h"
#include "edge.h"
#include "system.h" #include "system.h"
@ -96,7 +95,6 @@ cp
n->status.validkey = 0; n->status.validkey = 0;
n->status.waitingforkey = 0; n->status.waitingforkey = 0;
n->sent_seqno = 0;
/* Tell the others */ /* Tell the others */
@ -153,7 +151,7 @@ cp
if(to == myself) /* Yes, send our own key back */ if(to == myself) /* Yes, send our own key back */
{ {
mykeyused = 1; mykeyused = 1;
from->received_seqno = 0; from->sent_seqno = 0;
send_ans_key(c, myself, from); send_ans_key(c, myself, from);
} }
else else
@ -235,7 +233,8 @@ cp
from->status.validkey = 1; from->status.validkey = 1;
from->status.waitingforkey = 0; from->status.waitingforkey = 0;
from->received_seqno = 0;
/* Check and lookup cipher and digest algorithms */ /* Check and lookup cipher and digest algorithms */
if(cipher) if(cipher)

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -48,10 +48,13 @@ int send_add_node(connection_t *c, node_t *n)
int x; int x;
char *address, *port; char *address, *port;
cp cp
if(!n->status.reachable)
return 0;
sockaddr2str(&n->address, &address, &port); sockaddr2str(&n->address, &address, &port);
x = send_request(c, "%d %s %s %s %lx %d", ADD_NODE, x = send_request(c, "%d %s %s %s %lx %d", ADD_NODE,
n->name, address, port, n->name, address, port,
n->options, n->distance + 1); n->options, n->distance + 1); // Alternatively, use n->distance + c->estimated_weight
free(address); free(address);
free(port); free(port);
cp cp
@ -84,6 +87,11 @@ cp
return -1; return -1;
} }
/* This node is indirect if it's nexthop is as well */
if(c->node->options & OPTION_INDIRECT)
options |= OPTION_INDIRECT;
/* Lookup nodes */ /* Lookup nodes */
n = lookup_node(name); n = lookup_node(name);
@ -97,20 +105,27 @@ cp
n->hostname = sockaddr2hostname(&n->address); n->hostname = sockaddr2hostname(&n->address);
n->options = options; n->options = options;
n->distance = distance; n->distance = distance;
n->nexthop = c->node; n->via = n->nexthop = c->node;
n->status.reachable = 1;
node_add(n); node_add(n);
} }
else else
{ {
// If this ADD_NODE is closer or more direct, use it instead of the old one. // 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); n->address = str2sockaddr(address, port);
avl_insert_node(node_udp_tree, node);
if(n->hostname)
free(n->hostname);
n->hostname = sockaddr2hostname(&n->address); n->hostname = sockaddr2hostname(&n->address);
n->options = options; n->options = options;
n->distance = distance; 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 else
// Otherwise, just ignore it. // Otherwise, just ignore it.
@ -185,11 +200,10 @@ cp
send_del_node(other, n); send_del_node(other, n);
} }
/* Delete the node */ /* "Delete" the node */
node_del(n); n->status.reachable = 0;
n->status.validkey = 0;
exit:
cp cp
return 0; return 0;
} }

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -40,8 +40,6 @@
#include "meta.h" #include "meta.h"
#include "connection.h" #include "connection.h"
#include "node.h" #include "node.h"
#include "edge.h"
#include "graph.h"
#include "system.h" #include "system.h"