2 This file is part of GNUnet.
3 (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @author Bartlomiej Polot
32 #if 0 /* keep Emacsens' auto-indent happy */
39 #define MESH_DEBUG GNUNET_YES
41 #define INITIAL_WINDOW_SIZE 8
42 #define ACK_THRESHOLD INITIAL_WINDOW_SIZE / 2
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>
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
59 * API CALL (GNUNET_MESH_*) MESSAGE USED
60 * ------------------------ ------------
61 * connect GNUNET_MESH_ClientConnect
62 * disconnect None (network level disconnect)
64 * tunnel_create GNUNET_MESH_TunnelMessage
65 * tunnel_destroy GNUNET_MESH_TunnelMessage
66 * tunnel_speed_max GNUNET_MESH_TunnelMessage
67 * tunnel_speed_min GNUNET_MESH_TunnelMessage
68 * tunnel_buffer GNUNET_MESH_TunnelMessage
70 * peer_request_connect_add GNUNET_MESH_PeerControl
71 * peer_request_connect_del GNUNET_MESH_PeerControl
72 * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType
73 * peer_request_connect_by_string GNUNET_MESH_ConnectPeerByString
75 * peer_blacklist GNUNET_MESH_PeerControl
76 * peer_unblacklist GNUNET_MESH_PeerControl
78 * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy)
79 * notify_transmit_ready_cancel None (clear of internal data structures)
84 * data GNUNET_MESH_Unicast OR
85 * GNUNET_MESH_Multicast OR
86 * GNUNET_MESH_ToOrigin
87 * data ack GNUNET_MESH_LocalAck
89 * new incoming tunnel GNUNET_MESH_PeerControl
90 * peer connects to a tunnel GNUNET_MESH_PeerControl
91 * peer disconnects from a tunnel GNUNET_MESH_PeerControl
94 /******************************************************************************/
95 /************************** CONSTANTS ******************************/
96 /******************************************************************************/
98 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
99 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
101 #define HIGH_PID 0xFFFF0000
102 #define LOW_PID 0x0000FFFF
104 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
106 /******************************************************************************/
107 /************************** MESSAGES ******************************/
108 /******************************************************************************/
110 GNUNET_NETWORK_STRUCT_BEGIN
113 * Message for a client to register to the service
115 struct GNUNET_MESH_ClientConnect
118 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
120 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
121 * sizeof(MESH_ApplicationType) * applications +
122 * sizeof(uint16_t) * types
124 struct GNUNET_MessageHeader header;
125 uint16_t applications GNUNET_PACKED;
126 uint16_t types GNUNET_PACKED;
127 /* uint32_t list_apps[applications] */
128 /* uint16_t list_types[types] */
133 * Type for tunnel numbering.
134 * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
135 * - Local tunnel numbers given by the client (created) are >= 0x80000000
136 * - Global tunnel numbers are < 0x80000000
138 typedef uint32_t MESH_TunnelNumber;
141 * Message for a client to create and destroy tunnels.
143 struct GNUNET_MESH_TunnelMessage
146 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
147 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN]
149 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
151 struct GNUNET_MessageHeader header;
154 * ID of a tunnel controlled by this client.
156 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
161 * Message for the service to let a client know about created tunnels.
163 struct GNUNET_MESH_TunnelNotification
166 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE
168 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
170 struct GNUNET_MessageHeader header;
173 * ID of a tunnel controlled by this client.
175 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
178 * Peer at the other end, if any
180 struct GNUNET_PeerIdentity peer;
183 * Tunnel options (speed, buffering)
189 * Message for announce of regular expressions.
191 struct GNUNET_MESH_RegexAnnounce
194 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX
196 * Size: sizeof(struct GNUNET_MESH_RegexAnnounce) + strlen (regex)
198 struct GNUNET_MessageHeader header;
201 * How many characters do we want to put in an edge label.
203 uint16_t compression_characters;
206 * Is this the last message for this regex? (for regex > 65k)
216 * - request adding and deleting peers from a tunnel
217 * - notify the client that peers have connected:
219 * -- unrequested (new incoming tunnels)
220 * - notify the client that peers have disconnected
222 struct GNUNET_MESH_PeerControl
226 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL|[UN]BLACKLIST]
227 * (client to service, client created tunnel)
228 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
229 * (service to client)
231 * Size: sizeof(struct GNUNET_MESH_PeerControl)
233 struct GNUNET_MessageHeader header;
236 * ID of a tunnel controlled by this client.
238 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
241 * Peer to connect/disconnect.
243 struct GNUNET_PeerIdentity peer;
248 * Message for connecting to peers offering a service, by service number.
250 struct GNUNET_MESH_ConnectPeerByType
253 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
254 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
256 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByType)
258 struct GNUNET_MessageHeader header;
261 * ID of a tunnel controlled by this client.
263 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
268 GNUNET_MESH_ApplicationType type GNUNET_PACKED;
273 * Message for connecting to peers offering a service, by service string.
275 struct GNUNET_MESH_ConnectPeerByString
278 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING
280 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByString) + strlen (string)
282 struct GNUNET_MessageHeader header;
285 * ID of a tunnel controlled by this client.
287 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
289 /* String describing the service */
294 * Message to allow the client send more data to the service
295 * (always service -> client).
297 struct GNUNET_MESH_LocalAck
300 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
302 struct GNUNET_MessageHeader header;
305 * ID of the tunnel allowed to send more data.
307 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
310 * ID of the last packet allowed.
312 uint32_t max_pid GNUNET_PACKED;
317 * Message to inform the client about tunnels in the service.
319 struct GNUNET_MESH_LocalMonitor
322 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
324 struct GNUNET_MessageHeader header;
327 * ID of the tunnel allowed to send more data.
329 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
332 * Number of peers in the tunnel.
334 uint32_t npeers GNUNET_PACKED;
339 uint32_t reserved GNUNET_PACKED;
342 * ID of the owner of the tunnel (can be local peer).
344 struct GNUNET_PeerIdentity owner;
346 /* struct GNUNET_PeerIdentity peers[npeers] */
350 GNUNET_NETWORK_STRUCT_END
352 /******************************************************************************/
353 /************************ ENUMERATIONS ****************************/
354 /******************************************************************************/
357 * All the states a peer participating in a tunnel can be in.
362 * Uninitialized status, should never appear in operation.
367 * Peer is the root and owner of the tree
372 * Peer only retransmits traffic, is not a final destination
377 * Path to the peer not known yet
382 * Request sent, not yet answered.
387 * Peer connected and ready to accept data
392 * Peer connected previosly but not responding
394 MESH_PEER_RECONNECTING
399 * Check if one pid is bigger than other, accounting for overflow.
401 * @param bigger Argument that should be bigger.
402 * @param smaller Argument that should be smaller.
404 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
407 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
411 * Get the higher ACK value out of two values, taking in account overflow.
413 * @param a First ACK value.
414 * @param b Second ACK value.
416 * @return Highest ACK value from the two.
419 GMC_max_pid (uint32_t a, uint32_t b);
423 * Get the lower ACK value out of two values, taking in account overflow.
425 * @param a First ACK value.
426 * @param b Second ACK value.
428 * @return Lowest ACK value from the two.
431 GMC_min_pid (uint32_t a, uint32_t b);
435 * Convert a message type into a string to help debug
437 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
438 * REPLACE: " case \2: return "\1"; break;"
440 * @param m Message type.
442 * @return Human readable string description.
445 GNUNET_MESH_DEBUG_M2S (uint16_t m);
447 #if 0 /* keep Emacsens' auto-indent happy */