fixing 2012: network structure alignment now forced to be correct even on W32 using...
[oweals/gnunet.git] / src / mesh / mesh.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @author Bartlomiej Polot
23  * @file mesh/mesh.h
24  */
25
26 #ifndef MESH_H_
27 #define MESH_H_
28 #include <stdint.h>
29
30 #define MESH_DEBUG              GNUNET_YES
31
32
33 #include "platform.h"
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>
40
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
46  * associated event.
47  *
48  * API CALL (GNUNET_MESH_*)             MESSAGE USED
49  * ------------------------             ------------
50  * connect                              GNUNET_MESH_ClientConnect
51  * disconnect                           None (network level disconnect)
52  *
53  * tunnel_create                        GNUNET_MESH_TunnelMessage
54  * tunnel_destroy                       GNUNET_MESH_TunnelMessage
55  *
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
59  *
60  * notify_transmit_ready                *GNUNET_MESH_TransmitReady?*
61  * notify_transmit_ready_cancel         None (clear of internal data structures)
62  *
63  *
64  *
65  * EVENT                                MESSAGE USED
66  * -----                                ------------
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
72  */
73
74 /******************************************************************************/
75 /**************************       CONSTANTS      ******************************/
76 /******************************************************************************/
77
78 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
79 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
80
81 #define CORE_QUEUE_SIZE         10
82 #define LOCAL_QUEUE_SIZE        100
83
84 /******************************************************************************/
85 /**************************        MESSAGES      ******************************/
86 /******************************************************************************/
87
88 GNUNET_NETWORK_STRUCT_BEGIN
89
90 /**
91  * Message for a client to register to the service
92  */
93 struct GNUNET_MESH_ClientConnect
94 {
95     /**
96      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
97      *
98      * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
99      *       sizeof(MESH_ApplicationType) * applications +
100      *       sizeof(uint16_t) * types
101      */
102   struct GNUNET_MessageHeader header;
103   uint16_t applications GNUNET_PACKED;
104   uint16_t types GNUNET_PACKED;
105   /* uint16_t                 list_apps[applications]     */
106   /* uint16_t                 list_types[types]           */
107 };
108
109
110 /**
111  * Type for tunnel numbering.
112  * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000
113  * - Local tunnel numbers given by the client (created) are >= 0x80000000
114  * - Global tunnel numbers are < 0x80000000
115  */
116 typedef uint32_t MESH_TunnelNumber;
117
118 /**
119  * Message for a client to create and destroy tunnels.
120  */
121 struct GNUNET_MESH_TunnelMessage
122 {
123     /**
124      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
125      *
126      * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
127      */
128   struct GNUNET_MessageHeader header;
129
130     /**
131      * ID of a tunnel controlled by this client.
132      */
133   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
134 };
135
136
137 /**
138  * Message for the service to let a client know about created tunnels.
139  */
140 struct GNUNET_MESH_TunnelNotification
141 {
142     /**
143      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE
144      *
145      * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
146      */
147   struct GNUNET_MessageHeader header;
148
149     /**
150      * ID of a tunnel controlled by this client.
151      */
152   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
153
154     /**
155      * Peer at the other end, if any
156      */
157   struct GNUNET_PeerIdentity peer;
158 };
159
160 /**
161  * Message for:
162  * - request adding and deleting peers from a tunnel
163  * - notify the client that peers have connected:
164  *   -- requested
165  *   -- unrequested (new incoming tunnels)
166  * - notify the client that peers have disconnected
167  */
168 struct GNUNET_MESH_PeerControl
169 {
170
171   /**
172    * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL]
173    *       (client to service, client created tunnel)
174    *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
175    *       (service to client)
176    *
177    * Size: sizeof(struct GNUNET_MESH_PeerControl)
178    */
179   struct GNUNET_MessageHeader header;
180
181   /**
182    * ID of a tunnel controlled by this client.
183    */
184   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
185
186   /**
187    * Peer to connect/disconnect.
188    */
189   struct GNUNET_PeerIdentity peer;
190 };
191
192
193 /**
194  * Message for connecting to peers offering a certain service.
195  */
196 struct GNUNET_MESH_ConnectPeerByType
197 {
198     /**
199      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
200      *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
201      */
202   struct GNUNET_MessageHeader header;
203
204   /**
205    * ID of a tunnel controlled by this client.
206    */
207   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
208
209   /**
210    * Type specification
211    */
212   GNUNET_MESH_ApplicationType type GNUNET_PACKED;
213 };
214 GNUNET_NETWORK_STRUCT_END
215
216 /******************************************************************************/
217 /************************        ENUMERATIONS      ****************************/
218 /******************************************************************************/
219
220 /**
221  * All the states a peer participating in a tunnel can be in.
222  */
223 enum MeshPeerState
224 {
225     /**
226      * Uninitialized status, should never appear in operation.
227      */
228   MESH_PEER_INVALID,
229
230     /**
231      * Peer is the root and owner of the tree
232      */
233   MESH_PEER_ROOT,
234
235     /**
236      * Peer only retransmits traffic, is not a final destination
237      */
238   MESH_PEER_RELAY,
239
240     /**
241      * Path to the peer not known yet
242      */
243   MESH_PEER_SEARCHING,
244
245     /**
246      * Request sent, not yet answered.
247      */
248   MESH_PEER_WAITING,
249
250     /**
251      * Peer connected and ready to accept data
252      */
253   MESH_PEER_READY,
254
255     /**
256      * Peer connected previosly but not responding
257      */
258   MESH_PEER_RECONNECTING
259 };
260
261
262
263 #endif