/* 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 */
/* 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;
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;
/* 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);
/* 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)
/* 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) {
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;
#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) {
}
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) {
}
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) {
n.name = name;
- return splay_search(node_tree, &n);
+ return splay_search(mesh->nodes, &n);
}
node_t *lookup_node_udp(const sockaddr_t *sa) {
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__));
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);
}
/* 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);
}