From: Ivo Timmermans Date: Thu, 2 May 2002 11:50:07 +0000 (+0000) Subject: Another file moved; random interface stuff. X-Git-Tag: import-tinc-1.1~798 X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=4c1a4e8a790584e4c7d5c0f2485706f4c01e1911;p=meshlink Another file moved; random interface stuff. --- diff --git a/lib/Makefile.am b/lib/Makefile.am index c49b613d..f0a01221 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,17 +1,17 @@ ## Process this file with automake to produce Makefile.in -# $Id: Makefile.am,v 1.7 2002/04/28 12:46:25 zarq Exp $ +# $Id: Makefile.am,v 1.8 2002/05/02 11:50:07 zarq Exp $ noinst_LIBRARIES = libtinc.a INCLUDES = @INCLUDES@ -I. -I$(top_builddir) -I$(top_srcdir)/intl libtinc_a_SOURCES = xmalloc.c pidfile.c utils.c getopt.c getopt1.c \ - list.c avl_tree.c hooks.c dropin.c edge.c conf.c netutl.c logging.c connection.c subnet.c node.c + list.c avl_tree.c hooks.c dropin.c edge.c conf.c netutl.c logging.c connection.c subnet.c node.c graph.c libtinc_a_LIBADD = @LIBOBJS@ @ALLOCA@ libtinc_a_DEPENDENCIES = $(libvpn_a_LIBADD) noinst_HEADERS = xalloc.h pidfile.h utils.h getopt.h list.h avl_tree.h \ - hooks.h dropin.h edge.h net.h conf.h netutl.h logging.h connection.h subnet.h node.h + hooks.h dropin.h edge.h net.h conf.h netutl.h logging.h connection.h subnet.h node.h graph.h EXTRA_DIST = README diff --git a/lib/graph.c b/lib/graph.c new file mode 100644 index 00000000..f9532632 --- /dev/null +++ b/lib/graph.c @@ -0,0 +1,285 @@ +/* + graph.c -- graph algorithms + Copyright (C) 2001-2002 Guus Sliepen , + 2001-2002 Ivo Timmermans + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: graph.c,v 1.1 2002/05/02 11:50:07 zarq Exp $ +*/ + +/* We need to generate two trees from the graph: + + 1. A minimum spanning tree for broadcasts, + 2. A single-source shortest path tree for unicasts. + + Actually, the first one alone would suffice but would make unicast packets + take longer routes than necessary. + + For the MST algorithm we can choose from Prim's or Kruskal's. I personally + favour Kruskal's, because we make an extra AVL tree of edges sorted on + weights (metric). That tree only has to be updated when an edge is added or + removed, and during the MST algorithm we just have go linearly through that + tree, adding safe edges until #edges = #nodes - 1. The implementation here + however is not so fast, because I tried to avoid having to make a forest and + merge trees. + + For the SSSP algorithm Dijkstra's seems to be a nice choice. Currently a + simple breadth-first search is presented here. + + The SSSP algorithm will also be used to determine whether nodes are directly, + indirectly or not reachable from the source. It will also set the correct + destination address and port of a node if possible. +*/ + +#include "config.h" + +#include +#include +#include +#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) + #include +#endif +#include + +#include +#include +#include + +#include "netutl.h" +#include "node.h" +#include "edge.h" +#include "connection.h" +#include "logging.h" + +#include "system.h" + +/* Implementation of Kruskal's algorithm. + Running time: O(EN) + Please note that sorting on weight is already done by add_edge(). +*/ + +void mst_kruskal(void) +{ + avl_node_t *node, *next; + edge_t *e; + node_t *n; + connection_t *c; + int nodes = 0; + int safe_edges = 0; + int skipped; + + /* Clear MST status on connections */ + + for(node = connection_tree->head; node; node = node->next) + { + c = (connection_t *)node->data; + c->status.mst = 0; + } + + /* Do we have something to do at all? */ + + if(!edge_weight_tree->head) + return; + + if(debug_lvl >= DEBUG_SCARY_THINGS) + syslog(LOG_DEBUG, "Running Kruskal's algorithm:"); + + /* Clear visited status on nodes */ + + for(node = node_tree->head; node; node = node->next) + { + n = (node_t *)node->data; + n->status.visited = 0; + nodes++; + } + + /* Starting point */ + + ((edge_t *)edge_weight_tree->head->data)->from.node->status.visited = 1; + + /* Add safe edges */ + + for(skipped = 0, node = edge_weight_tree->head; node; node = next) + { + next = node->next; + e = (edge_t *)node->data; + + if(e->from.node->status.visited == e->to.node->status.visited) + { + skipped = 1; + continue; + } + + e->from.node->status.visited = 1; + e->to.node->status.visited = 1; + if(e->connection) + e->connection->status.mst = 1; + + safe_edges++; + + if(debug_lvl >= DEBUG_SCARY_THINGS) + syslog(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from.node->name, e->to.node->name, e->weight); + + if(skipped) + { + next = edge_weight_tree->head; + continue; + } + } + + if(debug_lvl >= DEBUG_SCARY_THINGS) + syslog(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes, safe_edges); +} + +/* Implementation of a simple breadth-first search algorithm. + Running time: O(E) +*/ + +void sssp_bfs(void) +{ + avl_node_t *node, *from, *next, *to; + edge_t *e; + node_t *n; + halfconnection_t to_hc, from_hc; + avl_tree_t *todo_tree; + int indirect; + + todo_tree = avl_alloc_tree(NULL, NULL); + + /* Clear visited status on nodes */ + + for(node = node_tree->head; node; node = node->next) + { + n = (node_t *)node->data; + n->status.visited = 0; + n->status.indirect = 1; + } + + /* Begin with myself */ + + myself->status.visited = 1; + myself->status.indirect = 0; + myself->nexthop = myself; + myself->via = myself; + node = avl_alloc_node(); + node->data = myself; + avl_insert_top(todo_tree, node); + + /* Loop while todo_tree is filled */ + + while(todo_tree->head) + { + for(from = todo_tree->head; from; from = next) /* "from" is the node from which we start */ + { + next = from->next; + n = (node_t *)from->data; + + for(to = n->edge_tree->head; to; to = to->next) /* "to" is the edge connected to "from" */ + { + e = (edge_t *)to->data; + + if(e->from.node == n) /* "from_hc" is the halfconnection with .node == from */ + to_hc = e->to, from_hc = e->from; + else + to_hc = e->from, from_hc = e->to; + + /* Situation: + + / + / + ------(n)from_hc-----to_hc + \ + \ + + n->address is set to the to_hc.udpaddress of the edge left of n. + We are currently examining the edge right of n: + + - If from_hc.udpaddress != n->address, then to_hc.node is probably + not reachable for the nodes left of n. We do as if the indirectdata + flag is set on edge e. + - If edge e provides for better reachability of to_hc.node, update + to_hc.node and (re)add it to the todo_tree to (re)examine the reachability + of nodes behind it. + */ + + indirect = n->status.indirect || e->options & OPTION_INDIRECT || ((n != myself) && sockaddrcmp(&n->address, &from_hc.udpaddress)); + + if(to_hc.node->status.visited && (!to_hc.node->status.indirect || indirect)) + continue; + + to_hc.node->status.visited = 1; + to_hc.node->status.indirect = indirect; + to_hc.node->nexthop = (n->nexthop == myself) ? to_hc.node : n->nexthop; + to_hc.node->via = indirect ? n->via : to_hc.node; + to_hc.node->options = e->options; + if(sockaddrcmp(&to_hc.node->address, &to_hc.udpaddress)) + { + node = avl_unlink(node_udp_tree, to_hc.node); + to_hc.node->address = to_hc.udpaddress; + if(to_hc.node->hostname) + free(to_hc.node->hostname); + to_hc.node->hostname = sockaddr2hostname(&to_hc.udpaddress); + avl_insert_node(node_udp_tree, node); + } + node = avl_alloc_node(); + node->data = to_hc.node; + avl_insert_before(todo_tree, from, node); + } + + avl_delete_node(todo_tree, from); + } + } + + avl_free_tree(todo_tree); + + /* Check reachability status. */ + + for(node = node_tree->head; node; node = next) + { + next = node->next; + n = (node_t *)node->data; + + if(n->status.visited) + { + if(!n->status.reachable) + { + if(debug_lvl >= DEBUG_TRAFFIC) + syslog(LOG_DEBUG, _("Node %s (%s) became reachable"), n->name, n->hostname); + n->status.reachable = 1; + run_hooks("node-visible", n); + } + } + else + { + if(n->status.reachable) + { + if(debug_lvl >= DEBUG_TRAFFIC) + syslog(LOG_DEBUG, _("Node %s (%s) became unreachable"), n->name, n->hostname); + n->status.reachable = 0; + n->status.validkey = 0; + n->status.waitingforkey = 0; + n->sent_seqno = 0; + run_hooks("node-invisible", n); + } + } + } +} + +void graph(void) +{ + mst_kruskal(); + sssp_bfs(); +} diff --git a/lib/graph.h b/lib/graph.h new file mode 100644 index 00000000..b14841ea --- /dev/null +++ b/lib/graph.h @@ -0,0 +1,25 @@ +/* + graph.h -- header for graph.c + Copyright (C) 2001-2002 Guus Sliepen , + 2001-2002 Ivo Timmermans + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: graph.h,v 1.1 2002/05/02 11:50:07 zarq Exp $ +*/ + +extern void graph(void); +extern void mst_kruskal(void); +extern void sssp_bfs(void); diff --git a/lib/hooks.c b/lib/hooks.c new file mode 100644 index 00000000..9cb64780 --- /dev/null +++ b/lib/hooks.c @@ -0,0 +1,120 @@ +/* + hooks.c -- hooks management + Copyright (C) 2002 Guus Sliepen , + 2002 Ivo Timmermans + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: hooks.c,v 1.2 2002/05/02 11:50:07 zarq Exp $ +*/ + +#include "config.h" + +#include +#include +#include + +#include +#include +#include + +avl_tree_t *hooks_tree = NULL; + +struct hooks_node { + const char *type; + avl_tree_t *hooks; +} hooks_node; + +static int hook_type_compare(const void *a, const void *b) +{ + return strcmp(((const struct hooks_node*)a)->type, + ((const struct hooks_node*)b)->type); +} + +static int hook_dummy_compare(const void *a, const void *b) +{ + if(a < b) + return -1; + if(a > b) + return 1; + return 0; +} + +void run_hooks(const char *type, ...) +{ + avl_node_t *avlnode; + va_list args; + struct hooks_node *hn; + struct hooks_node target; + + if(!hooks_tree) + return; + + target.type = type; + hn = (struct hooks_node*)avl_search(hooks_tree, &target); + if(!hn || !(hn->hooks->head)) + { + fprintf(stderr, "Warning, no hooks found for `%s'\n", type); + return; + } + + va_start(args, type); + for(avlnode = hn->hooks->head; avlnode; avlnode = avlnode->next) + { + assert(avlnode->data); + ((hook_function_t*)(avlnode->data))(type, args); + } + va_end(args); +} + +void add_hook(const char *type, hook_function_t *hook) +{ + struct hooks_node *hn; + struct hooks_node target; + + if(!hooks_tree) + hooks_tree = avl_alloc_tree(hook_type_compare, NULL); + + target.type = type; + hn = avl_search(hooks_tree, &target); + if(!hn) + { + avl_tree_t *t; + + hn = xmalloc(sizeof(struct hooks_node)); + t = avl_alloc_tree(hook_dummy_compare, NULL); + hn->type = type; + hn->hooks = t; + avl_insert(hooks_tree, (void*)hn); + } + + avl_insert(hn->hooks, (void*)hook); +} + +void del_hook(const char *type, hook_function_t *hook) +{ + avl_tree_t *t; + struct hooks_node target; + + if(!hooks_tree) + return; + + target.type = type; + t = avl_search(hooks_tree, &target); + if(!t) + return; + + avl_delete(t, (void*)hook); +} diff --git a/lib/node.h b/lib/node.h index b43c2b46..3a2dbf46 100644 --- a/lib/node.h +++ b/lib/node.h @@ -17,13 +17,15 @@ 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 2002/04/28 12:46:26 zarq Exp $ + $Id: node.h,v 1.2 2002/05/02 11:50:07 zarq Exp $ */ #ifndef __TINC_NODE_H__ #define __TINC_NODE_H__ +#ifdef USE_GCRYPT #include +#endif #include diff --git a/src/Makefile.am b/src/Makefile.am index fbf98387..b4efc964 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ ## Produce this file with automake to get Makefile.in -# $Id: Makefile.am,v 1.10 2002/04/28 12:46:26 zarq Exp $ +# $Id: Makefile.am,v 1.11 2002/05/02 11:50:07 zarq Exp $ SUBDIRS = pokey @@ -7,14 +7,14 @@ sbin_PROGRAMS = tincd EXTRA_DIST = linux/device.c freebsd/device.c openbsd/device.c solaris/device.c -tincd_SOURCES = read_conf.c device.c event.c graph.c meta.c net_packet.c net_setup.c \ +tincd_SOURCES = read_conf.c device.c event.c meta.c net_packet.c net_setup.c \ net_socket.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c \ - protocol_key.c protocol_subnet.c route.c tincd.c net.c + protocol_key.c protocol_subnet.c route.c tincd.c net.c callbacks.c INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib -I$(top_srcdir)/intl -noinst_HEADERS = read_conf.h device.h event.h graph.h meta.h process.h \ - protocol.h route.h +noinst_HEADERS = read_conf.h device.h event.h meta.h process.h \ + protocol.h route.h callbacks.h LIBS = @LIBS@ @INTLLIBS@ diff --git a/src/graph.c b/src/graph.c deleted file mode 100644 index e8e8baf4..00000000 --- a/src/graph.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - graph.c -- graph algorithms - Copyright (C) 2001-2002 Guus Sliepen , - 2001-2002 Ivo Timmermans - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id: graph.c,v 1.4 2002/04/28 12:46:26 zarq Exp $ -*/ - -/* We need to generate two trees from the graph: - - 1. A minimum spanning tree for broadcasts, - 2. A single-source shortest path tree for unicasts. - - Actually, the first one alone would suffice but would make unicast packets - take longer routes than necessary. - - For the MST algorithm we can choose from Prim's or Kruskal's. I personally - favour Kruskal's, because we make an extra AVL tree of edges sorted on - weights (metric). That tree only has to be updated when an edge is added or - removed, and during the MST algorithm we just have go linearly through that - tree, adding safe edges until #edges = #nodes - 1. The implementation here - however is not so fast, because I tried to avoid having to make a forest and - merge trees. - - For the SSSP algorithm Dijkstra's seems to be a nice choice. Currently a - simple breadth-first search is presented here. - - The SSSP algorithm will also be used to determine whether nodes are directly, - indirectly or not reachable from the source. It will also set the correct - destination address and port of a node if possible. -*/ - -#include "config.h" - -#include -#include -#include -#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) - #include -#endif -#include - -#include -#include - -#include "netutl.h" -#include "node.h" -#include "edge.h" -#include "connection.h" -#include "process.h" -#include "logging.h" - -#include "system.h" - -/* Implementation of Kruskal's algorithm. - Running time: O(EN) - Please note that sorting on weight is already done by add_edge(). -*/ - -void mst_kruskal(void) -{ - avl_node_t *node, *next; - edge_t *e; - node_t *n; - connection_t *c; - int nodes = 0; - int safe_edges = 0; - int skipped; - - /* Clear MST status on connections */ - - for(node = connection_tree->head; node; node = node->next) - { - c = (connection_t *)node->data; - c->status.mst = 0; - } - - /* Do we have something to do at all? */ - - if(!edge_weight_tree->head) - return; - - if(debug_lvl >= DEBUG_SCARY_THINGS) - syslog(LOG_DEBUG, "Running Kruskal's algorithm:"); - - /* Clear visited status on nodes */ - - for(node = node_tree->head; node; node = node->next) - { - n = (node_t *)node->data; - n->status.visited = 0; - nodes++; - } - - /* Starting point */ - - ((edge_t *)edge_weight_tree->head->data)->from.node->status.visited = 1; - - /* Add safe edges */ - - for(skipped = 0, node = edge_weight_tree->head; node; node = next) - { - next = node->next; - e = (edge_t *)node->data; - - if(e->from.node->status.visited == e->to.node->status.visited) - { - skipped = 1; - continue; - } - - e->from.node->status.visited = 1; - e->to.node->status.visited = 1; - if(e->connection) - e->connection->status.mst = 1; - - safe_edges++; - - if(debug_lvl >= DEBUG_SCARY_THINGS) - syslog(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from.node->name, e->to.node->name, e->weight); - - if(skipped) - { - next = edge_weight_tree->head; - continue; - } - } - - if(debug_lvl >= DEBUG_SCARY_THINGS) - syslog(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes, safe_edges); -} - -/* Implementation of a simple breadth-first search algorithm. - Running time: O(E) -*/ - -void sssp_bfs(void) -{ - avl_node_t *node, *from, *next, *to; - edge_t *e; - node_t *n; - halfconnection_t to_hc, from_hc; - avl_tree_t *todo_tree; - int indirect; - char *name; - - todo_tree = avl_alloc_tree(NULL, NULL); - - /* Clear visited status on nodes */ - - for(node = node_tree->head; node; node = node->next) - { - n = (node_t *)node->data; - n->status.visited = 0; - n->status.indirect = 1; - } - - /* Begin with myself */ - - myself->status.visited = 1; - myself->status.indirect = 0; - myself->nexthop = myself; - myself->via = myself; - node = avl_alloc_node(); - node->data = myself; - avl_insert_top(todo_tree, node); - - /* Loop while todo_tree is filled */ - - while(todo_tree->head) - { - for(from = todo_tree->head; from; from = next) /* "from" is the node from which we start */ - { - next = from->next; - n = (node_t *)from->data; - - for(to = n->edge_tree->head; to; to = to->next) /* "to" is the edge connected to "from" */ - { - e = (edge_t *)to->data; - - if(e->from.node == n) /* "from_hc" is the halfconnection with .node == from */ - to_hc = e->to, from_hc = e->from; - else - to_hc = e->from, from_hc = e->to; - - /* Situation: - - / - / - ------(n)from_hc-----to_hc - \ - \ - - n->address is set to the to_hc.udpaddress of the edge left of n. - We are currently examining the edge right of n: - - - If from_hc.udpaddress != n->address, then to_hc.node is probably - not reachable for the nodes left of n. We do as if the indirectdata - flag is set on edge e. - - If edge e provides for better reachability of to_hc.node, update - to_hc.node and (re)add it to the todo_tree to (re)examine the reachability - of nodes behind it. - */ - - indirect = n->status.indirect || e->options & OPTION_INDIRECT || ((n != myself) && sockaddrcmp(&n->address, &from_hc.udpaddress)); - - if(to_hc.node->status.visited && (!to_hc.node->status.indirect || indirect)) - continue; - - to_hc.node->status.visited = 1; - to_hc.node->status.indirect = indirect; - to_hc.node->nexthop = (n->nexthop == myself) ? to_hc.node : n->nexthop; - to_hc.node->via = indirect ? n->via : to_hc.node; - to_hc.node->options = e->options; - if(sockaddrcmp(&to_hc.node->address, &to_hc.udpaddress)) - { - node = avl_unlink(node_udp_tree, to_hc.node); - to_hc.node->address = to_hc.udpaddress; - if(to_hc.node->hostname) - free(to_hc.node->hostname); - to_hc.node->hostname = sockaddr2hostname(&to_hc.udpaddress); - avl_insert_node(node_udp_tree, node); - } - node = avl_alloc_node(); - node->data = to_hc.node; - avl_insert_before(todo_tree, from, node); - } - - avl_delete_node(todo_tree, from); - } - } - - avl_free_tree(todo_tree); - - /* Check reachability status. */ - - for(node = node_tree->head; node; node = next) - { - next = node->next; - n = (node_t *)node->data; - - if(n->status.visited) - { - if(!n->status.reachable) - { - if(debug_lvl >= DEBUG_TRAFFIC) - syslog(LOG_DEBUG, _("Node %s (%s) became reachable"), n->name, n->hostname); - n->status.reachable = 1; - asprintf(&name, "hosts/%s-up", n->name); - execute_script(name); - free(name); - } - } - else - { - if(n->status.reachable) - { - if(debug_lvl >= DEBUG_TRAFFIC) - syslog(LOG_DEBUG, _("Node %s (%s) became unreachable"), n->name, n->hostname); - n->status.reachable = 0; - n->status.validkey = 0; - n->status.waitingforkey = 0; - n->sent_seqno = 0; - asprintf(&name, "hosts/%s-down", n->name); - execute_script(name); - free(name); - } - } - } -} - -void graph(void) -{ - mst_kruskal(); - sssp_bfs(); -} diff --git a/src/graph.h b/src/graph.h deleted file mode 100644 index ab8fff20..00000000 --- a/src/graph.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - graph.h -- header for graph.c - Copyright (C) 2001-2002 Guus Sliepen , - 2001-2002 Ivo Timmermans - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id: graph.h,v 1.2 2002/04/09 15:26:00 zarq Exp $ -*/ - -extern void graph(void); -extern void mst_kruskal(void); -extern void sssp_bfs(void); diff --git a/src/pokey/Makefile.am b/src/pokey/Makefile.am index 021ba0a2..20281743 100644 --- a/src/pokey/Makefile.am +++ b/src/pokey/Makefile.am @@ -1,18 +1,18 @@ ## Produce this file with automake to get Makefile.in -# $Id: Makefile.am,v 1.2 2002/04/28 12:46:26 zarq Exp $ +# $Id: Makefile.am,v 1.3 2002/05/02 11:50:07 zarq Exp $ sbin_PROGRAMS = pokey pokey_SOURCES = event.c graph.c \ - interface.c logging.c meta.c net.c net_packet.c net_setup.c net_socket.c netutl.c \ + interface.c meta.c net.c net_packet.c net_setup.c net_socket.c netutl.c \ process.c protocol.c protocol_auth.c protocol_edge.c \ protocol_misc.c protocol_key.c protocol_subnet.c route.c \ - pokey.c + pokey.c read_conf.c INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib -I$(top_srcdir)/intl -I$(top_srcdir)/src -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/include/libglade-1.0 -I/usr/include/gnome-1.0 -I/usr/include/gnome-xml -I/usr/include/libglade-1.0 -I/usr/include/gnome-1.0 -DNEED_GNOMESUPPORT_H -I/usr/lib/gnome-libs/include -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/include/orbit-1.0 -I/usr/include/gtk-1.2 -I/usr/X11R6/include noinst_HEADERS = device.h event.h graph.h meta.h net.h netutl.h process.h \ - protocol.h route.h + protocol.h route.h read_conf.h LIBS = @LIBS@ @INTLLIBS@ diff --git a/src/pokey/interface.c b/src/pokey/interface.c index 950f6596..706c5fab 100644 --- a/src/pokey/interface.c +++ b/src/pokey/interface.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: interface.c,v 1.4 2002/04/28 12:46:26 zarq Exp $ + $Id: interface.c,v 1.5 2002/05/02 11:50:07 zarq Exp $ */ #include "config.h" @@ -50,13 +50,23 @@ #include "system.h" -extern GladeXML *xml; +/* Node tree & main window stuff */ +static GladeXML *xml; +static GtkWidget *nodetree; +static GtkCTreeNode *hosts_ctn; -#ifdef MAXBUFSIZE -#undef MAXBUFSIZE -#endif -#define MAXBUFSIZE 1024 +/* Graph canvas stuff */ +static GladeXML *canvas_xml; + +static GnomeCanvasGroup *edge_group = NULL; + +static int canvas_width; +static int canvas_height; + +static GtkWidget *canvas = NULL; + +static int canvas_visible = 0; int build_graph = 0; @@ -77,30 +87,30 @@ double y[MAX_NODES]; double k[MAX_NODES][MAX_NODES]; double d[MAX_NODES][MAX_NODES]; double l[MAX_NODES][MAX_NODES]; -const double epsilon = 0.001; +static const double epsilon = 0.001; static int inited = 0; static int number_of_nodes = 0; -static GtkWidget *nodetree; -static GtkCTreeNode *hosts_ctn; +static double canvas_zoom = 1.00; -static GnomeCanvasGroup *edge_group = NULL; -static int canvas_width; -static int canvas_height; +/* Log window stuff */ +#ifdef MAXBUFSIZE +#undef MAXBUFSIZE +#endif -static GtkWidget *canvas = NULL; +#define MAXBUFSIZE 1024 static int log_inited = 0; static int follow_log = 1; static int keep_drawing = 1; -static GtkCList *connlist = NULL; +static int log_visible = 0; +static GtkWidget *log_window = NULL; -static double canvas_zoom = 1.00; void if_node_add(const char *hooktype, va_list ap); void if_node_del(const char *hooktype, va_list ap); @@ -111,8 +121,19 @@ void if_edge_del(const char *hooktype, va_list ap); void if_node_visible(const char *hooktype, va_list ap); void if_node_invisible(const char *hooktype, va_list ap); +void if_node_create(node_t *n); + GtkWidget *create_canvas(void) { + canvas_xml = glade_xml_new(INTERFACE_FILE, "GraphWindow"); + if(!canvas_xml) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "GraphWindow"); + return NULL; + } + canvas = glade_xml_get_widget(xml, "canvas1"); if(!canvas) { @@ -120,7 +141,7 @@ GtkWidget *create_canvas(void) return NULL; } - gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), -00.0, -00.0, 700, 500); + gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0.0, 0.0, 700, 500); canvas_width = 300.0; canvas_height = 500.0; @@ -132,17 +153,12 @@ void log_gtk(int level, int priority, char *fmt, va_list ap) { char buffer1[MAXBUFSIZE]; char buffer2[MAXBUFSIZE]; - GtkWidget *w; int len; char *p; struct tm *tm; time_t t; - if(!xml) - return; - - w = glade_xml_get_widget(xml, "Messages"); - if(!w) + if(!log_visible) return; /* Use vsnprintf instead of vasprintf: faster, no memory @@ -172,19 +188,19 @@ void log_gtk(int level, int priority, char *fmt, va_list ap) } } - gtk_text_freeze(GTK_TEXT(w)); + gtk_text_freeze(GTK_TEXT(log_window)); if(log_inited) - gtk_text_insert(GTK_TEXT(w), NULL, NULL, NULL, "\n", 1); + gtk_text_insert(GTK_TEXT(log_window), NULL, NULL, NULL, "\n", 1); - gtk_text_insert(GTK_TEXT(w), NULL, &timecolor, NULL, buffer2, strlen(buffer2)); - gtk_text_insert(GTK_TEXT(w), NULL, NULL, NULL, buffer1, len); - gtk_text_thaw(GTK_TEXT(w)); + gtk_text_insert(GTK_TEXT(log_window), NULL, &timecolor, NULL, buffer2, strlen(buffer2)); + gtk_text_insert(GTK_TEXT(log_window), NULL, NULL, NULL, buffer1, len); + gtk_text_thaw(GTK_TEXT(log_window)); log_inited = 1; if(follow_log) /* gtk_text_set_point(GTK_TEXT(w), -1); */ - gtk_editable_set_position(GTK_EDITABLE(w), gtk_text_get_length(GTK_TEXT(w))); + gtk_editable_set_position(GTK_EDITABLE(log_window), gtk_text_get_length(GTK_TEXT(log_window))); } void if_hostinfoclosebutton_clicked(GtkWidget *w, gpointer data) @@ -272,7 +288,7 @@ void update_hostinfo_dialog(GladeXML *x, node_t *n) } } -void on_settings1_activate(GtkMenuItem *mi, gpointer data) +void on_preferences1_activate(GtkMenuItem *mi, gpointer data) { GtkWidget *w; GladeXML *x; @@ -293,9 +309,7 @@ void on_settings1_activate(GtkMenuItem *mi, gpointer data) void on_logcontext_clear_activate(GtkMenuItem *mi, gpointer data) { - GtkWidget *l = glade_xml_get_widget(xml, "Messages"); - if(!l) { log(0, TLOG_ERROR, _("Couldn't find widget `%s'"), "Messages"); return; } - gtk_editable_delete_text(GTK_EDITABLE(l), 0, -1); /* Delete from 0 to end of buffer */ + gtk_editable_delete_text(GTK_EDITABLE(log_window), 0, -1); /* Delete from 0 to end of buffer */ log_inited = 0; } @@ -304,6 +318,11 @@ void on_logcontext_follow_activate(GtkMenuItem *mi, gpointer data) follow_log = !follow_log; } +void on_logcontext_close1_activate(GtkMenuItem *mi, gpointer data) +{ + +} + void on_messages_button_press_event(GtkWidget *w, GdkEventButton *event, gpointer data) { GladeXML *x; @@ -333,7 +352,7 @@ void on_messages_button_press_event(GtkWidget *w, GdkEventButton *event, gpointe } } -void on_canvascontext_shuffle_activate(GtkMenuItem *mi, gpointer data) +void shuffle_nodes(void) { avl_node_t *avlnode; double newx, newy; @@ -355,9 +374,23 @@ void on_canvascontext_shuffle_activate(GtkMenuItem *mi, gpointer data) build_graph = 1; } +void on_canvascontext_shuffle_activate(GtkMenuItem *mi, gpointer data) +{ + shuffle_nodes(); +} + void on_canvascontext_keep_drawing_activate(GtkMenuItem *mi, gpointer data) { + GtkWidget *w; + keep_drawing = !keep_drawing; + + /* No need to fuss with the checkbox in the menu, because that is + transient. Do need to update the checkbox at the bottom of the + window though. */ + w = glade_xml_get_widget(canvas_xml, "KeepDrawingButton"); + if(!w) { log(0, TLOG_ERROR, _("Couldn't find widget `%s'"), "KeepDrawingButton"); return; } + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), keep_drawing); } void on_canvascontext_minus50_activate(GtkMenuItem *mi, gpointer data) @@ -491,7 +524,7 @@ void on_exit1_activate(GtkMenuItem *mi, gpointer data) gtk_exit(0); } -void on_info1_activate(GtkMenuItem *mi, gpointer data) +void on_about1_activate(GtkMenuItem *mi, gpointer data) { GladeXML *x; x = glade_xml_new(INTERFACE_FILE, "AboutWindow"); @@ -502,6 +535,150 @@ void on_info1_activate(GtkMenuItem *mi, gpointer data) "AboutWindow"); return; } + glade_xml_signal_autoconnect(x); +} + +void on_graph_window1_activate(GtkMenuItem *mi, gpointer data) +{ + int i; + avl_node_t *avlnode; + double newx, newy; + + canvas_xml = glade_xml_new(INTERFACE_FILE, "GraphWindow"); + if(canvas_xml == NULL) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "GraphWindow"); + return; + } + glade_xml_signal_autoconnect(canvas_xml); + canvas = glade_xml_get_widget(canvas_xml, "canvas1"); + if(canvas == NULL) { log(0, TLOG_ERROR, _("Could not find widget `%s'"), "canvas1"); return; } + + for(i = 0, avlnode = node_tree->head; avlnode; avlnode = avlnode->next) + { + node_t *n = (node_t*)(avlnode->data); + + if(!((struct if_node_data*)(n->data))->item) + if_node_create(n); + + if(!n->status.reachable) + continue; + + newx = 250.0 + 200.0 * sin(i / 10.0 * M_PI); + newy = 150.0 - 100.0 * cos(i / 10.0 * M_PI); + gnome_canvas_item_move(GNOME_CANVAS_ITEM(((struct if_node_data*)(n->data))->item), newx - ((struct if_node_data*)(n->data))->x, newy - ((struct if_node_data*)(n->data))->y); + ((struct if_node_data*)(n->data))->x = newx; + ((struct if_node_data*)(n->data))->y = newy; + + ((struct if_node_data*)(n->data))->id = i; + + gnome_canvas_item_show(GNOME_CANVAS_ITEM(((struct if_node_data*)(n->data))->item)); + gnome_canvas_update_now(GNOME_CANVAS(canvas)); + nodes[i] = n; + i++; + } + + number_of_nodes = i; + + inited = 0; + build_graph = 1; + canvas_visible = 1; +} + +void on_log_window1_activate(GtkMenuItem *mi, gpointer data) +{ + GladeXML *x; + GtkWidget *w; + + x = glade_xml_new(INTERFACE_FILE, "LogWindow"); + if(x == NULL) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "LogWindow"); + return; + } + log_window = glade_xml_get_widget(x, "Messages"); + if(!log_window) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "Messages"); + return; + } + w = glade_xml_get_widget(x, "DebugLevelSpinbutton"); + if(!w) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "DebugLevelSpinbutton"); + return; + } + gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), (float)debug_lvl); + + glade_xml_signal_autoconnect(x); + log_visible = 1; + log_add_hook(log_gtk); + log(0, TLOG_NOTICE, "Logging started.\n"); + +} + +void on_debug_level_changed(GtkSpinButton *sb, gpointer data) +{ + debug_lvl = gtk_spin_button_get_value_as_int(sb); +} + +void on_logwindow_close_clicked(GtkButton *b, gpointer data) +{ + GladeXML *x; + GtkWidget *w; + + x = glade_xml_new(INTERFACE_FILE, "LogWindow"); + if(x == NULL) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "LogWindow"); + return; + } + w = glade_xml_get_widget(x, "LogWindow"); + if(!w) + { + log(0, TLOG_ERROR, + _("Could not find widget `%s'"), + "LogWindow"); + return; + } + gtk_widget_destroy(w); +} + +void on_spinbutton2_changed(GtkSpinButton *sb, gpointer data) +{ + canvas_zoom = gtk_spin_button_get_value_as_float(sb) / 100.0; + gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(canvas), canvas_zoom); +} + +void on_checkbutton1_toggled(GtkCheckButton *cb, gpointer data) +{ + keep_drawing = !keep_drawing; +} + +void on_button19_clicked(GtkWidget *bt, GdkEventButton *ev, gpointer data) +{ + shuffle_nodes(); +} + +void on_button18_clicked(GtkWidget *bt, GdkEventButton *ev, gpointer data) +{ + GtkWidget *w; + + w = glade_xml_get_widget(canvas_xml, "GraphWindow"); + if(!w) { log(0, TLOG_ERROR, _("Couldn't find widget `%s'"), "GraphWindow"); return; } + gtk_object_destroy(GTK_OBJECT(w)); + build_graph = 0; + canvas_visible = 0; } int init_interface(void) @@ -536,11 +713,8 @@ int init_interface(void) FALSE, TRUE); gtk_clist_thaw(GTK_CLIST(nodetree)); - create_canvas(); - glade_xml_signal_autoconnect(xml); - log_add_hook(log_gtk); log_del_hook(log_default); add_hook("node-add", if_node_add); @@ -660,8 +834,12 @@ void if_node_visible(const char *hooktype, va_list ap) avl_node_t *avlnode; double newx, newy; node_t *n = va_arg(ap, node_t*); + + if(!n->data) + return; if(!((struct if_node_data*)(n->data))->item) + /* No GnomeCanvasItem has been created for this node yet */ return; if(((struct if_node_data*)(n->data))->visible) @@ -736,7 +914,7 @@ void if_node_add(const char *hooktype, va_list ap) if(!xml) return; - nd = xmalloc(sizeof(*nd)); + nd = xmalloc_and_zero(sizeof(*nd)); l[0] = n->name; gtk_clist_freeze(GTK_CLIST(nodetree)); nd->ctn = gtk_ctree_insert_node(GTK_CTREE(nodetree), @@ -748,8 +926,11 @@ void if_node_add(const char *hooktype, va_list ap) n->data = (void*)nd; - if_node_create(n); - if_node_visible(hooktype, ap); + if(canvas_visible) + { + if_node_create(n); + if_node_visible(hooktype, ap); + } } void if_node_del(const char *hooktype, va_list ap) @@ -765,7 +946,10 @@ void if_node_del(const char *hooktype, va_list ap) gtk_clist_thaw(GTK_CLIST(nodetree)); } - if_node_invisible(hooktype, ap); + if(canvas_visible) + { + if_node_invisible(hooktype, ap); + } free(nd); n->data = NULL; @@ -778,7 +962,7 @@ void if_subnet_add(const char *hooktype, va_list ap) struct if_subnet_data *sd; GtkCTreeNode *parent; - sd = xmalloc(sizeof(*sd)); + sd = xmalloc_and_zero(sizeof(*sd)); l[0] = net2str(subnet); parent = subnet->owner->data ? ((struct if_subnet_data*)(subnet->owner->data))->ctn @@ -1045,10 +1229,10 @@ void if_build_graph(void) } } - min_d = 0.0; + min_d = INFINITY; for(i = 0; i < number_of_nodes; i++) for(j = i + 1; j < number_of_nodes; j++) - if(d[i][j] < min_d && d[i][j] > 0) + if(d[i][j] < min_d && d[i][j] > 0.0) min_d = d[i][j]; L = 5.0 / sqrt(min_d + 1.0); diff --git a/src/pokey/pokey.glade b/src/pokey/pokey.glade index 3ec5e4af..fbb6c22a 100644 --- a/src/pokey/pokey.glade +++ b/src/pokey/pokey.glade @@ -1703,7 +1703,8 @@ Ivo Timmermans <ivo@o2w.nl> GtkScrolledWindow GnomeDock:contents scrolledwindow1 - 250 + 300 + 200 GTK_POLICY_AUTOMATIC GTK_POLICY_AUTOMATIC GTK_UPDATE_CONTINUOUS @@ -1766,25 +1767,124 @@ Ivo Timmermans <ivo@o2w.nl> False - GtkScrolledWindow - scrolledwindow2 - GTK_POLICY_NEVER - GTK_POLICY_ALWAYS - GTK_UPDATE_CONTINUOUS - GTK_UPDATE_CONTINUOUS + GtkVBox + vbox7 + False + 0 - GtkText - Messages - 500 - 300 - - button_press_event - on_messages_button_press_event - Sun, 14 Apr 2002 19:34:28 GMT - - False - + GtkScrolledWindow + scrolledwindow2 + GTK_POLICY_NEVER + GTK_POLICY_ALWAYS + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + 0 + True + True + + + + GtkText + Messages + 500 + 300 + + button_press_event + on_messages_button_press_event + Sun, 14 Apr 2002 19:34:28 GMT + + False + + + + + + GtkHBox + hbox4 + False + 10 + + 0 + True + True + + + + GtkHBox + hbox5 + False + 9 + + 0 + True + True + + + + GtkLabel + label32 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkSpinButton + DebugLevelSpinbutton + True + + changed + on_debug_level_changed + Mon, 29 Apr 2002 21:31:08 GMT + + 1 + 0 + True + GTK_UPDATE_IF_VALID + False + False + 1 + 0 + 1000 + 1 + 10 + 10 + + 0 + False + False + + + + + + GtkButton + button17 + True + + clicked + on_logwindow_close_clicked + Mon, 29 Apr 2002 21:37:37 GMT + + GNOME_STOCK_BUTTON_CLOSE + GTK_RELIEF_NORMAL + + 0 + False + False + + @@ -1801,30 +1901,168 @@ Ivo Timmermans <ivo@o2w.nl> False - GtkScrolledWindow - scrolledwindow3 - GTK_POLICY_ALWAYS - GTK_POLICY_ALWAYS - GTK_UPDATE_CONTINUOUS - GTK_UPDATE_CONTINUOUS + GtkVBox + vbox8 + False + 0 - GnomeCanvas - canvas1 - 500 - 300 - True - - button_press_event - on_canvas_button_press_event - Sun, 14 Apr 2002 15:21:11 GMT - - True - 0 - 0 - 100 - 100 - 1 + GtkScrolledWindow + scrolledwindow3 + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + 0 + True + True + + + + GnomeCanvas + canvas1 + 500 + 300 + True + + button_press_event + on_canvas_button_press_event + Sun, 14 Apr 2002 15:21:11 GMT + + True + 0 + 0 + 100 + 100 + 1 + + + + + GtkHBox + hbox6 + False + 0 + + 0 + False + False + + + + GtkHBox + hbox7 + False + 0 + + 0 + False + False + + + + GtkLabel + label33 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkSpinButton + spinbutton2 + True + + changed + on_spinbutton2_changed + Wed, 01 May 2002 17:18:44 GMT + + 1 + 0 + True + GTK_UPDATE_IF_VALID + False + False + 100 + 1 + 1000 + 1 + 10 + 10 + + 0 + False + False + + + + + + GtkCheckButton + KeepDrawingButton + True + + toggled + on_checkbutton1_toggled + Wed, 01 May 2002 17:18:37 GMT + + + False + True + + 0 + False + False + + + + + GtkButton + button18 + True + + clicked + on_button18_clicked + Wed, 01 May 2002 17:18:25 GMT + + GNOME_STOCK_BUTTON_CLOSE + GTK_RELIEF_NORMAL + + 0 + False + False + GTK_PACK_END + + + + + GtkButton + button19 + True + + clicked + on_button19_clicked + Wed, 01 May 2002 17:18:19 GMT + + + GTK_RELIEF_NORMAL + + 0 + False + False + GTK_PACK_END + + diff --git a/src/pokey/protocol.c b/src/pokey/protocol.c index e60598cb..57030d3d 100644 --- a/src/pokey/protocol.c +++ b/src/pokey/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.1 2002/04/28 12:46:26 zarq Exp $ + $Id: protocol.c,v 1.2 2002/05/02 11:50:07 zarq Exp $ */ #include "config.h" @@ -226,7 +226,7 @@ int (*request_handlers[])(connection_t*) = { id_h, metakey_h, challenge_h, chal_reply_h, ack_h, status_h, error_h, termreq_h, ping_h, pong_h, -// add_node_h, del_node_h, + /* add_node_h, del_node_h,*/ add_subnet_h, del_subnet_h, add_edge_h, del_edge_h, key_changed_h, req_key_h, ans_key_h, @@ -238,7 +238,7 @@ char (*request_name[]) = { "ID", "METAKEY", "CHALLENGE", "CHAL_REPLY", "ACK", "STATUS", "ERROR", "TERMREQ", "PING", "PONG", -// "ADD_NODE", "DEL_NODE", + /* "ADD_NODE", "DEL_NODE",*/ "ADD_SUBNET", "DEL_SUBNET", "ADD_EDGE", "DEL_EDGE", "KEY_CHANGED", "REQ_KEY", "ANS_KEY", diff --git a/src/pokey/protocol.h b/src/pokey/protocol.h index 9e4c09ea..4fae2958 100644 --- a/src/pokey/protocol.h +++ b/src/pokey/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.1 2002/04/28 12:46:26 zarq Exp $ + $Id: protocol.h,v 1.2 2002/05/02 11:50:07 zarq Exp $ */ #ifndef __TINC_PROTOCOL_H__ @@ -40,7 +40,7 @@ enum { ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK, STATUS, ERROR, TERMREQ, PING, PONG, -// ADD_NODE, DEL_NODE, + /* ADD_NODE, DEL_NODE,*/ ADD_SUBNET, DEL_SUBNET, ADD_EDGE, DEL_EDGE, KEY_CHANGED, REQ_KEY, ANS_KEY, @@ -81,8 +81,8 @@ 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_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 *); @@ -106,8 +106,8 @@ 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_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 *); diff --git a/src/pokey/protocol_auth.c b/src/pokey/protocol_auth.c index f45a4634..c94bad96 100644 --- a/src/pokey/protocol_auth.c +++ b/src/pokey/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 2002/04/28 12:46:26 zarq Exp $ + $Id: protocol_auth.c,v 1.2 2002/05/02 11:50:07 zarq Exp $ */ #include "config.h" @@ -564,10 +564,10 @@ cp c->edge = new_edge(); cp c->edge->from.node = myself; -// c->edge->from.tcpaddress = str2sockaddr(address, port); + /* c->edge->from.tcpaddress = str2sockaddr(address, port);*/ c->edge->from.udpaddress = str2sockaddr(myaddress, myport); c->edge->to.node = n; -// c->edge->to.tcpaddress = c->address; + /* c->edge->to.tcpaddress = c->address; */ sockaddr2str(&c->address, &hisaddress, &dummy); c->edge->to.udpaddress = str2sockaddr(hisaddress, hisport); free(hisaddress); diff --git a/src/pokey/protocol_edge.c b/src/pokey/protocol_edge.c index 89dd6f44..90c946c6 100644 --- a/src/pokey/protocol_edge.c +++ b/src/pokey/protocol_edge.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_edge.c,v 1.1 2002/04/28 12:46:26 zarq Exp $ + $Id: protocol_edge.c,v 1.2 2002/05/02 11:50:07 zarq Exp $ */ #include "config.h" @@ -52,20 +52,20 @@ int send_add_edge(connection_t *c, edge_t *e) char *from_udpaddress, *from_udpport; char *to_udpaddress, *to_udpport; cp -// sockaddr2str(&e->from.tcpaddress, &from_tcpaddress, &from_tcpport); + /* sockaddr2str(&e->from.tcpaddress, &from_tcpaddress, &from_tcpport); */ sockaddr2str(&e->from.udpaddress, &from_udpaddress, &from_udpport); -// sockaddr2str(&e->to.tcpaddress, &to_tcpaddress, &to_tcpport); + /* sockaddr2str(&e->to.tcpaddress, &to_tcpaddress, &to_tcpport); */ sockaddr2str(&e->to.udpaddress, &to_udpaddress, &to_udpport); x = send_request(c, "%d %lx %s %s %s %s %s %s %lx %d", ADD_EDGE, random(), e->from.node->name, from_udpaddress, from_udpport, e->to.node->name, to_udpaddress, to_udpport, e->options, e->weight); -// free(from_tcpaddress); -// free(from_tcpport); + /* free(from_tcpaddress); */ + /* free(from_tcpport); */ free(from_udpaddress); free(from_udpport); -// free(to_tcpaddress); -// free(to_tcpport); + /* free(to_tcpaddress); */ + /* free(to_tcpport); */ free(to_udpaddress); free(to_udpport); cp @@ -80,10 +80,10 @@ int add_edge_h(connection_t *c) char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; char from_address[MAX_STRING_SIZE]; -// char from_tcpport[MAX_STRING_SIZE]; + /* char from_tcpport[MAX_STRING_SIZE]; */ char from_udpport[MAX_STRING_SIZE]; char to_address[MAX_STRING_SIZE]; -// char to_tcpport[MAX_STRING_SIZE]; + /* char to_tcpport[MAX_STRING_SIZE]; */ char to_udpport[MAX_STRING_SIZE]; sockaddr_t from_udpaddress; sockaddr_t to_udpaddress; @@ -139,9 +139,9 @@ cp /* Convert addresses */ -// from_tcpaddress = str2sockaddr(from_address, from_tcpport); + /* from_tcpaddress = str2sockaddr(from_address, from_tcpport); */ from_udpaddress = str2sockaddr(from_address, from_udpport); -// to_tcpaddress = str2sockaddr(to_address, to_tcpport); + /* to_tcpaddress = str2sockaddr(to_address, to_tcpport); */ to_udpaddress = str2sockaddr(to_address, to_udpport); /* Check if edge already exists */ @@ -186,10 +186,10 @@ cp e = new_edge(); e->from.node = from; -// e->from.tcpaddress = from_tcpaddress; + /* e->from.tcpaddress = from_tcpaddress; */ e->from.udpaddress = from_udpaddress; e->to.node = to; -// e->to.tcpaddress = to_tcpaddress; + /* e->to.tcpaddress = to_tcpaddress; */ e->to.udpaddress = to_udpaddress; e->options = options; e->weight = weight; diff --git a/src/read_conf.h b/src/read_conf.h index e6e26d68..b8a7cd41 100644 --- a/src/read_conf.h +++ b/src/read_conf.h @@ -17,12 +17,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: read_conf.h,v 1.1 2002/04/28 12:46:26 zarq Exp $ + $Id: read_conf.h,v 1.2 2002/05/02 11:50:07 zarq Exp $ */ #ifndef __TINC_READ_CONF_H__ #define __TINC_READ_CONF_H__ +#include + extern int read_config_file(avl_tree_t *, const char *); extern int read_server_config(void); extern FILE *ask_and_safe_open(const char*, const char*, const char *); diff --git a/src/tincd.c b/src/tincd.c index 0f518372..c732b7c2 100644 --- a/src/tincd.c +++ b/src/tincd.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: tincd.c,v 1.15 2002/04/28 12:46:26 zarq Exp $ + $Id: tincd.c,v 1.16 2002/05/02 11:50:07 zarq Exp $ */ #include "config.h" @@ -51,7 +51,8 @@ #include #include -#include "conf.h" +#include "callbacks.h" +#include "read_conf.h" #include "net.h" #include "netutl.h" #include "process.h" @@ -380,6 +381,8 @@ cp cp if(detach()) exit(0); + + init_callbacks(); cp for(;;) {