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
34 #include "gnunet_common.h"
35 #include "gnunet_util_lib.h"
36 #include "gnunet_peer_lib.h"
37 #include "gnunet_core_service.h"
38 #include "gnunet_protocols.h"
39 #include <gnunet_mesh_service.h>
41 /******************************************************************************/
42 /******************** MESH LOCAL MESSAGES *************************/
43 /******************************************************************************/
44 /* Any API call should be documented in the folowing table under API CALL.
45 * Also, any message type should be documented in the following table, with the
48 * API CALL (GNUNET_MESH_*) MESSAGE USED
49 * ------------------------ ------------
50 * connect GNUNET_MESH_ClientConnect
51 * disconnect None (network level disconnect)
53 * tunnel_create GNUNET_MESH_TunnelMessage
54 * tunnel_destroy GNUNET_MESH_TunnelMessage
56 * peer_request_connect_add GNUNET_MESH_PeerControl
57 * peer_request_connect_del GNUNET_MESH_PeerControl
58 * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType
60 * notify_transmit_ready *GNUNET_MESH_TransmitReady?*
61 * notify_transmit_ready_cancel None (clear of internal data structures)
67 * data GNUNET_MESH_Data OR
68 * GNUNET_MESH_DataBroadcast
69 * new incoming tunnel GNUNET_MESH_PeerControl
70 * peer connects to a tunnel GNUNET_MESH_PeerControl
71 * peer disconnects from a tunnel GNUNET_MESH_PeerControl
74 /******************************************************************************/
75 /************************** CONSTANTS ******************************/
76 /******************************************************************************/
78 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
79 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
81 #define HIGH_PID 0xFFFF0000
82 #define LOW_PID 0x0000FFFF
84 #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID)
86 /******************************************************************************/
87 /************************** MESSAGES ******************************/
88 /******************************************************************************/
90 GNUNET_NETWORK_STRUCT_BEGIN
93 * Message for a client to register to the service
95 struct GNUNET_MESH_ClientConnect
98 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
100 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
101 * sizeof(MESH_ApplicationType) * applications +
102 * sizeof(uint16_t) * types
104 struct GNUNET_MessageHeader header;
105 uint16_t applications GNUNET_PACKED;
106 uint16_t types GNUNET_PACKED;
107 /* uint16_t list_apps[applications] */
108 /* uint16_t list_types[types] */
113 * Type for tunnel numbering.
114 * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
115 * - Local tunnel numbers given by the client (created) are >= 0x80000000
116 * - Global tunnel numbers are < 0x80000000
118 typedef uint32_t MESH_TunnelNumber;
121 * Message for a client to create and destroy tunnels.
123 struct GNUNET_MESH_TunnelMessage
126 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
127 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN]
129 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
131 struct GNUNET_MessageHeader header;
134 * ID of a tunnel controlled by this client.
136 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
141 * Message for the service to let a client know about created tunnels.
143 struct GNUNET_MESH_TunnelNotification
146 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE
148 * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
150 struct GNUNET_MessageHeader header;
153 * ID of a tunnel controlled by this client.
155 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
158 * Peer at the other end, if any
160 struct GNUNET_PeerIdentity peer;
165 * - request adding and deleting peers from a tunnel
166 * - notify the client that peers have connected:
168 * -- unrequested (new incoming tunnels)
169 * - notify the client that peers have disconnected
171 struct GNUNET_MESH_PeerControl
175 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL|[UN]BLACKLIST]
176 * (client to service, client created tunnel)
177 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
178 * (service to client)
180 * Size: sizeof(struct GNUNET_MESH_PeerControl)
182 struct GNUNET_MessageHeader header;
185 * ID of a tunnel controlled by this client.
187 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
190 * Peer to connect/disconnect.
192 struct GNUNET_PeerIdentity peer;
197 * Message for connecting to peers offering a service, by service number.
199 struct GNUNET_MESH_ConnectPeerByType
202 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
203 * GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
205 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByType)
207 struct GNUNET_MessageHeader header;
210 * ID of a tunnel controlled by this client.
212 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
217 GNUNET_MESH_ApplicationType type GNUNET_PACKED;
222 * Message for connecting to peers offering a service, by service string.
224 struct GNUNET_MESH_ConnectPeerByString
227 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING
229 * Size: sizeof(struct GNUNET_MESH_ConnectPeerByString) + strlen (string)
231 struct GNUNET_MessageHeader header;
234 * ID of a tunnel controlled by this client.
236 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
238 /* String describing the service */
243 * Message to allow the client send more data to the service
244 * (always service -> client).
246 struct GNUNET_MESH_LocalAck
249 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK
251 struct GNUNET_MessageHeader header;
254 * ID of the tunnel allowed to send more data.
256 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
259 * ID of the last packet allowed.
261 uint32_t max_pid GNUNET_PACKED;
265 GNUNET_NETWORK_STRUCT_END
267 /******************************************************************************/
268 /************************ ENUMERATIONS ****************************/
269 /******************************************************************************/
272 * All the states a peer participating in a tunnel can be in.
277 * Uninitialized status, should never appear in operation.
282 * Peer is the root and owner of the tree
287 * Peer only retransmits traffic, is not a final destination
292 * Path to the peer not known yet
297 * Request sent, not yet answered.
302 * Peer connected and ready to accept data
307 * Peer connected previosly but not responding
309 MESH_PEER_RECONNECTING