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
30 #define MESH_DEBUG GNUNET_YES
32 #define INITIAL_WINDOW_SIZE 8
33 #define ACK_THRESHOLD INITIAL_WINDOW_SIZE / 2
36 #include "gnunet_common.h"
37 #include "gnunet_util_lib.h"
38 #include "gnunet_peer_lib.h"
39 #include "gnunet_core_service.h"
40 #include "gnunet_protocols.h"
41 #include <gnunet_mesh_service.h>
43 /******************************************************************************/
44 /******************** MESH LOCAL MESSAGES *************************/
45 /******************************************************************************/
46 /* Any API call should be documented in the folowing table under API CALL.
47 * Also, any message type should be documented in the following table, with the
50 * API CALL (GNUNET_MESH_*) MESSAGE USED
51 * ------------------------ ------------
52 * connect GNUNET_MESH_ClientConnect
53 * disconnect None (network level disconnect)
55 * tunnel_create GNUNET_MESH_TunnelMessage
56 * tunnel_destroy GNUNET_MESH_TunnelMessage
57 * tunnel_speed_max GNUNET_MESH_TunnelMessage
58 * tunnel_speed_min GNUNET_MESH_TunnelMessage
59 * tunnel_buffer GNUNET_MESH_TunnelMessage
61 * peer_request_connect_add GNUNET_MESH_PeerControl
62 * peer_request_connect_del GNUNET_MESH_PeerControl
63 * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType
64 * peer_request_connect_by_string GNUNET_MESH_ConnectPeerByString
66 * peer_blacklist GNUNET_MESH_PeerControl
67 * peer_unblacklist GNUNET_MESH_PeerControl
69 * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy)
70 * notify_transmit_ready_cancel None (clear of internal data structures)
75 * data GNUNET_MESH_Unicast OR
76 * GNUNET_MESH_Multicast OR
77 * GNUNET_MESH_ToOrigin
78 * data ack GNUNET_MESH_LocalAck
80 * new incoming tunnel GNUNET_MESH_PeerControl
81 * peer connects to a tunnel GNUNET_MESH_PeerControl
82 * peer disconnects from a tunnel GNUNET_MESH_PeerControl
85 /******************************************************************************/
86 /************************** CONSTANTS ******************************/
87 /******************************************************************************/
89 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
90 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
92 #define HIGH_PID 0xFFFF0000
93 #define LOW_PID 0x0000FFFF
95 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
97 /******************************************************************************/
98 /************************** MESSAGES ******************************/
99 /******************************************************************************/
101 GNUNET_NETWORK_STRUCT_BEGIN
104 * Message for a client to register to the service
106 struct GNUNET_MESH_ClientConnect
109 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
111 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
112 * sizeof(MESH_ApplicationType) * applications +
113 * sizeof(uint16_t) * types
115 struct GNUNET_MessageHeader header;
116 uint16_t applications GNUNET_PACKED;
117 uint16_t types GNUNET_PACKED;
118 /* uint32_t list_apps[applications] */
119 /* uint16_t list_types[types] */
124 * Type for tunnel numbering.
125 * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
126 * - Local tunnel numbers given by the client (created) are >= 0x80000000
127 * - Global tunnel numbers are < 0x80000000
129 typedef uint32_t MESH_TunnelNumber;
132 * Message for a client to create and destroy tunnels.
134 struct GNUNET_MESH_TunnelMessage
137 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
138 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN]
140 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
142 struct GNUNET_MessageHeader header;
145 * ID of a tunnel controlled by this client.
147 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
152 * Message for the service to let a client know about created tunnels.
154 struct GNUNET_MESH_TunnelNotification
157 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE
159 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
161 struct GNUNET_MessageHeader header;
164 * ID of a tunnel controlled by this client.
166 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
169 * Peer at the other end, if any
171 struct GNUNET_PeerIdentity peer;
174 * Tunnel options (speed, buffering)
181 * - request adding and deleting peers from a tunnel
182 * - notify the client that peers have connected:
184 * -- unrequested (new incoming tunnels)
185 * - notify the client that peers have disconnected
187 struct GNUNET_MESH_PeerControl
191 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL|[UN]BLACKLIST]
192 * (client to service, client created tunnel)
193 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
194 * (service to client)
196 * Size: sizeof(struct GNUNET_MESH_PeerControl)
198 struct GNUNET_MessageHeader header;
201 * ID of a tunnel controlled by this client.
203 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
206 * Peer to connect/disconnect.
208 struct GNUNET_PeerIdentity peer;
213 * Message for connecting to peers offering a service, by service number.
215 struct GNUNET_MESH_ConnectPeerByType
218 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
219 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
221 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByType)
223 struct GNUNET_MessageHeader header;
226 * ID of a tunnel controlled by this client.
228 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
233 GNUNET_MESH_ApplicationType type GNUNET_PACKED;
238 * Message for connecting to peers offering a service, by service string.
240 struct GNUNET_MESH_ConnectPeerByString
243 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING
245 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByString) + strlen (string)
247 struct GNUNET_MessageHeader header;
250 * ID of a tunnel controlled by this client.
252 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
254 /* String describing the service */
259 * Message to allow the client send more data to the service
260 * (always service -> client).
262 struct GNUNET_MESH_LocalAck
265 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
267 struct GNUNET_MessageHeader header;
270 * ID of the tunnel allowed to send more data.
272 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
275 * ID of the last packet allowed.
277 uint32_t max_pid GNUNET_PACKED;
281 GNUNET_NETWORK_STRUCT_END
283 /******************************************************************************/
284 /************************ ENUMERATIONS ****************************/
285 /******************************************************************************/
288 * All the states a peer participating in a tunnel can be in.
293 * Uninitialized status, should never appear in operation.
298 * Peer is the root and owner of the tree
303 * Peer only retransmits traffic, is not a final destination
308 * Path to the peer not known yet
313 * Request sent, not yet answered.
318 * Peer connected and ready to accept data
323 * Peer connected previosly but not responding
325 MESH_PEER_RECONNECTING
330 * Check if one pid is bigger than other, accounting for overflow.
332 * @param bigger Argument that should be bigger.
333 * @param smaller Argument that should be smaller.
335 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
338 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
342 * Get the higher ACK value out of two values, taking in account overflow.
344 * @param a First ACK value.
345 * @param b Second ACK value.
347 * @return Highest ACK value from the two.
350 GMC_max_pid (uint32_t a, uint32_t b);
354 * Get the lower ACK value out of two values, taking in account overflow.
356 * @param a First ACK value.
357 * @param b Second ACK value.
359 * @return Lowest ACK value from the two.
362 GMC_min_pid (uint32_t a, uint32_t b);
366 * Convert a message type into a string to help debug
368 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
369 * REPLACE: " case \2: return "\1"; break;"
371 * @param m Message type.
373 * @return Human readable string description.
376 GNUNET_MESH_DEBUG_M2S (uint16_t m);