diff options
Diffstat (limited to 'src/cadet/cadet_path.c')
-rw-r--r-- | src/cadet/cadet_path.c | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/src/cadet/cadet_path.c b/src/cadet/cadet_path.c index 47241292b..0358d64ca 100644 --- a/src/cadet/cadet_path.c +++ b/src/cadet/cadet_path.c | |||
@@ -33,10 +33,7 @@ | |||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * @brief Destroy a path after some time has past. | 35 | * @brief Destroy a path after some time has past. |
36 | * | 36 | * Removes the path from the peer (must not be used for direct paths). |
37 | * If the path is returned from DHT again after a while, try again. | ||
38 | * | ||
39 | * Removes the path from the peer (except for direct paths). | ||
40 | * | 37 | * |
41 | * @param cls Closure (path to destroy). | 38 | * @param cls Closure (path to destroy). |
42 | */ | 39 | */ |
@@ -45,28 +42,17 @@ path_destroy_delayed (void *cls) | |||
45 | { | 42 | { |
46 | struct CadetPeerPath *path = cls; | 43 | struct CadetPeerPath *path = cls; |
47 | struct CadetPeer *peer; | 44 | struct CadetPeer *peer; |
48 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
49 | 45 | ||
50 | LOG (GNUNET_ERROR_TYPE_INFO, "Destroy delayed %p (%u)\n", path, path->length); | ||
51 | path->path_delete = NULL; | 46 | path->path_delete = NULL; |
52 | 47 | LOG (GNUNET_ERROR_TYPE_INFO, | |
53 | /* During shutdown, the peers peermap might not exist anymore. */ | 48 | "Destroy delayed %p (%u)\n", |
54 | tc = GNUNET_SCHEDULER_get_task_context (); | 49 | path, |
55 | if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) == 0) | 50 | path->length); |
56 | { | 51 | GNUNET_assert (2 < path->length); |
57 | if (2 >= path->length) | 52 | peer = GCP_get_short (path->peers[path->length - 1], |
58 | { | 53 | GNUNET_NO); |
59 | /* This is not the place to destroy direct paths, only core_disconnect | 54 | GNUNET_assert (NULL != peer); |
60 | * should do it and never delay it. | 55 | GCP_remove_path (peer, path); |
61 | */ | ||
62 | GNUNET_break (0); | ||
63 | } | ||
64 | peer = GCP_get_short (path->peers[path->length - 1], GNUNET_NO); | ||
65 | if (NULL != peer) | ||
66 | GCP_remove_path (peer, path); | ||
67 | } | ||
68 | else | ||
69 | path_destroy (path); | ||
70 | } | 56 | } |
71 | 57 | ||
72 | 58 | ||
@@ -74,7 +60,6 @@ path_destroy_delayed (void *cls) | |||
74 | * Create a new path | 60 | * Create a new path |
75 | * | 61 | * |
76 | * @param length How many hops will the path have. | 62 | * @param length How many hops will the path have. |
77 | * | ||
78 | * @return A newly allocated path with a peer array of the specified length. | 63 | * @return A newly allocated path with a peer array of the specified length. |
79 | */ | 64 | */ |
80 | struct CadetPeerPath * | 65 | struct CadetPeerPath * |
@@ -125,7 +110,9 @@ path_duplicate (const struct CadetPeerPath *path) | |||
125 | unsigned int i; | 110 | unsigned int i; |
126 | 111 | ||
127 | aux = path_new (path->length); | 112 | aux = path_new (path->length); |
128 | memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id)); | 113 | memcpy (aux->peers, |
114 | path->peers, | ||
115 | path->length * sizeof (GNUNET_PEER_Id)); | ||
129 | for (i = 0; i < aux->length; i++) | 116 | for (i = 0; i < aux->length; i++) |
130 | GNUNET_PEER_change_rc (aux->peers[i], 1); | 117 | GNUNET_PEER_change_rc (aux->peers[i], 1); |
131 | return aux; | 118 | return aux; |
@@ -167,9 +154,13 @@ path_invalidate (struct CadetPeerPath *p) | |||
167 | if (NULL != p->path_delete) | 154 | if (NULL != p->path_delete) |
168 | return; | 155 | return; |
169 | 156 | ||
170 | LOG (GNUNET_ERROR_TYPE_INFO, "Invalidating path %p (%u)\n", p, p->length); | 157 | LOG (GNUNET_ERROR_TYPE_INFO, |
171 | p->path_delete = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 158 | "Invalidating path %p (%u)\n", |
172 | &path_destroy_delayed, p); | 159 | p, |
160 | p->length); | ||
161 | p->path_delete | ||
162 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
163 | &path_destroy_delayed, p); | ||
173 | } | 164 | } |
174 | 165 | ||
175 | 166 | ||
@@ -242,8 +233,8 @@ path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers, | |||
242 | * @param p1 First path | 233 | * @param p1 First path |
243 | * @param p2 Second path | 234 | * @param p2 Second path |
244 | * | 235 | * |
245 | * @return GNUNET_YES if both paths are equivalent | 236 | * @return #GNUNET_YES if both paths are equivalent |
246 | * GNUNET_NO otherwise | 237 | * #GNUNET_NO otherwise |
247 | */ | 238 | */ |
248 | int | 239 | int |
249 | path_equivalent (const struct CadetPeerPath *p1, | 240 | path_equivalent (const struct CadetPeerPath *p1, |
@@ -293,7 +284,7 @@ path_is_valid (const struct CadetPeerPath *path) | |||
293 | * | 284 | * |
294 | * @param p the path to destroy | 285 | * @param p the path to destroy |
295 | * | 286 | * |
296 | * @return GNUNET_OK on success | 287 | * @return #GNUNET_OK on success |
297 | */ | 288 | */ |
298 | int | 289 | int |
299 | path_destroy (struct CadetPeerPath *p) | 290 | path_destroy (struct CadetPeerPath *p) |
@@ -301,7 +292,10 @@ path_destroy (struct CadetPeerPath *p) | |||
301 | if (NULL == p) | 292 | if (NULL == p) |
302 | return GNUNET_OK; | 293 | return GNUNET_OK; |
303 | 294 | ||
304 | LOG (GNUNET_ERROR_TYPE_INFO, "destroying path %p (%u)\n", p, p->length); | 295 | LOG (GNUNET_ERROR_TYPE_INFO, |
296 | "destroying path %p (%u)\n", | ||
297 | p, | ||
298 | p->length); | ||
305 | GNUNET_PEER_decrement_rcs (p->peers, p->length); | 299 | GNUNET_PEER_decrement_rcs (p->peers, p->length); |
306 | GNUNET_free_non_null (p->peers); | 300 | GNUNET_free_non_null (p->peers); |
307 | if (NULL != p->path_delete) | 301 | if (NULL != p->path_delete) |
@@ -322,7 +316,8 @@ path_destroy (struct CadetPeerPath *p) | |||
322 | * 0 if they are identical. | 316 | * 0 if they are identical. |
323 | */ | 317 | */ |
324 | int | 318 | int |
325 | path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2) | 319 | path_cmp (const struct CadetPeerPath *p1, |
320 | const struct CadetPeerPath *p2) | ||
326 | { | 321 | { |
327 | if (p1->length > p2->length) | 322 | if (p1->length > p2->length) |
328 | return 1; | 323 | return 1; |
@@ -330,7 +325,9 @@ path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2) | |||
330 | if (p1->length < p2->length) | 325 | if (p1->length < p2->length) |
331 | return -1; | 326 | return -1; |
332 | 327 | ||
333 | return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length); | 328 | return memcmp (p1->peers, |
329 | p2->peers, | ||
330 | sizeof (GNUNET_PEER_Id) * p1->length); | ||
334 | } | 331 | } |
335 | 332 | ||
336 | 333 | ||