From: Guus Sliepen Date: Mon, 21 Apr 2014 18:57:14 +0000 (+0200) Subject: Move edge_weight_tree to mesh->edges. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=a7ef599e6bdd8730c5a949d4c1727c38d5b6ff9e;p=meshlink Move edge_weight_tree to mesh->edges. --- diff --git a/src/edge.c b/src/edge.c index 88847909..d3dbf78e 100644 --- a/src/edge.c +++ b/src/edge.c @@ -22,13 +22,12 @@ #include "splay_tree.h" #include "edge.h" #include "logger.h" +#include "meshlink_internal.h" #include "netutl.h" #include "node.h" #include "utils.h" #include "xalloc.h" -splay_tree_t *edge_weight_tree; - static int edge_compare(const edge_t *a, const edge_t *b) { return strcmp(a->to->name, b->to->name); } @@ -50,7 +49,7 @@ static int edge_weight_compare(const edge_t *a, const edge_t *b) { } void init_edges(void) { - edge_weight_tree = splay_alloc_tree((splay_compare_t) edge_weight_compare, NULL); + mesh->edges = splay_alloc_tree((splay_compare_t) edge_weight_compare, NULL); } splay_tree_t *new_edge_tree(void) { @@ -62,7 +61,7 @@ void free_edge_tree(splay_tree_t *edge_tree) { } void exit_edges(void) { - splay_delete_tree(edge_weight_tree); + splay_delete_tree(mesh->edges); } /* Creation and deletion of connection elements */ @@ -78,7 +77,7 @@ void free_edge(edge_t *e) { } void edge_add(edge_t *e) { - splay_insert(edge_weight_tree, e); + splay_insert(mesh->edges, e); splay_insert(e->from->edge_tree, e); e->reverse = lookup_edge(e->to, e->from); @@ -91,7 +90,7 @@ void edge_del(edge_t *e) { if(e->reverse) e->reverse->reverse = NULL; - splay_delete(edge_weight_tree, e); + splay_delete(mesh->edges, e); splay_delete(e->from->edge_tree, e); } diff --git a/src/edge.h b/src/edge.h index 77f761dc..75d4f94e 100644 --- a/src/edge.h +++ b/src/edge.h @@ -37,8 +37,6 @@ typedef struct edge_t { struct edge_t *reverse; /* edge in the opposite direction, if available */ } edge_t; -extern struct splay_tree_t *edge_weight_tree; /* Tree with all known edges sorted on weight */ - extern void init_edges(void); extern void exit_edges(void); extern edge_t *new_edge(void) __attribute__ ((__malloc__)); diff --git a/src/graph.c b/src/graph.c index 43e526b0..ce8fa626 100644 --- a/src/graph.c +++ b/src/graph.c @@ -76,7 +76,7 @@ static void mst_kruskal(void) { /* Starting point */ - for splay_each(edge_t, e, edge_weight_tree) { + for splay_each(edge_t, e, mesh->edges) { if(e->from->status.reachable) { e->from->status.visited = true; break; @@ -87,7 +87,7 @@ static void mst_kruskal(void) { bool skipped = false; - for splay_each(edge_t, e, edge_weight_tree) { + for splay_each(edge_t, e, mesh->edges) { if(!e->reverse || (e->from->status.visited == e->to->status.visited)) { skipped = true; continue; @@ -106,7 +106,7 @@ static void mst_kruskal(void) { if(skipped) { skipped = false; - next = edge_weight_tree->head; + next = mesh->edges->head; } } } diff --git a/src/net.c b/src/net.c index 4cae25c1..b8ea3cbd 100644 --- a/src/net.c +++ b/src/net.c @@ -64,7 +64,7 @@ void purge(void) { for splay_each(node_t, n, node_tree) { if(!n->status.reachable) { - for splay_each(edge_t, e, edge_weight_tree) + for splay_each(edge_t, e, mesh->edges) if(e->to == n) return; } diff --git a/src/net_packet.c b/src/net_packet.c index 7457b3bd..29f4fb8e 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -602,7 +602,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { bool hard = false; static time_t last_hard_try = 0; - for splay_each(edge_t, e, edge_weight_tree) { + for splay_each(edge_t, e, mesh->edges) { if(!e->to->status.reachable || e->to == mesh->self) continue;