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_buffer GNUNET_MESH_TunnelMessage
68 * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy)
69 * notify_transmit_ready_cancel None (clear of internal data structures)
74 * data GNUNET_MESH_Unicast OR
75 * GNUNET_MESH_Multicast OR
76 * GNUNET_MESH_ToOrigin
77 * data ack GNUNET_MESH_LocalAck
79 * new incoming tunnel GNUNET_MESH_PeerControl
80 * peer connects to a tunnel FIXME
81 * peer disconnects from a tunnel FIXME
84 /******************************************************************************/
85 /************************** CONSTANTS ******************************/
86 /******************************************************************************/
88 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
89 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
91 #define HIGH_PID 0xFFFF0000
92 #define LOW_PID 0x0000FFFF
94 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
96 /******************************************************************************/
97 /************************** MESSAGES ******************************/
98 /******************************************************************************/
100 GNUNET_NETWORK_STRUCT_BEGIN
103 * Message for a client to register to the service
105 struct GNUNET_MESH_ClientConnect
108 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
110 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
111 * sizeof(MESH_ApplicationType) * applications +
112 * sizeof(uint16_t) * types
114 struct GNUNET_MessageHeader header;
115 uint16_t types GNUNET_PACKED;
116 uint16_t ports GNUNET_PACKED;
117 /* uint16_t list_types[types] */
118 /* uint32_t list_ports[ports] */
123 * Type for tunnel numbering.
124 * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
125 * - Local tunnel numbers given by the client (created) are >= 0x80000000
126 * - Global tunnel numbers are < 0x80000000
128 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]
139 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
141 struct GNUNET_MessageHeader header;
144 * ID of a tunnel controlled by this client.
146 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
151 struct GNUNET_PeerIdentity peer;
154 * Port of the tunnel.
156 uint32_t port 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.
180 struct GNUNET_PeerIdentity peer;
183 * Port for this tunnel
185 uint32_t port GNUNET_PACKED;
188 * Tunnel options (speed, buffering)
190 uint32_t opt GNUNET_PACKED;
195 * Message to allow the client send more data to the service
196 * (always service -> client).
198 struct GNUNET_MESH_LocalAck
201 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
203 struct GNUNET_MessageHeader header;
206 * ID of the tunnel allowed to send more data.
208 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
211 * ID of the last packet allowed.
213 uint32_t max_pid GNUNET_PACKED;
218 * Message to inform the client about tunnels in the service.
220 struct GNUNET_MESH_LocalMonitor
223 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
225 struct GNUNET_MessageHeader header;
228 * ID of the tunnel allowed to send more data.
230 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
235 uint32_t reserved GNUNET_PACKED;
238 * ID of the owner of the tunnel (can be local peer).
240 struct GNUNET_PeerIdentity owner;
243 * ID of the destination of the tunnel (can be local peer).
245 struct GNUNET_PeerIdentity destination;
249 GNUNET_NETWORK_STRUCT_END
251 /******************************************************************************/
252 /************************ ENUMERATIONS ****************************/
253 /******************************************************************************/
256 * All the states a tunnel can be in.
261 * Uninitialized status, should never appear in operation.
266 * Path to the peer not known yet
268 MESH_TUNNEL_SEARCHING,
271 * Request sent, not yet answered.
276 * Peer connected and ready to accept data
281 * Peer connected previosly but not responding
283 MESH_TUNNEL_RECONNECTING
288 * Check if one pid is bigger than other, accounting for overflow.
290 * @param bigger Argument that should be bigger.
291 * @param smaller Argument that should be smaller.
293 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
296 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
300 * Get the higher ACK value out of two values, taking in account overflow.
302 * @param a First ACK value.
303 * @param b Second ACK value.
305 * @return Highest ACK value from the two.
308 GMC_max_pid (uint32_t a, uint32_t b);
312 * Get the lower ACK value out of two values, taking in account overflow.
314 * @param a First ACK value.
315 * @param b Second ACK value.
317 * @return Lowest ACK value from the two.
320 GMC_min_pid (uint32_t a, uint32_t b);
324 * Expand a 32 bit value (message type) into a hash for a MultiHashMap (fast).
325 * WARNING: do not use for anything other than MultiHashMap!
326 * does not alter anything other than bits used by idx_of !
328 * @param i 32 bit integer value.
329 * @param h Hash code to fill.
332 GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h);
336 * Convert a message type into a string to help debug
338 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
339 * REPLACE: " case \2: return "\1"; break;"
341 * @param m Message type.
343 * @return Human readable string description.
346 GNUNET_MESH_DEBUG_M2S (uint16_t m);
348 #if 0 /* keep Emacsens' auto-indent happy */