Make autoconnect faster
When AutoConnect is enabled tinc tries to connect to other nodes picking them at random. This may be sane default behavior but it may take ages if only few nodes have defined Address in thier config. Proposed solution to this problem: - Filter out nodes without known address in periodic_handler I have added new node->status.has_known_address bool - On update_node_udp() update this flag
This commit is contained in:
parent
d16a43c06c
commit
3c67735720
4 changed files with 33 additions and 16 deletions
37
src/net.c
37
src/net.c
|
|
@ -209,15 +209,14 @@ static void periodic_handler(void *data) {
|
|||
and we are not already trying to make one, create an
|
||||
outgoing connection to this node.
|
||||
*/
|
||||
int r = rand() % node_tree->count;
|
||||
int i = 0;
|
||||
splay_tree_t *tmp_node_tree;
|
||||
|
||||
tmp_node_tree = splay_alloc_tree((splay_compare_t) node_compare, NULL);
|
||||
|
||||
for splay_each(node_t, n, node_tree) {
|
||||
if(i++ != r)
|
||||
continue;
|
||||
|
||||
if(n->connection)
|
||||
break;
|
||||
if(!n->status.has_known_address || n->connection)
|
||||
continue;
|
||||
|
||||
bool found = false;
|
||||
|
||||
|
|
@ -227,16 +226,26 @@ static void periodic_handler(void *data) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
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);
|
||||
setup_outgoing_connection(outgoing);
|
||||
if (!found)
|
||||
splay_insert(tmp_node_tree, n);
|
||||
}
|
||||
break;
|
||||
|
||||
int r = rand() % tmp_node_tree->count;
|
||||
int i = 0;
|
||||
|
||||
for splay_each(node_t, n, tmp_node_tree) {
|
||||
|
||||
if(i++ != r)
|
||||
continue;
|
||||
|
||||
|
||||
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);
|
||||
setup_outgoing_connection(outgoing);
|
||||
}
|
||||
splay_delete_tree(tmp_node_tree);
|
||||
} else if(nc > 3) {
|
||||
/* Too many active connections, try to remove one.
|
||||
Choose a random outgoing connection to a node
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue