diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-04-07 11:36:07 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-04-07 11:36:07 +0000 |
commit | 83e0dcf80c9ade6c9e83c33b4add635a258bdbb4 (patch) | |
tree | 90cc49151fbdee192a3ff836689f218d6eec641e /src/mesh | |
parent | 8b099f451e69cb0e2f8c27e441a7d08a739c08e0 (diff) | |
download | gnunet-83e0dcf80c9ade6c9e83c33b4add635a258bdbb4.tar.gz gnunet-83e0dcf80c9ade6c9e83c33b4add635a258bdbb4.zip |
Work in progress
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 134 | ||||
-rw-r--r-- | src/mesh/mesh_api_new.c | 125 |
2 files changed, 205 insertions, 54 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 8332100b6..e927d2737 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -23,6 +23,14 @@ | |||
23 | * @brief GNUnet MESH service | 23 | * @brief GNUnet MESH service |
24 | * @author Bartlomiej Polot | 24 | * @author Bartlomiej Polot |
25 | * | 25 | * |
26 | * STRUCTURE: | ||
27 | * - MESH NETWORK MESSAGES | ||
28 | * - DATA STRUCTURES | ||
29 | * - GLOBAL VARIABLES | ||
30 | * - MESH NETWORK HANDLES | ||
31 | * - MESH LOCAL HANDLES | ||
32 | * - MAIN FUNCTIONS (main & run) | ||
33 | * | ||
26 | * TODO: | 34 | * TODO: |
27 | * - soft stateing (keep-alive (CHANGE?) / timeout / disconnect) -- not a message issue | 35 | * - soft stateing (keep-alive (CHANGE?) / timeout / disconnect) -- not a message issue |
28 | * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message! | 36 | * - error reporting (CREATE/CHANGE/ADD/DEL?) -- new message! |
@@ -52,12 +60,14 @@ struct GNUNET_MESH_ManipulatePath | |||
52 | /** | 60 | /** |
53 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DEL] | 61 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DEL] |
54 | * | 62 | * |
55 | * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + path_length * sizeof (struct GNUNET_PeerIdentity) | 63 | * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + |
64 | * path_length * sizeof (struct GNUNET_PeerIdentity) | ||
56 | */ | 65 | */ |
57 | struct GNUNET_MessageHeader header; | 66 | struct GNUNET_MessageHeader header; |
58 | 67 | ||
59 | /** | 68 | /** |
60 | * (global) Id of the tunnel this path belongs to, unique in conjunction with the origin. | 69 | * Global id of the tunnel this path belongs to, |
70 | * unique in conjunction with the origin. | ||
61 | */ | 71 | */ |
62 | uint32_t tid GNUNET_PACKED; | 72 | uint32_t tid GNUNET_PACKED; |
63 | 73 | ||
@@ -76,7 +86,7 @@ struct GNUNET_MESH_ManipulatePath | |||
76 | * path_length structs defining the *whole* path from the origin [0] to the | 86 | * path_length structs defining the *whole* path from the origin [0] to the |
77 | * final destination [path_length-1]. | 87 | * final destination [path_length-1]. |
78 | */ | 88 | */ |
79 | // struct GNUNET_PeerIdentity peers[path_length]; | 89 | /* struct GNUNET_PeerIdentity peers[path_length]; */ |
80 | }; | 90 | }; |
81 | 91 | ||
82 | /** | 92 | /** |
@@ -215,12 +225,8 @@ enum PeerState | |||
215 | /** | 225 | /** |
216 | * Peer connected previosly but not responding | 226 | * Peer connected previosly but not responding |
217 | */ | 227 | */ |
218 | MESH_PEER_UNAVAILABLE, | 228 | MESH_PEER_RECONNECTING, |
219 | 229 | ||
220 | /** | ||
221 | * Peer requested but not ever connected | ||
222 | */ | ||
223 | MESH_PEER_UNREACHABLE | ||
224 | }; | 230 | }; |
225 | 231 | ||
226 | /** | 232 | /** |
@@ -231,7 +237,7 @@ struct PeerInfo | |||
231 | /** | 237 | /** |
232 | * ID of the peer | 238 | * ID of the peer |
233 | */ | 239 | */ |
234 | GNUNET_PEER_Id id; | 240 | GNUNET_PEER_Id id; |
235 | 241 | ||
236 | /** | 242 | /** |
237 | * Is the peer reachable? Is the peer even connected? | 243 | * Is the peer reachable? Is the peer even connected? |
@@ -241,14 +247,15 @@ struct PeerInfo | |||
241 | /** | 247 | /** |
242 | * Who to send the data to --- what about multiple (alternate) paths? | 248 | * Who to send the data to --- what about multiple (alternate) paths? |
243 | */ | 249 | */ |
244 | GNUNET_PEER_Id first_hop; | 250 | GNUNET_PEER_Id first_hop; |
245 | 251 | ||
246 | /** | 252 | /** |
247 | * Max data rate to this peer | 253 | * Max data rate to this peer |
248 | */ | 254 | */ |
249 | uint32_t max_speed; | 255 | uint32_t max_speed; |
250 | }; | 256 | }; |
251 | 257 | ||
258 | typedef uint32_t MESH_PathID; | ||
252 | /** | 259 | /** |
253 | * Information regarding a path | 260 | * Information regarding a path |
254 | */ | 261 | */ |
@@ -257,19 +264,20 @@ struct Path | |||
257 | /** | 264 | /** |
258 | * Id of the path, in case it's needed | 265 | * Id of the path, in case it's needed |
259 | */ | 266 | */ |
260 | uint32_t id; | 267 | MESH_PathID id; |
261 | 268 | ||
262 | /** | 269 | /** |
263 | * Whether the path is serving traffic in a tunnel or is a backup | 270 | * Whether the path is serving traffic in a tunnel or is a backup |
264 | */ | 271 | */ |
265 | int in_use; | 272 | int in_use; |
266 | 273 | ||
267 | /** | 274 | /** |
268 | * List of all the peers that form the path from origin to target | 275 | * List of all the peers that form the path from origin to target |
269 | */ | 276 | */ |
270 | GNUNET_PEER_Id *peers; | 277 | GNUNET_PEER_Id *peers; |
271 | }; | 278 | }; |
272 | 279 | ||
280 | typedef uint32_t MESH_TunnelID; | ||
273 | /** | 281 | /** |
274 | * Struct containing all information regarding a tunnel | 282 | * Struct containing all information regarding a tunnel |
275 | * For an intermediate node the improtant info used will be: | 283 | * For an intermediate node the improtant info used will be: |
@@ -282,34 +290,36 @@ struct Path | |||
282 | struct MESH_tunnel | 290 | struct MESH_tunnel |
283 | { | 291 | { |
284 | 292 | ||
285 | struct MESH_tunnel *next; | 293 | /** |
286 | 294 | * Double linked list | |
287 | struct MESH_tunnel *prev; | 295 | */ |
296 | struct MESH_tunnel *next; | ||
297 | struct MESH_tunnel *prev; | ||
288 | 298 | ||
289 | /** | 299 | /** |
290 | * Origin ID: Node that created the tunnel | 300 | * Origin ID: Node that created the tunnel |
291 | */ | 301 | */ |
292 | GNUNET_PEER_Id oid; | 302 | GNUNET_PEER_Id oid; |
293 | 303 | ||
294 | /** | 304 | /** |
295 | * Tunnel number (unique for a given oid) | 305 | * Tunnel number (unique for a given oid) |
296 | */ | 306 | */ |
297 | uint32_t tid; | 307 | MESH_TunnelID tid; |
298 | 308 | ||
299 | /** | 309 | /** |
300 | * Whether the tunnel is in a state to transmit data | 310 | * Whether the tunnel is in a state to transmit data |
301 | */ | 311 | */ |
302 | int ready; | 312 | int ready; |
303 | 313 | ||
304 | /** | 314 | /** |
305 | * Minimal speed for this tunnel in kb/s | 315 | * Minimal speed for this tunnel in kb/s |
306 | */ | 316 | */ |
307 | uint32_t speed_min; | 317 | uint32_t speed_min; |
308 | 318 | ||
309 | /** | 319 | /** |
310 | * Maximal speed for this tunnel in kb/s | 320 | * Maximal speed for this tunnel in kb/s |
311 | */ | 321 | */ |
312 | uint32_t speed_max; | 322 | uint32_t speed_max; |
313 | 323 | ||
314 | /** | 324 | /** |
315 | * Last time the tunnel was used | 325 | * Last time the tunnel was used |
@@ -319,20 +329,20 @@ struct MESH_tunnel | |||
319 | /** | 329 | /** |
320 | * Peers in the tunnel, for future optimizations | 330 | * Peers in the tunnel, for future optimizations |
321 | */ | 331 | */ |
322 | struct PeerInfo *peers; | 332 | struct PeerInfo *peers; |
323 | 333 | ||
324 | /** | 334 | /** |
325 | * Paths (used and backup) | 335 | * Paths (used and backup) |
326 | */ | 336 | */ |
327 | struct Path *paths; | 337 | struct Path *paths; |
328 | 338 | ||
329 | /** | 339 | /** |
330 | * Messages ready to transmit??? -- real queues needed | 340 | * Messages ready to transmit??? -- FIXME real queues needed |
331 | */ | 341 | */ |
332 | struct GNUNET_MessageHeader *msg_out; | 342 | struct GNUNET_MessageHeader *msg_out; |
333 | 343 | ||
334 | /** | 344 | /** |
335 | * Messages received and not processed??? -- real queues needed | 345 | * Messages received and not processed??? -- FIXME real queues needed |
336 | */ | 346 | */ |
337 | struct GNUNET_MessageHeader *msg_in; | 347 | struct GNUNET_MessageHeader *msg_in; |
338 | 348 | ||
@@ -348,32 +358,46 @@ struct MESH_tunnel | |||
348 | */ | 358 | */ |
349 | struct Client | 359 | struct Client |
350 | { | 360 | { |
361 | /** | ||
362 | * Double linked list | ||
363 | */ | ||
364 | struct Client *next; | ||
365 | struct Client *prev; | ||
351 | 366 | ||
352 | struct Client *next; | 367 | /** |
353 | 368 | * Tunnels that belong to this client | |
354 | struct Client *prev; | 369 | */ |
355 | 370 | struct MESH_tunnel *my_tunnels_head; | |
356 | struct MESH_tunnel *my_tunnels_head; | 371 | struct MESH_tunnel *my_tunnels_tail; |
357 | |||
358 | struct MESH_tunnel *my_tunnels_tail; | ||
359 | 372 | ||
360 | /** | 373 | /** |
361 | * If this tunnel was created by a local client, what's its handle? | 374 | * If this tunnel was created by a local client, what's its handle? |
362 | */ | 375 | */ |
363 | struct GNUNET_SERVER_Client *handle; | 376 | struct GNUNET_SERVER_Client *handle; |
364 | 377 | ||
365 | unsigned int messages_subscribed_counter; | 378 | /** |
366 | 379 | * Messages that this client has declared interest in | |
367 | uint16_t *messages_subscribed; | 380 | */ |
381 | uint16_t *messages_subscribed; | ||
382 | unsigned int messages_subscribed_counter; | ||
368 | 383 | ||
369 | }; | 384 | }; |
370 | 385 | ||
386 | /******************************************************************************/ | ||
387 | /*********************** GLOBAL VARIABLES ****************************/ | ||
388 | /******************************************************************************/ | ||
371 | 389 | ||
372 | // static struct MESH_tunnel *tunnel_participation_head; | 390 | /** |
373 | 391 | * All the clients | |
374 | // static struct MESH_tunnel *tunnel_participation_tail; | 392 | */ |
375 | 393 | // static struct Client clients_head; | |
394 | // static struct Client clients_tail; | ||
376 | 395 | ||
396 | /** | ||
397 | * All the tunnels | ||
398 | */ | ||
399 | // static struct MESH_tunnel *tunnel_participation_head; | ||
400 | // static struct MESH_tunnel *tunnel_participation_tail; | ||
377 | 401 | ||
378 | 402 | ||
379 | /******************************************************************************/ | 403 | /******************************************************************************/ |
@@ -549,8 +573,6 @@ handle_local_network_traffic (void *cls, | |||
549 | */ | 573 | */ |
550 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | 574 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { |
551 | {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, | 575 | {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, |
552 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY, 0}, | ||
553 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL, 0}, | ||
554 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, | 576 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, |
555 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, | 577 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, |
556 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, | 578 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, |
@@ -608,6 +630,10 @@ core_disconnect (void *cls, | |||
608 | return; | 630 | return; |
609 | } | 631 | } |
610 | 632 | ||
633 | /******************************************************************************/ | ||
634 | /************************ MAIN FUNCTIONS ****************************/ | ||
635 | /******************************************************************************/ | ||
636 | |||
611 | /** | 637 | /** |
612 | * Process mesh requests. FIXME NON FUNCTIONAL, SKELETON | 638 | * Process mesh requests. FIXME NON FUNCTIONAL, SKELETON |
613 | * | 639 | * |
@@ -624,17 +650,17 @@ run (void *cls, | |||
624 | 650 | ||
625 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 651 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
626 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 652 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
627 | core = GNUNET_CORE_connect (c, /* Main configuration */ | 653 | core = GNUNET_CORE_connect (c, /* Main configuration */ |
628 | 32, /* queue size */ | 654 | 32, /* queue size */ |
629 | NULL, /* Closure passed to MESH functions */ | 655 | NULL, /* Closure passed to MESH functions */ |
630 | &core_init, /* Call core_init once connected */ | 656 | &core_init, /* Call core_init once connected */ |
631 | &core_connect, /* Handle connects */ | 657 | &core_connect, /* Handle connects */ |
632 | &core_disconnect, /* remove peers on disconnects */ | 658 | &core_disconnect, /* remove peers on disconnects */ |
633 | NULL, /* Do we care about "status" updates? */ | 659 | NULL, /* Do we care about "status" updates? */ |
634 | NULL, /* Don't want notified about all incoming messages */ | 660 | NULL, /* Don't notify about all incoming messages */ |
635 | GNUNET_NO, /* For header only inbound notification */ | 661 | GNUNET_NO, /* For header only in notification */ |
636 | NULL, /* Don't want notified about all outbound messages */ | 662 | NULL, /* Don't notify about all outbound messages */ |
637 | GNUNET_NO, /* For header only outbound notification */ | 663 | GNUNET_NO, /* For header-only out notification */ |
638 | core_handlers); /* Register these handlers */ | 664 | core_handlers); /* Register these handlers */ |
639 | 665 | ||
640 | if (core == NULL) | 666 | if (core == NULL) |
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c new file mode 100644 index 000000000..f7b0e9034 --- /dev/null +++ b/src/mesh/mesh_api_new.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file mesh/mesh_api_new.c | ||
23 | * @brief mesh api: client implementation of mesh service | ||
24 | * @author Bartlomiej Polot | ||
25 | */ | ||
26 | |||
27 | #ifdef __cplusplus | ||
28 | |||
29 | extern "C" | ||
30 | { | ||
31 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
32 | } | ||
33 | #endif | ||
34 | #endif | ||
35 | |||
36 | |||
37 | #include <stdint.h> | ||
38 | #include "gnunet_mesh_service.h" | ||
39 | |||
40 | /** | ||
41 | * Opaque handle to the service. | ||
42 | */ | ||
43 | struct GNUNET_MESH_Handle { | ||
44 | struct GNUNET_MESH_Tunnel *head; | ||
45 | struct GNUNET_MESH_Tunnel *tail; | ||
46 | GNUNET_MESH_TunnelEndHandler cleaner; | ||
47 | }; | ||
48 | |||
49 | /** | ||
50 | * Opaque handle to a tunnel. | ||
51 | */ | ||
52 | struct GNUNET_MESH_Tunnel { | ||
53 | GNUNET_PEER_Id owner; | ||
54 | GNUNET_PEER_Id destination; | ||
55 | GNUNET_MESH_TunnelConnectHandler connect_handler; | ||
56 | GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; | ||
57 | GNUNET_PEER_Id *peers; | ||
58 | }; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Connect to the mesh service. | ||
63 | * | ||
64 | * @param cfg configuration to use | ||
65 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) | ||
66 | * @param cleaner function called when an *inbound* tunnel is destroyed | ||
67 | * @param handlers callbacks for messages we care about, NULL-terminated | ||
68 | * note that the mesh is allowed to drop notifications about inbound | ||
69 | * messages if the client does not process them fast enough (for this | ||
70 | * notification type, a bounded queue is used) | ||
71 | * @return handle to the mesh service | ||
72 | * NULL on error (in this case, init is never called) | ||
73 | */ | ||
74 | struct GNUNET_MESH_Handle * | ||
75 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
76 | void *cls, | ||
77 | GNUNET_MESH_TunnelEndHandler cleaner, | ||
78 | const struct GNUNET_MESH_MessageHandler *handlers, | ||
79 | const GNUNET_MESH_ApplicationType *stypes) { | ||
80 | GNUNET_MESH_Handle *h; | ||
81 | h = GNUNET_malloc(sizeof(GNUNET_MESH_Handle)); | ||
82 | |||
83 | h->cleaner = cleaner; | ||
84 | return h; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * Disconnect from the mesh service. | ||
89 | * | ||
90 | * @param handle connection to mesh to disconnect | ||
91 | */ | ||
92 | void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) { | ||
93 | return; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * Create a new tunnel (we're initiator and will be allowed to add/remove peers and | ||
98 | * to broadcast). | ||
99 | * | ||
100 | * @param h mesh handle | ||
101 | * @param connect_handler function to call when peers are actually connected | ||
102 | * @param disconnect_handler function to call when peers are disconnected | ||
103 | * @param handler_cls closure for connect/disconnect handlers | ||
104 | */ | ||
105 | struct GNUNET_MESH_Tunnel * | ||
106 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | ||
107 | GNUNET_MESH_TunnelConnectHandler connect_handler, | ||
108 | GNUNET_MESH_TunnelDisconnectHandler disconnect_handler, | ||
109 | void *handler_cls) { | ||
110 | GNUNET_MESH_Tunnel *tunnel; | ||
111 | tunnel = GNUNET_malloc(sizeof(GNUNET_MESH_Tunnel)); | ||
112 | |||
113 | tunnel->connect_handler = connect_handler; | ||
114 | tunnel->disconnect_handler = disconnect_handler; | ||
115 | tunnel->peers = NULL; | ||
116 | |||
117 | return tunnel; | ||
118 | } | ||
119 | |||
120 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
121 | { | ||
122 | #endif | ||
123 | #ifdef __cplusplus | ||
124 | } | ||
125 | #endif \ No newline at end of file | ||