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