X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fautoconnect.c;h=d819ee468800c92e96b6d1f3c164c804d4612ca5;hb=2c6b2d70e6640f39563ad7bb0aa0ba87f883848c;hp=132467e69eb2b73fe42e81230fa7f527877ebb98;hpb=6123ed30992d671b94fc016660086be6a62a3871;p=tinc diff --git a/src/autoconnect.c b/src/autoconnect.c index 132467e6..d819ee46 100644 --- a/src/autoconnect.c +++ b/src/autoconnect.c @@ -54,7 +54,7 @@ static void make_new_connection() { bool found = false; for list_each(outgoing_t, outgoing, outgoing_list) { - if(!strcmp(outgoing->name, n->name)) { + if(outgoing->node == n) { found = true; break; } @@ -63,7 +63,7 @@ static void make_new_connection() { if(!found) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name); outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); - outgoing->name = xstrdup(n->name); + outgoing->node = n; list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing, false); } @@ -80,7 +80,7 @@ static void connect_to_unreachable() { * are only a few reachable nodes, and many unreachable ones, we're * going to try harder to connect to them. */ - int r = rand() % node_tree->count; + unsigned int r = rand() % node_tree->count; for splay_each(node_t, n, node_tree) { if(r--) { @@ -92,15 +92,16 @@ static void connect_to_unreachable() { return; } - /* Are we already trying to make an outgoing connection to it? If not, return. */ - for list_each(outgoing_t, outgoing, outgoing_list) - if(!strcmp(outgoing->name, n->name)) { + /* Are we already trying to make an outgoing connection to it? If so, return. */ + for list_each(outgoing_t, outgoing, outgoing_list) { + if(outgoing->node == n) { return; } + } logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name); outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); - outgoing->name = xstrdup(n->name); + outgoing->node = n; list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing, false); @@ -159,7 +160,7 @@ static void drop_superfluous_pending_connections() { continue; } - logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->name); + logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->node->name); list_delete_node(outgoing_list, node); } } @@ -185,10 +186,9 @@ void do_autoconnect() { drop_superfluous_outgoing_connection(); } + /* Drop pending outgoing connections from the outgoing list. */ + drop_superfluous_pending_connections(); /* Check if there are unreachable nodes that we should try to connect to. */ connect_to_unreachable(); - - /* Drop pending outgoing connections from the outgoing list. */ - drop_superfluous_pending_connections(); }