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
42 #include "gnunet_common.h"
43 #include "gnunet_util_lib.h"
44 #include "gnunet_peer_lib.h"
45 #include "gnunet_core_service.h"
46 #include "gnunet_protocols.h"
47 #include <gnunet_mesh_service.h>
49 /******************************************************************************/
50 /******************** MESH LOCAL MESSAGES *************************/
51 /******************************************************************************/
52 /* Any API call should be documented in the folowing table under API CALL.
53 * Also, any message type should be documented in the following table, with the
56 * API CALL (GNUNET_MESH_*) MESSAGE USED
57 * ------------------------ ------------
58 * connect GNUNET_MESH_ClientConnect
59 * disconnect None (network level disconnect)
61 * tunnel_create GNUNET_MESH_TunnelMessage
62 * tunnel_destroy GNUNET_MESH_TunnelMessage
63 * tunnel_buffer GNUNET_MESH_TunnelMessage
65 * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy)
66 * notify_transmit_ready_cancel None (clear of internal data structures)
71 * data GNUNET_MESH_Unicast OR
72 * GNUNET_MESH_Multicast OR
73 * GNUNET_MESH_ToOrigin
74 * data ack GNUNET_MESH_LocalAck
76 * new incoming tunnel GNUNET_MESH_PeerControl
77 * peer connects to a tunnel FIXME
78 * peer disconnects from a tunnel FIXME
81 /******************************************************************************/
82 /************************** CONSTANTS ******************************/
83 /******************************************************************************/
85 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
86 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
88 #define HIGH_PID 0xFFFF0000
89 #define LOW_PID 0x0000FFFF
91 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
93 /******************************************************************************/
94 /************************** MESSAGES ******************************/
95 /******************************************************************************/
97 GNUNET_NETWORK_STRUCT_BEGIN
100 * Message for a client to register to the service
102 struct GNUNET_MESH_ClientConnect
105 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
107 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
108 * sizeof(MESH_ApplicationType) * applications +
109 * sizeof(uint16_t) * types
111 struct GNUNET_MessageHeader header;
112 /* uint32_t list_ports[] */
117 * Type for tunnel numbering.
118 * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
119 * - Local tunnel numbers given by the client (created) are >= 0x80000000
120 * - Global tunnel numbers are < 0x80000000
122 typedef uint32_t MESH_TunnelNumber;
126 * Message for a client to create and destroy tunnels.
128 struct GNUNET_MESH_TunnelMessage
131 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
133 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
135 struct GNUNET_MessageHeader header;
138 * ID of a tunnel controlled by this client.
140 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
145 struct GNUNET_PeerIdentity peer;
148 * Port of the tunnel.
150 uint32_t port GNUNET_PACKED;
155 * Message for the service to let a client know about created tunnels.
157 struct GNUNET_MESH_TunnelNotification
160 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE
162 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
164 struct GNUNET_MessageHeader header;
167 * ID of a tunnel controlled by this client.
169 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
172 * Peer at the other end.
174 struct GNUNET_PeerIdentity peer;
177 * Port for this tunnel
179 uint32_t port GNUNET_PACKED;
182 * Tunnel options (speed, buffering)
184 uint32_t opt GNUNET_PACKED;
189 * Message to allow the client send more data to the service
190 * (always service -> client).
192 struct GNUNET_MESH_LocalAck
195 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
197 struct GNUNET_MessageHeader header;
200 * ID of the tunnel allowed to send more data.
202 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
205 * ID of the last packet allowed.
207 uint32_t ack GNUNET_PACKED;
212 * Message to inform the client about tunnels in the service.
214 struct GNUNET_MESH_LocalMonitor
217 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
219 struct GNUNET_MessageHeader header;
222 * ID of the tunnel allowed to send more data.
224 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
229 uint32_t reserved GNUNET_PACKED;
232 * ID of the owner of the tunnel (can be local peer).
234 struct GNUNET_PeerIdentity owner;
237 * ID of the destination of the tunnel (can be local peer).
239 struct GNUNET_PeerIdentity destination;
243 GNUNET_NETWORK_STRUCT_END
245 /******************************************************************************/
246 /************************ ENUMERATIONS ****************************/
247 /******************************************************************************/
250 * All the states a tunnel can be in.
255 * Uninitialized status, should never appear in operation.
260 * Path to the peer not known yet
262 MESH_TUNNEL_SEARCHING,
265 * Request sent, not yet answered.
270 * Peer connected and ready to accept data
275 * Peer connected previosly but not responding
277 MESH_TUNNEL_RECONNECTING
282 * Check if one pid is bigger than other, accounting for overflow.
284 * @param bigger Argument that should be bigger.
285 * @param smaller Argument that should be smaller.
287 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
290 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
294 * Get the higher ACK value out of two values, taking in account overflow.
296 * @param a First ACK value.
297 * @param b Second ACK value.
299 * @return Highest ACK value from the two.
302 GMC_max_pid (uint32_t a, uint32_t b);
306 * Get the lower ACK value out of two values, taking in account overflow.
308 * @param a First ACK value.
309 * @param b Second ACK value.
311 * @return Lowest ACK value from the two.
314 GMC_min_pid (uint32_t a, uint32_t b);
318 * Expand a 32 bit value (message type) into a hash for a MultiHashMap (fast).
319 * WARNING: do not use for anything other than MultiHashMap!
320 * does not alter anything other than bits used by idx_of !
322 * @param i 32 bit integer value.
323 * @param h Hash code to fill.
326 GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h);
330 * Convert a message type into a string to help debug
332 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
333 * REPLACE: " case \2: return "\1"; break;"
335 * @param m Message type.
337 * @return Human readable string description.
340 GNUNET_MESH_DEBUG_M2S (uint16_t m);
342 #if 0 /* keep Emacsens' auto-indent happy */