Very simple fix to lower bandwidth usage at startup.

This commit is contained in:
irungentoo 2014-02-28 21:14:55 -05:00
parent d0d9f95b34
commit 16b93e823b
2 changed files with 19 additions and 1 deletions

View File

@ -300,19 +300,26 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n
Onion_Node *list_nodes = NULL;
uint8_t *reference_id = NULL;
uint32_t *ping_nodes_sent_second = NULL;
if (num == 0) {
list_nodes = onion_c->clients_announce_list;
reference_id = onion_c->dht->c->self_public_key;
ping_nodes_sent_second = &onion_c->ping_nodes_sent_second;
} else {
list_nodes = onion_c->friends_list[num - 1].clients_list;
reference_id = onion_c->friends_list[num - 1].real_client_id;
ping_nodes_sent_second = &onion_c->friends_list[num - 1].ping_nodes_sent_second;
}
uint32_t i, j;
int lan_ips_accepted = (LAN_ip(source.ip) == 0);
for (i = 0; i < num_nodes; ++i) {
if (*ping_nodes_sent_second > MAX_PING_NODES_SECOND_PEER)
return 0;
to_host_family(&nodes[i].ip_port.ip);
if (!lan_ips_accepted)
@ -329,7 +336,8 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n
}
if (j == MAX_ONION_CLIENTS) {
client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL, ~0);
if (client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL, ~0) == 0)
++*ping_nodes_sent_second;
}
}
}
@ -923,8 +931,10 @@ void do_onion_client(Onion_Client *onion_c)
for (i = 0; i < onion_c->num_friends; ++i) {
do_friend(onion_c, i);
cleanup_friend(onion_c, i);
onion_c->friends_list[i].ping_nodes_sent_second = 0;
}
onion_c->ping_nodes_sent_second = 0;
onion_c->last_run = unix_time();
}

View File

@ -40,6 +40,11 @@
#define ONION_PATH_FIRST_TIMEOUT 5
#define ONION_PATH_TIMEOUT 30
/* A cheap way of making it take less bandwidth at startup:
by limiting the number of ping packets we can send per
second per peer. */
#define MAX_PING_NODES_SECOND_PEER 5
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
IP_Port ip_port;
@ -79,6 +84,7 @@ typedef struct {
uint64_t last_seen;
Onion_Client_Paths onion_paths;
uint32_t ping_nodes_sent_second;
} Onion_Friend;
typedef int (*oniondata_handler_callback)(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t len);
@ -98,6 +104,8 @@ typedef struct {
uint8_t temp_public_key[crypto_box_PUBLICKEYBYTES];
uint8_t temp_secret_key[crypto_box_SECRETKEYBYTES];
uint32_t ping_nodes_sent_second;
struct {
oniondata_handler_callback function;
void *object;