From 528a8616e36ff08ddf1f9f16f748a272e48846be Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 21 Apr 2014 21:00:21 +0200 Subject: [PATCH] Move node_tree to mesh->nodes. --- src/graph.c | 6 +++--- src/net.c | 10 +++++----- src/node.c | 11 +++++------ src/node.h | 2 -- src/protocol_auth.c | 2 +- src/protocol_key.c | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/graph.c b/src/graph.c index ce8fa626..a7612ab0 100644 --- a/src/graph.c +++ b/src/graph.c @@ -71,7 +71,7 @@ static void mst_kruskal(void) { /* Clear visited status on nodes */ - for splay_each(node_t, n, node_tree) + for splay_each(node_t, n, mesh->nodes) n->status.visited = false; /* Starting point */ @@ -120,7 +120,7 @@ static void sssp_bfs(void) { /* Clear visited status on nodes */ - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, mesh->nodes) { n->status.visited = false; n->status.indirect = true; n->distance = -1; @@ -196,7 +196,7 @@ static void sssp_bfs(void) { static void check_reachability(void) { /* Check reachability status. */ - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, mesh->nodes) { if(n->status.visited != n->status.reachable) { n->status.reachable = !n->status.reachable; n->last_state_change = now.tv_sec; diff --git a/src/net.c b/src/net.c index b8ea3cbd..8b118dde 100644 --- a/src/net.c +++ b/src/net.c @@ -49,7 +49,7 @@ void purge(void) { /* Remove all edges owned by unreachable nodes. */ - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, mesh->nodes) { if(!n->status.reachable) { logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Purging node %s (%s)", n->name, n->hostname); @@ -62,7 +62,7 @@ void purge(void) { /* Check if anyone else claims to have an edge to an unreachable node. If not, delete node. */ - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, mesh->nodes) { if(!n->status.reachable) { for splay_each(edge_t, e, mesh->edges) if(e->to == n) @@ -180,7 +180,7 @@ static void periodic_handler(void *data) { /* If AutoConnect is set, check if we need to make or break connections. */ - if(autoconnect && node_tree->count > 1) { + if(autoconnect && mesh->nodes->count > 1) { /* Count number of active connections */ int nc = 0; for list_each(connection_t, c, connection_list) { @@ -194,10 +194,10 @@ static void periodic_handler(void *data) { and we are not already trying to make one, create an outgoing connection to this node. */ - int r = rand() % node_tree->count; + int r = rand() % mesh->nodes->count; int i = 0; - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, mesh->nodes) { if(i++ != r) continue; diff --git a/src/node.c b/src/node.c index 83f4a743..52aa6d42 100644 --- a/src/node.c +++ b/src/node.c @@ -29,7 +29,6 @@ #include "utils.h" #include "xalloc.h" -splay_tree_t *node_tree; static hash_t *node_udp_cache; static int node_compare(const node_t *a, const node_t *b) { @@ -37,13 +36,13 @@ static int node_compare(const node_t *a, const node_t *b) { } void init_nodes(void) { - node_tree = splay_alloc_tree((splay_compare_t) node_compare, (splay_action_t) free_node); + mesh->nodes = splay_alloc_tree((splay_compare_t) node_compare, (splay_action_t) free_node); node_udp_cache = hash_alloc(0x100, sizeof(sockaddr_t)); } void exit_nodes(void) { hash_free(node_udp_cache); - splay_delete_tree(node_tree); + splay_delete_tree(mesh->nodes); } node_t *new_node(void) { @@ -81,14 +80,14 @@ void free_node(node_t *n) { } void node_add(node_t *n) { - splay_insert(node_tree, n); + splay_insert(mesh->nodes, n); } void node_del(node_t *n) { for splay_each(edge_t, e, n->edge_tree) edge_del(e); - splay_delete(node_tree, n); + splay_delete(mesh->nodes, n); } node_t *lookup_node(char *name) { @@ -96,7 +95,7 @@ node_t *lookup_node(char *name) { n.name = name; - return splay_search(node_tree, &n); + return splay_search(mesh->nodes, &n); } node_t *lookup_node_udp(const sockaddr_t *sa) { diff --git a/src/node.h b/src/node.h index a341f2bb..f6415a1d 100644 --- a/src/node.h +++ b/src/node.h @@ -88,8 +88,6 @@ typedef struct node_t { uint64_t out_bytes; } node_t; -extern struct splay_tree_t *node_tree; - extern void init_nodes(void); extern void exit_nodes(void); extern node_t *new_node(void) __attribute__ ((__malloc__)); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 14686ac9..2d5990e3 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -394,7 +394,7 @@ static void send_everything(connection_t *c) { send_tcppacket(c, &zeropkt.pkt); } - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, mesh->nodes) { for splay_each(edge_t, e, n->edge_tree) send_add_edge(c, e); } diff --git a/src/protocol_key.c b/src/protocol_key.c index ef182b34..c490a8d2 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -40,7 +40,7 @@ void send_key_changed(void) { /* Force key exchange for connections using SPTPS */ - for splay_each(node_t, n, node_tree) + for splay_each(node_t, n, mesh->nodes) if(n->status.reachable && n->status.validkey) sptps_force_kex(&n->sptps); } -- 2.39.2