diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-04-06 17:27:25 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-04-06 17:27:25 +0000 |
commit | 78821fe96de53ff40851c11cf2134654a0b63640 (patch) | |
tree | 1dfecd3050c4b62488c295e3bdbb8a702cce5723 /src | |
parent | ba830bbe8fe27e46ac748a2e02bdc7dfeb1f3b5c (diff) | |
download | gnunet-78821fe96de53ff40851c11cf2134654a0b63640.tar.gz gnunet-78821fe96de53ff40851c11cf2134654a0b63640.zip |
New mesh API
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_mesh_service_new.h | 316 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 100 | ||||
-rw-r--r-- | src/mesh/mesh.h | 102 |
3 files changed, 468 insertions, 50 deletions
diff --git a/src/include/gnunet_mesh_service_new.h b/src/include/gnunet_mesh_service_new.h new file mode 100644 index 000000000..d1e850f34 --- /dev/null +++ b/src/include/gnunet_mesh_service_new.h | |||
@@ -0,0 +1,316 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010 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 include/gnunet_mesh_service.h | ||
23 | * @brief mesh service; establish tunnels to distant peers | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_MESH_SERVICE_H | ||
28 | #define GNUNET_MESH_SERVICE_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_util_lib.h" | ||
39 | #include "gnunet_transport_service.h" | ||
40 | |||
41 | /** | ||
42 | * Version number of GNUnet-mesh API. | ||
43 | */ | ||
44 | #define GNUNET_MESH_VERSION 0x00000000 | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Opaque handle to the service. | ||
49 | */ | ||
50 | struct GNUNET_MESH_Handle; | ||
51 | |||
52 | /** | ||
53 | * Opaque handle to a tunnel. | ||
54 | */ | ||
55 | struct GNUNET_MESH_Tunnel; | ||
56 | |||
57 | /** | ||
58 | * Functions with this signature are called whenever a message is | ||
59 | * received or transmitted. | ||
60 | * | ||
61 | * @param cls closure (set from GNUNET_MESH_connect) | ||
62 | * @param tunnel connection to the other end | ||
63 | * @param tunnel_ctx place to store local state associated with the tunnel | ||
64 | * @param sender who sent the message | ||
65 | * @param message the actual message | ||
66 | * @param atsi performance data for the connection | ||
67 | * @return GNUNET_OK to keep the connection open, | ||
68 | * GNUNET_SYSERR to close it (signal serious error) | ||
69 | */ | ||
70 | typedef int | ||
71 | (*GNUNET_MESH_MessageCallback) (void *cls, | ||
72 | struct GNUNET_MESH_Tunnel *tunnel, | ||
73 | void **tunnel_ctx, | ||
74 | const struct GNUNET_PeerIdentity *sender, | ||
75 | const struct GNUNET_MessageHeader *message, | ||
76 | const struct GNUNET_TRANSPORT_ATS_Information *atsi); | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Message handler. Each struct specifies how to handle on particular | ||
81 | * type of message received. | ||
82 | */ | ||
83 | struct GNUNET_MESH_MessageHandler | ||
84 | { | ||
85 | /** | ||
86 | * Function to call for messages of "type". | ||
87 | */ | ||
88 | GNUNET_MESH_MessageCallback callback; | ||
89 | |||
90 | /** | ||
91 | * Type of the message this handler covers. | ||
92 | */ | ||
93 | uint16_t type; | ||
94 | |||
95 | /** | ||
96 | * Expected size of messages of this type. Use 0 for variable-size. | ||
97 | * If non-zero, messages of the given type will be discarded if they | ||
98 | * do not have the right size. | ||
99 | */ | ||
100 | uint16_t expected_size; | ||
101 | |||
102 | }; | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Function called whenever an inbound tunnel is destroyed. Should clean up | ||
107 | * any associated state. | ||
108 | * | ||
109 | * @param cls closure (set from GNUNET_MESH_connect) | ||
110 | * @param tunnel connection to the other end (henceforth invalid) | ||
111 | * @param tunnel_ctx place where local state associated with the tunnel is stored | ||
112 | */ | ||
113 | typedef void (GNUNET_MESH_TunnelEndHandler)(void *cls, | ||
114 | const struct GNUNET_MESH_Tunnel *tunnel, | ||
115 | void **tunnel_ctx); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Type for an application. Values defined in gnunet_applications.h | ||
120 | */ | ||
121 | typedef uint32_t GNUNET_MESH_ApplicationType; | ||
122 | |||
123 | |||
124 | /** | ||
125 | * Connect to the mesh service. | ||
126 | * | ||
127 | * @param cfg configuration to use | ||
128 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) | ||
129 | * @param cleaner function called when an *inbound* tunnel is destroyed | ||
130 | * @param handlers callbacks for messages we care about, NULL-terminated | ||
131 | * note that the mesh is allowed to drop notifications about inbound | ||
132 | * messages if the client does not process them fast enough (for this | ||
133 | * notification type, a bounded queue is used) | ||
134 | * @return handle to the mesh service | ||
135 | * NULL on error (in this case, init is never called) | ||
136 | */ | ||
137 | struct GNUNET_MESH_Handle * | ||
138 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
139 | void *cls, | ||
140 | GNUNET_MESH_TunnelEndHandler cleaner, | ||
141 | const struct GNUNET_MESH_MessageHandler *handlers, | ||
142 | const GNUNET_MESH_ApplicationType *stypes); | ||
143 | |||
144 | /** | ||
145 | * Get the peer on the other side of this tunnel if it is just one. Return NULL otherwise | ||
146 | * | ||
147 | * @deprecated | ||
148 | * @param tunnel the tunnel | ||
149 | * @return the peer or NULL | ||
150 | */ | ||
151 | const struct GNUNET_PeerIdentity* | ||
152 | GNUNET_MESH_get_peer (const struct GNUNET_MESH_Tunnel* tunnel); | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Disconnect from the mesh service. | ||
157 | * | ||
158 | * @param handle connection to mesh to disconnect | ||
159 | */ | ||
160 | void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle); | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Method called whenever a tunnel falls apart. | ||
165 | * | ||
166 | * @param cls closure | ||
167 | * @param peer peer identity the tunnel stopped working with | ||
168 | */ | ||
169 | typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls, | ||
170 | const struct GNUNET_PeerIdentity *peer); | ||
171 | |||
172 | |||
173 | /** | ||
174 | * Method called whenever a tunnel is established. | ||
175 | * | ||
176 | * @param cls closure | ||
177 | * @param peer peer identity the tunnel was created to, NULL on timeout | ||
178 | * @param atsi performance data for the connection | ||
179 | */ | ||
180 | typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls, | ||
181 | const struct GNUNET_PeerIdentity *peer, | ||
182 | const struct GNUNET_TRANSPORT_ATS_Information *atsi); | ||
183 | |||
184 | |||
185 | |||
186 | /** | ||
187 | * Create a new tunnel (we're initiator and will be allowed to add/remove peers and | ||
188 | * to broadcast). | ||
189 | * | ||
190 | * @param h mesh handle | ||
191 | * @param connect_handler function to call when peers are actually connected | ||
192 | * @param disconnect_handler function to call when peers are disconnected | ||
193 | * @param handler_cls closure for connect/disconnect handlers | ||
194 | */ | ||
195 | struct GNUNET_MESH_Tunnel * | ||
196 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | ||
197 | GNUNET_MESH_TunnelConnectHandler connect_handler, | ||
198 | GNUNET_MESH_TunnelDisconnectHandler disconnect_handler, | ||
199 | void *handler_cls); | ||
200 | |||
201 | /** | ||
202 | * Destroy an existing tunnel. | ||
203 | * | ||
204 | * @param tun tunnel handle | ||
205 | */ | ||
206 | void | ||
207 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun); | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Request that a peer should be added to the tunnel. The existing | ||
212 | * connect handler will be called ONCE with either success or failure. | ||
213 | * | ||
214 | * @param tunnel handle to existing tunnel | ||
215 | * @param timeout how long to try to establish a connection | ||
216 | * @param peer peer to add | ||
217 | */ | ||
218 | void | ||
219 | GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, | ||
220 | struct GNUNET_TIME_Relative timeout, | ||
221 | const struct GNUNET_PeerIdentity *peer); | ||
222 | |||
223 | |||
224 | /** | ||
225 | * Request that a peer should be removed from the tunnel. The existing | ||
226 | * disconnect handler will be called ONCE if we were connected. | ||
227 | * | ||
228 | * @param tunnel handle to existing tunnel | ||
229 | * @param peer peer to remove | ||
230 | */ | ||
231 | void | ||
232 | GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel, | ||
233 | const struct GNUNET_PeerIdentity *peer); | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Request that the mesh should try to connect to a peer supporting the given | ||
238 | * message type. | ||
239 | * | ||
240 | * @param tunnel handle to existing tunnel | ||
241 | * @param timeout how long to try to establish a connection | ||
242 | * @param app_type application type that must be supported by the peer (MESH should | ||
243 | * discover peer in proximity handling this type) | ||
244 | * @return NULL on error (handler will not be called), otherwise handle for cancellation | ||
245 | */ | ||
246 | struct GNUNET_MESH_Tunnel * | ||
247 | GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel, | ||
248 | struct GNUNET_TIME_Relative timeout, | ||
249 | GNUNET_MESH_ApplicationType app_type); | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Handle for a transmission request. | ||
254 | */ | ||
255 | struct GNUNET_MESH_TransmitHandle; | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Ask the mesh to call "notify" once it is ready to transmit the | ||
260 | * given number of bytes to the specified "target". If we are not yet | ||
261 | * connected to the specified peer, a call to this function will cause | ||
262 | * us to try to establish a connection. | ||
263 | * | ||
264 | * @param tunnel tunnel to use for transmission | ||
265 | * @param cork is corking allowed for this transmission? | ||
266 | * @param priority how important is the message? | ||
267 | * @param maxdelay how long can the message wait? | ||
268 | * @param target destination for the message, NULL for multicast to all tunnel targets | ||
269 | * @param notify_size how many bytes of buffer space does notify want? | ||
270 | * @param notify function to call when buffer space is available; | ||
271 | * will be called with NULL on timeout or if the overall queue | ||
272 | * for this peer is larger than queue_size and this is currently | ||
273 | * the message with the lowest priority | ||
274 | * @param notify_cls closure for notify | ||
275 | * @return non-NULL if the notify callback was queued, | ||
276 | * NULL if we can not even queue the request (insufficient | ||
277 | * memory); if NULL is returned, "notify" will NOT be called. | ||
278 | */ | ||
279 | struct GNUNET_MESH_TransmitHandle * | ||
280 | GNUNET_MESH_notify_transmit_ready (struct | ||
281 | GNUNET_MESH_Tunnel | ||
282 | *tunnel, | ||
283 | int cork, | ||
284 | uint32_t priority, | ||
285 | struct | ||
286 | GNUNET_TIME_Relative | ||
287 | maxdelay, | ||
288 | const struct GNUNET_PeerIdentity *target, | ||
289 | size_t | ||
290 | notify_size, | ||
291 | GNUNET_CONNECTION_TransmitReadyNotify | ||
292 | notify, | ||
293 | void | ||
294 | *notify_cls); | ||
295 | |||
296 | |||
297 | /** | ||
298 | * Cancel the specified transmission-ready notification. | ||
299 | * | ||
300 | * @param th handle that was returned by "notify_transmit_ready". | ||
301 | */ | ||
302 | void | ||
303 | GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle | ||
304 | *th); | ||
305 | |||
306 | |||
307 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
308 | { | ||
309 | #endif | ||
310 | #ifdef __cplusplus | ||
311 | } | ||
312 | #endif | ||
313 | |||
314 | /* ifndef GNUNET_MESH_SERVICE_H */ | ||
315 | #endif | ||
316 | /* end of gnunet_mesh_service.h */ | ||
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index fce2d1406..6725db563 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "platform.h" | 34 | #include "platform.h" |
35 | #include "gnunet_common.h" | 35 | #include "gnunet_common.h" |
36 | #include "gnunet_util_lib.h" | 36 | #include "gnunet_util_lib.h" |
37 | #include "gnunet_peer_lib.h" | ||
37 | #include "gnunet_core_service.h" | 38 | #include "gnunet_core_service.h" |
38 | #include "gnunet_protocols.h" | 39 | #include "gnunet_protocols.h" |
39 | #include "mesh.h" | 40 | #include "mesh.h" |
@@ -56,7 +57,7 @@ struct GNUNET_MESH_ManipulatePath | |||
56 | struct GNUNET_MessageHeader header; | 57 | struct GNUNET_MessageHeader header; |
57 | 58 | ||
58 | /** | 59 | /** |
59 | * Id of the tunnel this path belongs to, unique in conjunction with the origin. | 60 | * (global) Id of the tunnel this path belongs to, unique in conjunction with the origin. |
60 | */ | 61 | */ |
61 | uint32_t tid GNUNET_PACKED; | 62 | uint32_t tid GNUNET_PACKED; |
62 | 63 | ||
@@ -67,6 +68,11 @@ struct GNUNET_MESH_ManipulatePath | |||
67 | uint32_t speed_min GNUNET_PACKED; | 68 | uint32_t speed_min GNUNET_PACKED; |
68 | 69 | ||
69 | /** | 70 | /** |
71 | * 64-bit alignment. | ||
72 | */ | ||
73 | uint32_t reserved GNUNET_PACKED; | ||
74 | |||
75 | /** | ||
70 | * path_length structs defining the *whole* path from the origin [0] to the | 76 | * path_length structs defining the *whole* path from the origin [0] to the |
71 | * final destination [path_length-1]. | 77 | * final destination [path_length-1]. |
72 | */ | 78 | */ |
@@ -94,11 +100,6 @@ struct GNUNET_MESH_OriginMulticast | |||
94 | struct GNUNET_PeerIdentity oid; | 100 | struct GNUNET_PeerIdentity oid; |
95 | 101 | ||
96 | /** | 102 | /** |
97 | * FIXME: Some form of authentication | ||
98 | */ | ||
99 | // uint32_t token; | ||
100 | |||
101 | /** | ||
102 | * Payload follows | 103 | * Payload follows |
103 | */ | 104 | */ |
104 | }; | 105 | }; |
@@ -130,11 +131,6 @@ struct GNUNET_MESH_DataMessageFromOrigin | |||
130 | struct GNUNET_PeerIdentity destination; | 131 | struct GNUNET_PeerIdentity destination; |
131 | 132 | ||
132 | /** | 133 | /** |
133 | * FIXME: Some form of authentication | ||
134 | */ | ||
135 | // uint32_t token; | ||
136 | |||
137 | /** | ||
138 | * Payload follows | 134 | * Payload follows |
139 | */ | 135 | */ |
140 | }; | 136 | }; |
@@ -166,11 +162,6 @@ struct GNUNET_MESH_DataMessageToOrigin | |||
166 | struct GNUNET_PeerIdentity sender; | 162 | struct GNUNET_PeerIdentity sender; |
167 | 163 | ||
168 | /** | 164 | /** |
169 | * FIXME: Some form of authentication | ||
170 | */ | ||
171 | // uint32_t token; | ||
172 | |||
173 | /** | ||
174 | * Payload follows | 165 | * Payload follows |
175 | */ | 166 | */ |
176 | }; | 167 | }; |
@@ -240,7 +231,7 @@ struct PeerInfo | |||
240 | /** | 231 | /** |
241 | * ID of the peer | 232 | * ID of the peer |
242 | */ | 233 | */ |
243 | struct GNUNET_PeerIdentity id; | 234 | GNUNET_PEER_Id id; |
244 | 235 | ||
245 | /** | 236 | /** |
246 | * Is the peer reachable? Is the peer even connected? | 237 | * Is the peer reachable? Is the peer even connected? |
@@ -248,9 +239,9 @@ struct PeerInfo | |||
248 | enum PeerState state; | 239 | enum PeerState state; |
249 | 240 | ||
250 | /** | 241 | /** |
251 | * Who to send the data to | 242 | * Who to send the data to --- what about multiple (alternate) paths? |
252 | */ | 243 | */ |
253 | uint32_t first_hop; | 244 | GNUNET_PEER_Id first_hop; |
254 | 245 | ||
255 | /** | 246 | /** |
256 | * Max data rate to this peer | 247 | * Max data rate to this peer |
@@ -276,7 +267,7 @@ struct Path | |||
276 | /** | 267 | /** |
277 | * List of all the peers that form the path from origin to target | 268 | * List of all the peers that form the path from origin to target |
278 | */ | 269 | */ |
279 | struct PeerInfo *peers; | 270 | GNUNET_PEER_Id *peers; |
280 | }; | 271 | }; |
281 | 272 | ||
282 | /** | 273 | /** |
@@ -290,10 +281,15 @@ struct Path | |||
290 | */ | 281 | */ |
291 | struct MESH_tunnel | 282 | struct MESH_tunnel |
292 | { | 283 | { |
284 | |||
285 | struct MESH_tunnel *next; | ||
286 | |||
287 | struct MESH_tunnel *prev; | ||
288 | |||
293 | /** | 289 | /** |
294 | * Origin ID: Node that created the tunnel | 290 | * Origin ID: Node that created the tunnel |
295 | */ | 291 | */ |
296 | struct GNUNET_PeerIdentity oid; | 292 | GNUNET_PEER_Id oid; |
297 | 293 | ||
298 | /** | 294 | /** |
299 | * Tunnel number (unique for a given oid) | 295 | * Tunnel number (unique for a given oid) |
@@ -301,7 +297,7 @@ struct MESH_tunnel | |||
301 | uint32_t tid; | 297 | uint32_t tid; |
302 | 298 | ||
303 | /** | 299 | /** |
304 | * Whether the tunnel is in state to transmit data | 300 | * Whether the tunnel is in a state to transmit data |
305 | */ | 301 | */ |
306 | int ready; | 302 | int ready; |
307 | 303 | ||
@@ -331,33 +327,53 @@ struct MESH_tunnel | |||
331 | struct Path *paths; | 327 | struct Path *paths; |
332 | 328 | ||
333 | /** | 329 | /** |
334 | * Messages ready to transmit | 330 | * Messages ready to transmit??? -- real queues needed |
335 | */ | 331 | */ |
336 | struct GNUNET_MessageHeader *msg_out; | 332 | struct GNUNET_MessageHeader *msg_out; |
337 | 333 | ||
338 | /** | 334 | /** |
339 | * Messages received and not processed | 335 | * Messages received and not processed??? -- real queues needed |
340 | */ | 336 | */ |
341 | struct GNUNET_MessageHeader *msg_in; | 337 | struct GNUNET_MessageHeader *msg_in; |
342 | 338 | ||
343 | /** | 339 | /** |
344 | * FIXME Clients. Is anyone to be notified for traffic here? | 340 | * If this tunnel was created by a local client, what's its handle? |
345 | */ | 341 | */ |
342 | struct GNUNET_SERVER_Client *initiator; | ||
346 | }; | 343 | }; |
347 | 344 | ||
348 | /** | 345 | /** |
349 | * So, I'm an endpoint. Why am I receiveing traffic? | 346 | * So, I'm an endpoint. Why am I receiveing traffic? |
350 | * Who is interested in this? How to communicate with them? | 347 | * Who is interested in this? How to communicate with them? |
351 | */ | 348 | */ |
352 | struct Clients | 349 | struct Client |
353 | { | 350 | { |
351 | |||
352 | struct Client *next; | ||
353 | |||
354 | struct Client *prev; | ||
355 | |||
356 | struct MESH_tunnel *my_tunnels_head; | ||
357 | |||
358 | struct MESH_tunnel *my_tunnels_tail; | ||
359 | |||
354 | /** | 360 | /** |
355 | * FIXME add structures needed to handle client connections | 361 | * If this tunnel was created by a local client, what's its handle? |
356 | */ | 362 | */ |
357 | int fixme; | 363 | struct GNUNET_SERVER_Client *handle; |
364 | |||
365 | unsigned int messages_subscribed_counter; | ||
366 | |||
367 | uint16_t *messages_subscribed; | ||
368 | |||
358 | }; | 369 | }; |
359 | 370 | ||
360 | 371 | ||
372 | static struct MESH_tunnel *tunnel_participation_head; | ||
373 | |||
374 | static struct MESH_tunnel *tunnel_participation_tail; | ||
375 | |||
376 | |||
361 | 377 | ||
362 | /******************************************************************************/ | 378 | /******************************************************************************/ |
363 | /******************** MESH NETWORK HANDLERS **************************/ | 379 | /******************** MESH NETWORK HANDLERS **************************/ |
@@ -382,6 +398,28 @@ handle_mesh_path_create (void *cls, | |||
382 | const struct GNUNET_TRANSPORT_ATS_Information | 398 | const struct GNUNET_TRANSPORT_ATS_Information |
383 | *atsi) | 399 | *atsi) |
384 | { | 400 | { |
401 | /* | ||
402 | * EXAMPLE OF USING THE API | ||
403 | * NOT ACTUAL CODE!!!!! | ||
404 | */ | ||
405 | /*client *c; | ||
406 | tunnel *t; | ||
407 | |||
408 | t = new; | ||
409 | GNUNET_CONTAINER_DLL_insert (c->my_tunnels_head, | ||
410 | c->my_tunnels_tail, | ||
411 | t); | ||
412 | |||
413 | while (NULL != (t = c->my_tunnels_head)) | ||
414 | { | ||
415 | GNUNET_CONTAINER_DLL_remove (c->my_tunnels_head, | ||
416 | c->my_tunnels_tail, | ||
417 | t); | ||
418 | GNUNET_free (t); | ||
419 | } | ||
420 | */ | ||
421 | |||
422 | |||
385 | /* Extract path */ | 423 | /* Extract path */ |
386 | /* Find origin & self */ | 424 | /* Find origin & self */ |
387 | /* Search for origin in local tunnels */ | 425 | /* Search for origin in local tunnels */ |
@@ -515,8 +553,8 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | |||
515 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, | 553 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, |
516 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, | 554 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, |
517 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, | 555 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, |
518 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, sizeof(struct GNUNET_MESH_Control)}, | 556 | {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, 0}, |
519 | {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY, sizeof(struct GNUNET_MESH_Control)}, | 557 | {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY, 0}, |
520 | {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ | 558 | {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ |
521 | {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */ | 559 | {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */ |
522 | {NULL, NULL, 0, 0} | 560 | {NULL, NULL, 0, 0} |
@@ -620,4 +658,4 @@ main (int argc, char *const *argv) | |||
620 | "mesh", | 658 | "mesh", |
621 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 659 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
622 | return ret; | 660 | return ret; |
623 | } \ No newline at end of file | 661 | } |
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 2c260030d..a29c63f88 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h | |||
@@ -36,19 +36,20 @@ | |||
36 | /* API CALL MESSAGE USED | 36 | /* API CALL MESSAGE USED |
37 | * -------- ------------ | 37 | * -------- ------------ |
38 | * connect GNUNET_MESH_Connect | 38 | * connect GNUNET_MESH_Connect |
39 | * disconnect Server_disconnect | 39 | * disconnect None (network level disconnect) |
40 | * | ||
41 | * tunnel_create GNUNET_MESH_TunnelMessage | ||
42 | * tunnel_destroy GNUNET_MESH_TunnelMessage | ||
40 | * | 43 | * |
41 | * peer_request_connect_any GNUNET_MESH_ConnectPeer | ||
42 | * peer_request_connect_all GNUNET_MESH_ConnectPeer | ||
43 | * peer_request_connect_add GNUNET_MESH_ConnectPeer | 44 | * peer_request_connect_add GNUNET_MESH_ConnectPeer |
44 | * peer_request_connect_del GNUNET_MESH_ConnectPeer | 45 | * peer_request_connect_del GNUNET_MESH_ConnectPeer |
45 | * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType | 46 | * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType |
46 | * peer_request_connect_cancel GNUNET_MESH_Control | ||
47 | * | 47 | * |
48 | * notify_transmit_ready GNUNET_MESH_Control | 48 | * notify_transmit_ready GNUNET_MESH_Control |
49 | * notify_transmit_ready_cancel None | 49 | * notify_transmit_ready_cancel None |
50 | */ | 50 | */ |
51 | 51 | ||
52 | |||
52 | struct GNUNET_MESH_Connect { | 53 | struct GNUNET_MESH_Connect { |
53 | /** | 54 | /** |
54 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT | 55 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT |
@@ -60,74 +61,137 @@ struct GNUNET_MESH_Connect { | |||
60 | /* uint16_t messages_subscribed[] */ | 61 | /* uint16_t messages_subscribed[] */ |
61 | }; | 62 | }; |
62 | 63 | ||
63 | struct GNUNET_MESH_ConnectPeer { | 64 | |
65 | /** | ||
66 | * | ||
67 | */ | ||
68 | struct GNUNET_MESH_TunnelMessage { | ||
64 | /** | 69 | /** |
65 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ANY|ALL|ADD|DEL] | 70 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY] |
66 | * | ||
67 | * Size: sizeof(struct GNUNET_MESH_ConnectPeer) + npeers * sizeof (struct GNUNET_PeerIdentity) | ||
68 | */ | 71 | */ |
69 | struct GNUNET_MessageHeader header; | 72 | struct GNUNET_MessageHeader header; |
70 | 73 | ||
71 | /* struct GNUNET_PeerIdentity peers[] */ | 74 | /** |
75 | * ID of a tunnel controlled by this client. | ||
76 | */ | ||
77 | uint32_t tunnel_id GNUNET_PACKED; | ||
72 | }; | 78 | }; |
73 | 79 | ||
80 | |||
81 | struct GNUNET_MESH_PeerControl { | ||
82 | |||
83 | /** | ||
84 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL] (client to service, client created tunnel) | ||
85 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOTIFY[CONNECT|DISCONNECT] (service to client) | ||
86 | * | ||
87 | * Size: sizeof(struct GNUNET_MESH_PeerControl) | ||
88 | */ | ||
89 | struct GNUNET_MessageHeader header; | ||
90 | |||
91 | /** | ||
92 | * ID of a tunnel controlled by this client. | ||
93 | */ | ||
94 | uint32_t tunnel_id GNUNET_PACKED; | ||
95 | |||
96 | /** | ||
97 | * Peer to connect/disconnect. | ||
98 | */ | ||
99 | struct GNUNET_PeerIdentity peer; | ||
100 | }; | ||
101 | |||
102 | |||
103 | |||
104 | |||
74 | struct GNUNET_MESH_ConnectPeerByType { | 105 | struct GNUNET_MESH_ConnectPeerByType { |
75 | /** | 106 | /** |
76 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE | 107 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
77 | */ | 108 | */ |
78 | struct GNUNET_MessageHeader header; | 109 | struct GNUNET_MessageHeader header; |
79 | 110 | ||
80 | /* Type specification */ | 111 | /** |
112 | * ID of a tunnel controlled by this client. | ||
113 | */ | ||
114 | uint32_t tunnel_id GNUNET_PACKED; | ||
115 | |||
116 | /** | ||
117 | * Type specification | ||
118 | */ | ||
81 | GNUNET_MESH_ApplicationType type; | 119 | GNUNET_MESH_ApplicationType type; |
82 | }; | 120 | }; |
83 | 121 | ||
84 | struct GNUNET_MESH_Control { | 122 | |
123 | struct GNUNET_MESH_RequestTransmitReady { | ||
85 | /** | 124 | /** |
86 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL | 125 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_REQUEST_TRANSMIT_READY |
87 | * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY | ||
88 | */ | 126 | */ |
89 | struct GNUNET_MessageHeader header; | 127 | struct GNUNET_MessageHeader header; |
90 | 128 | ||
129 | /** | ||
130 | * ID of a tunnel controlled by this client. | ||
131 | */ | ||
91 | uint32_t tunnel_id GNUNET_PACKED; | 132 | uint32_t tunnel_id GNUNET_PACKED; |
92 | uint32_t variable GNUNET_PACKED; /* Size of data / connection ID */ | 133 | |
134 | /** | ||
135 | * Size of message we would like to transmit to this tunnel | ||
136 | */ | ||
137 | uint32_t msg_size GNUNET_PACKED; | ||
93 | }; | 138 | }; |
94 | 139 | ||
95 | struct GNUNET_MESH_TunnelEvent { | 140 | struct GNUNET_MESH_NotifyTransmitReady { |
96 | /** | 141 | /** |
97 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATED\DESTROYED] | 142 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_NOTIFY_TRANSMIT_READY |
98 | */ | 143 | */ |
99 | struct GNUNET_MessageHeader header; | 144 | struct GNUNET_MessageHeader header; |
100 | 145 | ||
146 | /** | ||
147 | * ID of a tunnel controlled by this client. | ||
148 | */ | ||
101 | uint32_t tunnel_id GNUNET_PACKED; | 149 | uint32_t tunnel_id GNUNET_PACKED; |
102 | uint32_t reason GNUNET_PACKED; /* incoming, connect, timeout, disconnect */ | 150 | |
151 | /** | ||
152 | * Size of message we can now transmit to this tunnel | ||
153 | */ | ||
154 | uint32_t msg_size GNUNET_PACKED; | ||
103 | }; | 155 | }; |
104 | 156 | ||
157 | |||
105 | struct GNUNET_MESH_Data { | 158 | struct GNUNET_MESH_Data { |
106 | /** | 159 | /** |
107 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA | 160 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA (client to service, or service to client) |
108 | * | 161 | * |
109 | * Size: sizeof(struct GNUNET_MESH_Data) + sizeof (data) | 162 | * Size: sizeof(struct GNUNET_MESH_Data) + sizeof (data) |
110 | */ | 163 | */ |
111 | struct GNUNET_MessageHeader header; | 164 | struct GNUNET_MessageHeader header; |
112 | 165 | ||
166 | /** | ||
167 | * ID of a tunnel controlled by this client. | ||
168 | */ | ||
113 | uint32_t tunnel_id GNUNET_PACKED; | 169 | uint32_t tunnel_id GNUNET_PACKED; |
114 | 170 | ||
171 | /** | ||
172 | * Source or destination of the message (depending on direction). | ||
173 | */ | ||
115 | struct GNUNET_PeerIdentity destination; | 174 | struct GNUNET_PeerIdentity destination; |
116 | 175 | ||
117 | /* uint8_t data[] */ | 176 | /* uint8_t data[] */ |
118 | }; | 177 | }; |
119 | 178 | ||
179 | |||
120 | struct GNUNET_MESH_DataBroadcast { | 180 | struct GNUNET_MESH_DataBroadcast { |
121 | /** | 181 | /** |
122 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST | 182 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST (client to service only, client created tunnel) |
123 | * | 183 | * |
124 | * Size: sizeof(struct GNUNET_MESH_DataBroadcast) + sizeof (data) | 184 | * Size: sizeof(struct GNUNET_MESH_DataBroadcast) + sizeof (data) |
125 | */ | 185 | */ |
126 | struct GNUNET_MessageHeader header; | 186 | struct GNUNET_MessageHeader header; |
127 | 187 | ||
188 | /** | ||
189 | * ID of a tunnel controlled by this client. | ||
190 | */ | ||
128 | uint32_t tunnel_id GNUNET_PACKED; | 191 | uint32_t tunnel_id GNUNET_PACKED; |
129 | 192 | ||
130 | /* uint8_t data[] */ | 193 | /* uint8_t data[] */ |
131 | }; | 194 | }; |
132 | 195 | ||
196 | |||
133 | #endif | 197 | #endif |