diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-11-02 18:46:43 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-11-02 18:46:43 +0000 |
commit | 1c91d8d5152a33db3522cc98c0b44eeeffb7eaa0 (patch) | |
tree | 364160a1550865161346901130b39ab1707b551f /src/mesh/mesh_tunnel_tree.h | |
parent | b8c9942ee1470ead06fbf0825a3265ebf8904ed6 (diff) | |
download | gnunet-1c91d8d5152a33db3522cc98c0b44eeeffb7eaa0.tar.gz gnunet-1c91d8d5152a33db3522cc98c0b44eeeffb7eaa0.zip |
Changed tree library to be completely detached from mesh, adapted testcases
Diffstat (limited to 'src/mesh/mesh_tunnel_tree.h')
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 172 |
1 files changed, 84 insertions, 88 deletions
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index 2cb28a28c..e946259da 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -58,83 +58,13 @@ struct MeshPeerPath | |||
58 | /** | 58 | /** |
59 | * Node of path tree for a tunnel | 59 | * Node of path tree for a tunnel |
60 | */ | 60 | */ |
61 | struct MeshTunnelTreeNode | 61 | struct MeshTunnelTreeNode; |
62 | { | ||
63 | /** | ||
64 | * Peer this node describes | ||
65 | */ | ||
66 | GNUNET_PEER_Id peer; | ||
67 | |||
68 | /** | ||
69 | * Parent node in the tree | ||
70 | */ | ||
71 | struct MeshTunnelTreeNode *parent; | ||
72 | |||
73 | /** | ||
74 | * DLL of siblings | ||
75 | */ | ||
76 | struct MeshTunnelTreeNode *next; | ||
77 | |||
78 | /** | ||
79 | * DLL of siblings | ||
80 | */ | ||
81 | struct MeshTunnelTreeNode *prev; | ||
82 | |||
83 | /** | ||
84 | * DLL of children | ||
85 | */ | ||
86 | struct MeshTunnelTreeNode *children_head; | ||
87 | |||
88 | /** | ||
89 | * DLL of children | ||
90 | */ | ||
91 | struct MeshTunnelTreeNode *children_tail; | ||
92 | |||
93 | /** | ||
94 | * Status of the peer in the tunnel | ||
95 | */ | ||
96 | enum MeshPeerState status; | ||
97 | }; | ||
98 | 62 | ||
99 | 63 | ||
100 | /** | 64 | /** |
101 | * Tree to reach all peers in the tunnel | 65 | * Tree to reach all peers in the tunnel |
102 | */ | 66 | */ |
103 | struct MeshTunnelTree | 67 | struct MeshTunnelTree; |
104 | { | ||
105 | /** | ||
106 | * How often to refresh the path | ||
107 | */ | ||
108 | struct GNUNET_TIME_Relative refresh; | ||
109 | |||
110 | /** | ||
111 | * Root node of peer tree | ||
112 | */ | ||
113 | struct MeshTunnelTreeNode *root; | ||
114 | |||
115 | /** | ||
116 | * Node that represents our position in the tree (for non local tunnels) | ||
117 | */ | ||
118 | struct MeshTunnelTreeNode *me; | ||
119 | |||
120 | /** | ||
121 | * DLL of disconneted nodes | ||
122 | */ | ||
123 | struct MeshTunnelTreeNode *disconnected_head; | ||
124 | |||
125 | /** | ||
126 | * DLL of disconneted nodes | ||
127 | */ | ||
128 | struct MeshTunnelTreeNode *disconnected_tail; | ||
129 | |||
130 | /** | ||
131 | * Cache of all peers and the first hop to them. | ||
132 | * Indexed by PeerIdentity, contains a pointer to the PeerIdentity | ||
133 | * of 1st hop. | ||
134 | */ | ||
135 | struct GNUNET_CONTAINER_MultiHashMap *first_hops; | ||
136 | |||
137 | }; | ||
138 | 68 | ||
139 | 69 | ||
140 | /******************************************************************************/ | 70 | /******************************************************************************/ |
@@ -229,14 +159,13 @@ path_destroy (struct MeshPeerPath *p); | |||
229 | * @param cls Closure. | 159 | * @param cls Closure. |
230 | * @param peer_id short ID of peer that is no longer reachable. | 160 | * @param peer_id short ID of peer that is no longer reachable. |
231 | */ | 161 | */ |
232 | typedef void (*MeshNodeDisconnectCB) (void *cls, | 162 | typedef void (*MeshTreeCallback) (void *cls, |
233 | GNUNET_PEER_Id peer_id); | 163 | GNUNET_PEER_Id peer_id); |
234 | 164 | ||
235 | 165 | ||
236 | /** | 166 | /** |
237 | * Create a new tunnel tree associated to a tunnel | 167 | * Create a new tunnel tree associated to a tunnel |
238 | * | 168 | * |
239 | * @param t Tunnel this tree will represent | ||
240 | * @param peer A short peer id of the root of the tree | 169 | * @param peer A short peer id of the root of the tree |
241 | * | 170 | * |
242 | * @return A newly allocated and initialized tunnel tree | 171 | * @return A newly allocated and initialized tunnel tree |
@@ -246,29 +175,96 @@ tree_new (GNUNET_PEER_Id peer); | |||
246 | 175 | ||
247 | 176 | ||
248 | /** | 177 | /** |
249 | * Recursively find the given peer in the tree. | 178 | * Set own identity in the tree |
179 | * | ||
180 | * @param tree Tree. | ||
181 | * @param peer A short peer id of local peer. | ||
182 | */ | ||
183 | void | ||
184 | tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer); | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Get the id of the local id of the tree. | ||
189 | * | ||
190 | * @param tree Tree whose local id we want to now. | ||
191 | * | ||
192 | * @return Short peer id of local peer. | ||
193 | */ | ||
194 | GNUNET_PEER_Id | ||
195 | tree_get_me (struct MeshTunnelTree *tree); | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Set the status of a node. | ||
200 | * | ||
201 | * @param tree Tree. | ||
202 | * @param peer A short peer id of local peer. | ||
203 | */ | ||
204 | void | ||
205 | tree_set_status (struct MeshTunnelTree *tree, | ||
206 | GNUNET_PEER_Id peer, | ||
207 | enum MeshPeerState status); | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Get the status of a node. | ||
212 | * | ||
213 | * @param tree Tree whose local id we want to now. | ||
214 | * | ||
215 | * @return Short peer id of local peer. | ||
216 | */ | ||
217 | enum MeshPeerState | ||
218 | tree_get_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer); | ||
219 | |||
220 | |||
221 | /** | ||
222 | * Get the id of the predecessor of the local node. | ||
250 | * | 223 | * |
251 | * @param parent Parent node where to start looking. | 224 | * @param tree Tree whose local id we want to now. |
252 | * @param peer Short ID of peer to find. | 225 | * |
226 | * @return Short peer id of local peer. | ||
227 | */ | ||
228 | GNUNET_PEER_Id | ||
229 | tree_get_predecessor (struct MeshTunnelTree *tree); | ||
230 | |||
231 | |||
232 | /** | ||
233 | * Find the given peer in the tree. | ||
234 | * | ||
235 | * @param tree Tree where to look for the peer. | ||
236 | * @param peer Peer to find. | ||
253 | * | 237 | * |
254 | * @return Pointer to the node of the peer. NULL if not found. | 238 | * @return Pointer to the node of the peer. NULL if not found. |
255 | */ | 239 | */ |
256 | struct MeshTunnelTreeNode * | 240 | struct MeshTunnelTreeNode * |
257 | tree_find_peer (struct MeshTunnelTreeNode *parent, | 241 | tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id); |
258 | GNUNET_PEER_Id peer); | 242 | |
243 | |||
244 | /** | ||
245 | * Iterate over all children of the local node. | ||
246 | * | ||
247 | * @param tree Tree to use. Must have "me" set. | ||
248 | * @param cb Callback to call over each child. | ||
249 | * @param cls Closure. | ||
250 | */ | ||
251 | void | ||
252 | tree_iterate_children (struct MeshTunnelTree *tree, | ||
253 | MeshTreeCallback cb, | ||
254 | void *cls); | ||
259 | 255 | ||
260 | 256 | ||
261 | /** | 257 | /** |
262 | * Recusively update the info about what is the first hop to reach the node | 258 | * Recusively update the info about what is the first hop to reach the node |
263 | * | 259 | * |
264 | * @param tree Tree this nodes belongs to | 260 | * @param tree Tree this nodes belongs to. |
265 | * @param parent Node to be start updating | 261 | * @param parent_id Short ID from node form which to start updating. |
266 | * @param hop If known, ID of the first hop. | 262 | * @param hop If known, ID of the first hop. |
267 | * If not known, NULL to find out and pass on children. | 263 | * If not known, NULL to find out and pass on children. |
268 | */ | 264 | */ |
269 | void | 265 | void |
270 | tree_update_first_hops (struct MeshTunnelTree *tree, | 266 | tree_update_first_hops (struct MeshTunnelTree *tree, |
271 | struct MeshTunnelTreeNode *parent, | 267 | GNUNET_PEER_Id parent_id, |
272 | struct GNUNET_PeerIdentity *hop); | 268 | struct GNUNET_PeerIdentity *hop); |
273 | 269 | ||
274 | /** | 270 | /** |
@@ -288,7 +284,7 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
288 | struct MeshTunnelTreeNode * | 284 | struct MeshTunnelTreeNode * |
289 | tree_del_path (struct MeshTunnelTree *t, | 285 | tree_del_path (struct MeshTunnelTree *t, |
290 | GNUNET_PEER_Id peer, | 286 | GNUNET_PEER_Id peer, |
291 | MeshNodeDisconnectCB cb, | 287 | MeshTreeCallback cb, |
292 | void *cbcls); | 288 | void *cbcls); |
293 | 289 | ||
294 | 290 | ||
@@ -321,7 +317,7 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, | |||
321 | int | 317 | int |
322 | tree_add_path (struct MeshTunnelTree *t, | 318 | tree_add_path (struct MeshTunnelTree *t, |
323 | const struct MeshPeerPath *p, | 319 | const struct MeshPeerPath *p, |
324 | MeshNodeDisconnectCB cb, | 320 | MeshTreeCallback cb, |
325 | void *cbcls); | 321 | void *cbcls); |
326 | 322 | ||
327 | 323 | ||
@@ -341,7 +337,7 @@ GNUNET_PEER_Id | |||
341 | tree_notify_connection_broken (struct MeshTunnelTree *t, | 337 | tree_notify_connection_broken (struct MeshTunnelTree *t, |
342 | GNUNET_PEER_Id p1, | 338 | GNUNET_PEER_Id p1, |
343 | GNUNET_PEER_Id p2, | 339 | GNUNET_PEER_Id p2, |
344 | MeshNodeDisconnectCB cb, | 340 | MeshTreeCallback cb, |
345 | void *cbcls); | 341 | void *cbcls); |
346 | 342 | ||
347 | 343 | ||
@@ -356,12 +352,12 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, | |||
356 | * @param cb Callback to notify client of disconnected peers. | 352 | * @param cb Callback to notify client of disconnected peers. |
357 | * @param cbcls Closure for cb. | 353 | * @param cbcls Closure for cb. |
358 | * | 354 | * |
359 | * @return GNUNET_OK or GNUNET_SYSERR | 355 | * @return GNUNET_YES if the tunnel still has nodes |
360 | */ | 356 | */ |
361 | int | 357 | int |
362 | tree_del_peer (struct MeshTunnelTree *t, | 358 | tree_del_peer (struct MeshTunnelTree *t, |
363 | GNUNET_PEER_Id peer, | 359 | GNUNET_PEER_Id peer, |
364 | MeshNodeDisconnectCB cb, | 360 | MeshTreeCallback cb, |
365 | void *cbcls); | 361 | void *cbcls); |
366 | 362 | ||
367 | /** | 363 | /** |