diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-21 20:42:20 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-21 20:42:20 +0000 |
commit | e73416feea2be995456c62f74b33e714501cdb33 (patch) | |
tree | e42d8b3cfef656ff3f21ac5be33406142f1f2499 /src/mesh/mesh_tunnel_tree.c | |
parent | 1b4c0a8b0c8cfc6e36197c37ca0cbaaeb5eb7927 (diff) | |
download | gnunet-e73416feea2be995456c62f74b33e714501cdb33.tar.gz gnunet-e73416feea2be995456c62f74b33e714501cdb33.zip |
Fixed double chaining on note reattachment
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.c')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index ef4e4a5a0..929b1b69b 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -178,6 +178,7 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | |||
178 | GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey); | 178 | GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey); |
179 | if (NULL != pi) | 179 | if (NULL != pi) |
180 | GNUNET_free(pi); | 180 | GNUNET_free(pi); |
181 | // FIXME: add to service code on callback | ||
181 | // struct GNUNET_MESH_PeerControl msg; | 182 | // struct GNUNET_MESH_PeerControl msg; |
182 | // if (NULL == parent->t->client) | 183 | // if (NULL == parent->t->client) |
183 | // return; | 184 | // return; |
@@ -192,6 +193,60 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | |||
192 | } | 193 | } |
193 | 194 | ||
194 | 195 | ||
196 | /** | ||
197 | * Recusively update the info about what is the first hop to reach the node | ||
198 | * | ||
199 | * @param tree Tree this nodes belongs to | ||
200 | * @param parent Node to be start updating | ||
201 | * @param hop If known, ID of the first hop. | ||
202 | * If not known, NULL to find out and pass on children. | ||
203 | */ | ||
204 | void | ||
205 | tree_update_first_hops (struct MeshTunnelTree *tree, | ||
206 | struct MeshTunnelTreeNode *parent, | ||
207 | struct GNUNET_PeerIdentity *hop) | ||
208 | { | ||
209 | struct GNUNET_PeerIdentity pi; | ||
210 | struct GNUNET_PeerIdentity *copy; | ||
211 | struct GNUNET_PeerIdentity id; | ||
212 | unsigned int i; | ||
213 | |||
214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
215 | "tree: Finding first hop for %u.\n", | ||
216 | parent->peer); | ||
217 | if (NULL == hop) | ||
218 | { | ||
219 | struct MeshTunnelTreeNode *aux; | ||
220 | struct MeshTunnelTreeNode *old; | ||
221 | |||
222 | old = parent; | ||
223 | aux = old->parent; | ||
224 | while (aux != tree->me) | ||
225 | { | ||
226 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "tree: ... its not %u.\n", | ||
228 | old->peer); | ||
229 | old = aux; | ||
230 | aux = aux->parent; | ||
231 | GNUNET_assert(NULL != aux); | ||
232 | } | ||
233 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
234 | "tree: It's %u!!\n", | ||
235 | old->peer); | ||
236 | hop = π | ||
237 | GNUNET_PEER_resolve(old->peer, hop); | ||
238 | } | ||
239 | copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | ||
240 | *copy = *hop; | ||
241 | GNUNET_PEER_resolve(parent->peer, &id); | ||
242 | GNUNET_CONTAINER_multihashmap_put(tree->first_hops, &id.hashPubKey, copy, | ||
243 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
244 | |||
245 | for (i = 0; i < parent->nchildren; i++) | ||
246 | { | ||
247 | tree_update_first_hops (tree, &parent->children[i], hop); | ||
248 | } | ||
249 | } | ||
195 | 250 | ||
196 | 251 | ||
197 | /** | 252 | /** |
@@ -213,7 +268,7 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, | |||
213 | struct MeshTunnelTreeNode *node; | 268 | struct MeshTunnelTreeNode *node; |
214 | struct MeshTunnelTreeNode *n; | 269 | struct MeshTunnelTreeNode *n; |
215 | 270 | ||
216 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting path to %u.\n", peer_id); | 271 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %u.\n", peer_id); |
217 | if (peer_id == t->root->peer) | 272 | if (peer_id == t->root->peer) |
218 | return NULL; | 273 | return NULL; |
219 | n = tree_find_peer (t->me, peer_id); | 274 | n = tree_find_peer (t->me, peer_id); |
@@ -231,7 +286,7 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, | |||
231 | while (t->root != parent && MESH_PEER_RELAY == parent->status && | 286 | while (t->root != parent && MESH_PEER_RELAY == parent->status && |
232 | 0 == parent->nchildren) | 287 | 0 == parent->nchildren) |
233 | { | 288 | { |
234 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting node %u.\n", parent->peer); | 289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %u.\n", parent->peer); |
235 | n = parent->parent; | 290 | n = parent->parent; |
236 | tree_node_destroy(parent); | 291 | tree_node_destroy(parent); |
237 | parent = n; | 292 | parent = n; |
@@ -309,7 +364,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
309 | unsigned int j; | 364 | unsigned int j; |
310 | 365 | ||
311 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 366 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
312 | "Adding path [%u] towards peer %u to peer %u.\n", | 367 | "tree: Adding path [%u] towards peer %u to peer %u.\n", |
313 | p->length, | 368 | p->length, |
314 | p->peers[p->length - 1], | 369 | p->peers[p->length - 1], |
315 | t->me->peer); | 370 | t->me->peer); |
@@ -333,7 +388,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
333 | for (i = 1; i < p->length; i++) | 388 | for (i = 1; i < p->length; i++) |
334 | { | 389 | { |
335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
336 | "Looking for peer %u.\n", | 391 | "tree: Looking for peer %u.\n", |
337 | p->peers[i]); | 392 | p->peers[i]); |
338 | parent = n; | 393 | parent = n; |
339 | if (p->peers[i] == myid) | 394 | if (p->peers[i] == myid) |
@@ -352,7 +407,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
352 | break; | 407 | break; |
353 | } | 408 | } |
354 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 409 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
355 | "All childen visited.\n"); | 410 | "tree: All childen visited.\n"); |
356 | if (-1 == me) | 411 | if (-1 == me) |
357 | { | 412 | { |
358 | /* New path deviates from tree before reaching us. What happened? */ | 413 | /* New path deviates from tree before reaching us. What happened? */ |
@@ -363,7 +418,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
363 | while (i < p->length) | 418 | while (i < p->length) |
364 | { | 419 | { |
365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
366 | "Adding peer %u, to %u.\n", | 421 | "tree: Adding peer %u, to %u.\n", |
367 | p->peers[i], | 422 | p->peers[i], |
368 | parent->peer); | 423 | parent->peer); |
369 | parent->nchildren++; | 424 | parent->nchildren++; |
@@ -371,27 +426,29 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
371 | parent->nchildren * | 426 | parent->nchildren * |
372 | sizeof(struct MeshTunnelTreeNode)); | 427 | sizeof(struct MeshTunnelTreeNode)); |
373 | n = &parent->children[parent->nchildren - 1]; | 428 | n = &parent->children[parent->nchildren - 1]; |
429 | n->parent = parent; | ||
374 | if (i == p->length - 1 && NULL != oldnode) | 430 | if (i == p->length - 1 && NULL != oldnode) |
375 | { | 431 | { |
376 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting old note into place.\n"); | 432 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Putting old node into place.\n"); |
377 | /* Assignation and free can be misleading, using explicit mempcy */ | 433 | /* Assignation and free can be misleading, using explicit mempcy */ |
378 | memcpy (n, oldnode, sizeof (struct MeshTunnelTreeNode)); | 434 | memcpy (n, oldnode, sizeof (struct MeshTunnelTreeNode)); |
435 | n->parent = parent; | ||
379 | GNUNET_free (oldnode); | 436 | GNUNET_free (oldnode); |
380 | for (j = 0; j < n->nchildren; j++) | 437 | for (j = 0; j < n->nchildren; j++) |
381 | { | 438 | { |
382 | n->children[j].parent = n; | 439 | n->children[j].parent = n; |
440 | tree_update_first_hops (t, &n->children[j], NULL); | ||
383 | } | 441 | } |
384 | } | 442 | } |
385 | else | 443 | else |
386 | { | 444 | { |
387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating new node.\n"); | 445 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); |
388 | n->t = t->t; | 446 | n->t = t->t; |
389 | n->status = MESH_PEER_RELAY; | 447 | n->status = MESH_PEER_RELAY; |
390 | n->peer = p->peers[i]; | 448 | n->peer = p->peers[i]; |
391 | n->nchildren = 0; | 449 | n->nchildren = 0; |
392 | n->children = NULL; | 450 | n->children = NULL; |
393 | } | 451 | } |
394 | n->parent = parent; | ||
395 | i++; | 452 | i++; |
396 | parent = n; | 453 | parent = n; |
397 | } | 454 | } |
@@ -410,7 +467,7 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | |||
410 | hop, | 467 | hop, |
411 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 468 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
412 | } | 469 | } |
413 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New node added.\n"); | 470 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); |
414 | return GNUNET_OK; | 471 | return GNUNET_OK; |
415 | } | 472 | } |
416 | 473 | ||
@@ -435,7 +492,7 @@ tree_node_destroy (struct MeshTunnelTreeNode *n) | |||
435 | if (n->children != NULL) | 492 | if (n->children != NULL) |
436 | GNUNET_free(n->children); | 493 | GNUNET_free(n->children); |
437 | } | 494 | } |
438 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying node %u.\n", n->peer); | 495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u.\n", n->peer); |
439 | if (NULL == (parent = n->parent)) | 496 | if (NULL == (parent = n->parent)) |
440 | return; | 497 | return; |
441 | i = (n - parent->children) / sizeof(struct MeshTunnelTreeNode); | 498 | i = (n - parent->children) / sizeof(struct MeshTunnelTreeNode); |
@@ -445,7 +502,7 @@ tree_node_destroy (struct MeshTunnelTreeNode *n) | |||
445 | parent->nchildren | 502 | parent->nchildren |
446 | * sizeof(struct MeshTunnelTreeNode)); | 503 | * sizeof(struct MeshTunnelTreeNode)); |
447 | 504 | ||
448 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroyed.\n"); | 505 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Destroyed.\n"); |
449 | } | 506 | } |
450 | 507 | ||
451 | 508 | ||