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
58 * peer_request_connect_add GNUNET_MESH_PeerControl
59 * peer_request_connect_del GNUNET_MESH_PeerControl
60 * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType
62 * notify_transmit_ready *GNUNET_MESH_TransmitReady?*
63 * notify_transmit_ready_cancel None (clear of internal data structures)
69 * data GNUNET_MESH_Data OR
70 * GNUNET_MESH_DataBroadcast
71 * new incoming tunnel GNUNET_MESH_PeerControl
72 * peer connects to a tunnel GNUNET_MESH_PeerControl
73 * peer disconnects from a tunnel GNUNET_MESH_PeerControl
76 /******************************************************************************/
77 /************************** CONSTANTS ******************************/
78 /******************************************************************************/
80 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
81 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
83 #define HIGH_PID 0xFFFF0000
84 #define LOW_PID 0x0000FFFF
86 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
88 /******************************************************************************/
89 /************************** MESSAGES ******************************/
90 /******************************************************************************/
92 GNUNET_NETWORK_STRUCT_BEGIN
95 * Message for a client to register to the service
97 struct GNUNET_MESH_ClientConnect
100 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
102 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
103 * sizeof(MESH_ApplicationType) * applications +
104 * sizeof(uint16_t) * types
106 struct GNUNET_MessageHeader header;
107 uint16_t applications GNUNET_PACKED;
108 uint16_t types GNUNET_PACKED;
109 /* uint16_t list_apps[applications] */
110 /* uint16_t list_types[types] */
115 * Type for tunnel numbering.
116 * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
117 * - Local tunnel numbers given by the client (created) are >= 0x80000000
118 * - Global tunnel numbers are < 0x80000000
120 typedef uint32_t MESH_TunnelNumber;
123 * Message for a client to create and destroy tunnels.
125 struct GNUNET_MESH_TunnelMessage
128 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
129 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN]
131 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
133 struct GNUNET_MessageHeader header;
136 * ID of a tunnel controlled by this client.
138 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
143 * Message for the service to let a client know about created tunnels.
145 struct GNUNET_MESH_TunnelNotification
148 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE
150 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
152 struct GNUNET_MessageHeader header;
155 * ID of a tunnel controlled by this client.
157 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
160 * Peer at the other end, if any
162 struct GNUNET_PeerIdentity peer;
167 * - request adding and deleting peers from a tunnel
168 * - notify the client that peers have connected:
170 * -- unrequested (new incoming tunnels)
171 * - notify the client that peers have disconnected
173 struct GNUNET_MESH_PeerControl
177 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL|[UN]BLACKLIST]
178 * (client to service, client created tunnel)
179 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
180 * (service to client)
182 * Size: sizeof(struct GNUNET_MESH_PeerControl)
184 struct GNUNET_MessageHeader header;
187 * ID of a tunnel controlled by this client.
189 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
192 * Peer to connect/disconnect.
194 struct GNUNET_PeerIdentity peer;
199 * Message for connecting to peers offering a service, by service number.
201 struct GNUNET_MESH_ConnectPeerByType
204 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
205 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
207 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByType)
209 struct GNUNET_MessageHeader header;
212 * ID of a tunnel controlled by this client.
214 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
219 GNUNET_MESH_ApplicationType type GNUNET_PACKED;
224 * Message for connecting to peers offering a service, by service string.
226 struct GNUNET_MESH_ConnectPeerByString
229 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING
231 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByString) + strlen (string)
233 struct GNUNET_MessageHeader header;
236 * ID of a tunnel controlled by this client.
238 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
240 /* String describing the service */
245 * Message to allow the client send more data to the service
246 * (always service -> client).
248 struct GNUNET_MESH_LocalAck
251 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
253 struct GNUNET_MessageHeader header;
256 * ID of the tunnel allowed to send more data.
258 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
261 * ID of the last packet allowed.
263 uint32_t max_pid GNUNET_PACKED;
267 GNUNET_NETWORK_STRUCT_END
269 /******************************************************************************/
270 /************************ ENUMERATIONS ****************************/
271 /******************************************************************************/
274 * All the states a peer participating in a tunnel can be in.
279 * Uninitialized status, should never appear in operation.
284 * Peer is the root and owner of the tree
289 * Peer only retransmits traffic, is not a final destination
294 * Path to the peer not known yet
299 * Request sent, not yet answered.
304 * Peer connected and ready to accept data
309 * Peer connected previosly but not responding
311 MESH_PEER_RECONNECTING
316 * Check if one pid is bigger than other, accounting for overflow.
318 * @param bigger Argument that should be bigger.
319 * @param smaller Argument that should be smaller.
321 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
324 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
328 * Get the higher ACK value out of two values, taking in account overflow.
330 * @param a First ACK value.
331 * @param b Second ACK value.
333 * @return Highest ACK value from the two.
336 GMC_max_pid (uint32_t a, uint32_t b);
340 * Get the lower ACK value out of two values, taking in account overflow.
342 * @param a First ACK value.
343 * @param b Second ACK value.
345 * @return Lowest ACK value from the two.
348 GMC_min_pid (uint32_t a, uint32_t b);
352 * Convert a message type into a string to help debug
354 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
355 * REPLACE: " case \2: return "\1"; break;"
357 * @param m Message type.
359 * @return Human readable string description.
362 GNUNET_MESH_DEBUG_M2S (uint16_t m);