diff options
-rw-r--r-- | toxcore/onion_client.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index e99dc713..14c89eb6 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -778,19 +778,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
778 | if (length == 0) | 778 | if (length == 0) |
779 | return -1; | 779 | return -1; |
780 | 780 | ||
781 | uint8_t nonce[crypto_box_NONCEBYTES]; | ||
782 | random_nonce(nonce); | ||
783 | |||
784 | uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; | ||
785 | memcpy(packet, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
786 | int len = encrypt_data(onion_c->friends_list[friend_num].real_client_id, onion_c->c->self_secret_key, nonce, data, | ||
787 | length, packet + crypto_box_PUBLICKEYBYTES); | ||
788 | |||
789 | if ((uint32_t)len + crypto_box_PUBLICKEYBYTES != sizeof(packet)) | ||
790 | return -1; | ||
791 | |||
792 | 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; |
793 | Onion_Path path[MAX_ONION_CLIENTS]; | ||
794 | 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; |
795 | 783 | ||
796 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { | 784 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
@@ -800,9 +788,6 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
800 | ++num_nodes; | 788 | ++num_nodes; |
801 | 789 | ||
802 | if (list_nodes[i].is_stored) { | 790 | if (list_nodes[i].is_stored) { |
803 | if (random_path(onion_c, &onion_c->onion_paths_friends, ~0, &path[num_good]) == -1) | ||
804 | continue; | ||
805 | |||
806 | good_nodes[num_good] = i; | 791 | good_nodes[num_good] = i; |
807 | ++num_good; | 792 | ++num_good; |
808 | } | 793 | } |
@@ -811,9 +796,25 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
811 | if (num_good < (num_nodes / 4) + 1) | 796 | if (num_good < (num_nodes / 4) + 1) |
812 | return -1; | 797 | return -1; |
813 | 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_client_id, 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 | |||
814 | unsigned int good = 0; | 810 | unsigned int good = 0; |
815 | 811 | ||
816 | 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 | |||
817 | uint8_t o_packet[ONION_MAX_PACKET_SIZE]; | 818 | uint8_t o_packet[ONION_MAX_PACKET_SIZE]; |
818 | 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_client_id, |
819 | 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)); |
@@ -821,7 +822,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
821 | if (len == -1) | 822 | if (len == -1) |
822 | continue; | 823 | continue; |
823 | 824 | ||
824 | 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) |
825 | ++good; | 826 | ++good; |
826 | } | 827 | } |
827 | 828 | ||