+ //} else if(nc > autoconnect) {
+ } else {
+ /* Min number of connections established. Now try
+ to connect to some unreachable nodes to attempt
+ to heal possible partitions.
+ */
+ int r = rand() % num_unreachable;
+ int i = 0;
+
+ for splay_each(node_t, n, mesh->nodes) {
+ if(n->status.reachable)
+ continue;
+
+ if(i++ != r)
+ continue;
+
+ if(n->connection)
+ break;
+
+ bool found = false;
+
+ for list_each(outgoing_t, outgoing, mesh->outgoings) {
+ if(!strcmp(outgoing->name, n->name)) {
+ found = true;
+ break;
+ }
+ }
+
+ if(!found) {
+ //TODO: if the node is blacklisted the connection will not happen, but
+ //the user will read this debug message "Autoconnecting to %s" that is misleading
+ logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
+ outgoing_t *outgoing = xzalloc(sizeof *outgoing);
+ outgoing->name = xstrdup(n->name);
+ list_insert_tail(mesh->outgoings, outgoing);
+ setup_outgoing_connection(mesh, outgoing);
+ }
+ break;
+ }
+ }
+ if(nc > autoconnect) {