bbfad3225f56c9e26fd5ca8885b45e5b7cd246d8
[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 #include <gnunet_mesh_service_new.h>
31 #include "gnunet_common.h"
32
33 /******************************************************************************/
34 /********************        MESH LOCAL MESSAGES      *************************/
35 /******************************************************************************/
36 /*  Any API call should be documented in the folowing table under API CALL.
37  *  Also, any message type should be documented in the following table, with the
38  * associated event.
39  * 
40  * API CALL (GNUNET_MESH_*)             MESSAGE USED
41  * ------------------------             ------------
42  * connect                              GNUNET_MESH_ClientConnect
43  * disconnect                           None (network level disconnect)
44  *
45  * tunnel_create                        GNUNET_MESH_TunnelMessage
46  * tunnel_destroy                       GNUNET_MESH_TunnelMessage
47  *
48  * peer_request_connect_add             GNUNET_MESH_PeerControl
49  * peer_request_connect_del             GNUNET_MESH_PeerControl
50  * peer_request_connect_by_type         GNUNET_MESH_ConnectPeerByType
51  *
52  * notify_transmit_ready                GNUNET_MESH_TransmitReady
53  * notify_transmit_ready_cancel         None (clear of internal data structures)
54  * 
55  * 
56  * 
57  * EVENT                                MESSAGE USED
58  * -----                                ------------
59  * notify_transmit_ready reply          GNUNET_MESH_TransmitReady
60  * notify_transmit_ready data           GNUNET_MESH_Data OR
61  *                                      GNUNET_MESH_DataBroadcast
62  * new incoming tunnel                  GNUNET_MESH_PeerControl
63  * peer connects to a tunnel            GNUNET_MESH_PeerControl
64  * peer disconnects from a tunnel       GNUNET_MESH_PeerControl
65  */
66
67 /******************************************************************************/
68 /**************************       CONSTANTS      ******************************/
69 /******************************************************************************/
70
71 #define GNUNET_MESH_LOCAL_TUNNEL_ID_MARK 0x80000000
72
73
74 /******************************************************************************/
75 /**************************        MESSAGES      ******************************/
76 /******************************************************************************/
77
78 /**
79  * Message for a client to register to the service
80  */
81 struct GNUNET_MESH_ClientConnect {
82     /**
83      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
84      *
85      * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
86      *       sizeof(uint16_t) * types +
87      *       sizeof(MESH_ApplicationType) * applications
88      */
89     struct GNUNET_MessageHeader header;
90     uint16_t                    types           GNUNET_PACKED;
91     uint16_t                    applications    GNUNET_PACKED;
92     /* uint16_t                 list_types[types]           */
93     /* uint16_t                 list_apps[applications]     */
94 };
95
96
97 /**
98  * Type for tunnel numbering.
99  * - Local tunnel numbers are >= 0x80000000
100  * - Global tunnel numbers are < 0x80000000
101  */
102 typedef uint32_t MESH_TunnelNumber;
103
104 /**
105  * Message for a client to create and destroy tunnels.
106  */
107 struct GNUNET_MESH_TunnelMessage {
108     /**
109      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
110      *
111      * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
112      */
113     struct GNUNET_MessageHeader header;
114
115     /**
116      * ID of a tunnel controlled by this client.
117      */
118     MESH_TunnelNumber           tunnel_id GNUNET_PACKED;
119 };
120
121 /**
122  * Message for:
123  * - request adding and deleting peers from a tunnel
124  * - notify the client that peers have connected:
125  *   -- requested
126  *   -- unrequested (new incoming tunnels)
127  * - notify the client that peers have disconnected
128  */
129 struct GNUNET_MESH_PeerControl {
130
131   /**
132    * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL]
133    *       (client to service, client created tunnel)
134    *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
135    *       (service to client)
136    * 
137    * Size: sizeof(struct GNUNET_MESH_PeerControl) 
138    */
139   struct GNUNET_MessageHeader   header;
140
141   /**
142    * ID of a tunnel controlled by this client.
143    */
144    MESH_TunnelNumber            tunnel_id GNUNET_PACKED;
145   
146   /**
147    * Peer to connect/disconnect.
148    */
149   struct GNUNET_PeerIdentity    peer;
150 };
151
152
153 /**
154  * Message for connecting to peers offering a certain service.
155  */
156 struct GNUNET_MESH_ConnectPeerByType {
157     /**
158      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE
159      */
160     struct GNUNET_MessageHeader header;
161
162   /**
163    * ID of a tunnel controlled by this client.
164    */
165    MESH_TunnelNumber            tunnel_id GNUNET_PACKED;
166  
167   /**
168    * Type specification 
169    */
170     GNUNET_MESH_ApplicationType type GNUNET_PACKED;
171 };
172
173
174 /**
175  *  Message for notifying the service that the client wants to send data or
176  * notifying a client that the service is ready to accept data.
177  */
178 struct GNUNET_MESH_TransmitReady {
179     /**
180      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_REQUEST_TRANSMIT_READY
181      *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_NOTIFY_TRANSMIT_READY
182      */
183     struct GNUNET_MessageHeader header;
184
185     /**
186      * ID of a tunnel controlled by this client.
187      */
188     MESH_TunnelNumber           tunnel_id GNUNET_PACKED;
189
190     /**
191      * Size of message we would like to transmit to this tunnel
192      */
193     uint32_t                    msg_size GNUNET_PACKED; 
194 };
195
196
197 /**
198  * Message to encapsulate data transmitted to/from the service
199  */
200 struct GNUNET_MESH_Data {
201     /**
202      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA
203      *       (client to service, or service to client)
204      * Size: sizeof(struct GNUNET_MESH_Data) + sizeof (data)
205      */
206     struct GNUNET_MessageHeader header;
207
208     /**
209      * ID of a tunnel controlled by this client.
210      */
211     MESH_TunnelNumber           tunnel_id GNUNET_PACKED;
212
213     /**
214      * Source or destination of the message (depending on direction).
215      */
216     struct GNUNET_PeerIdentity  peer_id;
217
218     /* uint8_t data[] */
219 };
220
221 /**
222  * Message to encapsulate broadcast data transmitted to the service
223  */
224 struct GNUNET_MESH_DataBroadcast {
225     /**
226      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST
227      *       (client to service only, client created tunnel)
228      * Size: sizeof(struct GNUNET_MESH_DataBroadcast) + sizeof (data)
229      */
230     struct GNUNET_MessageHeader header;
231
232     /**
233      * ID of a tunnel controlled by this client.
234      */
235     MESH_TunnelNumber           tunnel_id GNUNET_PACKED;
236
237     /* uint8_t data[] */
238 };
239
240
241 #endif