- encapsulate channel traffic in tunnel message
[oweals/gnunet.git] / src / mesh / mesh_protocol_enc.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_protocol_enc.h
24  */
25
26 #ifndef MESH_PROTOCOL_ENC_H_
27 #define MESH_PROTOCOL_ENC_H_
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31
32 #ifdef __cplusplus
33
34 struct GNUNET_MESH_TunnelMessage;
35 extern "C"
36 {
37 #if 0
38   /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 /******************************************************************************/
44 /********************      MESH NETWORK MESSAGES     **************************/
45 /******************************************************************************/
46
47 GNUNET_NETWORK_STRUCT_BEGIN
48
49 /**
50  * Message for mesh connection creation.
51  * TODO onionify path, add random tunnel ID
52  */
53 struct GNUNET_MESH_ConnectionCreate
54 {
55     /**
56      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE
57      *
58      * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
59      *              path_length * sizeof (struct GNUNET_PeerIdentity)
60      */
61   struct GNUNET_MessageHeader header;
62
63     /**
64      * ID of the connection for that tunnel.
65      */
66   uint32_t cid GNUNET_PACKED;
67
68     /**
69      * ID of the tunnel
70      */
71   struct GNUNET_HashCode tid;
72
73     /**
74      * path_length structs defining the *whole* path from the origin [0] to the
75      * final destination [path_length-1].
76      */
77   /* struct GNUNET_PeerIdentity peers[path_length]; */
78 };
79
80 /**
81  * Message for ack'ing a connection
82  */
83 struct GNUNET_MESH_ConnectionACK
84 {
85     /**
86      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK
87      */
88   struct GNUNET_MessageHeader header;
89
90     /**
91      * ID of the connection
92      */
93   uint32_t cid GNUNET_PACKED;
94
95     /**
96      * ID of the tunnel
97      */
98   struct GNUNET_HashCode tid;
99
100   /* TODO: signature */
101 };
102
103 /**
104  * Tunnel(ed) message.
105  */
106 struct GNUNET_MESH_Encrypted
107 {
108   /**
109    * Type: GNUNET_MESSAGE_TYPE_MESH_{FWD,BCK}
110    */
111   struct GNUNET_MessageHeader header;
112
113   /**
114    * ID of the connection.
115    */
116   uint32_t cid GNUNET_PACKED;
117
118   /**
119    * ID of the tunnel.
120    */
121   struct GNUNET_HashCode tid;
122
123   /**
124    * ID of the packet (hop by hop).
125    */
126   uint32_t pid GNUNET_PACKED;
127
128   /**
129    * Number of hops to live.
130    */
131   uint32_t ttl GNUNET_PACKED;
132
133   /**
134    * Initialization Vector for payload encryption.
135    */
136   uint64_t iv;
137
138   /**
139    * Encrypted content follows.
140    */
141 };
142
143 /**
144  * Message for mesh data traffic.
145  */
146 struct GNUNET_MESH_Data
147 {
148     /**
149      * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST,
150      *       GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
151      */
152   struct GNUNET_MessageHeader header;
153
154     /**
155      * Unique ID of the payload message
156      */
157   uint32_t mid GNUNET_PACKED;
158
159     /**
160      * ID of the channel
161      */
162   uint32_t chid GNUNET_PACKED;
163
164     /**
165      * Payload follows
166      */
167 };
168
169
170 /**
171  * Message to acknowledge end-to-end data.
172  */
173 struct GNUNET_MESH_DataACK
174 {
175   /**
176    * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK
177    */
178   struct GNUNET_MessageHeader header;
179
180   /**
181    * ID of the channel
182    */
183   uint32_t chid GNUNET_PACKED;
184
185   /**
186    * Bitfield of already-received newer messages
187    * pid +  1 @ LSB
188    * pid + 64 @ MSB
189    */
190   uint64_t futures GNUNET_PACKED;
191
192   /**
193    * Last message ID received.
194    */
195   uint32_t mid GNUNET_PACKED;
196 };
197
198
199 /**
200  * Message to acknowledge mesh data traffic.
201  */
202 struct GNUNET_MESH_ACK
203 {
204     /**
205      * Type: GNUNET_MESSAGE_TYPE_MESH_ACK
206      */
207   struct GNUNET_MessageHeader header;
208
209     /**
210      * Maximum packet ID authorized.
211      */
212   uint32_t ack GNUNET_PACKED;
213 };
214
215
216 /**
217  * Message to query a peer about its Flow Control status regarding a tunnel.
218  */
219 struct GNUNET_MESH_Poll
220 {
221   /**
222    * Type: GNUNET_MESSAGE_TYPE_MESH_POLL
223    */
224   struct GNUNET_MessageHeader header;
225
226   /**
227    * Last packet sent.
228    */
229   uint32_t pid GNUNET_PACKED;
230 };
231
232
233 /**
234  * Message for notifying a disconnection in a path
235  */
236 struct GNUNET_MESH_ConnectionBroken
237 {
238     /**
239      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN
240      */
241   struct GNUNET_MessageHeader header;
242
243     /**
244      * ID of the connection.
245      */
246   uint32_t cid GNUNET_PACKED;
247
248     /**
249      * ID of the tunnel
250      */
251   struct GNUNET_HashCode tid;
252
253     /**
254      * ID of the endpoint
255      */
256   struct GNUNET_PeerIdentity peer1;
257
258     /**
259      * ID of the endpoint
260      */
261   struct GNUNET_PeerIdentity peer2;
262
263   /* TODO: signature */
264 };
265
266
267 /**
268  * Message to destroy a connection.
269  */
270 struct GNUNET_MESH_ConnectionDestroy
271 {
272     /**
273      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY
274      */
275   struct GNUNET_MessageHeader header;
276
277     /**
278      * ID of the connection.
279      */
280   uint32_t cid GNUNET_PACKED;
281
282     /**
283      * ID of the tunnel
284      */
285   struct GNUNET_HashCode tid;
286
287   /* TODO: signature */
288 };
289
290
291 /**
292  * Message to keep a connection alive.
293  */
294 struct GNUNET_MESH_ConnectionKeepAlive
295 {
296   /**
297    * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE
298    */
299   struct GNUNET_MessageHeader header;
300
301   /**
302    * ID of the connection
303    */
304   uint32_t cid GNUNET_PACKED;
305
306   /**
307    * ID of the tunnel
308    */
309   struct GNUNET_HashCode tid;
310 };
311
312
313
314 GNUNET_NETWORK_STRUCT_END
315
316 #if 0                           /* keep Emacsens' auto-indent happy */
317 {
318 #endif
319 #ifdef __cplusplus
320 }
321 #endif
322
323 /* ifndef MESH_PROTOCOL_H */
324 #endif
325 /* end of mesh_protocol.h */