diff options
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 227 |
1 files changed, 118 insertions, 109 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index b02b7c24..61034167 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -38,7 +38,7 @@ | |||
38 | * return -1 on failure | 38 | * return -1 on failure |
39 | * return 0 on success | 39 | * return 0 on success |
40 | */ | 40 | */ |
41 | int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id) | 41 | int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) |
42 | { | 42 | { |
43 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) | 43 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) |
44 | return -1; | 44 | return -1; |
@@ -46,12 +46,12 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t | |||
46 | unsigned int i; | 46 | unsigned int i; |
47 | 47 | ||
48 | for (i = 0; i < MAX_PATH_NODES; ++i) { | 48 | for (i = 0; i < MAX_PATH_NODES; ++i) { |
49 | if (memcmp(client_id, onion_c->path_nodes_bs[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) | 49 | if (memcmp(public_key, onion_c->path_nodes_bs[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) |
50 | return -1; | 50 | return -1; |
51 | } | 51 | } |
52 | 52 | ||
53 | onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].ip_port = ip_port; | 53 | onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].ip_port = ip_port; |
54 | memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].client_id, client_id, | 54 | memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].public_key, public_key, |
55 | crypto_box_PUBLICKEYBYTES); | 55 | crypto_box_PUBLICKEYBYTES); |
56 | 56 | ||
57 | uint16_t last = onion_c->path_nodes_index_bs; | 57 | uint16_t last = onion_c->path_nodes_index_bs; |
@@ -68,7 +68,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t | |||
68 | * return -1 on failure | 68 | * return -1 on failure |
69 | * return 0 on success | 69 | * return 0 on success |
70 | */ | 70 | */ |
71 | static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id) | 71 | static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *public_key) |
72 | { | 72 | { |
73 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) | 73 | if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6) |
74 | return -1; | 74 | return -1; |
@@ -76,12 +76,13 @@ static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uin | |||
76 | unsigned int i; | 76 | unsigned int i; |
77 | 77 | ||
78 | for (i = 0; i < MAX_PATH_NODES; ++i) { | 78 | for (i = 0; i < MAX_PATH_NODES; ++i) { |
79 | if (memcmp(client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) | 79 | if (memcmp(public_key, onion_c->path_nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) |
80 | return -1; | 80 | return -1; |
81 | } | 81 | } |
82 | 82 | ||
83 | onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port; | 83 | onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port; |
84 | memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].client_id, client_id, crypto_box_PUBLICKEYBYTES); | 84 | memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].public_key, public_key, |
85 | crypto_box_PUBLICKEYBYTES); | ||
85 | 86 | ||
86 | uint16_t last = onion_c->path_nodes_index; | 87 | uint16_t last = onion_c->path_nodes_index; |
87 | ++onion_c->path_nodes_index; | 88 | ++onion_c->path_nodes_index; |
@@ -140,8 +141,15 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format | |||
140 | nodes[i] = onion_c->path_nodes[rand() % num_nodes]; | 141 | nodes[i] = onion_c->path_nodes[rand() % num_nodes]; |
141 | } | 142 | } |
142 | } else { | 143 | } else { |
144 | int random_tcp = get_random_tcp_con_number(onion_c->c); | ||
145 | |||
146 | if (random_tcp == -1) { | ||
147 | return 0; | ||
148 | } | ||
149 | |||
143 | if (num_nodes >= 2) { | 150 | if (num_nodes >= 2) { |
144 | nodes[0].ip_port.ip.family = TCP_FAMILY; | 151 | nodes[0].ip_port.ip.family = TCP_FAMILY; |
152 | nodes[0].ip_port.ip.ip4.uint32 = random_tcp; | ||
145 | 153 | ||
146 | for (i = 1; i < max_num; ++i) { | 154 | for (i = 1; i < max_num; ++i) { |
147 | nodes[i] = onion_c->path_nodes[rand() % num_nodes]; | 155 | nodes[i] = onion_c->path_nodes[rand() % num_nodes]; |
@@ -154,6 +162,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format | |||
154 | return 0; | 162 | return 0; |
155 | 163 | ||
156 | nodes[0].ip_port.ip.family = TCP_FAMILY; | 164 | nodes[0].ip_port.ip.family = TCP_FAMILY; |
165 | nodes[0].ip_port.ip.ip4.uint32 = random_tcp; | ||
157 | 166 | ||
158 | for (i = 1; i < max_num; ++i) { | 167 | for (i = 1; i < max_num; ++i) { |
159 | nodes[i] = onion_c->path_nodes_bs[rand() % num_nodes_bs]; | 168 | nodes[i] = onion_c->path_nodes_bs[rand() % num_nodes_bs]; |
@@ -249,9 +258,9 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t | |||
249 | Onion_Client_Paths *onion_paths; | 258 | Onion_Client_Paths *onion_paths; |
250 | 259 | ||
251 | if (num == 0) { | 260 | if (num == 0) { |
252 | onion_paths = &onion_c->onion_paths; | 261 | onion_paths = &onion_c->onion_paths_self; |
253 | } else { | 262 | } else { |
254 | onion_paths = &onion_c->friends_list[num - 1].onion_paths; | 263 | onion_paths = &onion_c->onion_paths_friends; |
255 | } | 264 | } |
256 | 265 | ||
257 | if (onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num) { | 266 | if (onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num) { |
@@ -265,7 +274,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t | |||
265 | unsigned int i; | 274 | unsigned int i; |
266 | 275 | ||
267 | for (i = 0; i < path_len; ++i) { | 276 | for (i = 0; i < path_len; ++i) { |
268 | onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].client_id); | 277 | onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key); |
269 | } | 278 | } |
270 | } | 279 | } |
271 | 280 | ||
@@ -301,7 +310,7 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa | |||
301 | if (len == -1) | 310 | if (len == -1) |
302 | return -1; | 311 | return -1; |
303 | 312 | ||
304 | return send_tcp_onion_request(onion_c->c, packet, len); | 313 | return send_tcp_onion_request(onion_c->c, path->ip_port1.ip.ip4.uint32, packet, len); |
305 | } else { | 314 | } else { |
306 | return -1; | 315 | return -1; |
307 | } | 316 | } |
@@ -377,10 +386,10 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_ | |||
377 | Onion_Path path; | 386 | Onion_Path path; |
378 | 387 | ||
379 | if (num == 0) { | 388 | if (num == 0) { |
380 | if (random_path(onion_c, &onion_c->onion_paths, pathnum, &path) == -1) | 389 | if (random_path(onion_c, &onion_c->onion_paths_self, pathnum, &path) == -1) |
381 | return -1; | 390 | return -1; |
382 | } else { | 391 | } else { |
383 | if (random_path(onion_c, &onion_c->friends_list[num - 1].onion_paths, pathnum, &path) == -1) | 392 | if (random_path(onion_c, &onion_c->onion_paths_friends, pathnum, &path) == -1) |
384 | return -1; | 393 | return -1; |
385 | } | 394 | } |
386 | 395 | ||
@@ -401,7 +410,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_ | |||
401 | 410 | ||
402 | } else { | 411 | } else { |
403 | len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->friends_list[num - 1].temp_public_key, | 412 | len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->friends_list[num - 1].temp_public_key, |
404 | onion_c->friends_list[num - 1].temp_secret_key, ping_id, onion_c->friends_list[num - 1].real_client_id, zero_ping_id, | 413 | onion_c->friends_list[num - 1].temp_secret_key, ping_id, onion_c->friends_list[num - 1].real_public_key, zero_ping_id, |
405 | sendback); | 414 | sendback); |
406 | } | 415 | } |
407 | 416 | ||
@@ -430,7 +439,7 @@ static int cmp_entry(const void *a, const void *b) | |||
430 | if (t2) | 439 | if (t2) |
431 | return 1; | 440 | return 1; |
432 | 441 | ||
433 | int close = id_closest(cmp_public_key, entry1.client_id, entry2.client_id); | 442 | int close = id_closest(cmp_public_key, entry1.public_key, entry2.public_key); |
434 | 443 | ||
435 | if (close == 1) | 444 | if (close == 1) |
436 | return 1; | 445 | return 1; |
@@ -463,7 +472,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
463 | return -1; | 472 | return -1; |
464 | 473 | ||
465 | list_nodes = onion_c->friends_list[num - 1].clients_list; | 474 | list_nodes = onion_c->friends_list[num - 1].clients_list; |
466 | reference_id = onion_c->friends_list[num - 1].real_client_id; | 475 | reference_id = onion_c->friends_list[num - 1].real_public_key; |
467 | } | 476 | } |
468 | 477 | ||
469 | memcpy(cmp_public_key, reference_id, crypto_box_PUBLICKEYBYTES); | 478 | memcpy(cmp_public_key, reference_id, crypto_box_PUBLICKEYBYTES); |
@@ -473,12 +482,12 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
473 | unsigned int i; | 482 | unsigned int i; |
474 | 483 | ||
475 | if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) | 484 | if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) |
476 | || id_closest(reference_id, list_nodes[0].client_id, public_key) == 2) { | 485 | || id_closest(reference_id, list_nodes[0].public_key, public_key) == 2) { |
477 | index = 0; | 486 | index = 0; |
478 | } | 487 | } |
479 | 488 | ||
480 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { | 489 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
481 | if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { | 490 | if (memcmp(list_nodes[i].public_key, public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
482 | index = i; | 491 | index = i; |
483 | stored = 1; | 492 | stored = 1; |
484 | break; | 493 | break; |
@@ -488,7 +497,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
488 | if (index == -1) | 497 | if (index == -1) |
489 | return 0; | 498 | return 0; |
490 | 499 | ||
491 | memcpy(list_nodes[index].client_id, public_key, CLIENT_ID_SIZE); | 500 | memcpy(list_nodes[index].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
492 | list_nodes[index].ip_port = ip_port; | 501 | list_nodes[index].ip_port = ip_port; |
493 | 502 | ||
494 | //TODO: remove this and find a better source of nodes to use for paths. | 503 | //TODO: remove this and find a better source of nodes to use for paths. |
@@ -510,17 +519,17 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
510 | return 0; | 519 | return 0; |
511 | } | 520 | } |
512 | 521 | ||
513 | static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, const uint8_t *client_id) | 522 | static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, const uint8_t *public_key) |
514 | { | 523 | { |
515 | unsigned int i; | 524 | unsigned int i; |
516 | 525 | ||
517 | for (i = 0; i < MAX_STORED_PINGED_NODES; ++i) { | 526 | for (i = 0; i < MAX_STORED_PINGED_NODES; ++i) { |
518 | if (!is_timeout(last_pinged[i].timestamp, MIN_NODE_PING_TIME)) | 527 | if (!is_timeout(last_pinged[i].timestamp, MIN_NODE_PING_TIME)) |
519 | if (memcmp(last_pinged[i].client_id, client_id, crypto_box_PUBLICKEYBYTES) == 0) | 528 | if (memcmp(last_pinged[i].public_key, public_key, crypto_box_PUBLICKEYBYTES) == 0) |
520 | return 0; | 529 | return 0; |
521 | } | 530 | } |
522 | 531 | ||
523 | memcpy(last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].client_id, client_id, crypto_box_PUBLICKEYBYTES); | 532 | memcpy(last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
524 | last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].timestamp = unix_time(); | 533 | last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].timestamp = unix_time(); |
525 | ++*last_pinged_index; | 534 | ++*last_pinged_index; |
526 | return 1; | 535 | return 1; |
@@ -548,7 +557,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for | |||
548 | last_pinged_index = &onion_c->last_pinged_index; | 557 | last_pinged_index = &onion_c->last_pinged_index; |
549 | } else { | 558 | } else { |
550 | list_nodes = onion_c->friends_list[num - 1].clients_list; | 559 | list_nodes = onion_c->friends_list[num - 1].clients_list; |
551 | reference_id = onion_c->friends_list[num - 1].real_client_id; | 560 | reference_id = onion_c->friends_list[num - 1].real_public_key; |
552 | last_pinged = onion_c->friends_list[num - 1].last_pinged; | 561 | last_pinged = onion_c->friends_list[num - 1].last_pinged; |
553 | last_pinged_index = &onion_c->friends_list[num - 1].last_pinged_index; | 562 | last_pinged_index = &onion_c->friends_list[num - 1].last_pinged_index; |
554 | } | 563 | } |
@@ -563,16 +572,16 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for | |||
563 | continue; | 572 | continue; |
564 | 573 | ||
565 | if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) | 574 | if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) |
566 | || id_closest(reference_id, list_nodes[0].client_id, nodes[i].client_id) == 2) { | 575 | || id_closest(reference_id, list_nodes[0].public_key, nodes[i].public_key) == 2) { |
567 | /* check if node is already in list. */ | 576 | /* check if node is already in list. */ |
568 | for (j = 0; j < MAX_ONION_CLIENTS; ++j) { | 577 | for (j = 0; j < MAX_ONION_CLIENTS; ++j) { |
569 | if (memcmp(list_nodes[j].client_id, nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) { | 578 | if (memcmp(list_nodes[j].public_key, nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
570 | break; | 579 | break; |
571 | } | 580 | } |
572 | } | 581 | } |
573 | 582 | ||
574 | if (j == MAX_ONION_CLIENTS && good_to_ping(last_pinged, last_pinged_index, nodes[i].client_id)) { | 583 | if (j == MAX_ONION_CLIENTS && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) { |
575 | client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL, ~0); | 584 | client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, NULL, ~0); |
576 | } | 585 | } |
577 | } | 586 | } |
578 | } | 587 | } |
@@ -670,17 +679,16 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac | |||
670 | sizeof(plain)); | 679 | sizeof(plain)); |
671 | } | 680 | } |
672 | 681 | ||
673 | #define FAKEID_DATA_ID 156 | 682 | #define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) |
674 | #define FAKEID_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) | 683 | #define DHTPK_DATA_MAX_LENGTH (DHTPK_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) |
675 | #define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) | 684 | static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length) |
676 | static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length) | ||
677 | { | 685 | { |
678 | Onion_Client *onion_c = object; | 686 | Onion_Client *onion_c = object; |
679 | 687 | ||
680 | if (length < FAKEID_DATA_MIN_LENGTH) | 688 | if (length < DHTPK_DATA_MIN_LENGTH) |
681 | return 1; | 689 | return 1; |
682 | 690 | ||
683 | if (length > FAKEID_DATA_MAX_LENGTH) | 691 | if (length > DHTPK_DATA_MAX_LENGTH) |
684 | return 1; | 692 | return 1; |
685 | 693 | ||
686 | int friend_num = onion_friend_num(onion_c, source_pubkey); | 694 | int friend_num = onion_friend_num(onion_c, source_pubkey); |
@@ -704,7 +712,7 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co | |||
704 | onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); | 712 | onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); |
705 | onion_c->friends_list[friend_num].last_seen = unix_time(); | 713 | onion_c->friends_list[friend_num].last_seen = unix_time(); |
706 | 714 | ||
707 | uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH; | 715 | uint16_t len_nodes = length - DHTPK_DATA_MIN_LENGTH; |
708 | 716 | ||
709 | if (len_nodes != 0) { | 717 | if (len_nodes != 0) { |
710 | Node_format nodes[MAX_SENT_NODES]; | 718 | Node_format nodes[MAX_SENT_NODES]; |
@@ -720,12 +728,12 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co | |||
720 | uint8_t family = nodes[i].ip_port.ip.family; | 728 | uint8_t family = nodes[i].ip_port.ip.family; |
721 | 729 | ||
722 | if (family == AF_INET || family == AF_INET6) { | 730 | if (family == AF_INET || family == AF_INET6) { |
723 | DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].client_id, onion_c->friends_list[friend_num].fake_client_id); | 731 | DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key); |
724 | } else if (family == TCP_INET || family == TCP_INET6) { | 732 | } else if (family == TCP_INET || family == TCP_INET6) { |
725 | if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { | 733 | if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { |
726 | void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object; | 734 | void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object; |
727 | uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number; | 735 | uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number; |
728 | onion_c->friends_list[friend_num].tcp_relay_node_callback(obj, number, nodes[i].ip_port, nodes[i].client_id); | 736 | onion_c->friends_list[friend_num].tcp_relay_node_callback(obj, number, nodes[i].ip_port, nodes[i].public_key); |
729 | } | 737 | } |
730 | } | 738 | } |
731 | } | 739 | } |
@@ -759,7 +767,7 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length) | |||
759 | * return the number of packets sent on success | 767 | * return the number of packets sent on success |
760 | * return -1 on failure. | 768 | * return -1 on failure. |
761 | */ | 769 | */ |
762 | int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length) | 770 | int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length) |
763 | { | 771 | { |
764 | if ((uint32_t)friend_num >= onion_c->num_friends) | 772 | if ((uint32_t)friend_num >= onion_c->num_friends) |
765 | return -1; | 773 | return -1; |
@@ -770,19 +778,7 @@ int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t * | |||
770 | if (length == 0) | 778 | if (length == 0) |
771 | return -1; | 779 | return -1; |
772 | 780 | ||
773 | uint8_t nonce[crypto_box_NONCEBYTES]; | ||
774 | random_nonce(nonce); | ||
775 | |||
776 | uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; | ||
777 | memcpy(packet, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
778 | int len = encrypt_data(onion_c->friends_list[friend_num].real_client_id, onion_c->c->self_secret_key, nonce, data, | ||
779 | length, packet + crypto_box_PUBLICKEYBYTES); | ||
780 | |||
781 | if ((uint32_t)len + crypto_box_PUBLICKEYBYTES != sizeof(packet)) | ||
782 | return -1; | ||
783 | |||
784 | unsigned int i, good_nodes[MAX_ONION_CLIENTS], num_good = 0, num_nodes = 0; | 781 | unsigned int i, good_nodes[MAX_ONION_CLIENTS], num_good = 0, num_nodes = 0; |
785 | Onion_Path path[MAX_ONION_CLIENTS]; | ||
786 | Onion_Node *list_nodes = onion_c->friends_list[friend_num].clients_list; | 782 | Onion_Node *list_nodes = onion_c->friends_list[friend_num].clients_list; |
787 | 783 | ||
788 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { | 784 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
@@ -792,9 +788,6 @@ int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t * | |||
792 | ++num_nodes; | 788 | ++num_nodes; |
793 | 789 | ||
794 | if (list_nodes[i].is_stored) { | 790 | if (list_nodes[i].is_stored) { |
795 | if (random_path(onion_c, &onion_c->friends_list[friend_num].onion_paths, ~0, &path[num_good]) == -1) | ||
796 | continue; | ||
797 | |||
798 | good_nodes[num_good] = i; | 791 | good_nodes[num_good] = i; |
799 | ++num_good; | 792 | ++num_good; |
800 | } | 793 | } |
@@ -803,36 +796,52 @@ int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t * | |||
803 | if (num_good < (num_nodes / 4) + 1) | 796 | if (num_good < (num_nodes / 4) + 1) |
804 | return -1; | 797 | return -1; |
805 | 798 | ||
799 | uint8_t nonce[crypto_box_NONCEBYTES]; | ||
800 | random_nonce(nonce); | ||
801 | |||
802 | uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; | ||
803 | memcpy(packet, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
804 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, | ||
805 | length, packet + crypto_box_PUBLICKEYBYTES); | ||
806 | |||
807 | if ((uint32_t)len + crypto_box_PUBLICKEYBYTES != sizeof(packet)) | ||
808 | return -1; | ||
809 | |||
806 | unsigned int good = 0; | 810 | unsigned int good = 0; |
807 | 811 | ||
808 | for (i = 0; i < num_good; ++i) { | 812 | for (i = 0; i < num_good; ++i) { |
813 | Onion_Path path; | ||
814 | |||
815 | if (random_path(onion_c, &onion_c->onion_paths_friends, ~0, &path) == -1) | ||
816 | continue; | ||
817 | |||
809 | uint8_t o_packet[ONION_MAX_PACKET_SIZE]; | 818 | uint8_t o_packet[ONION_MAX_PACKET_SIZE]; |
810 | len = create_data_request(o_packet, sizeof(o_packet), onion_c->friends_list[friend_num].real_client_id, | 819 | len = create_data_request(o_packet, sizeof(o_packet), onion_c->friends_list[friend_num].real_public_key, |
811 | list_nodes[good_nodes[i]].data_public_key, nonce, packet, sizeof(packet)); | 820 | list_nodes[good_nodes[i]].data_public_key, nonce, packet, sizeof(packet)); |
812 | 821 | ||
813 | if (len == -1) | 822 | if (len == -1) |
814 | continue; | 823 | continue; |
815 | 824 | ||
816 | if (send_onion_packet_tcp_udp(onion_c, &path[i], list_nodes[good_nodes[i]].ip_port, o_packet, len) == 0) | 825 | if (send_onion_packet_tcp_udp(onion_c, &path, list_nodes[good_nodes[i]].ip_port, o_packet, len) == 0) |
817 | ++good; | 826 | ++good; |
818 | } | 827 | } |
819 | 828 | ||
820 | return good; | 829 | return good; |
821 | } | 830 | } |
822 | 831 | ||
823 | /* Try to send the fakeid via the DHT instead of onion | 832 | /* Try to send the dht public key via the DHT instead of onion |
824 | * | 833 | * |
825 | * Even if this function succeeds, the friend might not receive any data. | 834 | * Even if this function succeeds, the friend might not receive any data. |
826 | * | 835 | * |
827 | * return the number of packets sent on success | 836 | * return the number of packets sent on success |
828 | * return -1 on failure. | 837 | * return -1 on failure. |
829 | */ | 838 | */ |
830 | static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length) | 839 | static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length) |
831 | { | 840 | { |
832 | if ((uint32_t)friend_num >= onion_c->num_friends) | 841 | if ((uint32_t)friend_num >= onion_c->num_friends) |
833 | return -1; | 842 | return -1; |
834 | 843 | ||
835 | if (!onion_c->friends_list[friend_num].is_fake_clientid) | 844 | if (!onion_c->friends_list[friend_num].know_dht_public_key) |
836 | return -1; | 845 | return -1; |
837 | 846 | ||
838 | uint8_t nonce[crypto_box_NONCEBYTES]; | 847 | uint8_t nonce[crypto_box_NONCEBYTES]; |
@@ -841,7 +850,7 @@ static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const ui | |||
841 | uint8_t temp[DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES + length]; | 850 | uint8_t temp[DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES + length]; |
842 | memcpy(temp, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); | 851 | memcpy(temp, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); |
843 | memcpy(temp + crypto_box_PUBLICKEYBYTES, nonce, crypto_box_NONCEBYTES); | 852 | memcpy(temp + crypto_box_PUBLICKEYBYTES, nonce, crypto_box_NONCEBYTES); |
844 | int len = encrypt_data(onion_c->friends_list[friend_num].real_client_id, onion_c->c->self_secret_key, nonce, data, | 853 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, |
845 | length, temp + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); | 854 | length, temp + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); |
846 | 855 | ||
847 | if ((uint32_t)len + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES != sizeof(temp)) | 856 | if ((uint32_t)len + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES != sizeof(temp)) |
@@ -849,37 +858,37 @@ static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const ui | |||
849 | 858 | ||
850 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; | 859 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; |
851 | len = create_request(onion_c->dht->self_public_key, onion_c->dht->self_secret_key, packet, | 860 | len = create_request(onion_c->dht->self_public_key, onion_c->dht->self_secret_key, packet, |
852 | onion_c->friends_list[friend_num].fake_client_id, temp, sizeof(temp), FAKEID_DATA_ID); | 861 | onion_c->friends_list[friend_num].dht_public_key, temp, sizeof(temp), CRYPTO_PACKET_FAKEID); |
853 | 862 | ||
854 | if (len == -1) | 863 | if (len == -1) |
855 | return -1; | 864 | return -1; |
856 | 865 | ||
857 | return route_tofriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, packet, len); | 866 | return route_tofriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, packet, len); |
858 | } | 867 | } |
859 | 868 | ||
860 | static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, | 869 | static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, |
861 | uint16_t length) | 870 | uint16_t length) |
862 | { | 871 | { |
863 | Onion_Client *onion_c = object; | 872 | Onion_Client *onion_c = object; |
864 | 873 | ||
865 | if (length < FAKEID_DATA_MIN_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) | 874 | if (length < DHTPK_DATA_MIN_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) |
866 | return 1; | 875 | return 1; |
867 | 876 | ||
868 | if (length > FAKEID_DATA_MAX_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) | 877 | if (length > DHTPK_DATA_MAX_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) |
869 | return 1; | 878 | return 1; |
870 | 879 | ||
871 | uint8_t plain[FAKEID_DATA_MAX_LENGTH]; | 880 | uint8_t plain[DHTPK_DATA_MAX_LENGTH]; |
872 | int len = decrypt_data(packet, onion_c->c->self_secret_key, packet + crypto_box_PUBLICKEYBYTES, | 881 | int len = decrypt_data(packet, onion_c->c->self_secret_key, packet + crypto_box_PUBLICKEYBYTES, |
873 | packet + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, | 882 | packet + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, |
874 | length - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), plain); | 883 | length - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), plain); |
875 | 884 | ||
876 | if ((uint32_t)len != length - (DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES)) | 885 | if (len != length - (DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES)) |
877 | return 1; | 886 | return 1; |
878 | 887 | ||
879 | if (memcmp(source_pubkey, plain + 1 + sizeof(uint64_t), crypto_box_PUBLICKEYBYTES) != 0) | 888 | if (memcmp(source_pubkey, plain + 1 + sizeof(uint64_t), crypto_box_PUBLICKEYBYTES) != 0) |
880 | return 1; | 889 | return 1; |
881 | 890 | ||
882 | return handle_fakeid_announce(onion_c, packet, plain, len); | 891 | return handle_dhtpk_announce(onion_c, packet, plain, len); |
883 | } | 892 | } |
884 | /* Send the packets to tell our friends what our DHT public key is. | 893 | /* Send the packets to tell our friends what our DHT public key is. |
885 | * | 894 | * |
@@ -890,13 +899,13 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source | |||
890 | * return the number of packets sent on success | 899 | * return the number of packets sent on success |
891 | * return -1 on failure. | 900 | * return -1 on failure. |
892 | */ | 901 | */ |
893 | static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both) | 902 | static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both) |
894 | { | 903 | { |
895 | if (friend_num >= onion_c->num_friends) | 904 | if (friend_num >= onion_c->num_friends) |
896 | return -1; | 905 | return -1; |
897 | 906 | ||
898 | uint8_t data[FAKEID_DATA_MAX_LENGTH]; | 907 | uint8_t data[DHTPK_DATA_MAX_LENGTH]; |
899 | data[0] = FAKEID_DATA_ID; | 908 | data[0] = ONION_DATA_DHTPK; |
900 | uint64_t no_replay = unix_time(); | 909 | uint64_t no_replay = unix_time(); |
901 | host_to_net((uint8_t *)&no_replay, sizeof(no_replay)); | 910 | host_to_net((uint8_t *)&no_replay, sizeof(no_replay)); |
902 | memcpy(data + 1, &no_replay, sizeof(no_replay)); | 911 | memcpy(data + 1, &no_replay, sizeof(no_replay)); |
@@ -908,7 +917,7 @@ static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num | |||
908 | int nodes_len = 0; | 917 | int nodes_len = 0; |
909 | 918 | ||
910 | if (num_nodes != 0) { | 919 | if (num_nodes != 0) { |
911 | nodes_len = pack_nodes(data + FAKEID_DATA_MIN_LENGTH, FAKEID_DATA_MAX_LENGTH - FAKEID_DATA_MIN_LENGTH, nodes, | 920 | nodes_len = pack_nodes(data + DHTPK_DATA_MIN_LENGTH, DHTPK_DATA_MAX_LENGTH - DHTPK_DATA_MIN_LENGTH, nodes, |
912 | num_nodes); | 921 | num_nodes); |
913 | 922 | ||
914 | if (nodes_len <= 0) | 923 | if (nodes_len <= 0) |
@@ -918,10 +927,10 @@ static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num | |||
918 | int num1 = -1, num2 = -1; | 927 | int num1 = -1, num2 = -1; |
919 | 928 | ||
920 | if (onion_dht_both != 1) | 929 | if (onion_dht_both != 1) |
921 | num1 = send_onion_data(onion_c, friend_num, data, FAKEID_DATA_MIN_LENGTH + nodes_len); | 930 | num1 = send_onion_data(onion_c, friend_num, data, DHTPK_DATA_MIN_LENGTH + nodes_len); |
922 | 931 | ||
923 | if (onion_dht_both != 0) | 932 | if (onion_dht_both != 0) |
924 | num2 = send_dht_fakeid(onion_c, friend_num, data, FAKEID_DATA_MIN_LENGTH + nodes_len); | 933 | num2 = send_dht_dhtpk(onion_c, friend_num, data, DHTPK_DATA_MIN_LENGTH + nodes_len); |
925 | 934 | ||
926 | if (num1 == -1) | 935 | if (num1 == -1) |
927 | return num2; | 936 | return num2; |
@@ -937,7 +946,7 @@ static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num | |||
937 | * return -1 on failure. | 946 | * return -1 on failure. |
938 | * return friend number on success. | 947 | * return friend number on success. |
939 | */ | 948 | */ |
940 | int onion_friend_num(const Onion_Client *onion_c, const uint8_t *client_id) | 949 | int onion_friend_num(const Onion_Client *onion_c, const uint8_t *public_key) |
941 | { | 950 | { |
942 | unsigned int i; | 951 | unsigned int i; |
943 | 952 | ||
@@ -945,7 +954,7 @@ int onion_friend_num(const Onion_Client *onion_c, const uint8_t *client_id) | |||
945 | if (onion_c->friends_list[i].status == 0) | 954 | if (onion_c->friends_list[i].status == 0) |
946 | continue; | 955 | continue; |
947 | 956 | ||
948 | if (memcmp(client_id, onion_c->friends_list[i].real_client_id, crypto_box_PUBLICKEYBYTES) == 0) | 957 | if (memcmp(public_key, onion_c->friends_list[i].real_public_key, crypto_box_PUBLICKEYBYTES) == 0) |
949 | return i; | 958 | return i; |
950 | } | 959 | } |
951 | 960 | ||
@@ -979,9 +988,9 @@ static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num) | |||
979 | * return -1 on failure. | 988 | * return -1 on failure. |
980 | * return the friend number on success or if the friend was already added. | 989 | * return the friend number on success or if the friend was already added. |
981 | */ | 990 | */ |
982 | int onion_addfriend(Onion_Client *onion_c, const uint8_t *client_id) | 991 | int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key) |
983 | { | 992 | { |
984 | int num = onion_friend_num(onion_c, client_id); | 993 | int num = onion_friend_num(onion_c, public_key); |
985 | 994 | ||
986 | if (num != -1) | 995 | if (num != -1) |
987 | return num; | 996 | return num; |
@@ -1005,7 +1014,7 @@ int onion_addfriend(Onion_Client *onion_c, const uint8_t *client_id) | |||
1005 | } | 1014 | } |
1006 | 1015 | ||
1007 | onion_c->friends_list[index].status = 1; | 1016 | onion_c->friends_list[index].status = 1; |
1008 | memcpy(onion_c->friends_list[index].real_client_id, client_id, crypto_box_PUBLICKEYBYTES); | 1017 | memcpy(onion_c->friends_list[index].real_public_key, public_key, crypto_box_PUBLICKEYBYTES); |
1009 | crypto_box_keypair(onion_c->friends_list[index].temp_public_key, onion_c->friends_list[index].temp_secret_key); | 1018 | crypto_box_keypair(onion_c->friends_list[index].temp_public_key, onion_c->friends_list[index].temp_secret_key); |
1010 | return index; | 1019 | return index; |
1011 | } | 1020 | } |
@@ -1020,8 +1029,8 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num) | |||
1020 | if ((uint32_t)friend_num >= onion_c->num_friends) | 1029 | if ((uint32_t)friend_num >= onion_c->num_friends) |
1021 | return -1; | 1030 | return -1; |
1022 | 1031 | ||
1023 | //if (onion_c->friends_list[friend_num].is_fake_clientid) | 1032 | //if (onion_c->friends_list[friend_num].know_dht_public_key) |
1024 | // DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, 0); | 1033 | // DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0); |
1025 | 1034 | ||
1026 | memset(&(onion_c->friends_list[friend_num]), 0, sizeof(Onion_Friend)); | 1035 | memset(&(onion_c->friends_list[friend_num]), 0, sizeof(Onion_Friend)); |
1027 | unsigned int i; | 1036 | unsigned int i; |
@@ -1092,17 +1101,17 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin | |||
1092 | if (onion_c->friends_list[friend_num].status == 0) | 1101 | if (onion_c->friends_list[friend_num].status == 0) |
1093 | return -1; | 1102 | return -1; |
1094 | 1103 | ||
1095 | if (onion_c->friends_list[friend_num].is_fake_clientid) { | 1104 | if (onion_c->friends_list[friend_num].know_dht_public_key) { |
1096 | if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) { | 1105 | if (memcmp(dht_key, onion_c->friends_list[friend_num].dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
1097 | return -1; | 1106 | return -1; |
1098 | } | 1107 | } |
1099 | 1108 | ||
1100 | onion_c->friends_list[friend_num].is_fake_clientid = 0; | 1109 | onion_c->friends_list[friend_num].know_dht_public_key = 0; |
1101 | } | 1110 | } |
1102 | 1111 | ||
1103 | onion_c->friends_list[friend_num].last_seen = unix_time(); | 1112 | onion_c->friends_list[friend_num].last_seen = unix_time(); |
1104 | onion_c->friends_list[friend_num].is_fake_clientid = 1; | 1113 | onion_c->friends_list[friend_num].know_dht_public_key = 1; |
1105 | memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES); | 1114 | memcpy(onion_c->friends_list[friend_num].dht_public_key, dht_key, crypto_box_PUBLICKEYBYTES); |
1106 | 1115 | ||
1107 | return 0; | 1116 | return 0; |
1108 | } | 1117 | } |
@@ -1120,18 +1129,18 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_ | |||
1120 | if (onion_c->friends_list[friend_num].status == 0) | 1129 | if (onion_c->friends_list[friend_num].status == 0) |
1121 | return 0; | 1130 | return 0; |
1122 | 1131 | ||
1123 | if (!onion_c->friends_list[friend_num].is_fake_clientid) | 1132 | if (!onion_c->friends_list[friend_num].know_dht_public_key) |
1124 | return 0; | 1133 | return 0; |
1125 | 1134 | ||
1126 | memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES); | 1135 | memcpy(dht_key, onion_c->friends_list[friend_num].dht_public_key, crypto_box_PUBLICKEYBYTES); |
1127 | return 1; | 1136 | return 1; |
1128 | } | 1137 | } |
1129 | 1138 | ||
1130 | /* Get the ip of friend friendnum and put it in ip_port | 1139 | /* Get the ip of friend friendnum and put it in ip_port |
1131 | * | 1140 | * |
1132 | * return -1, -- if client_id does NOT refer to a friend | 1141 | * return -1, -- if public_key does NOT refer to a friend |
1133 | * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) | 1142 | * return 0, -- if public_key refers to a friend and we failed to find the friend (yet) |
1134 | * return 1, ip if client_id refers to a friend and we found him | 1143 | * return 1, ip if public_key refers to a friend and we found him |
1135 | * | 1144 | * |
1136 | */ | 1145 | */ |
1137 | int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port) | 1146 | int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port) |
@@ -1176,15 +1185,15 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on | |||
1176 | static void populate_path_nodes(Onion_Client *onion_c) | 1185 | static void populate_path_nodes(Onion_Client *onion_c) |
1177 | { | 1186 | { |
1178 | Node_format nodes_list[MAX_SENT_NODES]; | 1187 | Node_format nodes_list[MAX_SENT_NODES]; |
1179 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | 1188 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
1180 | uint32_t random_num = rand(); | 1189 | uint32_t random_num = rand(); |
1181 | memcpy(client_id, &random_num, sizeof(random_num)); | 1190 | memcpy(public_key, &random_num, sizeof(random_num)); |
1182 | 1191 | ||
1183 | unsigned int num_nodes = get_close_nodes(onion_c->dht, client_id, nodes_list, (rand() % 2) ? AF_INET : AF_INET6, 1, 0); | 1192 | unsigned int num_nodes = get_close_nodes(onion_c->dht, public_key, nodes_list, (rand() % 2) ? AF_INET : AF_INET6, 1, 0); |
1184 | unsigned int i; | 1193 | unsigned int i; |
1185 | 1194 | ||
1186 | for (i = 0; i < num_nodes; ++i) { | 1195 | for (i = 0; i < num_nodes; ++i) { |
1187 | onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].client_id); | 1196 | onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key); |
1188 | } | 1197 | } |
1189 | } | 1198 | } |
1190 | 1199 | ||
@@ -1196,7 +1205,7 @@ static void populate_path_nodes_tcp(Onion_Client *onion_c) | |||
1196 | unsigned int i; | 1205 | unsigned int i; |
1197 | 1206 | ||
1198 | for (i = 0; i < num_nodes; ++i) { | 1207 | for (i = 0; i < num_nodes; ++i) { |
1199 | onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].client_id); | 1208 | onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key); |
1200 | } | 1209 | } |
1201 | } | 1210 | } |
1202 | 1211 | ||
@@ -1236,7 +1245,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
1236 | } | 1245 | } |
1237 | 1246 | ||
1238 | if (is_timeout(list_nodes[i].last_pinged, interval)) { | 1247 | if (is_timeout(list_nodes[i].last_pinged, interval)) { |
1239 | if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].client_id, 0, ~0) == 0) { | 1248 | if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].public_key, 0, ~0) == 0) { |
1240 | list_nodes[i].last_pinged = unix_time(); | 1249 | list_nodes[i].last_pinged = unix_time(); |
1241 | } | 1250 | } |
1242 | } | 1251 | } |
@@ -1256,7 +1265,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
1256 | for (j = 0; j < n; ++j) { | 1265 | for (j = 0; j < n; ++j) { |
1257 | unsigned int num = rand() % num_nodes; | 1266 | unsigned int num = rand() % num_nodes; |
1258 | client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port, | 1267 | client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port, |
1259 | onion_c->path_nodes[num].client_id, 0, ~0); | 1268 | onion_c->path_nodes[num].public_key, 0, ~0); |
1260 | } | 1269 | } |
1261 | 1270 | ||
1262 | ++onion_c->friends_list[friendnum].run_count; | 1271 | ++onion_c->friends_list[friendnum].run_count; |
@@ -1265,14 +1274,14 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
1265 | ++onion_c->friends_list[friendnum].run_count; | 1274 | ++onion_c->friends_list[friendnum].run_count; |
1266 | } | 1275 | } |
1267 | 1276 | ||
1268 | /* send packets to friend telling them our fake DHT id. */ | 1277 | /* send packets to friend telling them our DHT public key. */ |
1269 | if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) | 1278 | if (is_timeout(onion_c->friends_list[friendnum].last_dht_pk_onion_sent, ONION_DHTPK_SEND_INTERVAL)) |
1270 | if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) | 1279 | if (send_dhtpk_announce(onion_c, friendnum, 0) >= 1) |
1271 | onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); | 1280 | onion_c->friends_list[friendnum].last_dht_pk_onion_sent = unix_time(); |
1272 | 1281 | ||
1273 | if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) | 1282 | if (is_timeout(onion_c->friends_list[friendnum].last_dht_pk_dht_sent, DHT_DHTPK_SEND_INTERVAL)) |
1274 | if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) | 1283 | if (send_dhtpk_announce(onion_c, friendnum, 1) >= 1) |
1275 | onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); | 1284 | onion_c->friends_list[friendnum].last_dht_pk_dht_sent = unix_time(); |
1276 | 1285 | ||
1277 | } | 1286 | } |
1278 | } | 1287 | } |
@@ -1312,7 +1321,7 @@ static void do_announce(Onion_Client *onion_c) | |||
1312 | } | 1321 | } |
1313 | 1322 | ||
1314 | if (is_timeout(list_nodes[i].last_pinged, interval)) { | 1323 | if (is_timeout(list_nodes[i].last_pinged, interval)) { |
1315 | if (client_send_announce_request(onion_c, 0, list_nodes[i].ip_port, list_nodes[i].client_id, | 1324 | if (client_send_announce_request(onion_c, 0, list_nodes[i].ip_port, list_nodes[i].public_key, |
1316 | list_nodes[i].ping_id, list_nodes[i].path_used) == 0) { | 1325 | list_nodes[i].ping_id, list_nodes[i].path_used) == 0) { |
1317 | list_nodes[i].last_pinged = unix_time(); | 1326 | list_nodes[i].last_pinged = unix_time(); |
1318 | } | 1327 | } |
@@ -1335,7 +1344,7 @@ static void do_announce(Onion_Client *onion_c) | |||
1335 | if (num_nodes != 0) { | 1344 | if (num_nodes != 0) { |
1336 | for (i = 0; i < (MAX_ONION_CLIENTS / 2); ++i) { | 1345 | for (i = 0; i < (MAX_ONION_CLIENTS / 2); ++i) { |
1337 | unsigned int num = rand() % num_nodes; | 1346 | unsigned int num = rand() % num_nodes; |
1338 | client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].client_id, 0, ~0); | 1347 | client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, 0, ~0); |
1339 | } | 1348 | } |
1340 | } | 1349 | } |
1341 | } | 1350 | } |
@@ -1386,8 +1395,8 @@ Onion_Client *new_onion_client(Net_Crypto *c) | |||
1386 | crypto_box_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); | 1395 | crypto_box_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); |
1387 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); | 1396 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); |
1388 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); | 1397 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); |
1389 | oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c); | 1398 | oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, &handle_dhtpk_announce, onion_c); |
1390 | cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c); | 1399 | cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_FAKEID, &handle_dht_dhtpk, onion_c); |
1391 | tcp_onion_response_handler(onion_c->c, &handle_tcp_onion, onion_c); | 1400 | tcp_onion_response_handler(onion_c->c, &handle_tcp_onion, onion_c); |
1392 | 1401 | ||
1393 | return onion_c; | 1402 | return onion_c; |
@@ -1402,8 +1411,8 @@ void kill_onion_client(Onion_Client *onion_c) | |||
1402 | realloc_onion_friends(onion_c, 0); | 1411 | realloc_onion_friends(onion_c, 0); |
1403 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL); | 1412 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL); |
1404 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); | 1413 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); |
1405 | oniondata_registerhandler(onion_c, FAKEID_DATA_ID, NULL, NULL); | 1414 | oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL); |
1406 | cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, NULL, NULL); | 1415 | cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_FAKEID, NULL, NULL); |
1407 | tcp_onion_response_handler(onion_c->c, NULL, NULL); | 1416 | tcp_onion_response_handler(onion_c->c, NULL, NULL); |
1408 | memset(onion_c, 0, sizeof(Onion_Client)); | 1417 | memset(onion_c, 0, sizeof(Onion_Client)); |
1409 | free(onion_c); | 1418 | free(onion_c); |