summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-01-17 15:46:09 -0500
committerirungentoo <irungentoo@gmail.com>2014-01-17 15:46:09 -0500
commitd11cf9c5a824293dbd309026d8ab4946972f44bb (patch)
tree23273f0daabb30dd4abfcb3b5225820fe8347e66 /toxcore
parent608330efefafdd7631829c0e3d918871ebef058b (diff)
Small performance increases.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c32
-rw-r--r--toxcore/DHT.h4
-rw-r--r--toxcore/Messenger.c3
-rw-r--r--toxcore/onion_client.c2
4 files changed, 33 insertions, 8 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index f9297225..c8702c45 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -28,7 +28,11 @@
28#endif 28#endif
29 29
30#include "DHT.h" 30#include "DHT.h"
31
32#ifdef ENABLE_ASSOC_DHT
31#include "assoc.h" 33#include "assoc.h"
34#endif
35
32#include "ping.h" 36#include "ping.h"
33 37
34#include "network.h" 38#include "network.h"
@@ -304,7 +308,7 @@ static void get_close_nodes_inner(DHT *dht, uint8_t *client_id, Node_format *nod
304 if (LAN_ip(ipptp->ip_port.ip) == 0 && !is_LAN) 308 if (LAN_ip(ipptp->ip_port.ip) == 0 && !is_LAN)
305 continue; 309 continue;
306 310
307 if (want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK && !id_equal(client_id, client->client_id)) 311 if (LAN_ip(ipptp->ip_port.ip) != 0 && want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK && !id_equal(client_id, client->client_id))
308 continue; 312 continue;
309 313
310 if (num_nodes < MAX_SENT_NODES) { 314 if (num_nodes < MAX_SENT_NODES) {
@@ -366,9 +370,13 @@ static int get_somewhat_close_nodes(DHT *dht, uint8_t *client_id, Node_format *n
366int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, 370int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN,
367 uint8_t want_good) 371 uint8_t want_good)
368{ 372{
373#ifdef ENABLE_ASSOC_DHT
374
369 if (!dht->assoc) 375 if (!dht->assoc)
376#endif
370 return get_somewhat_close_nodes(dht, client_id, nodes_list, sa_family, is_LAN, want_good); 377 return get_somewhat_close_nodes(dht, client_id, nodes_list, sa_family, is_LAN, want_good);
371 378
379#ifdef ENABLE_ASSOC_DHT
372 Client_data *result[MAX_SENT_NODES]; 380 Client_data *result[MAX_SENT_NODES];
373 381
374 Assoc_close_entries request; 382 Assoc_close_entries request;
@@ -420,6 +428,7 @@ int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_fa
420 } 428 }
421 429
422 return num_returned; 430 return num_returned;
431#endif
423} 432}
424 433
425/* Replace first bad (or empty) node with this one. 434/* Replace first bad (or empty) node with this one.
@@ -566,7 +575,7 @@ static int replace_good( Client_data *list,
566 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) 575 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6))
567 return 1; 576 return 1;
568 577
569 sort_list(list, length, comp_client_id); 578 //sort_list(list, length, comp_client_id);
570 579
571 int8_t replace = -1; 580 int8_t replace = -1;
572 581
@@ -669,6 +678,8 @@ int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id)
669 used++; 678 used++;
670 } 679 }
671 680
681#ifdef ENABLE_ASSOC_DHT
682
672 if (dht->assoc) { 683 if (dht->assoc) {
673 IPPTs ippts; 684 IPPTs ippts;
674 685
@@ -678,6 +689,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id)
678 Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); 689 Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0);
679 } 690 }
680 691
692#endif
681 return used; 693 return used;
682} 694}
683 695
@@ -734,6 +746,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, uint8_t *client_id, uint8
734 } 746 }
735 747
736end: 748end:
749#ifdef ENABLE_ASSOC_DHT
737 750
738 if (dht->assoc) { 751 if (dht->assoc) {
739 IPPTs ippts; 752 IPPTs ippts;
@@ -744,6 +757,7 @@ end:
744 Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); 757 Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0);
745 } 758 }
746 759
760#endif
747 return 0; 761 return 0;
748} 762}
749 763
@@ -1177,6 +1191,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id)
1177 1191
1178 dht->friends_list[dht->num_friends].nat.NATping_id = random_64b(); 1192 dht->friends_list[dht->num_friends].nat.NATping_id = random_64b();
1179 ++dht->num_friends; 1193 ++dht->num_friends;
1194#ifdef ENABLE_ASSOC_DHT
1180 1195
1181 if (dht->assoc) { 1196 if (dht->assoc) {
1182 /* get up to MAX_FRIEND_CLIENTS connectable nodes */ 1197 /* get up to MAX_FRIEND_CLIENTS connectable nodes */
@@ -1206,6 +1221,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id)
1206 } 1221 }
1207 } 1222 }
1208 1223
1224#endif
1209 /*TODO: make this better?*/ 1225 /*TODO: make this better?*/
1210 get_bunchnodes(dht, dht->close_clientlist, LCLIENT_LIST, MAX_FRIEND_CLIENTS, client_id); 1226 get_bunchnodes(dht, dht->close_clientlist, LCLIENT_LIST, MAX_FRIEND_CLIENTS, client_id);
1211 1227
@@ -1374,14 +1390,15 @@ void DHT_getnodes(DHT *dht, IP_Port *from_ipp, uint8_t *from_id, uint8_t *which_
1374 1390
1375void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key) 1391void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key)
1376{ 1392{
1377 /* 1393 /*#ifdef ENABLE_ASSOC_DHT
1378 if (dht->assoc) { 1394 if (dht->assoc) {
1379 IPPTs ippts; 1395 IPPTs ippts;
1380 ippts.ip_port = ip_port; 1396 ippts.ip_port = ip_port;
1381 ippts.timestamp = 0; 1397 ippts.timestamp = 0;
1382 1398
1383 Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0); 1399 Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0);
1384 }*/ 1400 }
1401 #endif*/
1385 1402
1386 getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); 1403 getnodes(dht, ip_port, public_key, dht->self_public_key, NULL);
1387} 1404}
@@ -2221,8 +2238,9 @@ DHT *new_DHT(Net_Crypto *c)
2221 2238
2222 new_symmetric_key(dht->secret_symmetric_key); 2239 new_symmetric_key(dht->secret_symmetric_key);
2223 crypto_box_keypair(dht->self_public_key, dht->self_secret_key); 2240 crypto_box_keypair(dht->self_public_key, dht->self_secret_key);
2241#ifdef ENABLE_ASSOC_DHT
2224 dht->assoc = new_Assoc_default(dht->self_public_key); 2242 dht->assoc = new_Assoc_default(dht->self_public_key);
2225 2243#endif
2226 return dht; 2244 return dht;
2227} 2245}
2228 2246
@@ -2239,15 +2257,19 @@ void do_DHT(DHT *dht)
2239 do_NAT(dht); 2257 do_NAT(dht);
2240 do_toping(dht->ping); 2258 do_toping(dht->ping);
2241 do_hardening(dht); 2259 do_hardening(dht);
2260#ifdef ENABLE_ASSOC_DHT
2242 2261
2243 if (dht->assoc) 2262 if (dht->assoc)
2244 do_Assoc(dht->assoc, dht); 2263 do_Assoc(dht->assoc, dht);
2245 2264
2265#endif
2246 dht->last_run = unix_time(); 2266 dht->last_run = unix_time();
2247} 2267}
2248void kill_DHT(DHT *dht) 2268void kill_DHT(DHT *dht)
2249{ 2269{
2270#ifdef ENABLE_ASSOC_DHT
2250 kill_Assoc(dht->assoc); 2271 kill_Assoc(dht->assoc);
2272#endif
2251 kill_ping(dht->ping); 2273 kill_ping(dht->ping);
2252 free(dht->friends_list); 2274 free(dht->friends_list);
2253 free(dht); 2275 free(dht);
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index a93fdb23..dc226a9f 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -154,9 +154,9 @@ typedef struct {
154 uint16_t num_friends; 154 uint16_t num_friends;
155 155
156 struct PING *ping; 156 struct PING *ping;
157 157#ifdef ENABLE_ASSOC_DHT
158 struct Assoc *assoc; 158 struct Assoc *assoc;
159 159#endif
160 uint64_t last_run; 160 uint64_t last_run;
161} DHT; 161} DHT;
162/*----------------------------------------------------------------------------------*/ 162/*----------------------------------------------------------------------------------*/
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 2f0bde29..3bc9f211 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2214,9 +2214,12 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
2214 if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { 2214 if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) {
2215 set_nospam(&(m->fr), *(uint32_t *)data); 2215 set_nospam(&(m->fr), *(uint32_t *)data);
2216 load_keys(m->net_crypto, &data[sizeof(uint32_t)]); 2216 load_keys(m->net_crypto, &data[sizeof(uint32_t)]);
2217#ifdef ENABLE_ASSOC_DHT
2217 2218
2218 if (m->dht->assoc) 2219 if (m->dht->assoc)
2219 Assoc_self_client_id_changed(m->dht->assoc, m->net_crypto->self_public_key); 2220 Assoc_self_client_id_changed(m->dht->assoc, m->net_crypto->self_public_key);
2221
2222#endif
2220 } else 2223 } else
2221 return -1; /* critical */ 2224 return -1; /* critical */
2222 2225
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index e68b6329..ff21659b 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -635,7 +635,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
635 635
636 /* send packets to friend telling them our fake DHT id. */ 636 /* send packets to friend telling them our fake DHT id. */
637 if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_sent, ONION_FAKEID_INTERVAL)) 637 if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_sent, ONION_FAKEID_INTERVAL))
638 if (send_fakeid_announce(onion_c, friendnum) > 3) 638 if (send_fakeid_announce(onion_c, friendnum) > 1)
639 onion_c->friends_list[friendnum].last_fakeid_sent = unix_time(); 639 onion_c->friends_list[friendnum].last_fakeid_sent = unix_time();
640} 640}
641/* Function to call when onion data packet with contents beginning with byte is received. */ 641/* Function to call when onion data packet with contents beginning with byte is received. */