#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);
}
}
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);
}
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);
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:");
struct splay_tree_t *edges;
struct splay_tree_t *nodes;
+ struct list_t *connections;
struct list_t *outgoing_connections;
};
#include "cipher.h"
#include "connection.h"
#include "logger.h"
+#include "meshlink_internal.h"
#include "meta.h"
#include "net.h"
#include "protocol.h"
}
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);
}
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) {
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++;
}
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;
*/
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;
/* 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) {
}
/* 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;
}
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);
}
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;
/* 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);
// 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;
// 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;