]> git.meshlink.io Git - meshlink/blobdiff - src/net.c
Move node_tree to mesh->nodes.
[meshlink] / src / net.c
index adec200393001353c60340d9f2fe1c79ada28935..8b118dde6d860b0012a474fc988ce664ad76364a 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -1,9 +1,6 @@
 /*
     net.c -- most of the network code
-    Copyright (C) 1998-2005 Ivo Timmermans,
-                  2000-2013 Guus Sliepen <guus@meshlink.io>
-                  2006      Scott Lamb <slamb@slamb.org>
-                  2011      Loïc Grenié <loic.grenie@gmail.com>
+    Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -27,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"
@@ -51,13 +49,12 @@ 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);
 
                        for splay_each(edge_t, e, n->edge_tree) {
-                               if(!tunnelserver)
-                                       send_del_edge(everyone, e);
+                               send_del_edge(everyone, e);
                                edge_del(e);
                        }
                }
@@ -65,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;
                }
@@ -90,7 +87,7 @@ void terminate_connection(connection_t *c, bool report) {
                c->node->connection = NULL;
 
        if(c->edge) {
-               if(report && !tunnelserver)
+               if(report)
                        send_del_edge(everyone, c->edge);
 
                edge_del(c->edge);
@@ -104,10 +101,9 @@ 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) {
-                               if(!tunnelserver)
-                                       send_del_edge(everyone, e);
+                               send_del_edge(everyone, e);
                                edge_del(e);
                        }
                }
@@ -184,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) {
@@ -198,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;
 
@@ -295,9 +291,7 @@ int reload_configuration(void) {
                return EINVAL;
        }
 
-       read_config_options(config_tree, NULL);
-
-       xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
+       xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, mesh->self->name);
        read_config_file(config_tree, fname);
        free(fname);