aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-09-23 10:17:48 +0000
committerBart Polot <bart@net.in.tum.de>2011-09-23 10:17:48 +0000
commita44aa9923dd14613116939e659817f985cb89ef5 (patch)
treea1ceb1826bf2dbc02db9ddb2bc0f12a9d03a4d89 /src/mesh
parent17e4c95ee4c555db7ab3ab9c57412b7866ee5411 (diff)
downloadgnunet-a44aa9923dd14613116939e659817f985cb89ef5.tar.gz
gnunet-a44aa9923dd14613116939e659817f985cb89ef5.zip
Fixed bugs and completed API
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c23
-rw-r--r--src/mesh/mesh_tunnel_tree.c245
-rw-r--r--src/mesh/mesh_tunnel_tree.h124
-rw-r--r--src/mesh/test_mesh_path_api.c13
4 files changed, 229 insertions, 176 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 77986f90c..9af81333a 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -818,7 +818,7 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *const *get_path,
818 GNUNET_PEER_Id id; 818 GNUNET_PEER_Id id;
819 int i; 819 int i;
820 820
821 p = GNUNET_malloc (sizeof (struct MeshPeerPath)); 821 p = path_new (0);
822 for (i = 0; get_path[i] != NULL; i++) ; 822 for (i = 0; get_path[i] != NULL; i++) ;
823 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); 823 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i);
824 for (i--; i >= 0; i--) 824 for (i--; i >= 0; i--)
@@ -1606,9 +1606,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1606 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1606 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1607 } 1607 }
1608 1608
1609 path = GNUNET_malloc (sizeof (struct MeshPeerPath)); 1609 path = path_new (size);
1610 path->length = size;
1611 path->peers = GNUNET_malloc (size * sizeof (GNUNET_PEER_Id));
1612 own_pos = 0; 1610 own_pos = 0;
1613 for (i = 0; i < size; i++) 1611 for (i = 0; i < size; i++)
1614 { 1612 {
@@ -1781,7 +1779,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
1781 * Using path here as just a collection of peers, not a path per se. 1779 * Using path here as just a collection of peers, not a path per se.
1782 */ 1780 */
1783 neighbors.t = t; 1781 neighbors.t = t;
1784 neighbors.path = GNUNET_malloc (sizeof (struct MeshPeerPath)); 1782 neighbors.path = path_new (0);
1785 GNUNET_CONTAINER_multihashmap_iterate (t->peers, &iterate_collect_neighbors, 1783 GNUNET_CONTAINER_multihashmap_iterate (t->peers, &iterate_collect_neighbors,
1786 &neighbors); 1784 &neighbors);
1787 if (0 == neighbors.path->length) 1785 if (0 == neighbors.path->length)
@@ -2459,14 +2457,9 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
2459 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2457 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2460 return; 2458 return;
2461 } 2459 }
2462 t->tree = GNUNET_malloc (sizeof(struct MeshTunnelTree)); 2460 t->tree = tree_new (t, myid);
2463 t->tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
2464 t->tree->t = t;
2465 t->tree->refresh = REFRESH_PATH_TIME; 2461 t->tree->refresh = REFRESH_PATH_TIME;
2466 t->tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
2467 t->tree->root->status = MESH_PEER_READY; 2462 t->tree->root->status = MESH_PEER_READY;
2468 t->tree->root->t = t;
2469 t->tree->root->peer = myid;
2470 t->tree->me = t->tree->root; 2463 t->tree->me = t->tree->root;
2471 2464
2472 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2465 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -2981,9 +2974,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
2981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); 2974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n");
2982 return; 2975 return;
2983 } 2976 }
2984 path = GNUNET_malloc (sizeof (struct MeshPeerPath)); 2977 path = path_new (2);
2985 path->length = 2;
2986 path->peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * 2);
2987 path->peers[0] = myid; 2978 path->peers[0] = myid;
2988 path->peers[1] = peer_info->id; 2979 path->peers[1] = peer_info->id;
2989 path_add_to_peer (peer_info, path); 2980 path_add_to_peer (peer_info, path);
@@ -3165,9 +3156,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
3165 3156
3166 /* Create a peer_info for the local peer */ 3157 /* Create a peer_info for the local peer */
3167 peer = peer_info_get(&my_full_id); 3158 peer = peer_info_get(&my_full_id);
3168 p = GNUNET_malloc (sizeof (struct MeshPeerPath)); 3159 p = path_new (1);
3169 p->peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id));
3170 p->length = 1;
3171 p->peers[0] = myid; 3160 p->peers[0] = myid;
3172 path_add_to_peer(peer, p); 3161 path_add_to_peer(peer, p);
3173 3162
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index 766960dd4..748683a34 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -28,42 +28,28 @@
28#include "mesh_tunnel_tree.h" 28#include "mesh_tunnel_tree.h"
29 29
30 30
31static void 31/**
32debug_node(struct MeshTunnelTreeNode *n, uint16_t level) 32 * Create a new path
33 *
34 * @param lenght How many hops will the path have.
35 *
36 * @return A newly allocated path with a peer array of the specified length.
37 */
38struct MeshPeerPath *
39path_new (unsigned int length)
33{ 40{
34 struct MeshTunnelTreeNode *c; 41 struct MeshPeerPath *p;
35 uint16_t i;
36
37 for (i = 0; i < level; i++)
38 fprintf(stderr, " ");
39 if (n->status == MESH_PEER_READY)
40 fprintf(stderr, "#");
41 if (n->status == MESH_PEER_SEARCHING)
42 fprintf(stderr, "+");
43 if (n->status == MESH_PEER_RELAY)
44 fprintf(stderr, "-");
45 if (n->status == MESH_PEER_RECONNECTING)
46 fprintf(stderr, "*");
47
48 fprintf(stderr, "%u [%p] ", n->peer, n);
49 if (NULL != n->parent)
50 fprintf(stderr, "(-> %u)\n", n->parent->peer);
51 else
52 fprintf(stderr, "(root)\n");
53 for (c = n->children_head; NULL != c; c = c->next)
54 debug_node(c, level + 1);
55}
56
57
58 42
59void 43 p = GNUNET_malloc (sizeof(struct MeshPeerPath));
60tree_debug(struct MeshTunnelTree *t) 44 if (length > 0)
61{ 45 {
62 debug_node(t->root, 0); 46 p->length = length;
47 p->peers = GNUNET_malloc (length * sizeof(GNUNET_PEER_Id));
48 }
49 return p;
63} 50}
64 51
65 52
66
67/** 53/**
68 * Invert the path 54 * Invert the path
69 * 55 *
@@ -84,22 +70,6 @@ path_invert (struct MeshPeerPath *path)
84} 70}
85 71
86 72
87/**
88 * Destroy the path and free any allocated resources linked to it
89 *
90 * @param p the path to destroy
91 *
92 * @return GNUNET_OK on success
93 */
94int
95path_destroy (struct MeshPeerPath *p)
96{
97 GNUNET_PEER_decrement_rcs (p->peers, p->length);
98 GNUNET_free (p->peers);
99 GNUNET_free (p);
100 return GNUNET_OK;
101}
102
103 73
104/** 74/**
105 * Find the first peer whom to send a packet to go down this path 75 * Find the first peer whom to send a packet to go down this path
@@ -157,6 +127,129 @@ path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path)
157 127
158 128
159/** 129/**
130 * Destroy the path and free any allocated resources linked to it
131 *
132 * @param p the path to destroy
133 *
134 * @return GNUNET_OK on success
135 */
136int
137path_destroy (struct MeshPeerPath *p)
138{
139 GNUNET_PEER_decrement_rcs (p->peers, p->length);
140 GNUNET_free (p->peers);
141 GNUNET_free (p);
142 return GNUNET_OK;
143}
144
145
146
147/**
148 * Allocates and initializes a new node.
149 * Sets ID and parent of the new node and inserts it in the DLL of the parent
150 *
151 * @param parent Node that will be the parent from the new node, NULL for root
152 * @param peer Short Id of the new node
153 *
154 * @return Newly allocated node
155 */
156static struct MeshTunnelTreeNode *
157tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
158{
159 struct MeshTunnelTreeNode *node;
160
161 node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
162 node->peer = peer;
163 GNUNET_PEER_change_rc(peer, 1);
164 node->parent = parent;
165 if (NULL != parent)
166 GNUNET_CONTAINER_DLL_insert(parent->children_head,
167 parent->children_tail,
168 node);
169
170 return node;
171}
172
173
174static void
175tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level)
176{
177 struct MeshTunnelTreeNode *c;
178 uint16_t i;
179
180 for (i = 0; i < level; i++)
181 fprintf(stderr, " ");
182 if (n->status == MESH_PEER_READY)
183 fprintf(stderr, "#");
184 if (n->status == MESH_PEER_SEARCHING)
185 fprintf(stderr, "+");
186 if (n->status == MESH_PEER_RELAY)
187 fprintf(stderr, "-");
188 if (n->status == MESH_PEER_RECONNECTING)
189 fprintf(stderr, "*");
190
191 fprintf(stderr, "%u [%p] ", n->peer, n);
192 if (NULL != n->parent)
193 fprintf(stderr, "(-> %u)\n", n->parent->peer);
194 else
195 fprintf(stderr, "(root)\n");
196 for (c = n->children_head; NULL != c; c = c->next)
197 tree_node_debug(c, level + 1);
198}
199
200
201/**
202 * Destroys and frees the node and all children
203 *
204 * @param n Parent node to be destroyed
205 */
206static void
207tree_node_destroy (struct MeshTunnelTreeNode *parent)
208{
209 struct MeshTunnelTreeNode *n;
210 struct MeshTunnelTreeNode *next;
211
212 n = parent->children_head;
213 while (NULL != n)
214 {
215 next = n->next;
216 tree_node_destroy(n);
217 n = next;
218 }
219 GNUNET_PEER_change_rc(parent->peer, -1);
220 if (NULL != parent->parent)
221 GNUNET_CONTAINER_DLL_remove(parent->parent->children_head,
222 parent->parent->children_tail,
223 parent);
224 GNUNET_free(parent);
225}
226
227
228
229/**
230 * Create a new tunnel tree associated to a tunnel
231 *
232 * @param t Tunnel this tree will represent
233 * @param peer A short peer id of the root of the tree
234 *
235 * @return A newly allocated and initialized tunnel tree
236 */
237struct MeshTunnelTree *
238tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer)
239{
240 struct MeshTunnelTree *tree;
241
242 tree = GNUNET_malloc(sizeof (struct MeshTunnelTree));
243 tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
244 tree->root = tree_node_new(NULL, peer);
245 tree->t = t;
246 tree->root->t = t;
247
248 return tree;
249}
250
251
252/**
160 * Recursively find the given peer in the tree. 253 * Recursively find the given peer in the tree.
161 * 254 *
162 * @param t Tunnel where to look for the peer. 255 * @param t Tunnel where to look for the peer.
@@ -189,7 +282,7 @@ tree_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id)
189 * @param parent Node to be clean, potentially with children 282 * @param parent Node to be clean, potentially with children
190 * @param cb Callback to use to notify about disconnected peers. 283 * @param cb Callback to use to notify about disconnected peers.
191 */ 284 */
192void 285static void
193tree_mark_peers_disconnected (struct MeshTunnelTree *tree, 286tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
194 struct MeshTunnelTreeNode *parent, 287 struct MeshTunnelTreeNode *parent,
195 MeshNodeDisconnectCB cb) 288 MeshNodeDisconnectCB cb)
@@ -225,7 +318,7 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
225 * @param hop If known, ID of the first hop. 318 * @param hop If known, ID of the first hop.
226 * If not known, NULL to find out and pass on children. 319 * If not known, NULL to find out and pass on children.
227 */ 320 */
228void 321static void
229tree_update_first_hops (struct MeshTunnelTree *tree, 322tree_update_first_hops (struct MeshTunnelTree *tree,
230 struct MeshTunnelTreeNode *parent, 323 struct MeshTunnelTreeNode *parent,
231 struct GNUNET_PeerIdentity *hop) 324 struct GNUNET_PeerIdentity *hop)
@@ -343,7 +436,7 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
343 GNUNET_PEER_Id myid = t->me->peer; 436 GNUNET_PEER_Id myid = t->me->peer;
344 437
345 n = tree_find_peer(t->me, peer); 438 n = tree_find_peer(t->me, peer);
346 p = GNUNET_malloc(sizeof(struct MeshPeerPath)); 439 p = path_new(0);
347 440
348 /* Building the path (inverted!) */ 441 /* Building the path (inverted!) */
349 while (n->peer != myid) 442 while (n->peer != myid)
@@ -496,56 +589,14 @@ tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
496 589
497 590
498/** 591/**
499 * Allocates and initializes a new node. 592 * Print the tree on stderr
500 * Sets ID and parent of the new node and inserts it in the DLL of the parent
501 *
502 * @param parent Node that will be the parent from the new node, NULL for root
503 * @param id Short Id of the new node
504 * 593 *
505 * @return Newly allocated node 594 * @param t The tree
506 */
507struct MeshTunnelTreeNode *
508tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id id)
509{
510 struct MeshTunnelTreeNode *node;
511
512 node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
513 node->peer = id;
514 GNUNET_PEER_change_rc(id, 1);
515 node->parent = parent;
516 if (NULL != parent)
517 GNUNET_CONTAINER_DLL_insert(parent->children_head,
518 parent->children_tail,
519 node);
520
521 return node;
522}
523
524
525/**
526 * Destroys and frees the node and all children
527 *
528 * @param n Parent node to be destroyed
529 */ 595 */
530void 596void
531tree_node_destroy (struct MeshTunnelTreeNode *parent) 597tree_debug(struct MeshTunnelTree *t)
532{ 598{
533 struct MeshTunnelTreeNode *n; 599 tree_node_debug(t->root, 0);
534 struct MeshTunnelTreeNode *next;
535
536 n = parent->children_head;
537 while (NULL != n)
538 {
539 next = n->next;
540 tree_node_destroy(n);
541 n = next;
542 }
543 GNUNET_PEER_change_rc(parent->peer, -1);
544 if (NULL != parent->parent)
545 GNUNET_CONTAINER_DLL_remove(parent->parent->children_head,
546 parent->parent->children_tail,
547 parent);
548 GNUNET_free(parent);
549} 600}
550 601
551 602
@@ -578,4 +629,4 @@ tree_destroy (struct MeshTunnelTree *t)
578 GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); 629 GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL);
579 GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); 630 GNUNET_CONTAINER_multihashmap_destroy(t->first_hops);
580 GNUNET_free(t); 631 GNUNET_free(t);
581} \ No newline at end of file 632}
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h
index a929f7a6d..252929549 100644
--- a/src/mesh/mesh_tunnel_tree.h
+++ b/src/mesh/mesh_tunnel_tree.h
@@ -141,13 +141,15 @@ struct MeshTunnelTree
141/************************* FUNCTIONS *****************************/ 141/************************* FUNCTIONS *****************************/
142/******************************************************************************/ 142/******************************************************************************/
143 143
144
145/** 144/**
146 * Method called whenever a node has been marked as disconnected. 145 * Create a new path
147 * 146 *
148 * @param node peer identity the tunnel stopped working with 147 * @param lenght How many hops will the path have.
148 *
149 * @return A newly allocated path with a peer array of the specified length.
149 */ 150 */
150typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node); 151struct MeshPeerPath *
152path_new (unsigned int length);
151 153
152 154
153/** 155/**
@@ -156,44 +158,33 @@ typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node);
156 * @param p the path to invert 158 * @param p the path to invert
157 */ 159 */
158void 160void
159path_invert (struct MeshPeerPath *path); 161path_invert (struct MeshPeerPath *p);
160
161
162
163/**
164 * Destroy the path and free any allocated resources linked to it
165 *
166 * @param p the path to destroy
167 *
168 * @return GNUNET_OK on success
169 */
170int
171path_destroy (struct MeshPeerPath *p);
172 162
173 163
174/** 164/**
175 * Find the first peer whom to send a packet to go down this path 165 * Find the first peer whom to send a packet to go down this path
176 * 166 *
177 * @param t The tunnel to use 167 * @param t The tunnel tree to use
178 * @param peer The peerinfo of the peer we are trying to reach 168 * @param peer The peerinfo of the peer we are trying to reach
179 * 169 *
180 * @return peerinfo of the peer who is the first hop in the tunnel 170 * @return peerinfo of the peer who is the first hop in the tunnel
181 * NULL on error 171 * NULL on error
182 */ 172 */
183struct GNUNET_PeerIdentity * 173struct GNUNET_PeerIdentity *
184path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer); 174path_get_first_hop (struct MeshTunnelTree *t,
175 GNUNET_PEER_Id peer);
185 176
186 177
187/** 178/**
188 * Get the length of a path 179 * Get the length of a path
189 * 180 *
190 * @param path The path to measure, with the local peer at any point of it 181 * @param p The path to measure, with the local peer at any point of it
191 * 182 *
192 * @return Number of hops to reach destination 183 * @return Number of hops to reach destination
193 * UINT_MAX in case the peer is not in the path 184 * UINT_MAX in case the peer is not in the path
194 */ 185 */
195unsigned int 186unsigned int
196path_get_length (struct MeshPeerPath *path); 187path_get_length (struct MeshPeerPath *p);
197 188
198 189
199/** 190/**
@@ -206,19 +197,54 @@ path_get_length (struct MeshPeerPath *path);
206 * in the path 197 * in the path
207 */ 198 */
208unsigned int 199unsigned int
209path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path); 200path_get_cost (struct MeshTunnelTree *t,
201 struct MeshPeerPath *path);
202
203
204/**
205 * Destroy the path and free any allocated resources linked to it
206 *
207 * @param p the path to destroy
208 *
209 * @return GNUNET_OK on success
210 */
211int
212path_destroy (struct MeshPeerPath *p);
213
214
215/******************************************************************************/
216
217/**
218 * Method called whenever a node has been marked as disconnected.
219 *
220 * @param node peer identity the tunnel stopped working with
221 */
222typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node);
223
224
225/**
226 * Create a new tunnel tree associated to a tunnel
227 *
228 * @param t Tunnel this tree will represent
229 * @param peer A short peer id of the root of the tree
230 *
231 * @return A newly allocated and initialized tunnel tree
232 */
233struct MeshTunnelTree *
234tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer);
210 235
211 236
212/** 237/**
213 * Recursively find the given peer in the tree. 238 * Recursively find the given peer in the tree.
214 * 239 *
215 * @param t Tunnel where to look for the peer. 240 * @param parent Parent node where to start looking.
216 * @param peer Peer to find 241 * @param peer Short ID of peer to find.
217 * 242 *
218 * @return Pointer to the node of the peer. NULL if not found. 243 * @return Pointer to the node of the peer. NULL if not found.
219 */ 244 */
220struct MeshTunnelTreeNode * 245struct MeshTunnelTreeNode *
221tree_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id); 246tree_find_peer (struct MeshTunnelTreeNode *parent,
247 GNUNET_PEER_Id peer);
222 248
223 249
224/** 250/**
@@ -226,15 +252,18 @@ tree_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id);
226 * The destination peer is NOT destroyed, it is returned in order to either set 252 * The destination peer is NOT destroyed, it is returned in order to either set
227 * a new path to it or destroy it explicitly, taking care of it's child nodes. 253 * a new path to it or destroy it explicitly, taking care of it's child nodes.
228 * 254 *
229 * @param t Tunnel where to delete the path from. 255 * @param t Tunnel tree where to delete the path from.
230 * @param peer Destination peer whose path we want to remove. 256 * @param peer Destination peer whose path we want to remove.
231 * @param cb Callback to use to notify about disconnected peers 257 * @param cb Callback to use to notify about which peers are going to be
258 * disconnected.
232 * 259 *
233 * @return pointer to the pathless node, NULL on error 260 * @return pointer to the pathless node.
261 * NULL when not found
234 */ 262 */
235struct MeshTunnelTreeNode * 263struct MeshTunnelTreeNode *
236tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, 264tree_del_path (struct MeshTunnelTree *t,
237 MeshNodeDisconnectCB cb); 265 GNUNET_PEER_Id peer,
266 MeshNodeDisconnectCB cb);
238 267
239 268
240/** 269/**
@@ -242,13 +271,14 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
242 * according to the path tree of some tunnel. 271 * according to the path tree of some tunnel.
243 * 272 *
244 * @param t Tunnel from which to read the path tree 273 * @param t Tunnel from which to read the path tree
245 * @param peer_info Destination peer to whom we want a path 274 * @param peer Destination peer to whom we want a path
246 * 275 *
247 * @return A newly allocated individual path to reach the destination peer. 276 * @return A newly allocated individual path to reach the destination peer.
248 * Path must be destroyed afterwards. 277 * Path must be destroyed afterwards.
249 */ 278 */
250struct MeshPeerPath * 279struct MeshPeerPath *
251tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer); 280tree_get_path_to_peer(struct MeshTunnelTree *t,
281 GNUNET_PEER_Id peer);
252 282
253 283
254/** 284/**
@@ -262,40 +292,24 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
262 * GNUNET_SYSERR in case of error. 292 * GNUNET_SYSERR in case of error.
263 */ 293 */
264int 294int
265tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, 295tree_add_path (struct MeshTunnelTree *t,
266 MeshNodeDisconnectCB cb); 296 const struct MeshPeerPath *p,
297 MeshNodeDisconnectCB cb);
267 298
268 299
269/** 300/**
270 * Allocates and initializes a new node. 301 * Print the tree on stderr
271 * Sets ID and parent of the new node and inserts it in the DLL of the parent
272 *
273 * @param parent Node that will be the parent from the new node, NULL for root
274 * @param id Short Id of the new node
275 * 302 *
276 * @return Newly allocated node 303 * @param t The tree
277 */
278struct MeshTunnelTreeNode *
279tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id id);
280
281
282/**
283 * Destroy the node and all children
284 *
285 * @param n Parent node to be destroyed
286 */ 304 */
287void 305void
288tree_node_destroy (struct MeshTunnelTreeNode *n); 306tree_debug(struct MeshTunnelTree *t);
289 307
290 308
291/** 309/**
292 * Destroy the whole tree and free all used memory and Peer_Ids 310 * Destroy the whole tree and free all used memory and Peer_Ids
293 * 311 *
294 * @param t Tree to be destroyed 312 * @param t Tree to be destroyed
295 */ 313 */
296void 314void
297tree_destroy (struct MeshTunnelTree *t); 315tree_destroy (struct MeshTunnelTree *t);
298
299
300void
301tree_debug(struct MeshTunnelTree *t); \ No newline at end of file
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c
index a397752e9..337ce35de 100644
--- a/src/mesh/test_mesh_path_api.c
+++ b/src/mesh/test_mesh_path_api.c
@@ -57,7 +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 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
61 for (i = 0; i < 10; i++) 61 for (i = 0; i < 10; i++)
62 { 62 {
63 GNUNET_free(pi[i]); 63 GNUNET_free(pi[i]);
@@ -340,11 +340,7 @@ main (int argc, char *argv[])
340 { 340 {
341 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 341 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
342 failed++; 342 failed++;
343 } 343 }
344
345 path_destroy(path);
346 finish();
347
348 node = tree_find_peer(tree->root, 2); 344 node = tree_find_peer(tree->root, 2);
349 if (node->peer != 2) 345 if (node->peer != 2)
350 { 346 {
@@ -394,6 +390,9 @@ main (int argc, char *argv[])
394 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); 390 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
395 return 1; 391 return 1;
396 } 392 }
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n"); 393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: OK\n");
394 path_destroy(path);
395 finish();
396
398 return 0; 397 return 0;
399} 398}