X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fautoconnect.c;h=d771078af7a0a19e5c575697b25ba68f435800b1;hb=344c632c7a9f8047a412239dcd22ba1531bdfda5;hp=4279cd37e1acd769a6284e218af6fce2fa1bb5fa;hpb=914d1be411229c28e6e8e4a0df99afa076a8b448;p=tinc diff --git a/src/autoconnect.c b/src/autoconnect.c index 4279cd37..d771078a 100644 --- a/src/autoconnect.c +++ b/src/autoconnect.c @@ -1,6 +1,6 @@ /* autoconnect.c -- automatic connection establishment - Copyright (C) 2017 Guus Sliepen + Copyright (C) 2017-2022 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,14 +19,16 @@ #include "system.h" +#include "autoconnect.h" #include "connection.h" +#include "crypto.h" #include "logger.h" #include "node.h" #include "xalloc.h" -static void make_new_connection() { +static void make_new_connection(void) { /* Select a random node we haven't connected to yet. */ - int count = 0; + uint32_t count = 0; for splay_each(node_t, n, &node_tree) { if(n == myself || n->connection || !(n->status.has_address || n->status.reachable)) { @@ -40,14 +42,15 @@ static void make_new_connection() { return; } - int r = rand() % count; + uint32_t r = prng(count); for splay_each(node_t, n, &node_tree) { if(n == myself || n->connection || !(n->status.has_address || n->status.reachable)) { continue; } - if(r--) { + if(r) { + --r; continue; } @@ -72,7 +75,7 @@ static void make_new_connection() { } } -static void connect_to_unreachable() { +static void connect_to_unreachable(void) { /* Select a random known node. The rationale is that if there are many * reachable nodes, and only a few unreachable nodes, we don't want all * reachable nodes to try to connect to the unreachable ones at the @@ -80,7 +83,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. */ - unsigned int r = rand() % node_tree.count; + uint32_t r = prng(node_tree.count); for splay_each(node_t, n, &node_tree) { if(r--) { @@ -109,9 +112,9 @@ static void connect_to_unreachable() { } } -static void drop_superfluous_outgoing_connection() { +static void drop_superfluous_outgoing_connection(void) { /* Choose a random outgoing connection to a node that has at least one other connection. */ - int count = 0; + uint32_t count = 0; for list_each(connection_t, c, &connection_list) { if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree.count < 2) { @@ -125,7 +128,7 @@ static void drop_superfluous_outgoing_connection() { return; } - int r = rand() % count; + uint32_t r = prng(count); for list_each(connection_t, c, &connection_list) { if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree.count < 2) { @@ -144,7 +147,7 @@ static void drop_superfluous_outgoing_connection() { } } -static void drop_superfluous_pending_connections() { +static void drop_superfluous_pending_connections(void) { for list_each(outgoing_t, o, &outgoing_list) { /* Only look for connections that are waiting to be retried later. */ bool found = false; @@ -165,9 +168,9 @@ static void drop_superfluous_pending_connections() { } } -void do_autoconnect() { +void do_autoconnect(void) { /* Count number of active connections. */ - int nc = 0; + uint32_t nc = 0; for list_each(connection_t, c, &connection_list) { if(c->edge) {