diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-05-07 12:12:09 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-05-07 12:12:09 +0000 |
commit | 5128f85f632d1803ab3827b62a535b89e27f53ac (patch) | |
tree | 640f80144706eed998bef5531e091e839f0a8015 /src | |
parent | 0365741f83213f474346d732842a624c00621b8d (diff) | |
download | gnunet-5128f85f632d1803ab3827b62a535b89e27f53ac.tar.gz gnunet-5128f85f632d1803ab3827b62a535b89e27f53ac.zip |
- make api compile
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-new.c | 4 | ||||
-rw-r--r-- | src/mesh/mesh2.h | 343 | ||||
-rw-r--r-- | src/mesh/mesh2_api.c | 342 | ||||
-rw-r--r-- | src/mesh/mesh2_protocol.h | 376 |
4 files changed, 740 insertions, 325 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index 5b7e9991f..72295b0bb 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c | |||
@@ -46,8 +46,8 @@ | |||
46 | */ | 46 | */ |
47 | 47 | ||
48 | #include "platform.h" | 48 | #include "platform.h" |
49 | #include "mesh.h" | 49 | #include "mesh2.h" |
50 | #include "mesh_protocol.h" | 50 | #include "mesh2_protocol.h" |
51 | #include "mesh_tunnel_tree.h" | 51 | #include "mesh_tunnel_tree.h" |
52 | #include "block_mesh.h" | 52 | #include "block_mesh.h" |
53 | #include "gnunet_dht_service.h" | 53 | #include "gnunet_dht_service.h" |
diff --git a/src/mesh/mesh2.h b/src/mesh/mesh2.h new file mode 100644 index 000000000..39533e654 --- /dev/null +++ b/src/mesh/mesh2.h | |||
@@ -0,0 +1,343 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001 - 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 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh.h | ||
24 | */ | ||
25 | |||
26 | #ifndef MESH_H_ | ||
27 | #define MESH_H_ | ||
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" | ||
31 | { | ||
32 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
33 | } | ||
34 | #endif | ||
35 | #endif | ||
36 | |||
37 | #include <stdint.h> | ||
38 | |||
39 | #define MESH_DEBUG GNUNET_YES | ||
40 | |||
41 | #define INITIAL_WINDOW_SIZE 8 | ||
42 | #define ACK_THRESHOLD INITIAL_WINDOW_SIZE / 2 | ||
43 | |||
44 | #include "platform.h" | ||
45 | #include "gnunet_common.h" | ||
46 | #include "gnunet_util_lib.h" | ||
47 | #include "gnunet_peer_lib.h" | ||
48 | #include "gnunet_core_service.h" | ||
49 | #include "gnunet_protocols.h" | ||
50 | #include <gnunet_mesh_service.h> | ||
51 | |||
52 | /******************************************************************************/ | ||
53 | /******************** MESH LOCAL MESSAGES *************************/ | ||
54 | /******************************************************************************/ | ||
55 | /* Any API call should be documented in the folowing table under API CALL. | ||
56 | * Also, any message type should be documented in the following table, with the | ||
57 | * associated event. | ||
58 | * | ||
59 | * API CALL (GNUNET_MESH_*) MESSAGE USED | ||
60 | * ------------------------ ------------ | ||
61 | * connect GNUNET_MESH_ClientConnect | ||
62 | * disconnect None (network level disconnect) | ||
63 | * | ||
64 | * tunnel_create GNUNET_MESH_TunnelMessage | ||
65 | * tunnel_destroy GNUNET_MESH_TunnelMessage | ||
66 | * tunnel_buffer GNUNET_MESH_TunnelMessage | ||
67 | * | ||
68 | * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy) | ||
69 | * notify_transmit_ready_cancel None (clear of internal data structures) | ||
70 | * | ||
71 | * | ||
72 | * EVENT MESSAGE USED | ||
73 | * ----- ------------ | ||
74 | * data GNUNET_MESH_Unicast OR | ||
75 | * GNUNET_MESH_Multicast OR | ||
76 | * GNUNET_MESH_ToOrigin | ||
77 | * data ack GNUNET_MESH_LocalAck | ||
78 | * | ||
79 | * new incoming tunnel GNUNET_MESH_PeerControl | ||
80 | * peer connects to a tunnel FIXME | ||
81 | * peer disconnects from a tunnel FIXME | ||
82 | */ | ||
83 | |||
84 | /******************************************************************************/ | ||
85 | /************************** CONSTANTS ******************************/ | ||
86 | /******************************************************************************/ | ||
87 | |||
88 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000 | ||
89 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000 | ||
90 | |||
91 | #define HIGH_PID 0xFFFF0000 | ||
92 | #define LOW_PID 0x0000FFFF | ||
93 | |||
94 | #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) | ||
95 | |||
96 | /******************************************************************************/ | ||
97 | /************************** MESSAGES ******************************/ | ||
98 | /******************************************************************************/ | ||
99 | |||
100 | GNUNET_NETWORK_STRUCT_BEGIN | ||
101 | |||
102 | /** | ||
103 | * Message for a client to register to the service | ||
104 | */ | ||
105 | struct GNUNET_MESH_ClientConnect | ||
106 | { | ||
107 | /** | ||
108 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT | ||
109 | * | ||
110 | * Size: sizeof(struct GNUNET_MESH_ClientConnect) + | ||
111 | * sizeof(MESH_ApplicationType) * applications + | ||
112 | * sizeof(uint16_t) * types | ||
113 | */ | ||
114 | struct GNUNET_MessageHeader header; | ||
115 | uint16_t types GNUNET_PACKED; | ||
116 | /* uint16_t list_types[types] */ | ||
117 | }; | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Type for tunnel numbering. | ||
122 | * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000 | ||
123 | * - Local tunnel numbers given by the client (created) are >= 0x80000000 | ||
124 | * - Global tunnel numbers are < 0x80000000 | ||
125 | */ | ||
126 | typedef uint32_t MESH_TunnelNumber; | ||
127 | |||
128 | /** | ||
129 | * Message for a client to create and destroy tunnels. | ||
130 | */ | ||
131 | struct GNUNET_MESH_TunnelMessage | ||
132 | { | ||
133 | /** | ||
134 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY] | ||
135 | * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN] | ||
136 | * | ||
137 | * Size: sizeof(struct GNUNET_MESH_TunnelMessage) | ||
138 | */ | ||
139 | struct GNUNET_MessageHeader header; | ||
140 | |||
141 | /** | ||
142 | * ID of a tunnel controlled by this client. | ||
143 | */ | ||
144 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | ||
145 | |||
146 | /** | ||
147 | * Tunnel's peer | ||
148 | */ | ||
149 | struct GNUNET_PeerIdentity peer; | ||
150 | }; | ||
151 | |||
152 | |||
153 | /** | ||
154 | * Message for the service to let a client know about created tunnels. | ||
155 | */ | ||
156 | struct GNUNET_MESH_TunnelNotification | ||
157 | { | ||
158 | /** | ||
159 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE | ||
160 | * | ||
161 | * Size: sizeof(struct GNUNET_MESH_TunnelMessage) | ||
162 | */ | ||
163 | struct GNUNET_MessageHeader header; | ||
164 | |||
165 | /** | ||
166 | * ID of a tunnel controlled by this client. | ||
167 | */ | ||
168 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | ||
169 | |||
170 | /** | ||
171 | * Peer at the other end. | ||
172 | */ | ||
173 | struct GNUNET_PeerIdentity peer; | ||
174 | |||
175 | /** | ||
176 | * Tunnel options (speed, buffering) | ||
177 | */ | ||
178 | uint32_t opt; | ||
179 | }; | ||
180 | |||
181 | |||
182 | /** | ||
183 | * Message to allow the client send more data to the service | ||
184 | * (always service -> client). | ||
185 | */ | ||
186 | struct GNUNET_MESH_LocalAck | ||
187 | { | ||
188 | /** | ||
189 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK | ||
190 | */ | ||
191 | struct GNUNET_MessageHeader header; | ||
192 | |||
193 | /** | ||
194 | * ID of the tunnel allowed to send more data. | ||
195 | */ | ||
196 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | ||
197 | |||
198 | /** | ||
199 | * ID of the last packet allowed. | ||
200 | */ | ||
201 | uint32_t max_pid GNUNET_PACKED; | ||
202 | }; | ||
203 | |||
204 | |||
205 | /** | ||
206 | * Message to inform the client about tunnels in the service. | ||
207 | */ | ||
208 | struct GNUNET_MESH_LocalMonitor | ||
209 | { | ||
210 | /** | ||
211 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL] | ||
212 | */ | ||
213 | struct GNUNET_MessageHeader header; | ||
214 | |||
215 | /** | ||
216 | * ID of the tunnel allowed to send more data. | ||
217 | */ | ||
218 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | ||
219 | |||
220 | /** | ||
221 | * Number of peers in the tunnel. | ||
222 | */ | ||
223 | uint32_t npeers GNUNET_PACKED; | ||
224 | |||
225 | /** | ||
226 | * Alignment. | ||
227 | */ | ||
228 | uint32_t reserved GNUNET_PACKED; | ||
229 | |||
230 | /** | ||
231 | * ID of the owner of the tunnel (can be local peer). | ||
232 | */ | ||
233 | struct GNUNET_PeerIdentity owner; | ||
234 | |||
235 | /* struct GNUNET_PeerIdentity peers[npeers] */ | ||
236 | }; | ||
237 | |||
238 | |||
239 | GNUNET_NETWORK_STRUCT_END | ||
240 | |||
241 | /******************************************************************************/ | ||
242 | /************************ ENUMERATIONS ****************************/ | ||
243 | /******************************************************************************/ | ||
244 | |||
245 | /** | ||
246 | * All the states a peer participating in a tunnel can be in. | ||
247 | */ | ||
248 | enum MeshPeerState | ||
249 | { | ||
250 | /** | ||
251 | * Uninitialized status, should never appear in operation. | ||
252 | */ | ||
253 | MESH_PEER_INVALID, | ||
254 | |||
255 | /** | ||
256 | * Peer is the root and owner of the tree | ||
257 | */ | ||
258 | MESH_PEER_ROOT, | ||
259 | |||
260 | /** | ||
261 | * Peer only retransmits traffic, is not a final destination | ||
262 | */ | ||
263 | MESH_PEER_RELAY, | ||
264 | |||
265 | /** | ||
266 | * Path to the peer not known yet | ||
267 | */ | ||
268 | MESH_PEER_SEARCHING, | ||
269 | |||
270 | /** | ||
271 | * Request sent, not yet answered. | ||
272 | */ | ||
273 | MESH_PEER_WAITING, | ||
274 | |||
275 | /** | ||
276 | * Peer connected and ready to accept data | ||
277 | */ | ||
278 | MESH_PEER_READY, | ||
279 | |||
280 | /** | ||
281 | * Peer connected previosly but not responding | ||
282 | */ | ||
283 | MESH_PEER_RECONNECTING | ||
284 | }; | ||
285 | |||
286 | |||
287 | /** | ||
288 | * Check if one pid is bigger than other, accounting for overflow. | ||
289 | * | ||
290 | * @param bigger Argument that should be bigger. | ||
291 | * @param smaller Argument that should be smaller. | ||
292 | * | ||
293 | * @return True if bigger (arg1) has a higher value than smaller (arg 2). | ||
294 | */ | ||
295 | int | ||
296 | GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller); | ||
297 | |||
298 | |||
299 | /** | ||
300 | * Get the higher ACK value out of two values, taking in account overflow. | ||
301 | * | ||
302 | * @param a First ACK value. | ||
303 | * @param b Second ACK value. | ||
304 | * | ||
305 | * @return Highest ACK value from the two. | ||
306 | */ | ||
307 | uint32_t | ||
308 | GMC_max_pid (uint32_t a, uint32_t b); | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Get the lower ACK value out of two values, taking in account overflow. | ||
313 | * | ||
314 | * @param a First ACK value. | ||
315 | * @param b Second ACK value. | ||
316 | * | ||
317 | * @return Lowest ACK value from the two. | ||
318 | */ | ||
319 | uint32_t | ||
320 | GMC_min_pid (uint32_t a, uint32_t b); | ||
321 | |||
322 | |||
323 | /** | ||
324 | * Convert a message type into a string to help debug | ||
325 | * Generated with: | ||
326 | * FIND: "#define ([^ ]+)[ ]*([0-9]+)" | ||
327 | * REPLACE: " case \2: return "\1"; break;" | ||
328 | * | ||
329 | * @param m Message type. | ||
330 | * | ||
331 | * @return Human readable string description. | ||
332 | */ | ||
333 | const char * | ||
334 | GNUNET_MESH_DEBUG_M2S (uint16_t m); | ||
335 | |||
336 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
337 | { | ||
338 | #endif | ||
339 | #ifdef __cplusplus | ||
340 | } | ||
341 | #endif | ||
342 | |||
343 | #endif | ||
diff --git a/src/mesh/mesh2_api.c b/src/mesh/mesh2_api.c index 35b408552..98359dff6 100644 --- a/src/mesh/mesh2_api.c +++ b/src/mesh/mesh2_api.c | |||
@@ -36,8 +36,8 @@ | |||
36 | #include "gnunet_util_lib.h" | 36 | #include "gnunet_util_lib.h" |
37 | #include "gnunet_peer_lib.h" | 37 | #include "gnunet_peer_lib.h" |
38 | #include "gnunet_mesh2_service.h" | 38 | #include "gnunet_mesh2_service.h" |
39 | #include "mesh.h" | 39 | #include "mesh2.h" |
40 | #include "mesh_protocol.h" | 40 | #include "mesh2_protocol.h" |
41 | 41 | ||
42 | #define LOG(kind,...) GNUNET_log_from (kind, "mesh2-api",__VA_ARGS__) | 42 | #define LOG(kind,...) GNUNET_log_from (kind, "mesh2-api",__VA_ARGS__) |
43 | 43 | ||
@@ -168,11 +168,6 @@ struct GNUNET_MESH_Handle | |||
168 | unsigned int n_handlers; | 168 | unsigned int n_handlers; |
169 | 169 | ||
170 | /** | 170 | /** |
171 | * Number of applications in the applications array. | ||
172 | */ | ||
173 | unsigned int n_applications; | ||
174 | |||
175 | /** | ||
176 | * Have we started the task to receive messages from the service | 171 | * Have we started the task to receive messages from the service |
177 | * yet? We do this after we send the 'MESH_LOCAL_CONNECT' message. | 172 | * yet? We do this after we send the 'MESH_LOCAL_CONNECT' message. |
178 | */ | 173 | */ |
@@ -280,24 +275,9 @@ struct GNUNET_MESH_Tunnel | |||
280 | MESH_TunnelNumber tid; | 275 | MESH_TunnelNumber tid; |
281 | 276 | ||
282 | /** | 277 | /** |
283 | * Owner of the tunnel. (1 if the tunnel is a local client). | 278 | * Other end of the tunnel. |
284 | */ | ||
285 | GNUNET_PEER_Id owner; | ||
286 | |||
287 | /** | ||
288 | * Destination of the tunnel. | ||
289 | */ | ||
290 | GNUNET_PEER_Id destination; | ||
291 | |||
292 | /** | ||
293 | * Next hop for the tunnel. | ||
294 | */ | ||
295 | GNUNET_PEER_Id next_hop; | ||
296 | |||
297 | /** | ||
298 | * Previous hop for the tunnel. | ||
299 | */ | 279 | */ |
300 | GNUNET_PEER_Id prev_hop; | 280 | GNUNET_PEER_Id peer; |
301 | 281 | ||
302 | /** | 282 | /** |
303 | * Any data the caller wants to put in here | 283 | * Any data the caller wants to put in here |
@@ -310,16 +290,6 @@ struct GNUNET_MESH_Tunnel | |||
310 | unsigned int packet_size; | 290 | unsigned int packet_size; |
311 | 291 | ||
312 | /** | 292 | /** |
313 | * Number of applications requested this tunnel | ||
314 | */ | ||
315 | unsigned int napps; | ||
316 | |||
317 | /** | ||
318 | * Is the tunnel throttled to the slowest peer? | ||
319 | */ | ||
320 | int speed_min; | ||
321 | |||
322 | /** | ||
323 | * Is the tunnel allowed to buffer? | 293 | * Is the tunnel allowed to buffer? |
324 | */ | 294 | */ |
325 | int buffering; | 295 | int buffering; |
@@ -489,10 +459,8 @@ static void | |||
489 | destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) | 459 | destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) |
490 | { | 460 | { |
491 | struct GNUNET_MESH_Handle *h; | 461 | struct GNUNET_MESH_Handle *h; |
492 | struct GNUNET_PeerIdentity pi; | ||
493 | struct GNUNET_MESH_TransmitHandle *th; | 462 | struct GNUNET_MESH_TransmitHandle *th; |
494 | struct GNUNET_MESH_TransmitHandle *next; | 463 | struct GNUNET_MESH_TransmitHandle *next; |
495 | unsigned int i; | ||
496 | 464 | ||
497 | LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_tunnel %X\n", t->tid); | 465 | LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_tunnel %X\n", t->tid); |
498 | 466 | ||
@@ -505,13 +473,10 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) | |||
505 | 473 | ||
506 | /* free all peer's ID */ | 474 | /* free all peer's ID */ |
507 | GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); | 475 | GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); |
508 | GNUNET_PEER_change_rc (t->owner, -1); | 476 | GNUNET_PEER_change_rc (t->peer, -1); |
509 | GNUNET_PEER_change_rc (t->destination, -1); | ||
510 | GNUNET_PEER_change_rc (t->next_hop, -1); | ||
511 | GNUNET_PEER_change_rc (t->prev_hop, -1); | ||
512 | 477 | ||
513 | /* signal tunnel destruction */ | 478 | /* signal tunnel destruction */ |
514 | if ( (NULL != h->cleaner) && (0 != t->owner) && (GNUNET_YES == call_cleaner) ) | 479 | if ( (NULL != h->cleaner) && (0 != t->peer) && (GNUNET_YES == call_cleaner) ) |
515 | h->cleaner (h->cls, t, t->ctx); | 480 | h->cleaner (h->cls, t, t->ctx); |
516 | 481 | ||
517 | /* check that clients did not leave messages behind in the queue */ | 482 | /* check that clients did not leave messages behind in the queue */ |
@@ -539,89 +504,14 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) | |||
539 | h->th = NULL; | 504 | h->th = NULL; |
540 | } | 505 | } |
541 | 506 | ||
542 | 507 | if (0 != t->peer) | |
543 | if (t->npeers > 0) | 508 | GNUNET_PEER_change_rc (t->peer, -1); |
544 | GNUNET_free (t->peers); | ||
545 | if (0 != t->owner) | ||
546 | GNUNET_PEER_change_rc (t->owner, -1); | ||
547 | if (0 != t->napps && t->apps) | ||
548 | GNUNET_free (t->apps); | ||
549 | GNUNET_free (t); | 509 | GNUNET_free (t); |
550 | return; | 510 | return; |
551 | } | 511 | } |
552 | 512 | ||
553 | 513 | ||
554 | /** | 514 | /** |
555 | * Get the peer descriptor for the peer with id from the given tunnel | ||
556 | * @param t Tunnel handle | ||
557 | * @param id Short form ID of the wanted peer | ||
558 | * @return handle to the requested peer or NULL if not found | ||
559 | */ | ||
560 | static struct GNUNET_MESH_Peer * | ||
561 | retrieve_peer (struct GNUNET_MESH_Tunnel *t, GNUNET_PEER_Id id) | ||
562 | { | ||
563 | unsigned int i; | ||
564 | |||
565 | for (i = 0; i < t->npeers; i++) | ||
566 | if (t->peers[i]->id == id) | ||
567 | return t->peers[i]; | ||
568 | return NULL; | ||
569 | } | ||
570 | |||
571 | |||
572 | /** | ||
573 | * Add a peer into a tunnel | ||
574 | * @param t Tunnel handle | ||
575 | * @param pi Full ID of the new peer | ||
576 | * @return handle to the newly created peer | ||
577 | */ | ||
578 | static struct GNUNET_MESH_Peer * | ||
579 | add_peer_to_tunnel (struct GNUNET_MESH_Tunnel *t, | ||
580 | const struct GNUNET_PeerIdentity *pi) | ||
581 | { | ||
582 | struct GNUNET_MESH_Peer *p; | ||
583 | GNUNET_PEER_Id id; | ||
584 | |||
585 | if (0 != t->owner) | ||
586 | { | ||
587 | GNUNET_break (0); | ||
588 | return NULL; | ||
589 | } | ||
590 | id = GNUNET_PEER_intern (pi); | ||
591 | |||
592 | p = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer)); | ||
593 | p->id = id; | ||
594 | p->t = t; | ||
595 | GNUNET_array_append (t->peers, t->npeers, p); | ||
596 | return p; | ||
597 | } | ||
598 | |||
599 | |||
600 | /** | ||
601 | * Remove a peer from a tunnel | ||
602 | * @param p Peer handle | ||
603 | */ | ||
604 | static void | ||
605 | remove_peer_from_tunnel (struct GNUNET_MESH_Peer *p) | ||
606 | { | ||
607 | unsigned int i; | ||
608 | |||
609 | for (i = 0; i < p->t->npeers; i++) | ||
610 | { | ||
611 | if (p->t->peers[i] == p) | ||
612 | break; | ||
613 | } | ||
614 | if (i == p->t->npeers) | ||
615 | { | ||
616 | GNUNET_break (0); | ||
617 | return; | ||
618 | } | ||
619 | p->t->peers[i] = p->t->peers[p->t->npeers - 1]; | ||
620 | GNUNET_array_grow (p->t->peers, p->t->npeers, p->t->npeers - 1); | ||
621 | } | ||
622 | |||
623 | |||
624 | /** | ||
625 | * Notify client that the transmission has timed out | 515 | * Notify client that the transmission has timed out |
626 | * | 516 | * |
627 | * @param cls closure | 517 | * @param cls closure |
@@ -752,7 +642,6 @@ send_connect (struct GNUNET_MESH_Handle *h) | |||
752 | { | 642 | { |
753 | char buf[size] GNUNET_ALIGN; | 643 | char buf[size] GNUNET_ALIGN; |
754 | struct GNUNET_MESH_ClientConnect *msg; | 644 | struct GNUNET_MESH_ClientConnect *msg; |
755 | uint16_t napps; | ||
756 | uint16_t *types; | 645 | uint16_t *types; |
757 | uint16_t ntypes; | 646 | uint16_t ntypes; |
758 | 647 | ||
@@ -760,18 +649,17 @@ send_connect (struct GNUNET_MESH_Handle *h) | |||
760 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | 649 | msg = (struct GNUNET_MESH_ClientConnect *) buf; |
761 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | 650 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); |
762 | msg->header.size = htons (size); | 651 | msg->header.size = htons (size); |
763 | types = (uint16_t *) & apps[napps]; | 652 | types = (uint16_t *) & msg[1]; |
764 | for (ntypes = 0; ntypes < h->n_handlers; ntypes++) | 653 | for (ntypes = 0; ntypes < h->n_handlers; ntypes++) |
765 | { | 654 | { |
766 | types[ntypes] = htons (h->message_handlers[ntypes].type); | 655 | types[ntypes] = htons (h->message_handlers[ntypes].type); |
767 | LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n", | 656 | LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n", |
768 | h->message_handlers[ntypes].type); | 657 | h->message_handlers[ntypes].type); |
769 | } | 658 | } |
770 | msg->applications = htons (napps); | ||
771 | msg->types = htons (ntypes); | 659 | msg->types = htons (ntypes); |
772 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 660 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
773 | "Sending %lu bytes long message %d types and %d apps\n", | 661 | "Sending %lu bytes long message %d types\n", |
774 | ntohs (msg->header.size), ntypes, napps); | 662 | ntohs (msg->header.size), ntypes); |
775 | send_packet (h, &msg->header, NULL); | 663 | send_packet (h, &msg->header, NULL); |
776 | } | 664 | } |
777 | } | 665 | } |
@@ -789,7 +677,6 @@ static int | |||
789 | do_reconnect (struct GNUNET_MESH_Handle *h) | 677 | do_reconnect (struct GNUNET_MESH_Handle *h) |
790 | { | 678 | { |
791 | struct GNUNET_MESH_Tunnel *t; | 679 | struct GNUNET_MESH_Tunnel *t; |
792 | unsigned int i; | ||
793 | 680 | ||
794 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); | 681 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); |
795 | LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n"); | 682 | LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n"); |
@@ -834,7 +721,6 @@ do_reconnect (struct GNUNET_MESH_Handle *h) | |||
834 | for (t = h->tunnels_head; NULL != t; t = t->next) | 721 | for (t = h->tunnels_head; NULL != t; t = t->next) |
835 | { | 722 | { |
836 | struct GNUNET_MESH_TunnelMessage tmsg; | 723 | struct GNUNET_MESH_TunnelMessage tmsg; |
837 | struct GNUNET_MESH_PeerControl pmsg; | ||
838 | 724 | ||
839 | if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | 725 | if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) |
840 | { | 726 | { |
@@ -850,36 +736,11 @@ do_reconnect (struct GNUNET_MESH_Handle *h) | |||
850 | tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); | 736 | tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); |
851 | tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 737 | tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
852 | tmsg.tunnel_id = htonl (t->tid); | 738 | tmsg.tunnel_id = htonl (t->tid); |
739 | GNUNET_PEER_resolve (t->peer, &tmsg.peer); | ||
853 | send_packet (h, &tmsg.header, t); | 740 | send_packet (h, &tmsg.header, t); |
854 | 741 | ||
855 | pmsg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); | ||
856 | pmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); | ||
857 | pmsg.tunnel_id = htonl (t->tid); | ||
858 | |||
859 | /* Reconnect all peers */ | ||
860 | /* If the tunnel was "by type", dont connect individual peers */ | ||
861 | for (i = 0; i < t->npeers && 0 == t->napps; i++) | ||
862 | { | ||
863 | GNUNET_PEER_resolve (t->peers[i]->id, &pmsg.peer); | ||
864 | if (NULL != t->disconnect_handler && t->peers[i]->connected) | ||
865 | t->disconnect_handler (t->cls, &pmsg.peer); | ||
866 | send_packet (t->mesh, &pmsg.header, t); | ||
867 | } | ||
868 | /* Reconnect all types, if any */ | ||
869 | for (i = 0; i < t->napps; i++) | ||
870 | { | ||
871 | struct GNUNET_MESH_ConnectPeerByType msg; | ||
872 | |||
873 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType)); | ||
874 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE); | ||
875 | msg.tunnel_id = htonl (t->tid); | ||
876 | msg.type = htonl (t->apps[i]); | ||
877 | send_packet (t->mesh, &msg.header, t); | ||
878 | } | ||
879 | if (GNUNET_NO == t->buffering) | 742 | if (GNUNET_NO == t->buffering) |
880 | GNUNET_MESH_tunnel_buffer (t, GNUNET_NO); | 743 | GNUNET_MESH_tunnel_buffer (t, GNUNET_NO); |
881 | if (GNUNET_YES == t->speed_min) | ||
882 | GNUNET_MESH_tunnel_speed_min (t); | ||
883 | } | 744 | } |
884 | return GNUNET_YES; | 745 | return GNUNET_YES; |
885 | } | 746 | } |
@@ -947,29 +808,17 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h, | |||
947 | } | 808 | } |
948 | if (NULL != h->new_tunnel) | 809 | if (NULL != h->new_tunnel) |
949 | { | 810 | { |
950 | struct GNUNET_ATS_Information atsi; | ||
951 | |||
952 | t = create_tunnel (h, tid); | 811 | t = create_tunnel (h, tid); |
953 | t->owner = GNUNET_PEER_intern (&msg->peer); | 812 | t->peer = GNUNET_PEER_intern (&msg->peer); |
954 | t->npeers = 1; | 813 | GNUNET_PEER_change_rc (t->peer, 1); |
955 | t->peers = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer *)); | ||
956 | t->peers[0] = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer)); | ||
957 | t->peers[0]->t = t; | ||
958 | t->peers[0]->connected = 1; | ||
959 | t->peers[0]->id = t->owner; | ||
960 | GNUNET_PEER_change_rc (t->owner, 1); | ||
961 | t->mesh = h; | 814 | t->mesh = h; |
962 | t->tid = tid; | 815 | t->tid = tid; |
963 | if ((msg->opt & MESH_TUNNEL_OPT_NOBUFFER) != 0) | 816 | if ((msg->opt & MESH_TUNNEL_OPT_NOBUFFER) != 0) |
964 | t->buffering = GNUNET_NO; | 817 | t->buffering = GNUNET_NO; |
965 | else | 818 | else |
966 | t->buffering = GNUNET_YES; | 819 | t->buffering = GNUNET_YES; |
967 | if ((msg->opt & MESH_TUNNEL_OPT_SPEED_MIN) != 0) | ||
968 | t->speed_min = GNUNET_YES; | ||
969 | atsi.type = 0; | ||
970 | atsi.value = 0; | ||
971 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); | 820 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); |
972 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi); | 821 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer); |
973 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); | 822 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); |
974 | } | 823 | } |
975 | else | 824 | else |
@@ -1008,10 +857,6 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h, | |||
1008 | { | 857 | { |
1009 | return; | 858 | return; |
1010 | } | 859 | } |
1011 | if (0 == t->owner) | ||
1012 | { | ||
1013 | GNUNET_break (0); | ||
1014 | } | ||
1015 | LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X destroyed\n", t->tid); | 860 | LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X destroyed\n", t->tid); |
1016 | destroy_tunnel (t, GNUNET_YES); | 861 | destroy_tunnel (t, GNUNET_YES); |
1017 | return; | 862 | return; |
@@ -1019,63 +864,6 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h, | |||
1019 | 864 | ||
1020 | 865 | ||
1021 | /** | 866 | /** |
1022 | * Process the new peer event and notify the upper level of it | ||
1023 | * | ||
1024 | * @param h The mesh handle | ||
1025 | * @param msg A message with the details of the peer event | ||
1026 | */ | ||
1027 | static void | ||
1028 | process_peer_event (struct GNUNET_MESH_Handle *h, | ||
1029 | const struct GNUNET_MESH_PeerControl *msg) | ||
1030 | { | ||
1031 | struct GNUNET_MESH_Tunnel *t; | ||
1032 | struct GNUNET_MESH_Peer *p; | ||
1033 | struct GNUNET_ATS_Information atsi; | ||
1034 | GNUNET_PEER_Id id; | ||
1035 | uint16_t size; | ||
1036 | |||
1037 | LOG (GNUNET_ERROR_TYPE_DEBUG, "processig peer event\n"); | ||
1038 | size = ntohs (msg->header.size); | ||
1039 | if (size != sizeof (struct GNUNET_MESH_PeerControl)) | ||
1040 | { | ||
1041 | GNUNET_break (0); | ||
1042 | return; | ||
1043 | } | ||
1044 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); | ||
1045 | if (NULL == t) | ||
1046 | { | ||
1047 | GNUNET_break (0); | ||
1048 | return; | ||
1049 | } | ||
1050 | id = GNUNET_PEER_search (&msg->peer); | ||
1051 | if ((p = retrieve_peer (t, id)) == NULL) | ||
1052 | p = add_peer_to_tunnel (t, &msg->peer); | ||
1053 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == ntohs (msg->header.type)) | ||
1054 | { | ||
1055 | LOG (GNUNET_ERROR_TYPE_DEBUG, "adding peer\n"); | ||
1056 | if (NULL != t->connect_handler) | ||
1057 | { | ||
1058 | atsi.type = 0; | ||
1059 | atsi.value = 0; | ||
1060 | t->connect_handler (t->cls, &msg->peer, &atsi); | ||
1061 | } | ||
1062 | p->connected = 1; | ||
1063 | } | ||
1064 | else | ||
1065 | { | ||
1066 | LOG (GNUNET_ERROR_TYPE_DEBUG, "removing peer\n"); | ||
1067 | if (NULL != t->disconnect_handler && p->connected) | ||
1068 | { | ||
1069 | t->disconnect_handler (t->cls, &msg->peer); | ||
1070 | } | ||
1071 | remove_peer_from_tunnel (p); | ||
1072 | GNUNET_free (p); | ||
1073 | } | ||
1074 | LOG (GNUNET_ERROR_TYPE_DEBUG, "processing peer event END\n"); | ||
1075 | } | ||
1076 | |||
1077 | |||
1078 | /** | ||
1079 | * Process the incoming data packets | 867 | * Process the incoming data packets |
1080 | * | 868 | * |
1081 | * @param h The mesh handle | 869 | * @param h The mesh handle |
@@ -1160,12 +948,8 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, | |||
1160 | handler = &h->message_handlers[i]; | 948 | handler = &h->message_handlers[i]; |
1161 | if (handler->type == type) | 949 | if (handler->type == type) |
1162 | { | 950 | { |
1163 | struct GNUNET_ATS_Information atsi; | ||
1164 | |||
1165 | atsi.type = 0; | ||
1166 | atsi.value = 0; | ||
1167 | if (GNUNET_OK != | 951 | if (GNUNET_OK != |
1168 | handler->callback (h->cls, t, &t->ctx, peer, payload, &atsi)) | 952 | handler->callback (h->cls, t, &t->ctx, peer, payload)) |
1169 | { | 953 | { |
1170 | LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n"); | 954 | LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n"); |
1171 | GNUNET_MESH_disconnect (h); | 955 | GNUNET_MESH_disconnect (h); |
@@ -1264,10 +1048,9 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h, | |||
1264 | return; | 1048 | return; |
1265 | } | 1049 | } |
1266 | h->tunnels_cb (h->tunnels_cls, | 1050 | h->tunnels_cb (h->tunnels_cls, |
1267 | &msg->owner, | ||
1268 | ntohl (msg->tunnel_id), | 1051 | ntohl (msg->tunnel_id), |
1269 | (struct GNUNET_PeerIdentity *) &msg[1], | 1052 | &msg->owner, |
1270 | npeers); | 1053 | (struct GNUNET_PeerIdentity *) &msg[1]); |
1271 | } | 1054 | } |
1272 | 1055 | ||
1273 | 1056 | ||
@@ -1368,11 +1151,6 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1368 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: | 1151 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: |
1369 | process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg); | 1152 | process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg); |
1370 | break; | 1153 | break; |
1371 | /* Notify of a new peer or a peer disconnect in the tunnel */ | ||
1372 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD: | ||
1373 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL: | ||
1374 | process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg); | ||
1375 | break; | ||
1376 | /* Notify of a new data packet in the tunnel */ | 1154 | /* Notify of a new data packet in the tunnel */ |
1377 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 1155 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: |
1378 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | 1156 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: |
@@ -1506,8 +1284,6 @@ send_callback (void *cls, size_t size, void *buf) | |||
1506 | uc.pid = htonl (t->next_send_pid); | 1284 | uc.pid = htonl (t->next_send_pid); |
1507 | uc.ttl = 0; | 1285 | uc.ttl = 0; |
1508 | memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); | 1286 | memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); |
1509 | GNUNET_PEER_resolve (th->target, &uc.destination); | ||
1510 | memcpy (cbuf, &uc, sizeof (uc)); | ||
1511 | } | 1287 | } |
1512 | } | 1288 | } |
1513 | t->next_send_pid++; | 1289 | t->next_send_pid++; |
@@ -1602,33 +1378,13 @@ send_packet (struct GNUNET_MESH_Handle *h, | |||
1602 | /********************** API CALL DEFINITIONS *************************/ | 1378 | /********************** API CALL DEFINITIONS *************************/ |
1603 | /******************************************************************************/ | 1379 | /******************************************************************************/ |
1604 | 1380 | ||
1605 | /** | ||
1606 | * Connect to the mesh service. | ||
1607 | * | ||
1608 | * @param cfg configuration to use | ||
1609 | * @param cls closure for the various callbacks that follow | ||
1610 | * (including handlers in the handlers array) | ||
1611 | * @param new_tunnel function called when an *inbound* tunnel is created | ||
1612 | * @param cleaner function called when an *inbound* tunnel is destroyed by the | ||
1613 | * remote peer, it is *not* called if GNUNET_MESH_tunnel_destroy | ||
1614 | * is called on the tunnel | ||
1615 | * @param handlers callbacks for messages we care about, NULL-terminated | ||
1616 | * note that the mesh is allowed to drop notifications about | ||
1617 | * inbound messages if the client does not process them fast | ||
1618 | * enough (for this notification type, a bounded queue is used) | ||
1619 | * @param stypes list of the applications that this client claims to provide | ||
1620 | * @return handle to the mesh service NULL on error | ||
1621 | * (in this case, init is never called) | ||
1622 | */ | ||
1623 | struct GNUNET_MESH_Handle * | 1381 | struct GNUNET_MESH_Handle * |
1624 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | 1382 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, |
1625 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, | 1383 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, |
1626 | GNUNET_MESH_TunnelEndHandler cleaner, | 1384 | GNUNET_MESH_TunnelEndHandler cleaner, |
1627 | const struct GNUNET_MESH_MessageHandler *handlers, | 1385 | const struct GNUNET_MESH_MessageHandler *handlers) |
1628 | const GNUNET_MESH_ApplicationType *stypes) | ||
1629 | { | 1386 | { |
1630 | struct GNUNET_MESH_Handle *h; | 1387 | struct GNUNET_MESH_Handle *h; |
1631 | size_t size; | ||
1632 | 1388 | ||
1633 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n"); | 1389 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n"); |
1634 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); | 1390 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); |
@@ -1649,16 +1405,6 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
1649 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | 1405 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; |
1650 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1406 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
1651 | 1407 | ||
1652 | /* count apps */ | ||
1653 | for (h->n_applications = 0; | ||
1654 | stypes && stypes[h->n_applications]; | ||
1655 | h->n_applications++) ; | ||
1656 | if (0 < h->n_applications) | ||
1657 | { | ||
1658 | size = h->n_applications * sizeof (GNUNET_MESH_ApplicationType *); | ||
1659 | h->applications = GNUNET_malloc (size); | ||
1660 | memcpy (h->applications, stypes, size); | ||
1661 | } | ||
1662 | /* count handlers */ | 1408 | /* count handlers */ |
1663 | for (h->n_handlers = 0; | 1409 | for (h->n_handlers = 0; |
1664 | handlers && handlers[h->n_handlers].type; | 1410 | handlers && handlers[h->n_handlers].type; |
@@ -1748,56 +1494,6 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1748 | } | 1494 | } |
1749 | 1495 | ||
1750 | 1496 | ||
1751 | /** | ||
1752 | * Announce to ther peer the availability of services described by the regex, | ||
1753 | * in order to be reachable to other peers via connect_by_string. | ||
1754 | * | ||
1755 | * Note that the first 8 characters are considered to be part of a prefix, | ||
1756 | * (for instance 'gnunet://'). If you put a variable part in there (*, +. ()), | ||
1757 | * all matching strings will be stored in the DHT. | ||
1758 | * | ||
1759 | * @param h Handle to mesh. | ||
1760 | * @param regex String with the regular expression describing local services. | ||
1761 | * @param compression_characters How many characters can be assigned to one | ||
1762 | * edge of the graph. The bigger the variability | ||
1763 | * of the data, the smaller this parameter should | ||
1764 | * be (down to 1). | ||
1765 | * For maximum compression, use strlen (regex) | ||
1766 | * or 0 (special value). Use with care! | ||
1767 | */ | ||
1768 | void | ||
1769 | GNUNET_MESH_announce_regex (struct GNUNET_MESH_Handle *h, | ||
1770 | const char *regex, | ||
1771 | unsigned int compression_characters) | ||
1772 | { | ||
1773 | struct GNUNET_MESH_RegexAnnounce *msg; | ||
1774 | size_t payload; | ||
1775 | size_t len; | ||
1776 | size_t msgsize; | ||
1777 | size_t offset; | ||
1778 | char buffer[UINT16_MAX]; | ||
1779 | |||
1780 | len = strlen (regex); | ||
1781 | payload = UINT16_MAX - sizeof(struct GNUNET_MESH_RegexAnnounce); | ||
1782 | msg = (struct GNUNET_MESH_RegexAnnounce *) buffer; | ||
1783 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX); | ||
1784 | msg->compression_characters = htons (compression_characters); | ||
1785 | offset = 0; | ||
1786 | do | ||
1787 | { | ||
1788 | msgsize = (len - offset > payload) ? payload : len - offset; | ||
1789 | memcpy (&msg[1], ®ex[offset], msgsize); | ||
1790 | offset += msgsize; | ||
1791 | msgsize += sizeof(struct GNUNET_MESH_RegexAnnounce); | ||
1792 | |||
1793 | msg->header.size = htons (msgsize); | ||
1794 | msg->last = htons (offset >= len); | ||
1795 | |||
1796 | send_packet (h, &msg->header, NULL); | ||
1797 | } while (len > offset); | ||
1798 | } | ||
1799 | |||
1800 | |||
1801 | struct GNUNET_MESH_Tunnel * | 1497 | struct GNUNET_MESH_Tunnel * |
1802 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | 1498 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, |
1803 | void *tunnel_ctx, | 1499 | void *tunnel_ctx, |
diff --git a/src/mesh/mesh2_protocol.h b/src/mesh/mesh2_protocol.h new file mode 100644 index 000000000..01f7f3487 --- /dev/null +++ b/src/mesh/mesh2_protocol.h | |||
@@ -0,0 +1,376 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001 - 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 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh_protocol.h | ||
24 | */ | ||
25 | |||
26 | #ifndef MESH_PROTOCOL_H_ | ||
27 | #define MESH_PROTOCOL_H_ | ||
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" | ||
31 | { | ||
32 | #if 0 | ||
33 | /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #define MESH_TUNNEL_OPT_SPEED_MIN 0x1 | ||
39 | #define MESH_TUNNEL_OPT_NOBUFFER 0x2 | ||
40 | |||
41 | |||
42 | /******************************************************************************/ | ||
43 | /******************** MESH NETWORK MESSAGES **************************/ | ||
44 | /******************************************************************************/ | ||
45 | |||
46 | GNUNET_NETWORK_STRUCT_BEGIN | ||
47 | |||
48 | /** | ||
49 | * Message for mesh path management | ||
50 | */ | ||
51 | struct GNUNET_MESH_ManipulatePath | ||
52 | { | ||
53 | /** | ||
54 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DESTROY] | ||
55 | * | ||
56 | * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + | ||
57 | * path_length * sizeof (struct GNUNET_PeerIdentity) | ||
58 | */ | ||
59 | struct GNUNET_MessageHeader header; | ||
60 | |||
61 | /** | ||
62 | * Global id of the tunnel this path belongs to, | ||
63 | * unique in conjunction with the origin. | ||
64 | */ | ||
65 | uint32_t tid GNUNET_PACKED; | ||
66 | |||
67 | /** | ||
68 | * Tunnel options (MESH_TUNNEL_OPT_*). | ||
69 | */ | ||
70 | uint32_t opt GNUNET_PACKED; | ||
71 | |||
72 | /** | ||
73 | * 64 bit alignment padding. | ||
74 | */ | ||
75 | uint32_t reserved GNUNET_PACKED; | ||
76 | |||
77 | /** | ||
78 | * path_length structs defining the *whole* path from the origin [0] to the | ||
79 | * final destination [path_length-1]. | ||
80 | */ | ||
81 | /* struct GNUNET_PeerIdentity peers[path_length]; */ | ||
82 | }; | ||
83 | |||
84 | /** | ||
85 | * Message for mesh data traffic to all tunnel targets. | ||
86 | */ | ||
87 | struct GNUNET_MESH_Multicast | ||
88 | { | ||
89 | /** | ||
90 | * Type: GNUNET_MESSAGE_TYPE_MESH_MULTICAST | ||
91 | */ | ||
92 | struct GNUNET_MessageHeader header; | ||
93 | |||
94 | /** | ||
95 | * TID of the tunnel | ||
96 | */ | ||
97 | uint32_t tid GNUNET_PACKED; | ||
98 | |||
99 | /** | ||
100 | * Number of hops to live | ||
101 | */ | ||
102 | uint32_t ttl GNUNET_PACKED; | ||
103 | |||
104 | /** | ||
105 | * Unique ID of the packet | ||
106 | */ | ||
107 | uint32_t pid GNUNET_PACKED; | ||
108 | |||
109 | /** | ||
110 | * OID of the tunnel | ||
111 | */ | ||
112 | struct GNUNET_PeerIdentity oid; | ||
113 | |||
114 | /** | ||
115 | * Payload follows | ||
116 | */ | ||
117 | }; | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Message for mesh data traffic to a particular destination from origin. | ||
122 | */ | ||
123 | struct GNUNET_MESH_Unicast | ||
124 | { | ||
125 | /** | ||
126 | * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST | ||
127 | */ | ||
128 | struct GNUNET_MessageHeader header; | ||
129 | |||
130 | /** | ||
131 | * TID of the tunnel | ||
132 | */ | ||
133 | uint32_t tid GNUNET_PACKED; | ||
134 | |||
135 | /** | ||
136 | * Number of hops to live | ||
137 | */ | ||
138 | uint32_t ttl GNUNET_PACKED; | ||
139 | |||
140 | /** | ||
141 | * Unique ID of the packet | ||
142 | */ | ||
143 | uint32_t pid GNUNET_PACKED; | ||
144 | |||
145 | /** | ||
146 | * OID of the tunnel | ||
147 | */ | ||
148 | struct GNUNET_PeerIdentity oid; | ||
149 | |||
150 | /** | ||
151 | * Destination. | ||
152 | */ | ||
153 | struct GNUNET_PeerIdentity destination; | ||
154 | |||
155 | /** | ||
156 | * Payload follows | ||
157 | */ | ||
158 | }; | ||
159 | |||
160 | |||
161 | /** | ||
162 | * Message for mesh data traffic from a tunnel participant to origin. | ||
163 | */ | ||
164 | struct GNUNET_MESH_ToOrigin | ||
165 | { | ||
166 | /** | ||
167 | * Type: GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN | ||
168 | */ | ||
169 | struct GNUNET_MessageHeader header; | ||
170 | |||
171 | /** | ||
172 | * TID of the tunnel | ||
173 | */ | ||
174 | uint32_t tid GNUNET_PACKED; | ||
175 | |||
176 | /** | ||
177 | * Number of hops to live | ||
178 | */ | ||
179 | uint32_t ttl GNUNET_PACKED; | ||
180 | |||
181 | /** | ||
182 | * Unique ID of the packet | ||
183 | */ | ||
184 | uint32_t pid GNUNET_PACKED; | ||
185 | |||
186 | /** | ||
187 | * OID of the tunnel | ||
188 | */ | ||
189 | struct GNUNET_PeerIdentity oid; | ||
190 | |||
191 | /** | ||
192 | * Sender of the message. | ||
193 | */ | ||
194 | struct GNUNET_PeerIdentity sender; | ||
195 | |||
196 | /** | ||
197 | * Payload follows | ||
198 | */ | ||
199 | }; | ||
200 | |||
201 | |||
202 | /** | ||
203 | * Message to acknowledge mesh data traffic. | ||
204 | */ | ||
205 | struct GNUNET_MESH_ACK | ||
206 | { | ||
207 | /** | ||
208 | * Type: GNUNET_MESSAGE_TYPE_MESH_ACK | ||
209 | */ | ||
210 | struct GNUNET_MessageHeader header; | ||
211 | |||
212 | /** | ||
213 | * TID of the tunnel | ||
214 | */ | ||
215 | uint32_t tid GNUNET_PACKED; | ||
216 | |||
217 | /** | ||
218 | * OID of the tunnel | ||
219 | */ | ||
220 | struct GNUNET_PeerIdentity oid; | ||
221 | |||
222 | /** | ||
223 | * Maximum packet ID authorized. | ||
224 | */ | ||
225 | uint32_t pid; | ||
226 | |||
227 | }; | ||
228 | |||
229 | /** | ||
230 | * Message to query a peer about its Flow Control status regarding a tunnel. | ||
231 | */ | ||
232 | struct GNUNET_MESH_Poll | ||
233 | { | ||
234 | /** | ||
235 | * Type: GNUNET_MESSAGE_TYPE_MESH_POLL | ||
236 | */ | ||
237 | struct GNUNET_MessageHeader header; | ||
238 | |||
239 | /** | ||
240 | * TID of the tunnel | ||
241 | */ | ||
242 | uint32_t tid GNUNET_PACKED; | ||
243 | |||
244 | /** | ||
245 | * OID of the tunnel | ||
246 | */ | ||
247 | struct GNUNET_PeerIdentity oid; | ||
248 | |||
249 | /** | ||
250 | * Last ACK received. | ||
251 | */ | ||
252 | uint32_t last_ack; | ||
253 | }; | ||
254 | |||
255 | /** | ||
256 | * Message for ack'ing a path | ||
257 | */ | ||
258 | struct GNUNET_MESH_PathACK | ||
259 | { | ||
260 | /** | ||
261 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_ACK | ||
262 | */ | ||
263 | struct GNUNET_MessageHeader header; | ||
264 | |||
265 | /** | ||
266 | * TID of the tunnel | ||
267 | */ | ||
268 | uint32_t tid GNUNET_PACKED; | ||
269 | |||
270 | /** | ||
271 | * OID of the tunnel | ||
272 | */ | ||
273 | struct GNUNET_PeerIdentity oid; | ||
274 | |||
275 | /** | ||
276 | * ID of the endpoint | ||
277 | */ | ||
278 | struct GNUNET_PeerIdentity peer_id; | ||
279 | |||
280 | /* TODO: signature */ | ||
281 | }; | ||
282 | |||
283 | |||
284 | /** | ||
285 | * Message for notifying a disconnection in a path | ||
286 | */ | ||
287 | struct GNUNET_MESH_PathBroken | ||
288 | { | ||
289 | /** | ||
290 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN | ||
291 | */ | ||
292 | struct GNUNET_MessageHeader header; | ||
293 | |||
294 | /** | ||
295 | * TID of the tunnel | ||
296 | */ | ||
297 | uint32_t tid GNUNET_PACKED; | ||
298 | |||
299 | /** | ||
300 | * OID of the tunnel | ||
301 | */ | ||
302 | struct GNUNET_PeerIdentity oid; | ||
303 | |||
304 | /** | ||
305 | * ID of the endpoint | ||
306 | */ | ||
307 | struct GNUNET_PeerIdentity peer1; | ||
308 | |||
309 | /** | ||
310 | * ID of the endpoint | ||
311 | */ | ||
312 | struct GNUNET_PeerIdentity peer2; | ||
313 | |||
314 | /* TODO: signature */ | ||
315 | }; | ||
316 | |||
317 | |||
318 | /** | ||
319 | * Message to destroy a tunnel | ||
320 | */ | ||
321 | struct GNUNET_MESH_TunnelDestroy | ||
322 | { | ||
323 | /** | ||
324 | * Type: GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY | ||
325 | */ | ||
326 | struct GNUNET_MessageHeader header; | ||
327 | |||
328 | /** | ||
329 | * TID of the tunnel | ||
330 | */ | ||
331 | uint32_t tid GNUNET_PACKED; | ||
332 | |||
333 | /** | ||
334 | * OID of the tunnel | ||
335 | */ | ||
336 | struct GNUNET_PeerIdentity oid; | ||
337 | |||
338 | /* TODO: signature */ | ||
339 | }; | ||
340 | |||
341 | |||
342 | /** | ||
343 | * Message to destroy a tunnel | ||
344 | */ | ||
345 | struct GNUNET_MESH_TunnelKeepAlive | ||
346 | { | ||
347 | /** | ||
348 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE | ||
349 | */ | ||
350 | struct GNUNET_MessageHeader header; | ||
351 | |||
352 | /** | ||
353 | * TID of the tunnel | ||
354 | */ | ||
355 | uint32_t tid GNUNET_PACKED; | ||
356 | |||
357 | /** | ||
358 | * OID of the tunnel | ||
359 | */ | ||
360 | struct GNUNET_PeerIdentity oid; | ||
361 | }; | ||
362 | |||
363 | |||
364 | |||
365 | GNUNET_NETWORK_STRUCT_END | ||
366 | |||
367 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
368 | { | ||
369 | #endif | ||
370 | #ifdef __cplusplus | ||
371 | } | ||
372 | #endif | ||
373 | |||
374 | /* ifndef MESH_PROTOCOL_H */ | ||
375 | #endif | ||
376 | /* end of mesh_protocol.h */ | ||