From 523cc20eb0ae5f67a3848d27c2cd3d910ac6da2f Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Dec 2014 21:34:01 -0500 Subject: [PATCH] Remove useless code. --- toxcore/DHT.c | 76 ------------------------------------------ toxcore/DHT.h | 8 ----- toxcore/onion_client.c | 4 +-- 3 files changed, 2 insertions(+), 86 deletions(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index d28c1ecf..594e3e7b 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2082,82 +2082,6 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num) return count; } -/* Put a random node from list of list_size in node. LAN_ok is 1 if LAN ips are ok, 0 if we don't want them. */ -static int random_node_fromlist(Client_data *list, uint16_t list_size, Node_format *node, uint8_t LAN_ok) -{ - uint32_t i; - uint32_t num_nodes = 0; - Client_data *client_list[list_size * 2]; - IPPTsPng *assoc_list[list_size * 2]; - - for (i = 0; i < list_size; i++) { - /* If node is not dead. */ - Client_data *client = &list[i]; - IPPTsPng *assoc; - uint32_t a; - - for (a = 0, assoc = &client->assoc6; a < 2; a++, assoc = &client->assoc4) { - /* If node is good. */ - if (!is_timeout(assoc->timestamp, BAD_NODE_TIMEOUT)) { - if (!LAN_ok) { - if (LAN_ip(assoc->ip_port.ip) == 0) - continue; - } - - client_list[num_nodes] = client; - assoc_list[num_nodes] = assoc; - ++num_nodes; - } - } - } - - if (num_nodes == 0) - return -1; - - uint32_t rand_node = rand() % num_nodes; - node->ip_port = assoc_list[rand_node]->ip_port; - memcpy(node->client_id, client_list[rand_node]->client_id, CLIENT_ID_SIZE); - return 0; -} - -/* Put up to max_num random nodes in nodes. - * - * return the number of nodes. - * - * NOTE:this is used to pick nodes for paths. - * - * TODO: remove the LAN stuff from this. - */ -uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num) -{ - if (max_num == 0) - return 0; - - if (dht->num_friends == 0) - return 0; - - uint16_t count = 0; - uint16_t list_size = 0; - uint32_t i; - - for (i = 0; i < max_num; ++i) { - Client_data *list = NULL; - uint16_t rand_num = rand() % (dht->num_friends); - list = dht->friends_list[rand_num].client_list; - list_size = MAX_FRIEND_CLIENTS; - - uint8_t LAN_ok = 1; - - if (count != 0 && LAN_ip(nodes[0].ip_port.ip) != 0) - LAN_ok = 0; - - if (random_node_fromlist(list, list_size, &nodes[count], LAN_ok) == 0) - ++count; - } - - return count; -} - void do_hardening(DHT *dht) { uint32_t i; diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 35000c87..3f7a820e 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -324,14 +324,6 @@ int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes */ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num); -/* Put up to max_num random nodes in nodes. - * - * return the number of nodes. - * - * NOTE:this is used to pick nodes for paths. - */ -uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num); - /* Run this function at least a couple times per second (It's the main loop). */ void do_DHT(DHT *dht); diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 76d8bac0..9153216d 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -133,8 +133,8 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format //if (DHT_non_lan_connected(onion_c->dht)) { if (DHT_isconnected(onion_c->dht)) { - if (num_nodes < 3) - return random_nodes_path(onion_c->dht, nodes, max_num); + if (num_nodes == 0) + return 0; for (i = 0; i < max_num; ++i) { nodes[i] = onion_c->path_nodes[rand() % num_nodes];