summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-12 16:48:35 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-16 12:06:02 +0100
commit1494e474dde58ec6e446cdbfad9a8d89f6c4796c (patch)
treee454a18a0f61468d10833d8e80039d025f94f568 /toxcore/DHT.c
parent37c041f8159f7e89f2585243e9b8073f47d77fd1 (diff)
Ensure that all TODOs have an owner.
In the future, all TODOs added either need a bug number (TODO(#NN)) or a person's github user name. By default, I made irungentoo the owner of all toxcore TODOs, mannol the owner of toxav TODOs, and myself the owner of API TODOs.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index e7fd0a9d..2f078314 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -243,7 +243,7 @@ static int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
243 uint8_t net_family; 243 uint8_t net_family;
244 244
245 if (ip_port->ip.family == AF_INET) { 245 if (ip_port->ip.family == AF_INET) {
246 // FIXME use functions to convert endianness 246 // TODO(irungentoo): use functions to convert endianness
247 ipv6 = 0; 247 ipv6 = 0;
248 net_family = TOX_AF_INET; 248 net_family = TOX_AF_INET;
249 } else if (ip_port->ip.family == TCP_INET) { 249 } else if (ip_port->ip.family == TCP_INET) {
@@ -432,7 +432,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
432/* Check if client with public_key is already in list of length length. 432/* Check if client with public_key is already in list of length length.
433 * If it is then set its corresponding timestamp to current time. 433 * If it is then set its corresponding timestamp to current time.
434 * If the id is already in the list with a different ip_port, update it. 434 * If the id is already in the list with a different ip_port, update it.
435 * TODO: Maybe optimize this. 435 * TODO(irungentoo): Maybe optimize this.
436 * 436 *
437 * return True(1) or False(0) 437 * return True(1) or False(0)
438 */ 438 */
@@ -482,7 +482,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le
482 482
483 /* public_key not in list yet: see if we can find an identical ip_port, in 483 /* public_key not in list yet: see if we can find an identical ip_port, in
484 * that case we kill the old public_key by overwriting it with the new one 484 * that case we kill the old public_key by overwriting it with the new one
485 * TODO: maybe we SHOULDN'T do that if that public_key is in a friend_list 485 * TODO(irungentoo): maybe we SHOULDN'T do that if that public_key is in a friend_list
486 * and the one who is the actual friend's public_key/address set? */ 486 * and the one who is the actual friend's public_key/address set? */
487 for (i = 0; i < length; ++i) { 487 for (i = 0; i < length; ++i) {
488 /* MAYBE: check the other address, if valid, don't nuke? */ 488 /* MAYBE: check the other address, if valid, don't nuke? */
@@ -576,7 +576,7 @@ bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk
576 return 0; 576 return 0;
577} 577}
578 578
579/*TODO: change this to 7 when done*/ 579/* TODO(irungentoo): change this to 7 when done*/
580#define HARDENING_ALL_OK 2 580#define HARDENING_ALL_OK 2
581/* return 0 if not. 581/* return 0 if not.
582 * return 1 if route request are ok 582 * return 1 if route request are ok
@@ -657,8 +657,8 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
657/* Find MAX_SENT_NODES nodes closest to the public_key for the send nodes request: 657/* Find MAX_SENT_NODES nodes closest to the public_key for the send nodes request:
658 * put them in the nodes_list and return how many were found. 658 * put them in the nodes_list and return how many were found.
659 * 659 *
660 * TODO: For the love of based <your favorite deity, in doubt use "love"> make 660 * TODO(irungentoo): For the love of based <your favorite deity, in doubt use
661 * this function cleaner and much more efficient. 661 * "love"> make this function cleaner and much more efficient.
662 * 662 *
663 * want_good : do we want only good nodes as checked with the hardening returned or not? 663 * want_good : do we want only good nodes as checked with the hardening returned or not?
664 */ 664 */
@@ -669,12 +669,17 @@ static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, N
669 get_close_nodes_inner(public_key, nodes_list, sa_family, 669 get_close_nodes_inner(public_key, nodes_list, sa_family,
670 dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, 0); 670 dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, 0);
671 671
672 /*TODO uncomment this when hardening is added to close friend clients 672 /* TODO(irungentoo): uncomment this when hardening is added to close friend clients */
673 for (i = 0; i < dht->num_friends; ++i) 673#if 0
674 get_close_nodes_inner(dht, public_key, nodes_list, sa_family, 674
675 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 675 for (i = 0; i < dht->num_friends; ++i) {
676 &num_nodes, is_LAN, want_good); 676 get_close_nodes_inner(dht, public_key, nodes_list, sa_family,
677 */ 677 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
678 &num_nodes, is_LAN, want_good);
679 }
680
681#endif
682
678 for (i = 0; i < dht->num_friends; ++i) { 683 for (i = 0; i < dht->num_friends; ++i) {
679 get_close_nodes_inner(public_key, nodes_list, sa_family, 684 get_close_nodes_inner(public_key, nodes_list, sa_family,
680 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 685 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
@@ -695,7 +700,7 @@ int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *node
695 return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good); 700 return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good);
696 701
697#ifdef ENABLE_ASSOC_DHT 702#ifdef ENABLE_ASSOC_DHT
698 //TODO: assoc, sa_family 0 (don't care if ipv4 or ipv6) support. 703 // TODO(irungentoo): assoc, sa_family 0 (don't care if ipv4 or ipv6) support.
699 Client_data *result[MAX_SENT_NODES]; 704 Client_data *result[MAX_SENT_NODES];
700 705
701 Assoc_close_entries request; 706 Assoc_close_entries request;
@@ -970,7 +975,7 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k
970 dht->to_bootstrap[dht->num_to_bootstrap].ip_port = ip_port; 975 dht->to_bootstrap[dht->num_to_bootstrap].ip_port = ip_port;
971 ++dht->num_to_bootstrap; 976 ++dht->num_to_bootstrap;
972 } else { 977 } else {
973 //TODO: ipv6 vs v4 978 // TODO(irungentoo): ipv6 vs v4
974 add_to_list(dht->to_bootstrap, MAX_CLOSE_TO_BOOTSTRAP_NODES, public_key, ip_port, dht->self_public_key); 979 add_to_list(dht->to_bootstrap, MAX_CLOSE_TO_BOOTSTRAP_NODES, public_key, ip_port, dht->self_public_key);
975 } 980 }
976 } 981 }
@@ -1536,7 +1541,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1536 return 0; 1541 return 0;
1537} 1542}
1538 1543
1539/* TODO: Optimize this. */ 1544/* TODO(irungentoo): Optimize this. */
1540int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port) 1545int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1541{ 1546{
1542 uint32_t i, j; 1547 uint32_t i, j;
@@ -2113,7 +2118,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
2113 send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); 2118 send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key);
2114 } else { 2119 } else {
2115 for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { 2120 for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) {
2116 /* TODO: Improve port guessing algorithm. */ 2121 /* TODO(irungentoo): Improve port guessing algorithm. */
2117 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); 2122 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1);
2118 IP_Port pinging; 2123 IP_Port pinging;
2119 ip_copy(&pinging.ip, &ip); 2124 ip_copy(&pinging.ip, &ip);
@@ -2246,7 +2251,7 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto,
2246 return sendpacket(dht->net, sendto->ip_port, packet, len); 2251 return sendpacket(dht->net, sendto->ip_port, packet, len);
2247} 2252}
2248 2253
2249/* TODO: improve */ 2254/* TODO(irungentoo): improve */
2250static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_family_t sa_family) 2255static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_family_t sa_family)
2251{ 2256{
2252 uint32_t i; 2257 uint32_t i;
@@ -2270,7 +2275,7 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_
2270 2275
2271/* 2276/*
2272 * check how many nodes in nodes are also present in the closelist. 2277 * check how many nodes in nodes are also present in the closelist.
2273 * TODO: make this function better. 2278 * TODO(irungentoo): make this function better.
2274 */ 2279 */
2275static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) 2280static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num)
2276{ 2281{
@@ -2340,7 +2345,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
2340 Node_format nodes[MAX_SENT_NODES]; 2345 Node_format nodes[MAX_SENT_NODES];
2341 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + crypto_box_PUBLICKEYBYTES, length_nodes, 0); 2346 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + crypto_box_PUBLICKEYBYTES, length_nodes, 0);
2342 2347
2343 /* TODO: MAX_SENT_NODES nodes should be returned at all times 2348 /* TODO(irungentoo): MAX_SENT_NODES nodes should be returned at all times
2344 (right now we have a small network size so it could cause problems for testing and etc..) */ 2349 (right now we have a small network size so it could cause problems for testing and etc..) */
2345 if (num_nodes <= 0) { 2350 if (num_nodes <= 0) {
2346 return 1; 2351 return 1;
@@ -2376,7 +2381,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
2376 2381
2377#if DHT_HARDENING 2382#if DHT_HARDENING
2378/* Return a random node from all the nodes we are connected to. 2383/* Return a random node from all the nodes we are connected to.
2379 * TODO: improve this function. 2384 * TODO(irungentoo): improve this function.
2380 */ 2385 */
2381static Node_format random_node(DHT *dht, sa_family_t sa_family) 2386static Node_format random_node(DHT *dht, sa_family_t sa_family)
2382{ 2387{
@@ -2515,7 +2520,7 @@ static void do_hardening(DHT *dht)
2515 to_test.ip_port = cur_iptspng->ip_port; 2520 to_test.ip_port = cur_iptspng->ip_port;
2516 memcpy(to_test.public_key, public_key, crypto_box_PUBLICKEYBYTES); 2521 memcpy(to_test.public_key, public_key, crypto_box_PUBLICKEYBYTES);
2517 2522
2518 //TODO: The search id should maybe not be ours? 2523 // TODO(irungentoo): The search id should maybe not be ours?
2519 if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) { 2524 if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) {
2520 memcpy(cur_iptspng->hardening.send_nodes_pingedid, rand_node.public_key, crypto_box_PUBLICKEYBYTES); 2525 memcpy(cur_iptspng->hardening.send_nodes_pingedid, rand_node.public_key, crypto_box_PUBLICKEYBYTES);
2521 cur_iptspng->hardening.send_nodes_timestamp = unix_time(); 2526 cur_iptspng->hardening.send_nodes_timestamp = unix_time();
@@ -2527,7 +2532,7 @@ static void do_hardening(DHT *dht)
2527 } 2532 }
2528 } 2533 }
2529 2534
2530 //TODO: add the 2 other testers. 2535 // TODO(irungentoo): add the 2 other testers.
2531 } 2536 }
2532} 2537}
2533#endif 2538#endif
@@ -2681,7 +2686,7 @@ void kill_DHT(DHT *dht)
2681} 2686}
2682 2687
2683/* new DHT format for load/save, more robust and forward compatible */ 2688/* new DHT format for load/save, more robust and forward compatible */
2684//TODO: Move this closer to Messenger. 2689// TODO(irungentoo): Move this closer to Messenger.
2685#define DHT_STATE_COOKIE_GLOBAL 0x159000d 2690#define DHT_STATE_COOKIE_GLOBAL 0x159000d
2686 2691
2687#define DHT_STATE_COOKIE_TYPE 0x11ce 2692#define DHT_STATE_COOKIE_TYPE 0x11ce