d317e805402948ae16bfccbd5a48a4db266110f5
[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  * Message for a client to register to the service
69  */
70 struct GNUNET_MESH_ClientConnect {
71     /**
72      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
73      *
74      * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
75      *       sizeof(uint16_t) * types +
76      *       sizeof(MESH_ApplicationType) * applications
77      */
78     struct GNUNET_MessageHeader header;
79     uint16_t                    types           GNUNET_PACKED;
80     uint16_t                    applications    GNUNET_PACKED;
81 };
82
83
84 /**
85  * Type for tunnel numbering.
86  * - Local tunnel numbers are >= 0x80000000
87  * - Global tunnel numbers are < 0x80000000
88  */
89 typedef uint32_t MESH_TunnelID;
90
91 /**
92  * Message for a client to create and destroy tunnels.
93  */
94 struct GNUNET_MESH_TunnelMessage {
95     /**
96      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
97      *
98      * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
99      */
100     struct GNUNET_MessageHeader header;
101
102     /**
103      * ID of a tunnel controlled by this client.
104      */
105     MESH_TunnelID               tunnel_id GNUNET_PACKED;
106 };
107
108 /**
109  * Message for:
110  * - request adding and deleting peers from a tunnel
111  * - notify the client that peers have connected:
112  *   -- requested
113  *   -- unrequested (new incoming tunnels)
114  * - notify the client that peers have disconnected
115  */
116 struct GNUNET_MESH_PeerControl {
117
118   /**
119    * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL]
120    *       (client to service, client created tunnel)
121    *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
122    *       (service to client)
123    * 
124    * Size: sizeof(struct GNUNET_MESH_PeerControl) 
125    */
126   struct GNUNET_MessageHeader   header;
127
128   /**
129    * ID of a tunnel controlled by this client.
130    */
131    MESH_TunnelID                tunnel_id GNUNET_PACKED;
132   
133   /**
134    * Peer to connect/disconnect.
135    */
136   struct GNUNET_PeerIdentity    peer;
137 };
138
139
140 /**
141  * Message for connecting to peers offering a certain service.
142  */
143 struct GNUNET_MESH_ConnectPeerByType {
144     /**
145      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE
146      */
147     struct GNUNET_MessageHeader header;
148
149   /**
150    * ID of a tunnel controlled by this client.
151    */
152    MESH_TunnelID                tunnel_id GNUNET_PACKED;
153  
154   /**
155    * Type specification 
156    */
157     GNUNET_MESH_ApplicationType type GNUNET_PACKED;
158 };
159
160
161 /**
162  *  Message for notifying the service that the client wants to send data or
163  * notifying a client that the service is ready to accept data.
164  */
165 struct GNUNET_MESH_TransmitReady {
166     /**
167      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_REQUEST_TRANSMIT_READY
168      *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_NOTIFY_TRANSMIT_READY
169      */
170     struct GNUNET_MessageHeader header;
171
172     /**
173      * ID of a tunnel controlled by this client.
174      */
175     MESH_TunnelID               tunnel_id GNUNET_PACKED;
176
177     /**
178      * Size of message we would like to transmit to this tunnel
179      */
180     uint32_t                    msg_size GNUNET_PACKED; 
181 };
182
183
184 /**
185  * Message to encapsulate data transmitted to/from the service
186  */
187 struct GNUNET_MESH_Data {
188     /**
189      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA
190      *       (client to service, or service to client)
191      * Size: sizeof(struct GNUNET_MESH_Data) + sizeof (data)
192      */
193     struct GNUNET_MessageHeader header;
194
195     /**
196      * ID of a tunnel controlled by this client.
197      */
198     MESH_TunnelID               tunnel_id GNUNET_PACKED;
199
200     /**
201      * Source or destination of the message (depending on direction).
202      */
203     struct GNUNET_PeerIdentity  peer_id;
204
205     /* uint8_t data[] */
206 };
207
208 /**
209  * Message to encapsulate broadcast data transmitted to the service
210  */
211 struct GNUNET_MESH_DataBroadcast {
212     /**
213      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST
214      *       (client to service only, client created tunnel)
215      * Size: sizeof(struct GNUNET_MESH_DataBroadcast) + sizeof (data)
216      */
217     struct GNUNET_MessageHeader header;
218
219     /**
220      * ID of a tunnel controlled by this client.
221      */
222     MESH_TunnelID               tunnel_id GNUNET_PACKED;
223
224     /* uint8_t data[] */
225 };
226
227
228 #endif