summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-12-30 21:34:01 -0500
committerirungentoo <irungentoo@gmail.com>2014-12-30 21:34:01 -0500
commit523cc20eb0ae5f67a3848d27c2cd3d910ac6da2f (patch)
tree0193b80a5dc36a0529b79d0a294fb89065cd4956 /toxcore
parent87fb1e4119d6762f0d082bccc420508fa7510dbc (diff)
Remove useless code.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c76
-rw-r--r--toxcore/DHT.h8
-rw-r--r--toxcore/onion_client.c4
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)
2082 return count; 2082 return count;
2083} 2083}
2084 2084
2085/* 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. */
2086static int random_node_fromlist(Client_data *list, uint16_t list_size, Node_format *node, uint8_t LAN_ok)
2087{
2088 uint32_t i;
2089 uint32_t num_nodes = 0;
2090 Client_data *client_list[list_size * 2];
2091 IPPTsPng *assoc_list[list_size * 2];
2092
2093 for (i = 0; i < list_size; i++) {
2094 /* If node is not dead. */
2095 Client_data *client = &list[i];
2096 IPPTsPng *assoc;
2097 uint32_t a;
2098
2099 for (a = 0, assoc = &client->assoc6; a < 2; a++, assoc = &client->assoc4) {
2100 /* If node is good. */
2101 if (!is_timeout(assoc->timestamp, BAD_NODE_TIMEOUT)) {
2102 if (!LAN_ok) {
2103 if (LAN_ip(assoc->ip_port.ip) == 0)
2104 continue;
2105 }
2106
2107 client_list[num_nodes] = client;
2108 assoc_list[num_nodes] = assoc;
2109 ++num_nodes;
2110 }
2111 }
2112 }
2113
2114 if (num_nodes == 0)
2115 return -1;
2116
2117 uint32_t rand_node = rand() % num_nodes;
2118 node->ip_port = assoc_list[rand_node]->ip_port;
2119 memcpy(node->client_id, client_list[rand_node]->client_id, CLIENT_ID_SIZE);
2120 return 0;
2121}
2122
2123/* Put up to max_num random nodes in nodes.
2124 *
2125 * return the number of nodes.
2126 *
2127 * NOTE:this is used to pick nodes for paths.
2128 *
2129 * TODO: remove the LAN stuff from this.
2130 */
2131uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num)
2132{
2133 if (max_num == 0)
2134 return 0;
2135
2136 if (dht->num_friends == 0)
2137 return 0;
2138
2139 uint16_t count = 0;
2140 uint16_t list_size = 0;
2141 uint32_t i;
2142
2143 for (i = 0; i < max_num; ++i) {
2144 Client_data *list = NULL;
2145 uint16_t rand_num = rand() % (dht->num_friends);
2146 list = dht->friends_list[rand_num].client_list;
2147 list_size = MAX_FRIEND_CLIENTS;
2148
2149 uint8_t LAN_ok = 1;
2150
2151 if (count != 0 && LAN_ip(nodes[0].ip_port.ip) != 0)
2152 LAN_ok = 0;
2153
2154 if (random_node_fromlist(list, list_size, &nodes[count], LAN_ok) == 0)
2155 ++count;
2156 }
2157
2158 return count;
2159}
2160
2161void do_hardening(DHT *dht) 2085void do_hardening(DHT *dht)
2162{ 2086{
2163 uint32_t i; 2087 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
324 */ 324 */
325uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num); 325uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
326 326
327/* Put up to max_num random nodes in nodes.
328 *
329 * return the number of nodes.
330 *
331 * NOTE:this is used to pick nodes for paths.
332 */
333uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num);
334
335/* Run this function at least a couple times per second (It's the main loop). */ 327/* Run this function at least a couple times per second (It's the main loop). */
336void do_DHT(DHT *dht); 328void do_DHT(DHT *dht);
337 329
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
133 133
134 //if (DHT_non_lan_connected(onion_c->dht)) { 134 //if (DHT_non_lan_connected(onion_c->dht)) {
135 if (DHT_isconnected(onion_c->dht)) { 135 if (DHT_isconnected(onion_c->dht)) {
136 if (num_nodes < 3) 136 if (num_nodes == 0)
137 return random_nodes_path(onion_c->dht, nodes, max_num); 137 return 0;
138 138
139 for (i = 0; i < max_num; ++i) { 139 for (i = 0; i < max_num; ++i) {
140 nodes[i] = onion_c->path_nodes[rand() % num_nodes]; 140 nodes[i] = onion_c->path_nodes[rand() % num_nodes];