Remove useless code.

This commit is contained in:
irungentoo 2014-12-30 21:34:01 -05:00
parent 87fb1e4119
commit 523cc20eb0
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 2 additions and 86 deletions

View File

@ -2082,82 +2082,6 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
return count; 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) void do_hardening(DHT *dht)
{ {
uint32_t i; uint32_t i;

View File

@ -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); 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). */ /* Run this function at least a couple times per second (It's the main loop). */
void do_DHT(DHT *dht); void do_DHT(DHT *dht);

View File

@ -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_non_lan_connected(onion_c->dht)) {
if (DHT_isconnected(onion_c->dht)) { if (DHT_isconnected(onion_c->dht)) {
if (num_nodes < 3) if (num_nodes == 0)
return random_nodes_path(onion_c->dht, nodes, max_num); return 0;
for (i = 0; i < max_num; ++i) { for (i = 0; i < max_num; ++i) {
nodes[i] = onion_c->path_nodes[rand() % num_nodes]; nodes[i] = onion_c->path_nodes[rand() % num_nodes];