diff options
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 9528a041..d11a91e8 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -236,7 +236,7 @@ uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uin | |||
236 | return 0; | 236 | return 0; |
237 | } | 237 | } |
238 | 238 | ||
239 | const uint16_t num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES; | 239 | const uint16_t num_nodes = min_u16(onion_c->path_nodes_index, MAX_PATH_NODES); |
240 | uint16_t i = 0; | 240 | uint16_t i = 0; |
241 | 241 | ||
242 | while (i < max_num && i < num_nodes) { | 242 | while (i < max_num && i < num_nodes) { |
@@ -275,7 +275,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format | |||
275 | return 0; | 275 | return 0; |
276 | } | 276 | } |
277 | 277 | ||
278 | const uint32_t num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES; | 278 | const uint16_t num_nodes = min_u16(onion_c->path_nodes_index, MAX_PATH_NODES); |
279 | 279 | ||
280 | // if (dht_non_lan_connected(onion_c->dht)) { | 280 | // if (dht_non_lan_connected(onion_c->dht)) { |
281 | if (dht_isconnected(onion_c->dht)) { | 281 | if (dht_isconnected(onion_c->dht)) { |
@@ -301,8 +301,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format | |||
301 | nodes[i] = onion_c->path_nodes[random_u32() % num_nodes]; | 301 | nodes[i] = onion_c->path_nodes[random_u32() % num_nodes]; |
302 | } | 302 | } |
303 | } else { | 303 | } else { |
304 | unsigned int num_nodes_bs = (onion_c->path_nodes_index_bs < MAX_PATH_NODES) ? onion_c->path_nodes_index_bs : | 304 | const uint16_t num_nodes_bs = min_u16(onion_c->path_nodes_index_bs, MAX_PATH_NODES); |
305 | MAX_PATH_NODES; | ||
306 | 305 | ||
307 | if (num_nodes_bs == 0) { | 306 | if (num_nodes_bs == 0) { |
308 | return 0; | 307 | return 0; |
@@ -1619,9 +1618,8 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
1619 | } | 1618 | } |
1620 | 1619 | ||
1621 | if (count != MAX_ONION_CLIENTS) { | 1620 | if (count != MAX_ONION_CLIENTS) { |
1622 | unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES; | 1621 | const uint16_t num_nodes = min_u16(onion_c->path_nodes_index, MAX_PATH_NODES); |
1623 | 1622 | uint16_t n = num_nodes; | |
1624 | unsigned int n = num_nodes; | ||
1625 | 1623 | ||
1626 | if (num_nodes > (MAX_ONION_CLIENTS / 2)) { | 1624 | if (num_nodes > (MAX_ONION_CLIENTS / 2)) { |
1627 | n = (MAX_ONION_CLIENTS / 2); | 1625 | n = (MAX_ONION_CLIENTS / 2); |
@@ -1740,14 +1738,14 @@ static void do_announce(Onion_Client *onion_c) | |||
1740 | } | 1738 | } |
1741 | 1739 | ||
1742 | if (count != MAX_ONION_CLIENTS_ANNOUNCE) { | 1740 | if (count != MAX_ONION_CLIENTS_ANNOUNCE) { |
1743 | unsigned int num_nodes; | 1741 | uint16_t num_nodes; |
1744 | Node_format *path_nodes; | 1742 | Node_format *path_nodes; |
1745 | 1743 | ||
1746 | if (random_u08() % 2 == 0 || onion_c->path_nodes_index == 0) { | 1744 | if (random_u08() % 2 == 0 || onion_c->path_nodes_index == 0) { |
1747 | num_nodes = (onion_c->path_nodes_index_bs < MAX_PATH_NODES) ? onion_c->path_nodes_index_bs : MAX_PATH_NODES; | 1745 | num_nodes = min_u16(onion_c->path_nodes_index_bs, MAX_PATH_NODES); |
1748 | path_nodes = onion_c->path_nodes_bs; | 1746 | path_nodes = onion_c->path_nodes_bs; |
1749 | } else { | 1747 | } else { |
1750 | num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES; | 1748 | num_nodes = min_u16(onion_c->path_nodes_index, MAX_PATH_NODES); |
1751 | path_nodes = onion_c->path_nodes; | 1749 | path_nodes = onion_c->path_nodes; |
1752 | } | 1750 | } |
1753 | 1751 | ||