diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-23 10:17:48 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-23 10:17:48 +0000 |
commit | a44aa9923dd14613116939e659817f985cb89ef5 (patch) | |
tree | a1ceb1826bf2dbc02db9ddb2bc0f12a9d03a4d89 /src/mesh/mesh_tunnel_tree.h | |
parent | 17e4c95ee4c555db7ab3ab9c57412b7866ee5411 (diff) | |
download | gnunet-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.h | 124 |
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 | */ |
150 | typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node); | 151 | struct MeshPeerPath * |
152 | path_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 | */ |
158 | void | 160 | void |
159 | path_invert (struct MeshPeerPath *path); | 161 | path_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 | */ | ||
170 | int | ||
171 | path_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 | */ |
183 | struct GNUNET_PeerIdentity * | 173 | struct GNUNET_PeerIdentity * |
184 | path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer); | 174 | path_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 | */ |
195 | unsigned int | 186 | unsigned int |
196 | path_get_length (struct MeshPeerPath *path); | 187 | path_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 | */ |
208 | unsigned int | 199 | unsigned int |
209 | path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path); | 200 | path_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 | */ | ||
211 | int | ||
212 | path_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 | */ | ||
222 | typedef 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 | */ | ||
233 | struct MeshTunnelTree * | ||
234 | tree_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 | */ |
220 | struct MeshTunnelTreeNode * | 245 | struct MeshTunnelTreeNode * |
221 | tree_find_peer (struct MeshTunnelTreeNode *root, GNUNET_PEER_Id peer_id); | 246 | tree_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 | */ |
235 | struct MeshTunnelTreeNode * | 263 | struct MeshTunnelTreeNode * |
236 | tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id, | 264 | tree_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 | */ |
250 | struct MeshPeerPath * | 279 | struct MeshPeerPath * |
251 | tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer); | 280 | tree_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 | */ |
264 | int | 294 | int |
265 | tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p, | 295 | tree_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 | */ | ||
278 | struct MeshTunnelTreeNode * | ||
279 | tree_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 | */ |
287 | void | 305 | void |
288 | tree_node_destroy (struct MeshTunnelTreeNode *n); | 306 | tree_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 | */ |
296 | void | 314 | void |
297 | tree_destroy (struct MeshTunnelTree *t); | 315 | tree_destroy (struct MeshTunnelTree *t); |
298 | |||
299 | |||
300 | void | ||
301 | tree_debug(struct MeshTunnelTree *t); \ No newline at end of file | ||