/*
graph.c -- graph algorithms
- Copyright (C) 2001-2011 Guus Sliepen <guus@tinc-vpn.org>,
+ Copyright (C) 2001-2012 Guus Sliepen <guus@tinc-vpn.org>,
2001-2005 Ivo Timmermans
This program is free software; you can redistribute it and/or modify
#include "connection.h"
#include "device.h"
#include "edge.h"
+#include "graph.h"
#include "logger.h"
#include "netutl.h"
#include "node.h"
Please note that sorting on weight is already done by add_edge().
*/
-void mst_kruskal(void) {
+static void mst_kruskal(void) {
splay_node_t *node, *next;
edge_t *e;
node_t *n;
c->status.mst = false;
}
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Running Kruskal's algorithm:");
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Running Kruskal's algorithm:");
/* Clear visited status on nodes */
if(e->reverse->connection)
e->reverse->connection->status.mst = true;
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
e->to->name, e->weight);
}
}
todo_list = list_alloc(NULL);
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Running Dijkstra's algorithm:");
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Running Dijkstra's algorithm:");
/* Clear visited status on nodes */
n->address is set to the e->address of the edge left of n to n.
We are currently examining the edge e right of n from n:
- - If e->reverse->address != n->address, then e->to 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 e->to, update e->to.
*/
e->to->via = indirect ? n->via : e->to;
e->to->options = e->options;
- if(sockaddrcmp(&e->to->address, &e->address)) {
- node = splay_unlink(node_udp_tree, e->to);
- sockaddrfree(&e->to->address);
- sockaddrcpy(&e->to->address, &e->address);
-
- if(e->to->hostname)
- free(e->to->hostname);
-
- e->to->hostname = sockaddr2hostname(&e->to->address);
-
- if(node)
- splay_insert_node(node_udp_tree, node);
-
- if(e->to->options & OPTION_PMTU_DISCOVERY) {
- e->to->mtuprobes = 0;
- e->to->minmtu = 0;
- e->to->maxmtu = MTU;
- if(e->to->status.validkey)
- send_mtu_probe(e->to);
- }
- }
+ if(e->to->address.sa.sa_family == AF_UNSPEC && e->address.sa.sa_family != AF_UNKNOWN)
+ update_node_udp(e->to, &e->address);
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Updating edge %s - %s weight %d distance %d", e->from->name,
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, " Updating edge %s - %s weight %d distance %d", e->from->name,
e->to->name, e->weight, e->to->distance);
}
}
Running time: O(E)
*/
-void sssp_bfs(void) {
+static void sssp_bfs(void) {
splay_node_t *node, *to;
edge_t *e;
node_t *n;
myself->status.visited = true;
myself->status.indirect = false;
myself->nexthop = myself;
+ myself->prevedge = NULL;
myself->via = myself;
list_insert_head(todo_list, myself);
e->to->status.visited = true;
e->to->status.indirect = indirect;
e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop;
+ e->to->prevedge = e;
e->to->via = indirect ? n->via : e->to;
e->to->options = e->options;
n->status.reachable = !n->status.reachable;
if(n->status.reachable) {
- ifdebug(TRAFFIC) logger(LOG_DEBUG, "Node %s (%s) became reachable",
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, "Node %s (%s) became reachable",
n->name, n->hostname);
} else {
- ifdebug(TRAFFIC) logger(LOG_DEBUG, "Node %s (%s) became unreachable",
+ logger(DEBUG_TRAFFIC, LOG_DEBUG, "Node %s (%s) became unreachable",
n->name, n->hostname);
}
void graph(void) {
subnet_cache_flush();
- sssp_dijkstra();
+ sssp_bfs();
check_reachability();
mst_kruskal();
}