]> git.meshlink.io Git - meshlink/blobdiff - src/node.c
Remove global variables from the event loop code.
[meshlink] / src / node.c
index 83f4a743e92547bd0a582a470647c2995870d1c8..54887a3bcda12eef09667edf8a3a9cbdca0025d2 100644 (file)
@@ -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) {
@@ -66,7 +65,7 @@ void free_node(node_t *n) {
        ecdsa_free(n->ecdsa);
        sptps_stop(&n->sptps);
 
-       timeout_del(&n->mtutimeout);
+       timeout_del(&mesh->loop, &n->mtutimeout);
 
        if(n->hostname)
                free(n->hostname);
@@ -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) {
@@ -114,8 +113,8 @@ void update_node_udp(node_t *n, const sockaddr_t *sa) {
        if(sa) {
                n->address = *sa;
                n->sock = 0;
-               for(int i = 0; i < listen_sockets; i++) {
-                       if(listen_socket[i].sa.sa.sa_family == sa->sa.sa_family) {
+               for(int i = 0; i < mesh->listen_sockets; i++) {
+                       if(mesh->listen_socket[i].sa.sa.sa_family == sa->sa.sa_family) {
                                n->sock = i;
                                break;
                        }