From: Guus Sliepen Date: Mon, 21 Apr 2014 19:04:13 +0000 (+0200) Subject: Move connection_list to mesh->connections. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=21f0bddfa4dca5fb21c9dc4970ac64fa8fe706e4;p=meshlink Move connection_list to mesh->connections. --- diff --git a/src/connection.c b/src/connection.c index d25159e6..c38bc4a0 100644 --- a/src/connection.c +++ b/src/connection.c @@ -25,21 +25,21 @@ #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); } diff --git a/src/connection.h b/src/connection.h index e1b270b3..0cc5ae6f 100644 --- a/src/connection.h +++ b/src/connection.h @@ -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); diff --git a/src/graph.c b/src/graph.c index a7612ab0..60d3b02f 100644 --- a/src/graph.c +++ b/src/graph.c @@ -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:"); diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index a41fa09b..fc40f301 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -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; }; diff --git a/src/meta.c b/src/meta.c index 64595496..160333b2 100644 --- a/src/meta.c +++ b/src/meta.c @@ -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); } diff --git a/src/net.c b/src/net.c index 8b118dde..74fb04b6 100644 --- 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; } diff --git a/src/net_packet.c b/src/net_packet.c index 29f4fb8e..c60d5a53 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -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); } diff --git a/src/net_setup.c b/src/net_setup.c index 63f02753..62b12b55 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -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; diff --git a/src/net_socket.c b/src/net_socket.c index 60f4de1d..1521208f 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -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); diff --git a/src/sptps_speed.c b/src/sptps_speed.c index 21850dd8..e88c81fc 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -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; diff --git a/src/sptps_test.c b/src/sptps_test.c index 0ff59cb4..63a48459 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -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;