Skip to content

Commit

Permalink
Speeded up onion requests.
Browse files Browse the repository at this point in the history
Also increased the maximum number of announce entries.
  • Loading branch information
irungentoo committed Mar 7, 2014
1 parent d058a59 commit 48d757f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion toxcore/onion_announce.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "onion.h"

#define ONION_ANNOUNCE_MAX_ENTRIES 32
#define ONION_ANNOUNCE_MAX_ENTRIES 48
#define ONION_ANNOUNCE_TIMEOUT 300
#define ONION_PING_ID_SIZE crypto_hash_sha256_BYTES

Expand Down
27 changes: 16 additions & 11 deletions toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,28 +519,33 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32
if ((uint32_t)len + crypto_box_PUBLICKEYBYTES != sizeof(packet))
return -1;

uint32_t i, good = 0;
uint32_t i, good_nodes[MAX_ONION_CLIENTS], num_good = 0;
Onion_Path path[MAX_ONION_CLIENTS];
Onion_Node *list_nodes = onion_c->friends_list[friend_num].clients_list;

for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT))
continue;

if (list_nodes[i].is_stored) {
Node_format nodes[4];
if (random_path(onion_c->dht, &onion_c->friends_list[friend_num].onion_paths, ~0, &path[num_good]) == -1)
continue;

Onion_Path path;
good_nodes[num_good] = i;
++num_good;
}
}

if (random_path(onion_c->dht, &onion_c->friends_list[friend_num].onion_paths, ~0, &path) == -1)
continue;
if (num_good < (MAX_ONION_CLIENTS / 4) + 1)
return -1;

memcpy(nodes[3].client_id, list_nodes[i].client_id, crypto_box_PUBLICKEYBYTES);
nodes[3].ip_port = list_nodes[i].ip_port;
uint32_t good = 0;

if (send_data_request(onion_c->net, &path, list_nodes[i].ip_port, onion_c->friends_list[friend_num].real_client_id,
list_nodes[i].data_public_key, nonce, packet, sizeof(packet)) == 0)
++good;
}
for (i = 0; i < num_good; ++i) {
if (send_data_request(onion_c->net, &path[i], list_nodes[good_nodes[i]].ip_port,
onion_c->friends_list[friend_num].real_client_id, list_nodes[good_nodes[i]].data_public_key, nonce, packet,
sizeof(packet)) == 0)
++good;
}

return good;
Expand Down

0 comments on commit 48d757f

Please sign in to comment.