diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 198 | ||||
-rw-r--r-- | toxcore/DHT.h | 57 | ||||
-rw-r--r-- | toxcore/Messenger.c | 8 | ||||
-rw-r--r-- | toxcore/assoc.c | 24 | ||||
-rw-r--r-- | toxcore/ping.c | 32 | ||||
-rw-r--r-- | toxcore/ping.h | 6 |
6 files changed, 163 insertions, 162 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 12789098..e21ff824 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -65,21 +65,21 @@ | |||
65 | /* Number of get node requests to send to quickly find close nodes. */ | 65 | /* Number of get node requests to send to quickly find close nodes. */ |
66 | #define MAX_BOOTSTRAP_TIMES 10 | 66 | #define MAX_BOOTSTRAP_TIMES 10 |
67 | 67 | ||
68 | /* Compares client_id1 and client_id2 with client_id. | 68 | /* Compares pk1 and pk2 with pk. |
69 | * | 69 | * |
70 | * return 0 if both are same distance. | 70 | * return 0 if both are same distance. |
71 | * return 1 if client_id1 is closer. | 71 | * return 1 if pk1 is closer. |
72 | * return 2 if client_id2 is closer. | 72 | * return 2 if pk2 is closer. |
73 | */ | 73 | */ |
74 | int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) | 74 | int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2) |
75 | { | 75 | { |
76 | size_t i; | 76 | size_t i; |
77 | uint8_t distance1, distance2; | 77 | uint8_t distance1, distance2; |
78 | 78 | ||
79 | for (i = 0; i < CLIENT_ID_SIZE; ++i) { | 79 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { |
80 | 80 | ||
81 | distance1 = id[i] ^ id1[i]; | 81 | distance1 = pk[i] ^ pk1[i]; |
82 | distance2 = id[i] ^ id2[i]; | 82 | distance2 = pk[i] ^ pk2[i]; |
83 | 83 | ||
84 | if (distance1 < distance2) | 84 | if (distance1 < distance2) |
85 | return 1; | 85 | return 1; |
@@ -97,15 +97,15 @@ int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) | |||
97 | * If shared key is already in shared_keys, copy it to shared_key. | 97 | * If shared key is already in shared_keys, copy it to shared_key. |
98 | * else generate it into shared_key and copy it to shared_keys | 98 | * else generate it into shared_key and copy it to shared_keys |
99 | */ | 99 | */ |
100 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *client_id) | 100 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *public_key) |
101 | { | 101 | { |
102 | uint32_t i, num = ~0, curr = 0; | 102 | uint32_t i, num = ~0, curr = 0; |
103 | 103 | ||
104 | for (i = 0; i < MAX_KEYS_PER_SLOT; ++i) { | 104 | for (i = 0; i < MAX_KEYS_PER_SLOT; ++i) { |
105 | int index = client_id[30] * MAX_KEYS_PER_SLOT + i; | 105 | int index = public_key[30] * MAX_KEYS_PER_SLOT + i; |
106 | 106 | ||
107 | if (shared_keys->keys[index].stored) { | 107 | if (shared_keys->keys[index].stored) { |
108 | if (memcmp(client_id, shared_keys->keys[index].client_id, CLIENT_ID_SIZE) == 0) { | 108 | if (memcmp(public_key, shared_keys->keys[index].public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
109 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); | 109 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); |
110 | ++shared_keys->keys[index].times_requested; | 110 | ++shared_keys->keys[index].times_requested; |
111 | shared_keys->keys[index].time_last_requested = unix_time(); | 111 | shared_keys->keys[index].time_last_requested = unix_time(); |
@@ -129,31 +129,31 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t | |||
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | encrypt_precompute(client_id, secret_key, shared_key); | 132 | encrypt_precompute(public_key, secret_key, shared_key); |
133 | 133 | ||
134 | if (num != (uint32_t)~0) { | 134 | if (num != (uint32_t)~0) { |
135 | shared_keys->keys[curr].stored = 1; | 135 | shared_keys->keys[curr].stored = 1; |
136 | shared_keys->keys[curr].times_requested = 1; | 136 | shared_keys->keys[curr].times_requested = 1; |
137 | memcpy(shared_keys->keys[curr].client_id, client_id, CLIENT_ID_SIZE); | 137 | memcpy(shared_keys->keys[curr].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
138 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); | 138 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); |
139 | shared_keys->keys[curr].time_last_requested = unix_time(); | 139 | shared_keys->keys[curr].time_last_requested = unix_time(); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 143 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
144 | * for packets that we receive. | 144 | * for packets that we receive. |
145 | */ | 145 | */ |
146 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *client_id) | 146 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key) |
147 | { | 147 | { |
148 | get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, client_id); | 148 | get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, public_key); |
149 | } | 149 | } |
150 | 150 | ||
151 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 151 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
152 | * for packets that we send. | 152 | * for packets that we send. |
153 | */ | 153 | */ |
154 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *client_id) | 154 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key) |
155 | { | 155 | { |
156 | get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, client_id); | 156 | get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, public_key); |
157 | } | 157 | } |
158 | 158 | ||
159 | void to_net_family(IP *ip) | 159 | void to_net_family(IP *ip) |
@@ -333,21 +333,21 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed | |||
333 | 333 | ||
334 | 334 | ||
335 | 335 | ||
336 | /* Check if client with client_id is already in list of length length. | 336 | /* Check if client with public_key is already in list of length length. |
337 | * If it is then set its corresponding timestamp to current time. | 337 | * If it is then set its corresponding timestamp to current time. |
338 | * If the id is already in the list with a different ip_port, update it. | 338 | * If the id is already in the list with a different ip_port, update it. |
339 | * TODO: Maybe optimize this. | 339 | * TODO: Maybe optimize this. |
340 | * | 340 | * |
341 | * return True(1) or False(0) | 341 | * return True(1) or False(0) |
342 | */ | 342 | */ |
343 | static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const uint8_t *client_id, IP_Port ip_port) | 343 | static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const uint8_t *public_key, IP_Port ip_port) |
344 | { | 344 | { |
345 | uint32_t i; | 345 | uint32_t i; |
346 | uint64_t temp_time = unix_time(); | 346 | uint64_t temp_time = unix_time(); |
347 | 347 | ||
348 | /* if client_id is in list, find it and maybe overwrite ip_port */ | 348 | /* if public_key is in list, find it and maybe overwrite ip_port */ |
349 | for (i = 0; i < length; ++i) | 349 | for (i = 0; i < length; ++i) |
350 | if (id_equal(list[i].client_id, client_id)) { | 350 | if (id_equal(list[i].public_key, public_key)) { |
351 | /* Refresh the client timestamp. */ | 351 | /* Refresh the client timestamp. */ |
352 | if (ip_port.ip.family == AF_INET) { | 352 | if (ip_port.ip.family == AF_INET) { |
353 | 353 | ||
@@ -382,18 +382,18 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u | |||
382 | return 1; | 382 | return 1; |
383 | } | 383 | } |
384 | 384 | ||
385 | /* client_id not in list yet: see if we can find an identical ip_port, in | 385 | /* public_key not in list yet: see if we can find an identical ip_port, in |
386 | * that case we kill the old client_id by overwriting it with the new one | 386 | * that case we kill the old public_key by overwriting it with the new one |
387 | * TODO: maybe we SHOULDN'T do that if that client_id is in a friend_list | 387 | * TODO: maybe we SHOULDN'T do that if that public_key is in a friend_list |
388 | * and the one who is the actual friend's client_id/address set? */ | 388 | * and the one who is the actual friend's public_key/address set? */ |
389 | for (i = 0; i < length; ++i) { | 389 | for (i = 0; i < length; ++i) { |
390 | /* MAYBE: check the other address, if valid, don't nuke? */ | 390 | /* MAYBE: check the other address, if valid, don't nuke? */ |
391 | if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { | 391 | if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { |
392 | /* Initialize client timestamp. */ | 392 | /* Initialize client timestamp. */ |
393 | list[i].assoc4.timestamp = temp_time; | 393 | list[i].assoc4.timestamp = temp_time; |
394 | memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); | 394 | memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
395 | 395 | ||
396 | LOGGER_DEBUG("coipil[%u]: switching client_id (ipv4)", i); | 396 | LOGGER_DEBUG("coipil[%u]: switching public_key (ipv4)", i); |
397 | 397 | ||
398 | /* kill the other address, if it was set */ | 398 | /* kill the other address, if it was set */ |
399 | memset(&list[i].assoc6, 0, sizeof(list[i].assoc6)); | 399 | memset(&list[i].assoc6, 0, sizeof(list[i].assoc6)); |
@@ -401,9 +401,9 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u | |||
401 | } else if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { | 401 | } else if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { |
402 | /* Initialize client timestamp. */ | 402 | /* Initialize client timestamp. */ |
403 | list[i].assoc6.timestamp = temp_time; | 403 | list[i].assoc6.timestamp = temp_time; |
404 | memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); | 404 | memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
405 | 405 | ||
406 | LOGGER_DEBUG("coipil[%u]: switching client_id (ipv6)", i); | 406 | LOGGER_DEBUG("coipil[%u]: switching public_key (ipv6)", i); |
407 | 407 | ||
408 | /* kill the other address, if it was set */ | 408 | /* kill the other address, if it was set */ |
409 | memset(&list[i].assoc4, 0, sizeof(list[i].assoc4)); | 409 | memset(&list[i].assoc4, 0, sizeof(list[i].assoc4)); |
@@ -414,7 +414,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u | |||
414 | return 0; | 414 | return 0; |
415 | } | 415 | } |
416 | 416 | ||
417 | /* Check if client with client_id is already in node format list of length length. | 417 | /* Check if client with public_key is already in node format list of length length. |
418 | * | 418 | * |
419 | * return 1 if true. | 419 | * return 1 if true. |
420 | * return 0 if false. | 420 | * return 0 if false. |
@@ -431,15 +431,15 @@ static int client_in_nodelist(const Node_format *list, uint16_t length, const ui | |||
431 | return 0; | 431 | return 0; |
432 | } | 432 | } |
433 | 433 | ||
434 | /* return friend number from the client_id. | 434 | /* return friend number from the public_key. |
435 | * return -1 if a failure occurs. | 435 | * return -1 if a failure occurs. |
436 | */ | 436 | */ |
437 | static int friend_number(const DHT *dht, const uint8_t *client_id) | 437 | static int friend_number(const DHT *dht, const uint8_t *public_key) |
438 | { | 438 | { |
439 | uint32_t i; | 439 | uint32_t i; |
440 | 440 | ||
441 | for (i = 0; i < dht->num_friends; ++i) { | 441 | for (i = 0; i < dht->num_friends; ++i) { |
442 | if (id_equal(dht->friends_list[i].client_id, client_id)) | 442 | if (id_equal(dht->friends_list[i].public_key, public_key)) |
443 | return i; | 443 | return i; |
444 | } | 444 | } |
445 | 445 | ||
@@ -461,7 +461,7 @@ static uint8_t hardening_correct(const Hardening *h) | |||
461 | /* | 461 | /* |
462 | * helper for get_close_nodes(). argument list is a monster :D | 462 | * helper for get_close_nodes(). argument list is a monster :D |
463 | */ | 463 | */ |
464 | static void get_close_nodes_inner(const uint8_t *client_id, Node_format *nodes_list, | 464 | static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_list, |
465 | sa_family_t sa_family, const Client_data *client_list, uint32_t client_list_length, | 465 | sa_family_t sa_family, const Client_data *client_list, uint32_t client_list_length, |
466 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) | 466 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) |
467 | { | 467 | { |
@@ -476,7 +476,7 @@ static void get_close_nodes_inner(const uint8_t *client_id, Node_format *nodes_l | |||
476 | const Client_data *client = &client_list[i]; | 476 | const Client_data *client = &client_list[i]; |
477 | 477 | ||
478 | /* node already in list? */ | 478 | /* node already in list? */ |
479 | if (client_in_nodelist(nodes_list, MAX_SENT_NODES, client->client_id)) | 479 | if (client_in_nodelist(nodes_list, MAX_SENT_NODES, client->public_key)) |
480 | continue; | 480 | continue; |
481 | 481 | ||
482 | const IPPTsPng *ipptp = NULL; | 482 | const IPPTsPng *ipptp = NULL; |
@@ -502,30 +502,30 @@ static void get_close_nodes_inner(const uint8_t *client_id, Node_format *nodes_l | |||
502 | continue; | 502 | continue; |
503 | 503 | ||
504 | if (LAN_ip(ipptp->ip_port.ip) != 0 && want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK | 504 | if (LAN_ip(ipptp->ip_port.ip) != 0 && want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK |
505 | && !id_equal(client_id, client->client_id)) | 505 | && !id_equal(public_key, client->public_key)) |
506 | continue; | 506 | continue; |
507 | 507 | ||
508 | if (num_nodes < MAX_SENT_NODES) { | 508 | if (num_nodes < MAX_SENT_NODES) { |
509 | memcpy(nodes_list[num_nodes].public_key, | 509 | memcpy(nodes_list[num_nodes].public_key, |
510 | client->client_id, | 510 | client->public_key, |
511 | crypto_box_PUBLICKEYBYTES ); | 511 | crypto_box_PUBLICKEYBYTES ); |
512 | 512 | ||
513 | nodes_list[num_nodes].ip_port = ipptp->ip_port; | 513 | nodes_list[num_nodes].ip_port = ipptp->ip_port; |
514 | num_nodes++; | 514 | num_nodes++; |
515 | } else { | 515 | } else { |
516 | /* see if node_list contains a client_id that's "further away" | 516 | /* see if node_list contains a public_key that's "further away" |
517 | * compared to the one we're looking at at the moment, if there | 517 | * compared to the one we're looking at at the moment, if there |
518 | * is, replace it | 518 | * is, replace it |
519 | */ | 519 | */ |
520 | for (j = 0; j < MAX_SENT_NODES; ++j) { | 520 | for (j = 0; j < MAX_SENT_NODES; ++j) { |
521 | closest = id_closest( client_id, | 521 | closest = id_closest( public_key, |
522 | nodes_list[j].public_key, | 522 | nodes_list[j].public_key, |
523 | client->client_id ); | 523 | client->public_key ); |
524 | 524 | ||
525 | /* second client_id is closer than current: change to it */ | 525 | /* second public_key is closer than current: change to it */ |
526 | if (closest == 2) { | 526 | if (closest == 2) { |
527 | memcpy( nodes_list[j].public_key, | 527 | memcpy( nodes_list[j].public_key, |
528 | client->client_id, | 528 | client->public_key, |
529 | crypto_box_PUBLICKEYBYTES); | 529 | crypto_box_PUBLICKEYBYTES); |
530 | 530 | ||
531 | nodes_list[j].ip_port = ipptp->ip_port; | 531 | nodes_list[j].ip_port = ipptp->ip_port; |
@@ -658,7 +658,7 @@ static int cmp_dht_entry(const void *a, const void *b) | |||
658 | return 1; | 658 | return 1; |
659 | } | 659 | } |
660 | 660 | ||
661 | int close = id_closest(cmp_public_key, entry1.client_id, entry2.client_id); | 661 | int close = id_closest(cmp_public_key, entry1.public_key, entry2.public_key); |
662 | 662 | ||
663 | if (close == 1) | 663 | if (close == 1) |
664 | return 1; | 664 | return 1; |
@@ -669,15 +669,15 @@ static int cmp_dht_entry(const void *a, const void *b) | |||
669 | return 0; | 669 | return 0; |
670 | } | 670 | } |
671 | 671 | ||
672 | /* Is it ok to store node with client_id in client. | 672 | /* Is it ok to store node with public_key in client. |
673 | * | 673 | * |
674 | * return 0 if node can't be stored. | 674 | * return 0 if node can't be stored. |
675 | * return 1 if it can. | 675 | * return 1 if it can. |
676 | */ | 676 | */ |
677 | static unsigned int store_node_ok(const Client_data *client, const uint8_t *client_id, const uint8_t *comp_client_id) | 677 | static unsigned int store_node_ok(const Client_data *client, const uint8_t *public_key, const uint8_t *comp_client_id) |
678 | { | 678 | { |
679 | if ((is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)) | 679 | if ((is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)) |
680 | || (id_closest(comp_client_id, client->client_id, client_id) == 2)) { | 680 | || (id_closest(comp_client_id, client->public_key, public_key) == 2)) { |
681 | return 1; | 681 | return 1; |
682 | } else { | 682 | } else { |
683 | return 0; | 683 | return 0; |
@@ -690,16 +690,16 @@ static unsigned int store_node_ok(const Client_data *client, const uint8_t *clie | |||
690 | * from the comp_client_id | 690 | * from the comp_client_id |
691 | * or replace a good node that is further | 691 | * or replace a good node that is further |
692 | * than any other in the list from the comp_client_id | 692 | * than any other in the list from the comp_client_id |
693 | * and further than client_id. | 693 | * and further than public_key. |
694 | * | 694 | * |
695 | * Do not replace any node if the list has no bad or possibly bad nodes | 695 | * Do not replace any node if the list has no bad or possibly bad nodes |
696 | * and all nodes in the list are closer to comp_client_id | 696 | * and all nodes in the list are closer to comp_client_id |
697 | * than client_id. | 697 | * than public_key. |
698 | * | 698 | * |
699 | * returns True(1) when the item was stored, False(0) otherwise */ | 699 | * returns True(1) when the item was stored, False(0) otherwise */ |
700 | static int replace_all( Client_data *list, | 700 | static int replace_all( Client_data *list, |
701 | uint16_t length, | 701 | uint16_t length, |
702 | const uint8_t *client_id, | 702 | const uint8_t *public_key, |
703 | IP_Port ip_port, | 703 | IP_Port ip_port, |
704 | const uint8_t *comp_client_id ) | 704 | const uint8_t *comp_client_id ) |
705 | { | 705 | { |
@@ -711,7 +711,7 @@ static int replace_all( Client_data *list, | |||
711 | 711 | ||
712 | Client_data *client = &list[0]; | 712 | Client_data *client = &list[0]; |
713 | 713 | ||
714 | if (store_node_ok(client, client_id, comp_client_id)) { | 714 | if (store_node_ok(client, public_key, comp_client_id)) { |
715 | IPPTsPng *ipptp_write = NULL; | 715 | IPPTsPng *ipptp_write = NULL; |
716 | IPPTsPng *ipptp_clear = NULL; | 716 | IPPTsPng *ipptp_clear = NULL; |
717 | 717 | ||
@@ -723,7 +723,7 @@ static int replace_all( Client_data *list, | |||
723 | ipptp_clear = &client->assoc4; | 723 | ipptp_clear = &client->assoc4; |
724 | } | 724 | } |
725 | 725 | ||
726 | id_copy(client->client_id, client_id); | 726 | id_copy(client->public_key, public_key); |
727 | ipptp_write->ip_port = ip_port; | 727 | ipptp_write->ip_port = ip_port; |
728 | ipptp_write->timestamp = unix_time(); | 728 | ipptp_write->timestamp = unix_time(); |
729 | 729 | ||
@@ -740,22 +740,22 @@ static int replace_all( Client_data *list, | |||
740 | return 0; | 740 | return 0; |
741 | } | 741 | } |
742 | 742 | ||
743 | /* Check if the node obtained with a get_nodes with client_id should be pinged. | 743 | /* Check if the node obtained with a get_nodes with public_key should be pinged. |
744 | * NOTE: for best results call it after addto_lists; | 744 | * NOTE: for best results call it after addto_lists; |
745 | * | 745 | * |
746 | * return 0 if the node should not be pinged. | 746 | * return 0 if the node should not be pinged. |
747 | * return 1 if it should. | 747 | * return 1 if it should. |
748 | */ | 748 | */ |
749 | static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *client_id) | 749 | static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key) |
750 | { | 750 | { |
751 | if (store_node_ok(&dht->close_clientlist[0], client_id, dht->self_public_key)) { | 751 | if (store_node_ok(&dht->close_clientlist[0], public_key, dht->self_public_key)) { |
752 | return 1; | 752 | return 1; |
753 | } | 753 | } |
754 | 754 | ||
755 | unsigned int i; | 755 | unsigned int i; |
756 | 756 | ||
757 | for (i = 0; i < dht->num_friends; ++i) { | 757 | for (i = 0; i < dht->num_friends; ++i) { |
758 | if (store_node_ok(&dht->friends_list[i].client_list[0], client_id, dht->self_public_key)) { | 758 | if (store_node_ok(&dht->friends_list[i].client_list[0], public_key, dht->self_public_key)) { |
759 | return 1; | 759 | return 1; |
760 | } | 760 | } |
761 | } | 761 | } |
@@ -763,12 +763,12 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *client_i | |||
763 | return 0; | 763 | return 0; |
764 | } | 764 | } |
765 | 765 | ||
766 | /* Attempt to add client with ip_port and client_id to the friends client list | 766 | /* Attempt to add client with ip_port and public_key to the friends client list |
767 | * and close_clientlist. | 767 | * and close_clientlist. |
768 | * | 768 | * |
769 | * returns 1+ if the item is used in any list, 0 else | 769 | * returns 1+ if the item is used in any list, 0 else |
770 | */ | 770 | */ |
771 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id) | 771 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key) |
772 | { | 772 | { |
773 | uint32_t i, used = 0; | 773 | uint32_t i, used = 0; |
774 | 774 | ||
@@ -781,8 +781,8 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id) | |||
781 | /* NOTE: Current behavior if there are two clients with the same id is | 781 | /* NOTE: Current behavior if there are two clients with the same id is |
782 | * to replace the first ip by the second. | 782 | * to replace the first ip by the second. |
783 | */ | 783 | */ |
784 | if (!client_or_ip_port_in_list(dht->close_clientlist, LCLIENT_LIST, client_id, ip_port)) { | 784 | if (!client_or_ip_port_in_list(dht->close_clientlist, LCLIENT_LIST, public_key, ip_port)) { |
785 | if (replace_all(dht->close_clientlist, LCLIENT_LIST, client_id, ip_port, dht->self_public_key)) | 785 | if (replace_all(dht->close_clientlist, LCLIENT_LIST, public_key, ip_port, dht->self_public_key)) |
786 | used++; | 786 | used++; |
787 | } else | 787 | } else |
788 | used++; | 788 | used++; |
@@ -791,13 +791,13 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id) | |||
791 | 791 | ||
792 | for (i = 0; i < dht->num_friends; ++i) { | 792 | for (i = 0; i < dht->num_friends; ++i) { |
793 | if (!client_or_ip_port_in_list(dht->friends_list[i].client_list, | 793 | if (!client_or_ip_port_in_list(dht->friends_list[i].client_list, |
794 | MAX_FRIEND_CLIENTS, client_id, ip_port)) { | 794 | MAX_FRIEND_CLIENTS, public_key, ip_port)) { |
795 | if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, | 795 | if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, |
796 | client_id, ip_port, dht->friends_list[i].client_id)) { | 796 | public_key, ip_port, dht->friends_list[i].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(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) { | 800 | if (memcmp(public_key, friend->public_key, CLIENT_ID_SIZE) == 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 *client_id) | |||
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(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) { | 809 | if (memcmp(public_key, friend->public_key, CLIENT_ID_SIZE) == 0) { |
810 | friend_foundip = friend; | 810 | friend_foundip = friend; |
811 | } | 811 | } |
812 | 812 | ||
@@ -832,17 +832,17 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id) | |||
832 | ippts.ip_port = ip_port; | 832 | ippts.ip_port = ip_port; |
833 | ippts.timestamp = unix_time(); | 833 | ippts.timestamp = unix_time(); |
834 | 834 | ||
835 | Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); | 835 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, used ? 1 : 0); |
836 | } | 836 | } |
837 | 837 | ||
838 | #endif | 838 | #endif |
839 | return used; | 839 | return used; |
840 | } | 840 | } |
841 | 841 | ||
842 | /* If client_id 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 | * nodeclient_id is the id of the node that sent us this info. |
844 | */ | 844 | */ |
845 | static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *client_id, const uint8_t *nodeclient_id) | 845 | static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodeclient_id) |
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(); |
@@ -855,9 +855,9 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *client_id, | |||
855 | ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; | 855 | ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; |
856 | } | 856 | } |
857 | 857 | ||
858 | if (id_equal(client_id, 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].client_id)) { | 860 | if (id_equal(nodeclient_id, 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; |
@@ -872,9 +872,9 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *client_id, | |||
872 | } | 872 | } |
873 | } else { | 873 | } else { |
874 | for (i = 0; i < dht->num_friends; ++i) { | 874 | for (i = 0; i < dht->num_friends; ++i) { |
875 | if (id_equal(client_id, dht->friends_list[i].client_id)) { | 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].client_id)) { | 877 | if (id_equal(nodeclient_id, 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; |
@@ -900,7 +900,7 @@ end: | |||
900 | ippts.timestamp = temp_time; | 900 | ippts.timestamp = temp_time; |
901 | /* this is only a hear-say entry, so ret-ipp is NULL, but used is required | 901 | /* this is only a hear-say entry, so ret-ipp is NULL, but used is required |
902 | * to decide how valuable it is ("used" may throw an "unused" entry out) */ | 902 | * to decide how valuable it is ("used" may throw an "unused" entry out) */ |
903 | Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); | 903 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, used ? 1 : 0); |
904 | } | 904 | } |
905 | 905 | ||
906 | #endif | 906 | #endif |
@@ -1197,7 +1197,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *client_id, void (*ip_callback)(void * | |||
1197 | dht->friends_list = temp; | 1197 | dht->friends_list = temp; |
1198 | DHT_Friend *friend = &dht->friends_list[dht->num_friends]; | 1198 | DHT_Friend *friend = &dht->friends_list[dht->num_friends]; |
1199 | memset(friend, 0, sizeof(DHT_Friend)); | 1199 | memset(friend, 0, sizeof(DHT_Friend)); |
1200 | memcpy(friend->client_id, client_id, CLIENT_ID_SIZE); | 1200 | memcpy(friend->public_key, client_id, CLIENT_ID_SIZE); |
1201 | 1201 | ||
1202 | friend->nat.NATping_id = random_64b(); | 1202 | friend->nat.NATping_id = random_64b(); |
1203 | ++dht->num_friends; | 1203 | ++dht->num_friends; |
@@ -1291,7 +1291,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *client_id, uint16_t lock_count) | |||
1291 | } | 1291 | } |
1292 | 1292 | ||
1293 | /* TODO: Optimize this. */ | 1293 | /* TODO: Optimize this. */ |
1294 | int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port) | 1294 | int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port) |
1295 | { | 1295 | { |
1296 | uint32_t i, j; | 1296 | uint32_t i, j; |
1297 | 1297 | ||
@@ -1300,11 +1300,11 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port) | |||
1300 | 1300 | ||
1301 | for (i = 0; i < dht->num_friends; ++i) { | 1301 | for (i = 0; i < dht->num_friends; ++i) { |
1302 | /* Equal */ | 1302 | /* Equal */ |
1303 | if (id_equal(dht->friends_list[i].client_id, client_id)) { | 1303 | if (id_equal(dht->friends_list[i].public_key, public_key)) { |
1304 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { | 1304 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { |
1305 | Client_data *client = &dht->friends_list[i].client_list[j]; | 1305 | Client_data *client = &dht->friends_list[i].client_list[j]; |
1306 | 1306 | ||
1307 | if (id_equal(client->client_id, client_id)) { | 1307 | if (id_equal(client->public_key, public_key)) { |
1308 | IPPTsPng *assoc = NULL; | 1308 | IPPTsPng *assoc = NULL; |
1309 | uint32_t a; | 1309 | uint32_t a; |
1310 | 1310 | ||
@@ -1324,7 +1324,7 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port) | |||
1324 | } | 1324 | } |
1325 | 1325 | ||
1326 | /* returns number of nodes not in kill-timeout */ | 1326 | /* returns number of nodes not in kill-timeout */ |
1327 | static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *client_id, | 1327 | static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key, |
1328 | Client_data *list, uint32_t list_count, uint32_t *bootstrap_times) | 1328 | Client_data *list, uint32_t list_count, uint32_t *bootstrap_times) |
1329 | { | 1329 | { |
1330 | uint32_t i; | 1330 | uint32_t i; |
@@ -1346,7 +1346,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co | |||
1346 | not_kill++; | 1346 | not_kill++; |
1347 | 1347 | ||
1348 | if (is_timeout(assoc->last_pinged, PING_INTERVAL)) { | 1348 | if (is_timeout(assoc->last_pinged, PING_INTERVAL)) { |
1349 | send_ping_request(dht->ping, assoc->ip_port, client->client_id ); | 1349 | send_ping_request(dht->ping, assoc->ip_port, client->public_key ); |
1350 | assoc->last_pinged = temp_time; | 1350 | assoc->last_pinged = temp_time; |
1351 | } | 1351 | } |
1352 | 1352 | ||
@@ -1361,8 +1361,8 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co | |||
1361 | 1361 | ||
1362 | if ((num_nodes != 0) && (is_timeout(*lastgetnode, GET_NODE_INTERVAL) || *bootstrap_times < MAX_BOOTSTRAP_TIMES)) { | 1362 | if ((num_nodes != 0) && (is_timeout(*lastgetnode, GET_NODE_INTERVAL) || *bootstrap_times < MAX_BOOTSTRAP_TIMES)) { |
1363 | uint32_t rand_node = rand() % num_nodes; | 1363 | uint32_t rand_node = rand() % num_nodes; |
1364 | getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->client_id, | 1364 | getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, |
1365 | client_id, NULL); | 1365 | public_key, NULL); |
1366 | *lastgetnode = temp_time; | 1366 | *lastgetnode = temp_time; |
1367 | ++*bootstrap_times; | 1367 | ++*bootstrap_times; |
1368 | } | 1368 | } |
@@ -1378,7 +1378,7 @@ static void do_DHT_friends(DHT *dht) | |||
1378 | uint32_t i; | 1378 | uint32_t i; |
1379 | 1379 | ||
1380 | for (i = 0; i < dht->num_friends; ++i) | 1380 | for (i = 0; i < dht->num_friends; ++i) |
1381 | do_ping_and_sendnode_requests(dht, &dht->friends_list[i].lastgetnode, dht->friends_list[i].client_id, | 1381 | do_ping_and_sendnode_requests(dht, &dht->friends_list[i].lastgetnode, dht->friends_list[i].public_key, |
1382 | dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &dht->friends_list[i].bootstrap_times); | 1382 | dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &dht->friends_list[i].bootstrap_times); |
1383 | } | 1383 | } |
1384 | 1384 | ||
@@ -1459,16 +1459,16 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable | |||
1459 | return 0; | 1459 | return 0; |
1460 | } | 1460 | } |
1461 | 1461 | ||
1462 | /* Send the given packet to node with client_id | 1462 | /* Send the given packet to node with public_key |
1463 | * | 1463 | * |
1464 | * return -1 if failure. | 1464 | * return -1 if failure. |
1465 | */ | 1465 | */ |
1466 | int route_packet(const DHT *dht, const uint8_t *client_id, const uint8_t *packet, uint16_t length) | 1466 | int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length) |
1467 | { | 1467 | { |
1468 | uint32_t i; | 1468 | uint32_t i; |
1469 | 1469 | ||
1470 | for (i = 0; i < LCLIENT_LIST; ++i) { | 1470 | for (i = 0; i < LCLIENT_LIST; ++i) { |
1471 | if (id_equal(client_id, dht->close_clientlist[i].client_id)) { | 1471 | if (id_equal(public_key, dht->close_clientlist[i].public_key)) { |
1472 | const Client_data *client = &dht->close_clientlist[i]; | 1472 | const Client_data *client = &dht->close_clientlist[i]; |
1473 | 1473 | ||
1474 | if (ip_isset(&client->assoc6.ip_port.ip)) | 1474 | if (ip_isset(&client->assoc6.ip_port.ip)) |
@@ -1517,7 +1517,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n | |||
1517 | ++num_ipv6s; | 1517 | ++num_ipv6s; |
1518 | } | 1518 | } |
1519 | 1519 | ||
1520 | if (id_equal(client->client_id, friend->client_id)) | 1520 | if (id_equal(client->public_key, friend->public_key)) |
1521 | if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT)) | 1521 | if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT)) |
1522 | return 0; /* direct connectivity */ | 1522 | return 0; /* direct connectivity */ |
1523 | } | 1523 | } |
@@ -1792,7 +1792,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1792 | IP_Port pinging; | 1792 | IP_Port pinging; |
1793 | ip_copy(&pinging.ip, &ip); | 1793 | ip_copy(&pinging.ip, &ip); |
1794 | pinging.port = htons(firstport); | 1794 | pinging.port = htons(firstport); |
1795 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | 1795 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); |
1796 | } else { | 1796 | } else { |
1797 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { | 1797 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { |
1798 | /* TODO: Improve port guessing algorithm. */ | 1798 | /* TODO: Improve port guessing algorithm. */ |
@@ -1800,7 +1800,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1800 | IP_Port pinging; | 1800 | IP_Port pinging; |
1801 | ip_copy(&pinging.ip, &ip); | 1801 | ip_copy(&pinging.ip, &ip); |
1802 | pinging.port = htons(port); | 1802 | pinging.port = htons(port); |
1803 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | 1803 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); |
1804 | } | 1804 | } |
1805 | 1805 | ||
1806 | dht->friends_list[friend_num].nat.punching_index = i; | 1806 | dht->friends_list[friend_num].nat.punching_index = i; |
@@ -1814,7 +1814,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1814 | 1814 | ||
1815 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { | 1815 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { |
1816 | pinging.port = htons(port + i); | 1816 | pinging.port = htons(port + i); |
1817 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | 1817 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); |
1818 | } | 1818 | } |
1819 | 1819 | ||
1820 | dht->friends_list[friend_num].nat.punching_index2 = i - (MAX_PUNCHING_PORTS / 2); | 1820 | dht->friends_list[friend_num].nat.punching_index2 = i - (MAX_PUNCHING_PORTS / 2); |
@@ -1837,7 +1837,7 @@ static void do_NAT(DHT *dht) | |||
1837 | continue; | 1837 | continue; |
1838 | 1838 | ||
1839 | if (dht->friends_list[i].nat.NATping_timestamp + PUNCH_INTERVAL < temp_time) { | 1839 | if (dht->friends_list[i].nat.NATping_timestamp + PUNCH_INTERVAL < temp_time) { |
1840 | send_NATping(dht, dht->friends_list[i].client_id, dht->friends_list[i].nat.NATping_id, NAT_PING_REQUEST); | 1840 | send_NATping(dht, dht->friends_list[i].public_key, dht->friends_list[i].nat.NATping_id, NAT_PING_REQUEST); |
1841 | dht->friends_list[i].nat.NATping_timestamp = temp_time; | 1841 | dht->friends_list[i].nat.NATping_timestamp = temp_time; |
1842 | } | 1842 | } |
1843 | 1843 | ||
@@ -1921,12 +1921,12 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, | |||
1921 | } | 1921 | } |
1922 | 1922 | ||
1923 | /* TODO: improve */ | 1923 | /* TODO: improve */ |
1924 | static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *client_id, sa_family_t sa_family) | 1924 | static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_family_t sa_family) |
1925 | { | 1925 | { |
1926 | uint32_t i; | 1926 | uint32_t i; |
1927 | 1927 | ||
1928 | for (i = 0; i < LCLIENT_LIST; ++i) { | 1928 | for (i = 0; i < LCLIENT_LIST; ++i) { |
1929 | if (memcmp(dht->close_clientlist[i].client_id, client_id, CLIENT_ID_SIZE) != 0) | 1929 | if (memcmp(dht->close_clientlist[i].public_key, public_key, CLIENT_ID_SIZE) != 0) |
1930 | continue; | 1930 | continue; |
1931 | 1931 | ||
1932 | if (sa_family == AF_INET) | 1932 | if (sa_family == AF_INET) |
@@ -2086,7 +2086,7 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num) | |||
2086 | } | 2086 | } |
2087 | 2087 | ||
2088 | if (assoc != NULL) { | 2088 | if (assoc != NULL) { |
2089 | memcpy(nodes[count].public_key, list[i - 1].client_id, CLIENT_ID_SIZE); | 2089 | memcpy(nodes[count].public_key, list[i - 1].public_key, CLIENT_ID_SIZE); |
2090 | nodes[count].ip_port = assoc->ip_port; | 2090 | nodes[count].ip_port = assoc->ip_port; |
2091 | ++count; | 2091 | ++count; |
2092 | 2092 | ||
@@ -2105,7 +2105,7 @@ void do_hardening(DHT *dht) | |||
2105 | for (i = 0; i < LCLIENT_LIST * 2; ++i) { | 2105 | for (i = 0; i < LCLIENT_LIST * 2; ++i) { |
2106 | IPPTsPng *cur_iptspng; | 2106 | IPPTsPng *cur_iptspng; |
2107 | sa_family_t sa_family; | 2107 | sa_family_t sa_family; |
2108 | uint8_t *client_id = dht->close_clientlist[i / 2].client_id; | 2108 | uint8_t *public_key = dht->close_clientlist[i / 2].public_key; |
2109 | 2109 | ||
2110 | if (i % 2 == 0) { | 2110 | if (i % 2 == 0) { |
2111 | cur_iptspng = &dht->close_clientlist[i / 2].assoc4; | 2111 | cur_iptspng = &dht->close_clientlist[i / 2].assoc4; |
@@ -2125,12 +2125,12 @@ void do_hardening(DHT *dht) | |||
2125 | if (!ipport_isset(&rand_node.ip_port)) | 2125 | if (!ipport_isset(&rand_node.ip_port)) |
2126 | continue; | 2126 | continue; |
2127 | 2127 | ||
2128 | if (id_equal(client_id, rand_node.public_key)) | 2128 | if (id_equal(public_key, rand_node.public_key)) |
2129 | continue; | 2129 | continue; |
2130 | 2130 | ||
2131 | Node_format to_test; | 2131 | Node_format to_test; |
2132 | to_test.ip_port = cur_iptspng->ip_port; | 2132 | to_test.ip_port = cur_iptspng->ip_port; |
2133 | memcpy(to_test.public_key, client_id, crypto_box_PUBLICKEYBYTES); | 2133 | memcpy(to_test.public_key, public_key, crypto_box_PUBLICKEYBYTES); |
2134 | 2134 | ||
2135 | //TODO: The search id should maybe not be ours? | 2135 | //TODO: The search id should maybe not be ours? |
2136 | if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) { | 2136 | if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) { |
@@ -2341,13 +2341,13 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2341 | 2341 | ||
2342 | for (num = 0, i = 0; i < LCLIENT_LIST; ++i) { | 2342 | for (num = 0, i = 0; i < LCLIENT_LIST; ++i) { |
2343 | if (dht->close_clientlist[i].assoc4.timestamp != 0) { | 2343 | if (dht->close_clientlist[i].assoc4.timestamp != 0) { |
2344 | memcpy(clients[num].public_key, dht->close_clientlist[i].client_id, crypto_box_PUBLICKEYBYTES); | 2344 | memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, crypto_box_PUBLICKEYBYTES); |
2345 | clients[num].ip_port = dht->close_clientlist[i].assoc4.ip_port; | 2345 | clients[num].ip_port = dht->close_clientlist[i].assoc4.ip_port; |
2346 | ++num; | 2346 | ++num; |
2347 | } | 2347 | } |
2348 | 2348 | ||
2349 | if (dht->close_clientlist[i].assoc6.timestamp != 0) { | 2349 | if (dht->close_clientlist[i].assoc6.timestamp != 0) { |
2350 | memcpy(clients[num].public_key, dht->close_clientlist[i].client_id, crypto_box_PUBLICKEYBYTES); | 2350 | memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, crypto_box_PUBLICKEYBYTES); |
2351 | clients[num].ip_port = dht->close_clientlist[i].assoc6.ip_port; | 2351 | clients[num].ip_port = dht->close_clientlist[i].assoc6.ip_port; |
2352 | ++num; | 2352 | ++num; |
2353 | } | 2353 | } |
@@ -2358,13 +2358,13 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2358 | 2358 | ||
2359 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { | 2359 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { |
2360 | if (fr->client_list[j].assoc4.timestamp != 0) { | 2360 | if (fr->client_list[j].assoc4.timestamp != 0) { |
2361 | memcpy(clients[num].public_key, fr->client_list[j].client_id, crypto_box_PUBLICKEYBYTES); | 2361 | memcpy(clients[num].public_key, fr->client_list[j].public_key, crypto_box_PUBLICKEYBYTES); |
2362 | clients[num].ip_port = fr->client_list[j].assoc4.ip_port; | 2362 | clients[num].ip_port = fr->client_list[j].assoc4.ip_port; |
2363 | ++num; | 2363 | ++num; |
2364 | } | 2364 | } |
2365 | 2365 | ||
2366 | if (fr->client_list[j].assoc6.timestamp != 0) { | 2366 | if (fr->client_list[j].assoc6.timestamp != 0) { |
2367 | memcpy(clients[num].public_key, fr->client_list[j].client_id, crypto_box_PUBLICKEYBYTES); | 2367 | memcpy(clients[num].public_key, fr->client_list[j].public_key, crypto_box_PUBLICKEYBYTES); |
2368 | clients[num].ip_port = fr->client_list[j].assoc6.ip_port; | 2368 | clients[num].ip_port = fr->client_list[j].assoc6.ip_port; |
2369 | ++num; | 2369 | ++num; |
2370 | } | 2370 | } |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 933bdcaf..a36ea252 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -104,7 +104,7 @@ typedef struct { | |||
104 | } IPPTsPng; | 104 | } IPPTsPng; |
105 | 105 | ||
106 | typedef struct { | 106 | typedef struct { |
107 | uint8_t client_id[CLIENT_ID_SIZE]; | 107 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
108 | IPPTsPng assoc4; | 108 | IPPTsPng assoc4; |
109 | IPPTsPng assoc6; | 109 | IPPTsPng assoc6; |
110 | } Client_data; | 110 | } Client_data; |
@@ -127,7 +127,7 @@ typedef struct { | |||
127 | #define DHT_FRIEND_MAX_LOCKS 32 | 127 | #define DHT_FRIEND_MAX_LOCKS 32 |
128 | 128 | ||
129 | typedef struct { | 129 | typedef struct { |
130 | uint8_t client_id[CLIENT_ID_SIZE]; | 130 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
131 | Client_data client_list[MAX_FRIEND_CLIENTS]; | 131 | Client_data client_list[MAX_FRIEND_CLIENTS]; |
132 | 132 | ||
133 | /* Time at which the last get_nodes request was sent. */ | 133 | /* Time at which the last get_nodes request was sent. */ |
@@ -182,7 +182,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed | |||
182 | #define KEYS_TIMEOUT 600 | 182 | #define KEYS_TIMEOUT 600 |
183 | typedef struct { | 183 | typedef struct { |
184 | struct { | 184 | struct { |
185 | uint8_t client_id[CLIENT_ID_SIZE]; | 185 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
186 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 186 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
187 | uint32_t times_requested; | 187 | uint32_t times_requested; |
188 | uint8_t stored; /* 0 if not, 1 if is */ | 188 | uint8_t stored; /* 0 if not, 1 if is */ |
@@ -241,22 +241,23 @@ typedef struct { | |||
241 | * If shared key is already in shared_keys, copy it to shared_key. | 241 | * If shared key is already in shared_keys, copy it to shared_key. |
242 | * else generate it into shared_key and copy it to shared_keys | 242 | * else generate it into shared_key and copy it to shared_keys |
243 | */ | 243 | */ |
244 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *client_id); | 244 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, |
245 | const uint8_t *public_key); | ||
245 | 246 | ||
246 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 247 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
247 | * for packets that we receive. | 248 | * for packets that we receive. |
248 | */ | 249 | */ |
249 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *client_id); | 250 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key); |
250 | 251 | ||
251 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 252 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
252 | * for packets that we send. | 253 | * for packets that we send. |
253 | */ | 254 | */ |
254 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *client_id); | 255 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key); |
255 | 256 | ||
256 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); | 257 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); |
257 | 258 | ||
258 | /* Add a new friend to the friends list. | 259 | /* Add a new friend to the friends list. |
259 | * client_id must be CLIENT_ID_SIZE bytes long. | 260 | * public_key must be crypto_box_PUBLICKEYBYTES bytes long. |
260 | * | 261 | * |
261 | * ip_callback is the callback of a function that will be called when the ip address | 262 | * ip_callback is the callback of a function that will be called when the ip address |
262 | * is found along with arguments data and number. | 263 | * is found along with arguments data and number. |
@@ -267,39 +268,39 @@ void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, con | |||
267 | * return 0 if success. | 268 | * return 0 if success. |
268 | * return -1 if failure (friends list is full). | 269 | * return -1 if failure (friends list is full). |
269 | */ | 270 | */ |
270 | int DHT_addfriend(DHT *dht, const uint8_t *client_id, void (*ip_callback)(void *data, int32_t number, IP_Port), | 271 | int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port), |
271 | void *data, int32_t number, uint16_t *lock_count); | 272 | void *data, int32_t number, uint16_t *lock_count); |
272 | 273 | ||
273 | /* Delete a friend from the friends list. | 274 | /* Delete a friend from the friends list. |
274 | * client_id must be CLIENT_ID_SIZE bytes long. | 275 | * public_key must be crypto_box_PUBLICKEYBYTES bytes long. |
275 | * | 276 | * |
276 | * return 0 if success. | 277 | * return 0 if success. |
277 | * return -1 if failure (client_id not in friends list). | 278 | * return -1 if failure (public_key not in friends list). |
278 | */ | 279 | */ |
279 | int DHT_delfriend(DHT *dht, const uint8_t *client_id, uint16_t lock_count); | 280 | int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count); |
280 | 281 | ||
281 | /* Get ip of friend. | 282 | /* Get ip of friend. |
282 | * client_id must be CLIENT_ID_SIZE bytes long. | 283 | * public_key must be crypto_box_PUBLICKEYBYTES bytes long. |
283 | * ip must be 4 bytes long. | 284 | * ip must be 4 bytes long. |
284 | * port must be 2 bytes long. | 285 | * port must be 2 bytes long. |
285 | * | 286 | * |
286 | * int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); | 287 | * int DHT_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port); |
287 | * | 288 | * |
288 | * return -1, -- if client_id does NOT refer to a friend | 289 | * return -1, -- if public_key does NOT refer to a friend |
289 | * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) | 290 | * return 0, -- if public_key refers to a friend and we failed to find the friend (yet) |
290 | * return 1, ip if client_id refers to a friend and we found him | 291 | * return 1, ip if public_key refers to a friend and we found him |
291 | */ | 292 | */ |
292 | int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port); | 293 | int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port); |
293 | 294 | ||
294 | /* Compares client_id1 and client_id2 with client_id. | 295 | /* Compares pk1 and pk2 with pk. |
295 | * | 296 | * |
296 | * return 0 if both are same distance. | 297 | * return 0 if both are same distance. |
297 | * return 1 if client_id1 is closer. | 298 | * return 1 if pk1 is closer. |
298 | * return 2 if client_id2 is closer. | 299 | * return 2 if pk2 is closer. |
299 | */ | 300 | */ |
300 | int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2); | 301 | int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2); |
301 | 302 | ||
302 | /* Get the (maximum MAX_SENT_NODES) closest nodes to client_id we know | 303 | /* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know |
303 | * and put them in nodes_list (must be MAX_SENT_NODES big). | 304 | * and put them in nodes_list (must be MAX_SENT_NODES big). |
304 | * | 305 | * |
305 | * sa_family = family (IPv4 or IPv6) (0 if we don't care)? | 306 | * sa_family = family (IPv4 or IPv6) (0 if we don't care)? |
@@ -309,7 +310,7 @@ int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2); | |||
309 | * return the number of nodes returned. | 310 | * return the number of nodes returned. |
310 | * | 311 | * |
311 | */ | 312 | */ |
312 | int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, | 313 | int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, sa_family_t sa_family, |
313 | uint8_t is_LAN, uint8_t want_good); | 314 | uint8_t is_LAN, uint8_t want_good); |
314 | 315 | ||
315 | 316 | ||
@@ -352,11 +353,11 @@ int DHT_connect_after_load(DHT *dht); | |||
352 | 353 | ||
353 | /* ROUTING FUNCTIONS */ | 354 | /* ROUTING FUNCTIONS */ |
354 | 355 | ||
355 | /* Send the given packet to node with client_id. | 356 | /* Send the given packet to node with public_key. |
356 | * | 357 | * |
357 | * return -1 if failure. | 358 | * return -1 if failure. |
358 | */ | 359 | */ |
359 | int route_packet(const DHT *dht, const uint8_t *client_id, const uint8_t *packet, uint16_t length); | 360 | int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length); |
360 | 361 | ||
361 | /* Send the following packet to everyone who tells us they are connected to friend_id. | 362 | /* Send the following packet to everyone who tells us they are connected to friend_id. |
362 | * | 363 | * |
@@ -399,7 +400,7 @@ int DHT_isconnected(const DHT *dht); | |||
399 | int DHT_non_lan_connected(const DHT *dht); | 400 | int DHT_non_lan_connected(const DHT *dht); |
400 | 401 | ||
401 | 402 | ||
402 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); | 403 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key); |
403 | 404 | ||
404 | #endif | 405 | #endif |
405 | 406 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 166e44f4..16e03cbc 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2340,7 +2340,7 @@ void do_messenger(Messenger *m) | |||
2340 | 2340 | ||
2341 | LOGGER_TRACE("C[%2u] %s:%u [%3u] %s", | 2341 | LOGGER_TRACE("C[%2u] %s:%u [%3u] %s", |
2342 | client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port), | 2342 | client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port), |
2343 | last_pinged, ID2String(cptr->client_id)); | 2343 | last_pinged, ID2String(cptr->public_key)); |
2344 | } | 2344 | } |
2345 | } | 2345 | } |
2346 | 2346 | ||
@@ -2360,7 +2360,7 @@ void do_messenger(Messenger *m) | |||
2360 | continue; | 2360 | continue; |
2361 | 2361 | ||
2362 | for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) | 2362 | for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) |
2363 | if (id_equal(m->friendlist[friend].real_pk, m->dht->friends_list[dhtfriend].client_id)) { | 2363 | if (id_equal(m->friendlist[friend].real_pk, m->dht->friends_list[dhtfriend].public_key)) { |
2364 | m2dht[friend] = dhtfriend; | 2364 | m2dht[friend] = dhtfriend; |
2365 | break; | 2365 | break; |
2366 | } | 2366 | } |
@@ -2390,7 +2390,7 @@ void do_messenger(Messenger *m) | |||
2390 | dht2m[friend], friend, msgfptr->name, | 2390 | dht2m[friend], friend, msgfptr->name, |
2391 | ID2String(msgfptr->real_pk)); | 2391 | ID2String(msgfptr->real_pk)); |
2392 | } else { | 2392 | } else { |
2393 | LOGGER_TRACE("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id)); | 2393 | LOGGER_TRACE("F[--:%2u] %s", friend, ID2String(dhtfptr->public_key)); |
2394 | } | 2394 | } |
2395 | 2395 | ||
2396 | for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { | 2396 | for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { |
@@ -2408,7 +2408,7 @@ void do_messenger(Messenger *m) | |||
2408 | LOGGER_TRACE("F[%2u] => C[%2u] %s:%u [%3u] %s", | 2408 | LOGGER_TRACE("F[%2u] => C[%2u] %s:%u [%3u] %s", |
2409 | friend, client, ip_ntoa(&assoc->ip_port.ip), | 2409 | friend, client, ip_ntoa(&assoc->ip_port.ip), |
2410 | ntohs(assoc->ip_port.port), last_pinged, | 2410 | ntohs(assoc->ip_port.port), last_pinged, |
2411 | ID2String(cptr->client_id)); | 2411 | ID2String(cptr->public_key)); |
2412 | } | 2412 | } |
2413 | } | 2413 | } |
2414 | } | 2414 | } |
diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 2e03dabe..553f4339 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c | |||
@@ -157,13 +157,13 @@ static Client_entry *dist_index_entry(Assoc *assoc, uint64_t dist_ind) | |||
157 | return NULL; | 157 | return NULL; |
158 | } | 158 | } |
159 | 159 | ||
160 | /* get actual entry's client_id to a distance_index */ | 160 | /* get actual entry's public_key to a distance_index */ |
161 | static uint8_t *dist_index_id(Assoc *assoc, uint64_t dist_ind) | 161 | static uint8_t *dist_index_id(Assoc *assoc, uint64_t dist_ind) |
162 | { | 162 | { |
163 | Client_entry *entry = dist_index_entry(assoc, dist_ind); | 163 | Client_entry *entry = dist_index_entry(assoc, dist_ind); |
164 | 164 | ||
165 | if (entry) | 165 | if (entry) |
166 | return entry->client.client_id; | 166 | return entry->client.public_key; |
167 | 167 | ||
168 | return NULL; | 168 | return NULL; |
169 | } | 169 | } |
@@ -356,7 +356,7 @@ static uint8_t candidates_search(const Assoc *assoc, const uint8_t *id, hash_t h | |||
356 | Client_entry *entry = &cnd_bckt->list[pos]; | 356 | Client_entry *entry = &cnd_bckt->list[pos]; |
357 | 357 | ||
358 | if (entry->hash == hash) | 358 | if (entry->hash == hash) |
359 | if (id_equal(entry->client.client_id, id)) { | 359 | if (id_equal(entry->client.public_key, id)) { |
360 | *entryptr = entry; | 360 | *entryptr = entry; |
361 | return 1; | 361 | return 1; |
362 | } | 362 | } |
@@ -476,7 +476,7 @@ static uint8_t candidates_create_new(const Assoc *assoc, hash_t hash, const uint | |||
476 | return 0; | 476 | return 0; |
477 | 477 | ||
478 | entry->hash = hash; | 478 | entry->hash = hash; |
479 | id_copy(entry->client.client_id, id); | 479 | id_copy(entry->client.public_key, id); |
480 | 480 | ||
481 | if (used) | 481 | if (used) |
482 | entry->used_at = unix_time(); | 482 | entry->used_at = unix_time(); |
@@ -536,7 +536,7 @@ static void client_id_self_update(Assoc *assoc) | |||
536 | Client_entry *entry = &cnd_bckt->list[pos]; | 536 | Client_entry *entry = &cnd_bckt->list[pos]; |
537 | 537 | ||
538 | if (entry->hash == assoc->self_hash) | 538 | if (entry->hash == assoc->self_hash) |
539 | if (id_equal(entry->client.client_id, assoc->self_client_id)) | 539 | if (id_equal(entry->client.public_key, assoc->self_client_id)) |
540 | entry->hash = 0; | 540 | entry->hash = 0; |
541 | } | 541 | } |
542 | } | 542 | } |
@@ -648,7 +648,7 @@ uint8_t Assoc_get_close_entries(Assoc *assoc, Assoc_close_entries *state) | |||
648 | continue; | 648 | continue; |
649 | } | 649 | } |
650 | 650 | ||
651 | uint64_t dist = state->distance_absolute_func(assoc, state->custom_data, state->wanted_id, entry->client.client_id); | 651 | uint64_t dist = state->distance_absolute_func(assoc, state->custom_data, state->wanted_id, entry->client.public_key); |
652 | uint32_t index = b * assoc->candidates_bucket_size + i; | 652 | uint32_t index = b * assoc->candidates_bucket_size + i; |
653 | dist_list[index] = (dist << DISTANCE_INDEX_INDEX_BITS) | index; | 653 | dist_list[index] = (dist << DISTANCE_INDEX_INDEX_BITS) | index; |
654 | } | 654 | } |
@@ -914,7 +914,7 @@ void do_Assoc(Assoc *assoc, DHT *dht) | |||
914 | continue; | 914 | continue; |
915 | 915 | ||
916 | if (!target_id) | 916 | if (!target_id) |
917 | target_id = entry->client.client_id; | 917 | target_id = entry->client.public_key; |
918 | 918 | ||
919 | if (entry->seen_at) { | 919 | if (entry->seen_at) { |
920 | if (!seen) | 920 | if (!seen) |
@@ -940,9 +940,9 @@ void do_Assoc(Assoc *assoc, DHT *dht) | |||
940 | IPPTsPng *ippts = seen->seen_family == AF_INET ? &seen->client.assoc4 : &seen->client.assoc6; | 940 | IPPTsPng *ippts = seen->seen_family == AF_INET ? &seen->client.assoc4 : &seen->client.assoc6; |
941 | 941 | ||
942 | LOGGER_DEBUG("[%u] => S[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count), | 942 | LOGGER_DEBUG("[%u] => S[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count), |
943 | idpart2str(seen->client.client_id, 8), ip_ntoa(&ippts->ip_port.ip), htons(ippts->ip_port.port)); | 943 | idpart2str(seen->client.public_key, 8), ip_ntoa(&ippts->ip_port.ip), htons(ippts->ip_port.port)); |
944 | 944 | ||
945 | DHT_getnodes(dht, &ippts->ip_port, seen->client.client_id, target_id); | 945 | DHT_getnodes(dht, &ippts->ip_port, seen->client.public_key, target_id); |
946 | seen->getnodes = unix_time(); | 946 | seen->getnodes = unix_time(); |
947 | } | 947 | } |
948 | 948 | ||
@@ -950,9 +950,9 @@ void do_Assoc(Assoc *assoc, DHT *dht) | |||
950 | IP_Port *ipp = heard->heard_family == AF_INET ? &heard->assoc_heard4 : &heard->assoc_heard6; | 950 | IP_Port *ipp = heard->heard_family == AF_INET ? &heard->assoc_heard4 : &heard->assoc_heard6; |
951 | 951 | ||
952 | LOGGER_DEBUG("[%u] => H[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count), | 952 | LOGGER_DEBUG("[%u] => H[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count), |
953 | idpart2str(heard->client.client_id, 8), ip_ntoa(&ipp->ip), htons(ipp->port)); | 953 | idpart2str(heard->client.public_key, 8), ip_ntoa(&ipp->ip), htons(ipp->port)); |
954 | 954 | ||
955 | DHT_getnodes(dht, ipp, heard->client.client_id, target_id); | 955 | DHT_getnodes(dht, ipp, heard->client.public_key, target_id); |
956 | heard->getnodes = unix_time(); | 956 | heard->getnodes = unix_time(); |
957 | } | 957 | } |
958 | 958 | ||
@@ -1012,7 +1012,7 @@ void Assoc_status(const Assoc *assoc) | |||
1012 | total++; | 1012 | total++; |
1013 | 1013 | ||
1014 | LOGGER_TRACE("[%3i:%3i] %08x => [%s...] %i, %i(%c), %i(%c)\n", | 1014 | LOGGER_TRACE("[%3i:%3i] %08x => [%s...] %i, %i(%c), %i(%c)\n", |
1015 | (int)bid, (int)cid, entry->hash, idpart2str(entry->client.client_id, 8), | 1015 | (int)bid, (int)cid, entry->hash, idpart2str(entry->client.public_key, 8), |
1016 | entry->used_at ? (int)(unix_time() - entry->used_at) : 0, | 1016 | entry->used_at ? (int)(unix_time() - entry->used_at) : 0, |
1017 | entry->seen_at ? (int)(unix_time() - entry->seen_at) : 0, | 1017 | entry->seen_at ? (int)(unix_time() - entry->seen_at) : 0, |
1018 | entry->seen_at ? (entry->seen_family == AF_INET ? '4' : (entry->seen_family == AF_INET6 ? '6' : '?')) : '?', | 1018 | entry->seen_at ? (entry->seen_family == AF_INET ? '4' : (entry->seen_family == AF_INET6 ? '6' : '?')) : '?', |
diff --git a/toxcore/ping.c b/toxcore/ping.c index 2decca0a..543ceec5 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -58,22 +58,22 @@ struct PING { | |||
58 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES) | 58 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES) |
59 | #define PING_DATA_SIZE (CLIENT_ID_SIZE + sizeof(IP_Port)) | 59 | #define PING_DATA_SIZE (CLIENT_ID_SIZE + sizeof(IP_Port)) |
60 | 60 | ||
61 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id) | 61 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key) |
62 | { | 62 | { |
63 | uint8_t pk[DHT_PING_SIZE]; | 63 | uint8_t pk[DHT_PING_SIZE]; |
64 | int rc; | 64 | int rc; |
65 | uint64_t ping_id; | 65 | uint64_t ping_id; |
66 | 66 | ||
67 | if (id_equal(client_id, ping->dht->self_public_key)) | 67 | if (id_equal(public_key, ping->dht->self_public_key)) |
68 | return 1; | 68 | return 1; |
69 | 69 | ||
70 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 70 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
71 | 71 | ||
72 | // generate key to encrypt ping_id with recipient privkey | 72 | // generate key to encrypt ping_id with recipient privkey |
73 | DHT_get_shared_key_sent(ping->dht, shared_key, client_id); | 73 | DHT_get_shared_key_sent(ping->dht, shared_key, public_key); |
74 | // Generate random ping_id. | 74 | // Generate random ping_id. |
75 | uint8_t data[PING_DATA_SIZE]; | 75 | uint8_t data[PING_DATA_SIZE]; |
76 | id_copy(data, client_id); | 76 | id_copy(data, public_key); |
77 | memcpy(data + CLIENT_ID_SIZE, &ipp, sizeof(IP_Port)); | 77 | memcpy(data + CLIENT_ID_SIZE, &ipp, sizeof(IP_Port)); |
78 | ping_id = ping_array_add(&ping->ping_array, data, sizeof(data)); | 78 | ping_id = ping_array_add(&ping->ping_array, data, sizeof(data)); |
79 | 79 | ||
@@ -100,13 +100,13 @@ int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id) | |||
100 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); | 100 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); |
101 | } | 101 | } |
102 | 102 | ||
103 | static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *client_id, uint64_t ping_id, | 103 | static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id, |
104 | uint8_t *shared_encryption_key) | 104 | uint8_t *shared_encryption_key) |
105 | { | 105 | { |
106 | uint8_t pk[DHT_PING_SIZE]; | 106 | uint8_t pk[DHT_PING_SIZE]; |
107 | int rc; | 107 | int rc; |
108 | 108 | ||
109 | if (id_equal(client_id, ping->dht->self_public_key)) | 109 | if (id_equal(public_key, ping->dht->self_public_key)) |
110 | return 1; | 110 | return 1; |
111 | 111 | ||
112 | uint8_t ping_plain[PING_PLAIN_SIZE]; | 112 | uint8_t ping_plain[PING_PLAIN_SIZE]; |
@@ -220,17 +220,17 @@ static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packe | |||
220 | return 0; | 220 | return 0; |
221 | } | 221 | } |
222 | 222 | ||
223 | /* Check if client_id with ip_port is in the list. | 223 | /* Check if public_key with ip_port is in the list. |
224 | * | 224 | * |
225 | * return 1 if it is. | 225 | * return 1 if it is. |
226 | * return 0 if it isn't. | 226 | * return 0 if it isn't. |
227 | */ | 227 | */ |
228 | static int in_list(const Client_data *list, uint16_t length, const uint8_t *client_id, IP_Port ip_port) | 228 | static int in_list(const Client_data *list, uint16_t length, const uint8_t *public_key, IP_Port ip_port) |
229 | { | 229 | { |
230 | uint32_t i; | 230 | uint32_t i; |
231 | 231 | ||
232 | for (i = 0; i < length; ++i) { | 232 | for (i = 0; i < length; ++i) { |
233 | if (id_equal(list[i].client_id, client_id)) { | 233 | if (id_equal(list[i].public_key, public_key)) { |
234 | const IPPTsPng *ipptp; | 234 | const IPPTsPng *ipptp; |
235 | 235 | ||
236 | if (ip_port.ip.family == AF_INET) { | 236 | if (ip_port.ip.family == AF_INET) { |
@@ -250,31 +250,31 @@ static int in_list(const Client_data *list, uint16_t length, const uint8_t *clie | |||
250 | /* Add nodes to the to_ping list. | 250 | /* Add nodes to the to_ping list. |
251 | * All nodes in this list are pinged every TIME_TO_PING seconds | 251 | * All nodes in this list are pinged every TIME_TO_PING seconds |
252 | * and are then removed from the list. | 252 | * and are then removed from the list. |
253 | * If the list is full the nodes farthest from our client_id are replaced. | 253 | * If the list is full the nodes farthest from our public_key are replaced. |
254 | * The purpose of this list is to enable quick integration of new nodes into the | 254 | * The purpose of this list is to enable quick integration of new nodes into the |
255 | * network while preventing amplification attacks. | 255 | * network while preventing amplification attacks. |
256 | * | 256 | * |
257 | * return 0 if node was added. | 257 | * return 0 if node was added. |
258 | * return -1 if node was not added. | 258 | * return -1 if node was not added. |
259 | */ | 259 | */ |
260 | int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port) | 260 | int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port) |
261 | { | 261 | { |
262 | if (!ip_isset(&ip_port.ip)) | 262 | if (!ip_isset(&ip_port.ip)) |
263 | return -1; | 263 | return -1; |
264 | 264 | ||
265 | if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, client_id, ip_port)) | 265 | if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, public_key, ip_port)) |
266 | return -1; | 266 | return -1; |
267 | 267 | ||
268 | uint32_t i; | 268 | uint32_t i; |
269 | 269 | ||
270 | for (i = 0; i < MAX_TO_PING; ++i) { | 270 | for (i = 0; i < MAX_TO_PING; ++i) { |
271 | if (!ip_isset(&ping->to_ping[i].ip_port.ip)) { | 271 | if (!ip_isset(&ping->to_ping[i].ip_port.ip)) { |
272 | memcpy(ping->to_ping[i].public_key, client_id, CLIENT_ID_SIZE); | 272 | memcpy(ping->to_ping[i].public_key, public_key, CLIENT_ID_SIZE); |
273 | ipport_copy(&ping->to_ping[i].ip_port, &ip_port); | 273 | ipport_copy(&ping->to_ping[i].ip_port, &ip_port); |
274 | return 0; | 274 | return 0; |
275 | } | 275 | } |
276 | 276 | ||
277 | if (memcmp(ping->to_ping[i].public_key, client_id, CLIENT_ID_SIZE) == 0) { | 277 | if (memcmp(ping->to_ping[i].public_key, public_key, CLIENT_ID_SIZE) == 0) { |
278 | return -1; | 278 | return -1; |
279 | } | 279 | } |
280 | } | 280 | } |
@@ -282,8 +282,8 @@ int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port) | |||
282 | uint32_t r = rand(); | 282 | uint32_t r = rand(); |
283 | 283 | ||
284 | for (i = 0; i < MAX_TO_PING; ++i) { | 284 | for (i = 0; i < MAX_TO_PING; ++i) { |
285 | if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].public_key, client_id) == 2) { | 285 | if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key) == 2) { |
286 | memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, client_id, CLIENT_ID_SIZE); | 286 | memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key, CLIENT_ID_SIZE); |
287 | ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port); | 287 | ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port); |
288 | return 0; | 288 | return 0; |
289 | } | 289 | } |
diff --git a/toxcore/ping.h b/toxcore/ping.h index c19c912a..904ad844 100644 --- a/toxcore/ping.h +++ b/toxcore/ping.h | |||
@@ -29,19 +29,19 @@ typedef struct PING PING; | |||
29 | /* Add nodes to the to_ping list. | 29 | /* Add nodes to the to_ping list. |
30 | * All nodes in this list are pinged every TIME_TOPING seconds | 30 | * All nodes in this list are pinged every TIME_TOPING seconds |
31 | * and are then removed from the list. | 31 | * and are then removed from the list. |
32 | * If the list is full the nodes farthest from our client_id are replaced. | 32 | * If the list is full the nodes farthest from our public_key are replaced. |
33 | * The purpose of this list is to enable quick integration of new nodes into the | 33 | * The purpose of this list is to enable quick integration of new nodes into the |
34 | * network while preventing amplification attacks. | 34 | * network while preventing amplification attacks. |
35 | * | 35 | * |
36 | * return 0 if node was added. | 36 | * return 0 if node was added. |
37 | * return -1 if node was not added. | 37 | * return -1 if node was not added. |
38 | */ | 38 | */ |
39 | int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port); | 39 | int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port); |
40 | void do_to_ping(PING *ping); | 40 | void do_to_ping(PING *ping); |
41 | 41 | ||
42 | PING *new_ping(DHT *dht); | 42 | PING *new_ping(DHT *dht); |
43 | void kill_ping(PING *ping); | 43 | void kill_ping(PING *ping); |
44 | 44 | ||
45 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id); | 45 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key); |
46 | 46 | ||
47 | #endif /* __PING_H__ */ | 47 | #endif /* __PING_H__ */ |