aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-09-21 20:42:20 +0000
committerBart Polot <bart@net.in.tum.de>2011-09-21 20:42:20 +0000
commite73416feea2be995456c62f74b33e714501cdb33 (patch)
treee42d8b3cfef656ff3f21ac5be33406142f1f2499 /src/mesh
parent1b4c0a8b0c8cfc6e36197c37ca0cbaaeb5eb7927 (diff)
downloadgnunet-e73416feea2be995456c62f74b33e714501cdb33.tar.gz
gnunet-e73416feea2be995456c62f74b33e714501cdb33.zip
Fixed double chaining on note reattachment
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_tunnel_tree.c81
-rw-r--r--src/mesh/mesh_tunnel_tree.h15
-rw-r--r--src/mesh/test_mesh_path_api.c20
3 files changed, 86 insertions, 30 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 */
204void
205tree_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 = &pi;
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
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h
index 4d46d734f..401ebb089 100644
--- a/src/mesh/mesh_tunnel_tree.h
+++ b/src/mesh/mesh_tunnel_tree.h
@@ -189,7 +189,7 @@ path_get_length (struct MeshPeerPath *path);
189/** 189/**
190 * Get the cost of the path relative to the already built tunnel tree 190 * Get the cost of the path relative to the already built tunnel tree
191 * 191 *
192 * @param t The tunnel to which compare 192 * @param t The tunnel tree to which compare
193 * @param path The individual path to reach a peer 193 * @param path The individual path to reach a peer
194 * 194 *
195 * @return Number of hops to reach destination, UINT_MAX in case the peer is not 195 * @return Number of hops to reach destination, UINT_MAX in case the peer is not
@@ -212,19 +212,6 @@ tree_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id);
212 212
213 213
214/** 214/**
215 * Recusively mark peer and children as disconnected, notify client
216 *
217 * @param tree Tree this node belongs to
218 * @param parent Node to be clean, potentially with children
219 * @param cb Callback to use to notify about disconnected peers
220 */
221void
222tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
223 struct MeshTunnelTreeNode *parent,
224 MeshNodeDisconnectCB cb);
225
226
227/**
228 * Delete the current path to the peer, including all now unused relays. 215 * Delete the current path to the peer, including all now unused relays.
229 * The destination peer is NOT destroyed, it is returned in order to either set 216 * The destination peer is NOT destroyed, it is returned in order to either set
230 * a new path to it or destroy it explicitly, taking care of it's child nodes. 217 * a new path to it or destroy it explicitly, taking care of it's child nodes.
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c
index d033d0c83..36eace93d 100644
--- a/src/mesh/test_mesh_path_api.c
+++ b/src/mesh/test_mesh_path_api.c
@@ -57,6 +57,7 @@ finish(void)
57{ 57{
58 unsigned int i; 58 unsigned int i;
59 59
60 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
60 for (i = 0; i < 10; i++) 61 for (i = 0; i < 10; i++)
61 { 62 {
62 GNUNET_free(pi[i]); 63 GNUNET_free(pi[i]);
@@ -117,6 +118,7 @@ main (int argc, char *argv[])
117 path->peers[3] = 3; 118 path->peers[3] = 3;
118 path->length = 4; 119 path->length = 4;
119 120
121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 0 1 2 3\n");
120 tree_add_path(tree, path, &cb); 122 tree_add_path(tree, path, &cb);
121 path1 = tree_get_path_to_peer(tree, 3); 123 path1 = tree_get_path_to_peer(tree, 3);
122 if (path->length != path1->length || 124 if (path->length != path1->length ||
@@ -182,11 +184,9 @@ main (int argc, char *argv[])
182 failed++; 184 failed++;
183 } 185 }
184 186
187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 0 1 2\n");
185 path->length--; 188 path->length--;
186 tree_add_path(tree, path, &cb); 189 tree_add_path(tree, path, &cb);
187 path->length++;
188 path_destroy(path);
189 finish();
190 190
191 node = tree_find_peer(tree->root, 2); 191 node = tree_find_peer(tree->root, 2);
192 if (node->peer != 2) 192 if (node->peer != 2)
@@ -207,11 +207,13 @@ main (int argc, char *argv[])
207 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) 207 if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
208 { 208 {
209 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); 209 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
210 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "3 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 3)));
210 failed++; 211 failed++;
211 } 212 }
212 if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1) 213 if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1)
213 { 214 {
214 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); 215 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
216 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "2 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 2)));
215 failed++; 217 failed++;
216 } 218 }
217 219
@@ -231,7 +233,11 @@ main (int argc, char *argv[])
231 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); 233 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
232 failed++; 234 failed++;
233 } 235 }
236 path->length++;
237 path_destroy(path);
238 finish();
234 239
240 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
235 path->length++; 241 path->length++;
236 path->peers[3] = 4; 242 path->peers[3] = 4;
237 tree_add_path(tree, path, &cb); 243 tree_add_path(tree, path, &cb);
@@ -286,6 +292,8 @@ main (int argc, char *argv[])
286 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 292 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
287 failed++; 293 failed++;
288 } 294 }
295
296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
289 node->status = MESH_PEER_READY; 297 node->status = MESH_PEER_READY;
290 cb_call = 1; 298 cb_call = 1;
291 node2 = tree_del_path(tree, 4, &cb); 299 node2 = tree_del_path(tree, 4, &cb);
@@ -299,7 +307,7 @@ main (int argc, char *argv[])
299 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 307 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
300 failed++; 308 failed++;
301 } 309 }
302// GNUNET_free(node2); FIXME destroy 310
303 node = tree_find_peer(tree->root, 2); 311 node = tree_find_peer(tree->root, 2);
304 if (node->peer != 2) 312 if (node->peer != 2)
305 { 313 {
@@ -317,6 +325,10 @@ main (int argc, char *argv[])
317 failed++; 325 failed++;
318 } 326 }
319 327
328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
329 tree_node_destroy(node2);
330
331 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding new shorter first path...\n");
320 path->length = 2; 332 path->length = 2;
321 path->peers[1] = 3; 333 path->peers[1] = 3;
322 cb_call = 1; 334 cb_call = 1;