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++;
}
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;
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;
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;
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;
/* 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;
}
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);
}
}
}
/* 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) {
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;
}