]> git.meshlink.io Git - meshlink/blobdiff - src/net.c
Move config_tree to mesh->config.
[meshlink] / src / net.c
index 87deb97b60d669bf19897a54b6dbd275de644f72..7a176ef2262a370e53a06bf885f5784985f9ae66 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -24,6 +24,7 @@
 #include "connection.h"
 #include "graph.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "net.h"
 #include "netutl.h"
@@ -48,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);
 
@@ -61,9 +62,9 @@ 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, edge_weight_tree)
+                       for splay_each(edge_t, e, mesh->edges)
                                if(e->to == n)
                                        return;
                }
@@ -100,7 +101,7 @@ void terminate_connection(connection_t *c, bool report) {
 
                if(report && !c->node->status.reachable) {
                        edge_t *e;
-                       e = lookup_edge(c->node, myself);
+                       e = lookup_edge(c->node, mesh->self);
                        if(e) {
                                send_del_edge(everyone, e);
                                edge_del(e);
@@ -132,7 +133,7 @@ void terminate_connection(connection_t *c, bool report) {
   and close the connection.
 */
 static void timeout_handler(void *data) {
-       for list_each(connection_t, c, connection_list) {
+       for list_each(connection_t, c, mesh->connections) {
                if(c->last_ping_time + pingtimeout <= now.tv_sec) {
                        if(c->status.active) {
                                if(c->status.pinged) {
@@ -179,10 +180,10 @@ 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) {
+               for list_each(connection_t, c, mesh->connections) {
                        if(c->status.active)
                                nc++;
                }
@@ -193,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;
 
@@ -205,7 +206,7 @@ static void periodic_handler(void *data) {
 
                                bool found = false;
 
-                               for list_each(outgoing_t, outgoing, outgoing_list) {
+                               for list_each(outgoing_t, outgoing, mesh->outgoings) {
                                        if(!strcmp(outgoing->name, n->name)) {
                                                found = true;
                                                break;
@@ -216,7 +217,7 @@ static void periodic_handler(void *data) {
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
                                        outgoing_t *outgoing = xzalloc(sizeof *outgoing);
                                        outgoing->name = xstrdup(n->name);
-                                       list_insert_tail(outgoing_list, outgoing);
+                                       list_insert_tail(mesh->outgoings, outgoing);
                                        setup_outgoing_connection(outgoing);
                                }
                                break;
@@ -229,7 +230,7 @@ static void periodic_handler(void *data) {
                        int r = rand() % nc;
                        int i = 0;
 
-                       for list_each(connection_t, c, connection_list) {
+                       for list_each(connection_t, c, mesh->connections) {
                                if(!c->status.active)
                                        continue;
 
@@ -240,7 +241,7 @@ static void periodic_handler(void *data) {
                                        break;
 
                                logger(DEBUG_CONNECTIONS, LOG_INFO, "Autodisconnecting from %s", c->name);
-                               list_delete(outgoing_list, c->outgoing);
+                               list_delete(mesh->outgoings, c->outgoing);
                                c->outgoing = NULL;
                                terminate_connection(c, c->status.active);
                                break;
@@ -251,9 +252,9 @@ static void periodic_handler(void *data) {
                        /* If we have enough active connections,
                           remove any pending outgoing connections.
                        */
-                       for list_each(outgoing_t, o, outgoing_list) {
+                       for list_each(outgoing_t, o, mesh->outgoings) {
                                bool found = false;
-                               for list_each(connection_t, c, connection_list) {
+                               for list_each(connection_t, c, mesh->connections) {
                                        if(c->outgoing == o) {
                                                found = true;
                                                break;
@@ -261,7 +262,7 @@ static void periodic_handler(void *data) {
                                }
                                if(!found) {
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->name);
-                                       list_delete_node(outgoing_list, node);
+                                       list_delete_node(mesh->outgoings, node);
                                }
                        }
                }
@@ -282,16 +283,16 @@ int reload_configuration(void) {
 
        /* Reread our own configuration file */
 
-       exit_configuration(&config_tree);
-       init_configuration(&config_tree);
+       exit_configuration(&mesh->config);
+       init_configuration(&mesh->config);
 
        if(!read_server_config()) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to reread configuration file.");
                return EINVAL;
        }
 
-       xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
-       read_config_file(config_tree, fname);
+       xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, mesh->self->name);
+       read_config_file(mesh->config, fname);
        free(fname);
 
        /* Parse some options that are allowed to be changed while tinc is running */
@@ -304,7 +305,7 @@ int reload_configuration(void) {
 
        /* Close connections to hosts that have a changed or deleted host config file */
 
-       for list_each(connection_t, c, connection_list) {
+       for list_each(connection_t, c, mesh->connections) {
                xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
                struct stat s;
                if(stat(fname, &s) || s.st_mtime > last_config_check) {
@@ -321,14 +322,14 @@ int reload_configuration(void) {
 
 void retry(void) {
        /* Reset the reconnection timers for all outgoing connections */
-       for list_each(outgoing_t, outgoing, outgoing_list) {
+       for list_each(outgoing_t, outgoing, mesh->outgoings) {
                outgoing->timeout = 0;
                if(outgoing->ev.cb)
                        timeout_set(&outgoing->ev, &(struct timeval){0, 0});
        }
 
        /* Check for outgoing connections that are in progress, and reset their ping timers */
-       for list_each(connection_t, c, connection_list) {
+       for list_each(connection_t, c, mesh->connections) {
                if(c->outgoing && !c->node)
                        c->last_ping_time = 0;
        }