summaryrefslogtreecommitdiff
path: root/toxcore/onion_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r--toxcore/onion_client.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 7fab76a7..03ffbaa7 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -505,7 +505,7 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t
505 if (len_nodes != 0) { 505 if (len_nodes != 0) {
506 Node_format nodes[MAX_SENT_NODES]; 506 Node_format nodes[MAX_SENT_NODES];
507 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, data + 1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES, 507 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, data + 1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES,
508 len_nodes, 0); 508 len_nodes, 1);
509 509
510 if (num_nodes <= 0) 510 if (num_nodes <= 0)
511 return 1; 511 return 1;
@@ -513,7 +513,17 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t
513 int i; 513 int i;
514 514
515 for (i = 0; i < num_nodes; ++i) { 515 for (i = 0; i < num_nodes; ++i) {
516 DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].client_id, onion_c->friends_list[friend_num].fake_client_id); 516 uint8_t family = nodes[i].ip_port.ip.family;
517
518 if (family == AF_INET || family == AF_INET6) {
519 DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].client_id, onion_c->friends_list[friend_num].fake_client_id);
520 } else if (family == TCP_INET || family == TCP_INET6) {
521 if (onion_c->friends_list[friend_num].tcp_relay_node_callback) {
522 void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object;
523 uint32_t number = onion_c->friends_list[friend_num].tcp_relay_node_callback_number;
524 onion_c->friends_list[friend_num].tcp_relay_node_callback(obj, number, nodes[i].ip_port, nodes[i].client_id);
525 }
526 }
517 } 527 }
518 } 528 }
519 529
@@ -664,8 +674,9 @@ static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint
664 memcpy(data + 1, &no_replay, sizeof(no_replay)); 674 memcpy(data + 1, &no_replay, sizeof(no_replay));
665 memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES); 675 memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
666 Node_format nodes[MAX_SENT_NODES]; 676 Node_format nodes[MAX_SENT_NODES];
667 uint16_t num_nodes = closelist_nodes(onion_c->dht, nodes, MAX_SENT_NODES); 677 uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, (MAX_SENT_NODES / 2));
668 678 uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays);
679 num_nodes += num_relays;
669 int nodes_len = 0; 680 int nodes_len = 0;
670 681
671 if (num_nodes != 0) { 682 if (num_nodes != 0) {
@@ -800,6 +811,26 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
800 return friend_num; 811 return friend_num;
801} 812}
802 813
814/* Set the function for this friend that will be callbacked with object and number
815 * when that friends gives us one of the TCP relays he is connected to.
816 *
817 * object and number will be passed as argument to this function.
818 *
819 * return -1 on failure.
820 * return 0 on success.
821 */
822int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object,
823 uint32_t number, IP_Port ip_port, uint8_t *public_key), void *object, uint32_t number)
824{
825 if ((uint32_t)friend_num >= onion_c->num_friends)
826 return -1;
827
828 onion_c->friends_list[friend_num].tcp_relay_node_callback = tcp_relay_node_callback;
829 onion_c->friends_list[friend_num].tcp_relay_node_callback_object = object;
830 onion_c->friends_list[friend_num].tcp_relay_node_callback_number = number;
831 return 0;
832}
833
803/* Set a friends DHT public key. 834/* Set a friends DHT public key.
804 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to 835 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
805 * the other peer. 836 * the other peer.