It's bad to have more than one path with the same first node in the

same path array.
This commit is contained in:
irungentoo 2014-05-14 12:08:30 -04:00
parent 8afe4a4fd7
commit 0b2c44a708
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 39 additions and 4 deletions

View File

@ -2230,6 +2230,8 @@ static int random_node_fromlist(Client_data *list, uint16_t list_size, Node_form
* return the number of nodes. * return the number of nodes.
* *
* NOTE:this is used to pick nodes for paths. * NOTE:this is used to pick nodes for paths.
*
* TODO: remove the LAN stuff from this.
*/ */
uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num) uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num)
{ {

View File

@ -33,6 +33,33 @@
#define ANNOUNCE_ARRAY_SIZE 256 #define ANNOUNCE_ARRAY_SIZE 256
#define ANNOUNCE_TIMEOUT 10 #define ANNOUNCE_TIMEOUT 10
/*
* return -1 if nodes are suitable for creating a new path.
* return path number of already existing similar path if one already exists.
*/
static int is_path_used(Onion_Client_Paths *onion_paths, Node_format *nodes)
{
uint32_t i;
for (i = 0; i < NUMBER_ONION_PATHS; ++i) {
if (is_timeout(onion_paths->last_path_success[i], ONION_PATH_TIMEOUT)) {
continue;
}
if (is_timeout(onion_paths->path_creation_time[i], ONION_PATH_MAX_LIFETIME)) {
continue;
}
if (ipport_equal(&onion_paths->paths[i].ip_port1, &nodes[0].ip_port)) {
printf("bad\n");
return i;
}
}
return -1;
}
/* Create a new path or use an old suitable one (if pathnum is valid) /* Create a new path or use an old suitable one (if pathnum is valid)
* or a rondom one from onion_paths. * or a rondom one from onion_paths.
* *
@ -54,11 +81,17 @@ static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathn
if (random_nodes_path(dht, nodes, 3) != 3) if (random_nodes_path(dht, nodes, 3) != 3)
return -1; return -1;
if (create_onion_path(dht, &onion_paths->paths[pathnum], nodes) == -1) int n = is_path_used(onion_paths, nodes);
return -1;
onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; if (n == -1) {
onion_paths->path_creation_time[pathnum] = unix_time(); if (create_onion_path(dht, &onion_paths->paths[pathnum], nodes) == -1)
return -1;
onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT;
onion_paths->path_creation_time[pathnum] = unix_time();
} else {
pathnum = n;
}
} }
memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path));