aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/mesh_tunnel_tree.h
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/mesh_tunnel_tree.h
parent17e4c95ee4c555db7ab3ab9c57412b7866ee5411 (diff)
downloadgnunet-a44aa9923dd14613116939e659817f985cb89ef5.tar.gz
gnunet-a44aa9923dd14613116939e659817f985cb89ef5.zip
Fixed bugs and completed API
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.h')
-rw-r--r--src/mesh/mesh_tunnel_tree.h124
1 files changed, 69 insertions, 55 deletions
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