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_util_lib.h"
43 #include "gnunet_core_service.h"
44 #include "gnunet_protocols.h"
45 #include <gnunet_mesh_service.h>
47 /******************************************************************************/
48 /******************** MESH LOCAL MESSAGES *************************/
49 /******************************************************************************/
50 /* Any API call should be documented in the folowing table under API CALL.
51 * Also, any message type should be documented in the following table, with the
54 * API CALL (GNUNET_MESH_*) MESSAGE USED
55 * ------------------------ ------------
56 * connect GNUNET_MESH_ClientConnect
57 * disconnect None (network level disconnect)
59 * tunnel_create GNUNET_MESH_TunnelMessage
60 * tunnel_destroy GNUNET_MESH_TunnelMessage
61 * tunnel_buffer GNUNET_MESH_TunnelMessage
63 * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy)
64 * notify_transmit_ready_cancel None (clear of internal data structures)
69 * data GNUNET_MESH_Unicast OR
70 * GNUNET_MESH_Multicast OR
71 * GNUNET_MESH_ToOrigin
72 * data ack GNUNET_MESH_LocalAck
74 * new incoming tunnel GNUNET_MESH_PeerControl
75 * peer connects to a tunnel FIXME
76 * peer disconnects from a tunnel FIXME
79 /******************************************************************************/
80 /************************** CONSTANTS ******************************/
81 /******************************************************************************/
83 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
84 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
86 #define HIGH_PID 0xFFFF0000
87 #define LOW_PID 0x0000FFFF
89 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
91 /******************************************************************************/
92 /************************** MESSAGES ******************************/
93 /******************************************************************************/
95 GNUNET_NETWORK_STRUCT_BEGIN
98 * Message for a client to register to the service
100 struct GNUNET_MESH_ClientConnect
103 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
105 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
106 * sizeof(MESH_ApplicationType) * applications +
107 * sizeof(uint16_t) * types
109 struct GNUNET_MessageHeader header;
110 /* uint32_t list_ports[] */
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;
124 * Message for a client to create and destroy tunnels.
126 struct GNUNET_MESH_TunnelMessage
129 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
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 struct GNUNET_PeerIdentity peer;
146 * Port of the tunnel.
148 uint32_t port GNUNET_PACKED;
153 uint32_t opt GNUNET_PACKED;
158 * Message for mesh data traffic.
160 struct GNUNET_MESH_LocalData
163 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA
165 struct GNUNET_MessageHeader header;
170 uint32_t tid GNUNET_PACKED;
179 * Message to allow the client send more data to the service
180 * (always service -> client).
182 struct GNUNET_MESH_LocalAck
185 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
187 struct GNUNET_MessageHeader header;
190 * ID of the tunnel allowed to send more data.
192 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
198 * Message to inform the client about tunnels in the service.
200 struct GNUNET_MESH_LocalMonitor
203 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
205 struct GNUNET_MessageHeader header;
208 * ID of the tunnel allowed to send more data.
210 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
215 uint32_t reserved GNUNET_PACKED;
218 * ID of the owner of the tunnel (can be local peer).
220 struct GNUNET_PeerIdentity owner;
223 * ID of the destination of the tunnel (can be local peer).
225 struct GNUNET_PeerIdentity destination;
229 GNUNET_NETWORK_STRUCT_END
231 /******************************************************************************/
232 /************************ ENUMERATIONS ****************************/
233 /******************************************************************************/
236 * All the states a tunnel can be in.
241 * Uninitialized status, should never appear in operation.
246 * Path to the peer not known yet
248 MESH_TUNNEL_SEARCHING,
251 * Request sent, not yet answered.
256 * Peer connected and ready to accept data
261 * Peer connected previosly but not responding
263 MESH_TUNNEL_RECONNECTING
268 * Check if one pid is bigger than other, accounting for overflow.
270 * @param bigger Argument that should be bigger.
271 * @param smaller Argument that should be smaller.
273 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
276 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
280 * Get the higher ACK value out of two values, taking in account overflow.
282 * @param a First ACK value.
283 * @param b Second ACK value.
285 * @return Highest ACK value from the two.
288 GMC_max_pid (uint32_t a, uint32_t b);
292 * Get the lower ACK value out of two values, taking in account overflow.
294 * @param a First ACK value.
295 * @param b Second ACK value.
297 * @return Lowest ACK value from the two.
300 GMC_min_pid (uint32_t a, uint32_t b);
304 * Convert a message type into a string to help debug
306 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
307 * REPLACE: " case \2: return "\1"; break;"
309 * @param m Message type.
311 * @return Human readable string description.
314 GNUNET_MESH_DEBUG_M2S (uint16_t m);
316 #if 0 /* keep Emacsens' auto-indent happy */