diff options
author | irungentoo <irungentoo@gmail.com> | 2014-05-14 12:08:30 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-05-14 12:08:30 -0400 |
commit | 0b2c44a708a7559cd7e7332747a851d18ad1e322 (patch) | |
tree | ea8c7fcdc585a6cf14a3c3e7260775530c4191d6 /toxcore | |
parent | 8afe4a4fd7c963c6e2375832a830437bc1a1620f (diff) |
It's bad to have more than one path with the same first node in the
same path array.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 2 | ||||
-rw-r--r-- | toxcore/onion_client.c | 41 |
2 files changed, 39 insertions, 4 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 5d6992f1..33802b61 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2230,6 +2230,8 @@ static int random_node_fromlist(Client_data *list, uint16_t list_size, Node_form | |||
2230 | * return the number of nodes. | 2230 | * return the number of nodes. |
2231 | * | 2231 | * |
2232 | * NOTE:this is used to pick nodes for paths. | 2232 | * NOTE:this is used to pick nodes for paths. |
2233 | * | ||
2234 | * TODO: remove the LAN stuff from this. | ||
2233 | */ | 2235 | */ |
2234 | uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num) | 2236 | uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num) |
2235 | { | 2237 | { |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 9c2bd93d..73726a59 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -33,6 +33,33 @@ | |||
33 | #define ANNOUNCE_ARRAY_SIZE 256 | 33 | #define ANNOUNCE_ARRAY_SIZE 256 |
34 | #define ANNOUNCE_TIMEOUT 10 | 34 | #define ANNOUNCE_TIMEOUT 10 |
35 | 35 | ||
36 | |||
37 | /* | ||
38 | * return -1 if nodes are suitable for creating a new path. | ||
39 | * return path number of already existing similar path if one already exists. | ||
40 | */ | ||
41 | static int is_path_used(Onion_Client_Paths *onion_paths, Node_format *nodes) | ||
42 | { | ||
43 | uint32_t i; | ||
44 | |||
45 | for (i = 0; i < NUMBER_ONION_PATHS; ++i) { | ||
46 | if (is_timeout(onion_paths->last_path_success[i], ONION_PATH_TIMEOUT)) { | ||
47 | continue; | ||
48 | } | ||
49 | |||
50 | if (is_timeout(onion_paths->path_creation_time[i], ONION_PATH_MAX_LIFETIME)) { | ||
51 | continue; | ||
52 | } | ||
53 | |||
54 | if (ipport_equal(&onion_paths->paths[i].ip_port1, &nodes[0].ip_port)) { | ||
55 | printf("bad\n"); | ||
56 | return i; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | return -1; | ||
61 | } | ||
62 | |||
36 | /* Create a new path or use an old suitable one (if pathnum is valid) | 63 | /* Create a new path or use an old suitable one (if pathnum is valid) |
37 | * or a rondom one from onion_paths. | 64 | * or a rondom one from onion_paths. |
38 | * | 65 | * |
@@ -54,11 +81,17 @@ static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathn | |||
54 | if (random_nodes_path(dht, nodes, 3) != 3) | 81 | if (random_nodes_path(dht, nodes, 3) != 3) |
55 | return -1; | 82 | return -1; |
56 | 83 | ||
57 | if (create_onion_path(dht, &onion_paths->paths[pathnum], nodes) == -1) | 84 | int n = is_path_used(onion_paths, nodes); |
58 | return -1; | ||
59 | 85 | ||
60 | onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; | 86 | if (n == -1) { |
61 | onion_paths->path_creation_time[pathnum] = unix_time(); | 87 | if (create_onion_path(dht, &onion_paths->paths[pathnum], nodes) == -1) |
88 | return -1; | ||
89 | |||
90 | onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; | ||
91 | onion_paths->path_creation_time[pathnum] = unix_time(); | ||
92 | } else { | ||
93 | pathnum = n; | ||
94 | } | ||
62 | } | 95 | } |
63 | 96 | ||
64 | memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); | 97 | memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); |