and we are not already trying to make one, create an
outgoing connection to this node.
*/
- int r = rand() % (node_tree->count - 1);
- int i = 0;
-
+ int count = 0;
for splay_each(node_t, n, node_tree) {
- if(n == myself)
+ if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
continue;
+ count++;
+ }
- if(i++ != r)
+ if(!count)
+ goto end;
+
+ int r = rand() % count;
+
+ for splay_each(node_t, n, node_tree) {
+ if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
continue;
- if(n->connection)
- break;
+ if(r--)
+ continue;
bool found = false;
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
}
+
break;
}
} else if(nc > 3) {
}
}
+end:
timeout_set(data, &(struct timeval){5, rand() % 100000});
}
for splay_each(subnet_t, subnet, subnet_tree)
if (subnet->owner)
subnet->expires = 1;
+ }
+
+ for splay_each(node_t, n, node_tree)
+ n->status.has_address = false;
- load_all_subnets();
+ load_all_nodes();
+ if(strictsubnets) {
for splay_each(subnet_t, subnet, subnet_tree) {
if (!subnet->owner)
continue;