summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-08-05 22:02:32 -0400
committerirungentoo <irungentoo@gmail.com>2015-08-05 22:02:32 -0400
commit540db7ec37c4e3d9a2f5ff76791e06727d4ff097 (patch)
tree522cd5df96aca35aa118abdea766e457724d1c73
parent1ef94e58cf7b62f4fec46e8dbe9b33293d34e2a6 (diff)
client_id -> public_key
-rw-r--r--toxcore/DHT.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index c703be4a..87b282ce 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -538,7 +538,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
538 *num_nodes_ptr = num_nodes; 538 *num_nodes_ptr = num_nodes;
539} 539}
540 540
541/* Find MAX_SENT_NODES nodes closest to the client_id for the send nodes request: 541/* Find MAX_SENT_NODES nodes closest to the public_key for the send nodes request:
542 * put them in the nodes_list and return how many were found. 542 * put them in the nodes_list and return how many were found.
543 * 543 *
544 * TODO: For the love of based <your favorite deity, in doubt use "love"> make 544 * TODO: For the love of based <your favorite deity, in doubt use "love"> make
@@ -546,28 +546,28 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
546 * 546 *
547 * want_good : do we want only good nodes as checked with the hardening returned or not? 547 * want_good : do we want only good nodes as checked with the hardening returned or not?
548 */ 548 */
549static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, 549static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list,
550 sa_family_t sa_family, uint8_t is_LAN, uint8_t want_good) 550 sa_family_t sa_family, uint8_t is_LAN, uint8_t want_good)
551{ 551{
552 uint32_t num_nodes = 0, i; 552 uint32_t num_nodes = 0, i;
553 get_close_nodes_inner(client_id, nodes_list, sa_family, 553 get_close_nodes_inner(public_key, nodes_list, sa_family,
554 dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, want_good); 554 dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, want_good);
555 555
556 /*TODO uncomment this when hardening is added to close friend clients 556 /*TODO uncomment this when hardening is added to close friend clients
557 for (i = 0; i < dht->num_friends; ++i) 557 for (i = 0; i < dht->num_friends; ++i)
558 get_close_nodes_inner(dht, client_id, nodes_list, sa_family, 558 get_close_nodes_inner(dht, public_key, nodes_list, sa_family,
559 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 559 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
560 &num_nodes, is_LAN, want_good); 560 &num_nodes, is_LAN, want_good);
561 */ 561 */
562 for (i = 0; i < dht->num_friends; ++i) 562 for (i = 0; i < dht->num_friends; ++i)
563 get_close_nodes_inner(client_id, nodes_list, sa_family, 563 get_close_nodes_inner(public_key, nodes_list, sa_family,
564 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 564 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
565 &num_nodes, is_LAN, 0); 565 &num_nodes, is_LAN, 0);
566 566
567 return num_nodes; 567 return num_nodes;
568} 568}
569 569
570int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, 570int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, sa_family_t sa_family,
571 uint8_t is_LAN, uint8_t want_good) 571 uint8_t is_LAN, uint8_t want_good)
572{ 572{
573 memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); 573 memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format));
@@ -575,7 +575,7 @@ int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes
575 575
576 if (!dht->assoc) 576 if (!dht->assoc)
577#endif 577#endif
578 return get_somewhat_close_nodes(dht, client_id, nodes_list, sa_family, is_LAN, want_good); 578 return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good);
579 579
580#ifdef ENABLE_ASSOC_DHT 580#ifdef ENABLE_ASSOC_DHT
581 //TODO: assoc, sa_family 0 (don't care if ipv4 or ipv6) support. 581 //TODO: assoc, sa_family 0 (don't care if ipv4 or ipv6) support.
@@ -586,14 +586,14 @@ int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes
586 request.count = MAX_SENT_NODES; 586 request.count = MAX_SENT_NODES;
587 request.count_good = MAX_SENT_NODES - 2; /* allow 2 'indirect' nodes */ 587 request.count_good = MAX_SENT_NODES - 2; /* allow 2 'indirect' nodes */
588 request.result = result; 588 request.result = result;
589 request.wanted_id = client_id; 589 request.wanted_id = public_key;
590 request.flags = (is_LAN ? LANOk : 0) + (sa_family == AF_INET ? ProtoIPv4 : ProtoIPv6); 590 request.flags = (is_LAN ? LANOk : 0) + (sa_family == AF_INET ? ProtoIPv4 : ProtoIPv6);
591 591
592 uint8_t num_found = Assoc_get_close_entries(dht->assoc, &request); 592 uint8_t num_found = Assoc_get_close_entries(dht->assoc, &request);
593 593
594 if (!num_found) { 594 if (!num_found) {
595 LOGGER_DEBUG("get_close_nodes(): Assoc_get_close_entries() returned zero nodes"); 595 LOGGER_DEBUG("get_close_nodes(): Assoc_get_close_entries() returned zero nodes");
596 return get_somewhat_close_nodes(dht, client_id, nodes_list, sa_family, is_LAN, want_good); 596 return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good);
597 } 597 }
598 598
599 LOGGER_DEBUG("get_close_nodes(): Assoc_get_close_entries() returned %i 'direct' and %i 'indirect' nodes", 599 LOGGER_DEBUG("get_close_nodes(): Assoc_get_close_entries() returned %i 'direct' and %i 'indirect' nodes",
@@ -605,7 +605,7 @@ int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes
605 Client_data *client = result[i]; 605 Client_data *client = result[i];
606 606
607 if (client) { 607 if (client) {
608 id_copy(nodes_list[num_returned].public_key, client->client_id); 608 id_copy(nodes_list[num_returned].public_key, client->public_key);
609 609
610 if (sa_family == AF_INET) 610 if (sa_family == AF_INET)
611 if (ipport_isset(&client->assoc4.ip_port)) { 611 if (ipport_isset(&client->assoc4.ip_port)) {
@@ -797,7 +797,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
797 797
798 DHT_Friend *friend = &dht->friends_list[i]; 798 DHT_Friend *friend = &dht->friends_list[i];
799 799
800 if (memcmp(public_key, friend->public_key, CLIENT_ID_SIZE) == 0) { 800 if (memcmp(public_key, friend->public_key, crypto_box_PUBLICKEYBYTES) == 0) {
801 friend_foundip = friend; 801 friend_foundip = friend;
802 } 802 }
803 803
@@ -806,7 +806,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
806 } else { 806 } else {
807 DHT_Friend *friend = &dht->friends_list[i]; 807 DHT_Friend *friend = &dht->friends_list[i];
808 808
809 if (memcmp(public_key, friend->public_key, CLIENT_ID_SIZE) == 0) { 809 if (memcmp(public_key, friend->public_key, crypto_box_PUBLICKEYBYTES) == 0) {
810 friend_foundip = friend; 810 friend_foundip = friend;
811 } 811 }
812 812
@@ -840,9 +840,9 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
840} 840}
841 841
842/* If public_key is a friend or us, update ret_ip_port 842/* If public_key is a friend or us, update ret_ip_port
843 * nodeclient_id is the id of the node that sent us this info. 843 * nodepublic_key is the id of the node that sent us this info.
844 */ 844 */
845static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodeclient_id) 845static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
846{ 846{
847 uint32_t i, j; 847 uint32_t i, j;
848 uint64_t temp_time = unix_time(); 848 uint64_t temp_time = unix_time();
@@ -857,7 +857,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key
857 857
858 if (id_equal(public_key, dht->self_public_key)) { 858 if (id_equal(public_key, dht->self_public_key)) {
859 for (i = 0; i < LCLIENT_LIST; ++i) { 859 for (i = 0; i < LCLIENT_LIST; ++i) {
860 if (id_equal(nodeclient_id, dht->close_clientlist[i].public_key)) { 860 if (id_equal(nodepublic_key, dht->close_clientlist[i].public_key)) {
861 if (ip_port.ip.family == AF_INET) { 861 if (ip_port.ip.family == AF_INET) {
862 dht->close_clientlist[i].assoc4.ret_ip_port = ip_port; 862 dht->close_clientlist[i].assoc4.ret_ip_port = ip_port;
863 dht->close_clientlist[i].assoc4.ret_timestamp = temp_time; 863 dht->close_clientlist[i].assoc4.ret_timestamp = temp_time;
@@ -874,7 +874,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key
874 for (i = 0; i < dht->num_friends; ++i) { 874 for (i = 0; i < dht->num_friends; ++i) {
875 if (id_equal(public_key, dht->friends_list[i].public_key)) { 875 if (id_equal(public_key, dht->friends_list[i].public_key)) {
876 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { 876 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
877 if (id_equal(nodeclient_id, dht->friends_list[i].client_list[j].public_key)) { 877 if (id_equal(nodepublic_key, dht->friends_list[i].client_list[j].public_key)) {
878 if (ip_port.ip.family == AF_INET) { 878 if (ip_port.ip.family == AF_INET) {
879 dht->friends_list[i].client_list[j].assoc4.ret_ip_port = ip_port; 879 dht->friends_list[i].client_list[j].assoc4.ret_ip_port = ip_port;
880 dht->friends_list[i].client_list[j].assoc4.ret_timestamp = temp_time; 880 dht->friends_list[i].client_list[j].assoc4.ret_timestamp = temp_time;
@@ -1047,7 +1047,7 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
1047} 1047}
1048/* return 0 if no 1048/* return 0 if no
1049 return 1 if yes */ 1049 return 1 if yes */
1050static uint8_t sent_getnode_to_node(DHT *dht, const uint8_t *client_id, IP_Port node_ip_port, uint64_t ping_id, 1050static uint8_t sent_getnode_to_node(DHT *dht, const uint8_t *public_key, IP_Port node_ip_port, uint64_t ping_id,
1051 Node_format *sendback_node) 1051 Node_format *sendback_node)
1052{ 1052{
1053 uint8_t data[sizeof(Node_format) * 2]; 1053 uint8_t data[sizeof(Node_format) * 2];
@@ -1063,7 +1063,7 @@ static uint8_t sent_getnode_to_node(DHT *dht, const uint8_t *client_id, IP_Port
1063 Node_format test; 1063 Node_format test;
1064 memcpy(&test, data, sizeof(Node_format)); 1064 memcpy(&test, data, sizeof(Node_format));
1065 1065
1066 if (!ipport_equal(&test.ip_port, &node_ip_port) || memcmp(test.public_key, client_id, CLIENT_ID_SIZE) != 0) 1066 if (!ipport_equal(&test.ip_port, &node_ip_port) || memcmp(test.public_key, public_key, crypto_box_PUBLICKEYBYTES) != 0)
1067 return 0; 1067 return 0;
1068 1068
1069 return 1; 1069 return 1;