Tox should now work on TCP only networks.

Coming soon: a function to disable UDP.
This commit is contained in:
irungentoo 2014-08-13 20:47:56 -04:00
parent 450ad2dd34
commit f4b10c99ff
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 16 additions and 8 deletions

View File

@ -38,16 +38,17 @@
* return -1 on failure
* return 0 on success
*/
static int add_path_node(Onion_Client *onion_c, Node_format *node)
int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id)
{
unsigned int i;
for (i = 0; i < MAX_PATH_NODES; ++i) {
if (memcmp(node->client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
if (memcmp(client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
return -1;
}
onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES] = *node;
onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port;
memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].client_id, client_id, crypto_box_PUBLICKEYBYTES);
uint16_t last = onion_c->path_nodes_index;
++onion_c->path_nodes_index;
@ -402,10 +403,8 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
memcpy(list_nodes[index].client_id, public_key, CLIENT_ID_SIZE);
list_nodes[index].ip_port = ip_port;
Node_format add_node; //TODO: remove this and find a better source of nodes to use for paths.
memcpy(add_node.client_id, public_key, CLIENT_ID_SIZE);
add_node.ip_port = ip_port;
add_path_node(onion_c, &add_node);
//TODO: remove this and find a better source of nodes to use for paths.
onion_add_path_node(onion_c, ip_port, public_key);
if (is_stored) {
memcpy(list_nodes[index].data_public_key, pingid_or_key, crypto_box_PUBLICKEYBYTES);
@ -1079,7 +1078,7 @@ static void populate_path_nodes(Onion_Client *onion_c)
unsigned int i;
for (i = 0; i < num_nodes; ++i) {
add_path_node(onion_c, nodes_list + i);
onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].client_id);
}
}
}

View File

@ -137,6 +137,14 @@ typedef struct {
} Onion_Data_Handlers[256];
} Onion_Client;
/* Add a node to the path_nodes array.
*
* return -1 on failure
* return 0 on success
*/
int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id);
/* Add a friend who we want to connect to.
*
* return -1 on failure.

View File

@ -775,6 +775,7 @@ static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled,
if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) {
ip_port_v64.port = port;
add_tcp_relay(m->net_crypto, ip_port_v64, public_key);
onion_add_path_node(m->onion_c, ip_port_v64, public_key); //TODO: move this
return 1;
} else {
return 0;