]> git.meshlink.io Git - meshlink/commitdiff
Move connection_list to mesh->connections.
authorGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 19:04:13 +0000 (21:04 +0200)
committerGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 19:04:13 +0000 (21:04 +0200)
src/connection.c
src/connection.h
src/graph.c
src/meshlink_internal.h
src/meta.c
src/net.c
src/net_packet.c
src/net_setup.c
src/net_socket.c
src/sptps_speed.c
src/sptps_test.c

index d25159e6438c2102b4d7747377ed0e3eba7dac01..c38bc4a071ca7cb205a5d85a5e7a9b91a4957191 100644 (file)
 #include "connection.h"
 #include "list.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "utils.h"
 #include "xalloc.h"
 
-list_t *connection_list;
 connection_t *everyone;
 
 void init_connections(void) {
-       connection_list = list_alloc((list_action_t) free_connection);
+       mesh->connections = list_alloc((list_action_t) free_connection);
        everyone = new_connection();
        everyone->name = xstrdup("everyone");
        everyone->hostname = xstrdup("BROADCAST");
 }
 
 void exit_connections(void) {
-       list_delete_list(connection_list);
+       list_delete_list(mesh->connections);
        free_connection(everyone);
 }
 
@@ -72,9 +72,9 @@ void free_connection(connection_t *c) {
 }
 
 void connection_add(connection_t *c) {
-       list_insert_tail(connection_list, c);
+       list_insert_tail(mesh->connections, c);
 }
 
 void connection_del(connection_t *c) {
-       list_delete(connection_list, c);
+       list_delete(mesh->connections, c);
 }
index e1b270b3f0225ff71c1573588920b034fae67f8f..0cc5ae6fa5d59d526c90bcf2c70d8590c123ff77 100644 (file)
@@ -90,7 +90,6 @@ typedef struct connection_t {
        splay_tree_t *config_tree;      /* Pointer to configuration tree belonging to him */
 } connection_t;
 
-extern list_t *connection_list;
 extern connection_t *everyone;
 
 extern void init_connections(void);
index a7612ab0aa6d94c01230f7d7cc0ed2e36a29f61b..60d3b02ff3ceb6d6e0625638d4b905e990ac5db8 100644 (file)
@@ -64,7 +64,7 @@
 static void mst_kruskal(void) {
        /* Clear MST status on connections */
 
-       for list_each(connection_t, c, connection_list)
+       for list_each(connection_t, c, mesh->connections)
                c->status.mst = false;
 
        logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Running Kruskal's algorithm:");
index a41fa09bbc78895e06d512371cbf6c3ab9f5edff..fc40f301df0a32b412c04f1bfa5053b1b7c10cf5 100644 (file)
@@ -43,6 +43,7 @@ struct meshlink_handle {
        struct splay_tree_t *edges;
        struct splay_tree_t *nodes;
 
+       struct list_t *connections;
        struct list_t *outgoing_connections;
 };
 
index 645954965550c601e098f18185c191617aaef540..160333b2c4cb140ced2bb17395ab550f0d6cb89d 100644 (file)
@@ -22,6 +22,7 @@
 #include "cipher.h"
 #include "connection.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "net.h"
 #include "protocol.h"
@@ -61,7 +62,7 @@ bool send_meta(connection_t *c, const char *buffer, int length) {
 }
 
 void broadcast_meta(connection_t *from, const char *buffer, int length) {
-       for list_each(connection_t, c, connection_list)
+       for list_each(connection_t, c, mesh->connections)
                if(c != from && c->status.active)
                        send_meta(c, buffer, length);
 }
index 8b118dde6d860b0012a474fc988ce664ad76364a..74fb04b694c6daea50246471d8a3e26abdf08365 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -133,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) {
@@ -183,7 +183,7 @@ static void periodic_handler(void *data) {
        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++;
                }
@@ -230,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;
 
@@ -254,7 +254,7 @@ static void periodic_handler(void *data) {
                        */
                        for list_each(outgoing_t, o, outgoing_list) {
                                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;
@@ -305,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) {
@@ -329,7 +329,7 @@ void retry(void) {
        }
 
        /* 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;
        }
index 29f4fb8e59aebfcd900c99b5230db87335c2913e..c60d5a531ae87bb22d8471bd8e6c608802bf7a37 100644 (file)
@@ -592,7 +592,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
        logger(DEBUG_TRAFFIC, LOG_INFO, "Broadcasting packet of %d bytes from %s (%s)",
                           packet->len, from->name, from->hostname);
 
-       for list_each(connection_t, c, connection_list)
+       for list_each(connection_t, c, mesh->connections)
                if(c->status.active && c->status.mst && c != from->nexthop->connection)
                        send_packet(c->node, packet);
 }
index 63f02753679e4867450e88408a538f0a60ddc510..62b12b55e062b835d0e66f7d31e9671f02f8cb58 100644 (file)
@@ -409,7 +409,7 @@ bool setup_network(void) {
   close all open network connections
 */
 void close_network_connections(void) {
-       for(list_node_t *node = connection_list->head, *next; node; node = next) {
+       for(list_node_t *node = mesh->connections->head, *next; node; node = next) {
                next = node->next;
                connection_t *c = node->data;
                c->outgoing = NULL;
index 60f4de1d270404e434e58af93ee0bcc8fbfc2f4e..1521208f76986ef518ce73934bcac7bfab7de7a1 100644 (file)
@@ -687,7 +687,7 @@ void try_outgoing_connections(void) {
 
        /* Terminate any connections whose outgoing_t is to be deleted. */
 
-       for list_each(connection_t, c, connection_list) {
+       for list_each(connection_t, c, mesh->connections) {
                if(c->outgoing && c->outgoing->timeout == -1) {
                        c->outgoing = NULL;
                        logger(DEBUG_CONNECTIONS, LOG_INFO, "No more outgoing connection to %s", c->name);
index 21850dd80733db5aa04666c930de73b4f852d0e2..e88c81fc9fcd08c164146514cc634b2a56930e1a 100644 (file)
@@ -29,7 +29,6 @@
 
 // Symbols necessary to link with logger.o
 bool send_request(void *c, const char *msg, ...) { return false; }
-struct list_t *connection_list = NULL;
 bool send_meta(void *c, const char *msg , int len) { return false; }
 char *logfilename = NULL;
 struct timeval now;
index 0ff59cb4558a488192a529d4ded441968908df8a..63a48459019395fd1049657600a40620a587677a 100644 (file)
@@ -34,7 +34,6 @@
 
 // Symbols necessary to link with logger.o
 bool send_request(void *c, const char *msg, ...) { return false; }
-struct list_t *connection_list = NULL;
 bool send_meta(void *c, const char *msg , int len) { return false; }
 char *logfilename = NULL;
 struct timeval now;