d034c63b0529d16050b43ce0fa2b1e233000de3d
[oweals/gnunet.git] / src / cadet / cadet_protocol.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001 - 2011 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Bartlomiej Polot
23  * @file cadet/cadet_protocol.h
24  */
25
26 #ifndef CADET_PROTOCOL_H_
27 #define CADET_PROTOCOL_H_
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "cadet.h"
32
33 #ifdef __cplusplus
34
35 struct GNUNET_CADET_TunnelMessage;
36 extern "C"
37 {
38 #if 0
39   /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 /******************************************************************************/
45 /********************      CADET NETWORK MESSAGES     **************************/
46 /******************************************************************************/
47
48 GNUNET_NETWORK_STRUCT_BEGIN
49
50
51 /******************************************************************************/
52 /*****************************   CONNECTION  **********************************/
53 /******************************************************************************/
54
55
56 /**
57  * Message for cadet connection creation.
58  */
59 struct GNUNET_CADET_ConnectionCreate
60 {
61   /**
62    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
63    *
64    * Size: sizeof (struct GNUNET_CADET_ConnectionCreate) +
65    *       path_length * sizeof (struct GNUNET_PeerIdentity)
66    */
67   struct GNUNET_MessageHeader header;
68
69   /**
70    * For alignment.
71    */
72   uint32_t reserved GNUNET_PACKED;
73   
74   /**
75    * ID of the connection
76    */
77   struct GNUNET_CADET_Hash cid;
78
79   /**
80    * path_length structs defining the *whole* path from the origin [0] to the
81    * final destination [path_length-1].
82    */
83   /* struct GNUNET_PeerIdentity peers[path_length]; */
84 };
85
86
87 /**
88  * Message for ack'ing a connection
89  */
90 struct GNUNET_CADET_ConnectionACK
91 {
92   /**
93    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK
94    */
95   struct GNUNET_MessageHeader header;
96
97   /**
98    * For alignment.
99    */
100   uint32_t reserved GNUNET_PACKED;
101
102   /**
103    * ID of the connection.
104    */
105   struct GNUNET_CADET_Hash cid;
106
107 };
108
109
110 /**
111  * Message for notifying a disconnection in a path
112  */
113 struct GNUNET_CADET_ConnectionBroken
114 {
115   /**
116    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
117    */
118   struct GNUNET_MessageHeader header;
119
120   /**
121    * For alignment.
122    */
123   uint32_t reserved GNUNET_PACKED;
124
125   /**
126    * ID of the connection.
127    */
128   struct GNUNET_CADET_Hash cid;
129
130   /**
131    * ID of the endpoint
132    */
133   struct GNUNET_PeerIdentity peer1;
134
135   /**
136    * ID of the endpoint
137    */
138   struct GNUNET_PeerIdentity peer2;
139 };
140
141
142 /**
143  * Message to destroy a connection.
144  */
145 struct GNUNET_CADET_ConnectionDestroy
146 {
147   /**
148    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
149    */
150   struct GNUNET_MessageHeader header;
151
152   /**
153    * For alignment.
154    */
155   uint32_t reserved GNUNET_PACKED;
156
157   /**
158    * ID of the connection.
159    */
160   struct GNUNET_CADET_Hash cid;
161 };
162
163
164 /**
165  * Message to acknowledge cadet encrypted traffic.
166  */
167 struct GNUNET_CADET_ACK
168 {
169   /**
170    * Type: #GNUNET_MESSAGE_TYPE_CADET_ACK
171    */
172   struct GNUNET_MessageHeader header;
173
174   /**
175    * Maximum packet ID authorized.
176    */
177   uint32_t ack GNUNET_PACKED;
178
179   /**
180    * ID of the connection.
181    */
182   struct GNUNET_CADET_Hash cid;
183 };
184
185
186 /**
187  * Message to query a peer about its Flow Control status regarding a tunnel.
188  */
189 struct GNUNET_CADET_Poll
190 {
191   /**
192    * Type: #GNUNET_MESSAGE_TYPE_CADET_POLL
193    */
194   struct GNUNET_MessageHeader header;
195
196   /**
197    * Last packet sent.
198    */
199   uint32_t pid GNUNET_PACKED;
200
201   /**
202    * ID of the connection.
203    */
204   struct GNUNET_CADET_Hash cid;
205
206 };
207
208
209
210 /******************************************************************************/
211 /*******************************   TUNNEL   ***********************************/
212 /******************************************************************************/
213
214 /**
215  * Flags to be used in GNUNET_CADET_KX.
216  */
217 enum GNUNET_CADET_KX_Flags {
218
219   /**
220    * Should the peer reply with its KX details?
221    */
222   GNUNET_CADET_KX_FLAG_NONE = 0,
223
224   /**
225    * The peer should reply with its KX details?
226    */
227   GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
228 };
229
230
231 /**
232  * Message for a Key eXchange for a tunnel.
233  */
234 struct GNUNET_CADET_KX
235 {
236   /**
237    * Type: #GNUNET_MESSAGE_TYPE_CADET_KX.
238    */
239   struct GNUNET_MessageHeader header;
240
241   /**
242    * Flags for the key exchange in NBO, based on
243    * `enum GNUNET_CADET_KX_Flags`.
244    */
245   uint32_t flags GNUNET_PACKED;
246
247   /**
248    * ID of the connection.
249    */
250   struct GNUNET_CADET_Hash cid;
251
252   /**
253    * Sender's ephemeral public ECC key encoded in a
254    * format suitable for network transmission, as created
255    * using 'gcry_sexp_sprint'.
256    */
257   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
258
259   /**
260    * Sender's next ephemeral public ECC key encoded in a
261    * format suitable for network transmission, as created
262    * using 'gcry_sexp_sprint'.
263    */
264   struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
265 };
266
267
268 /**
269  * Axolotl tunnel message.
270  */
271 struct GNUNET_CADET_Encrypted
272 {
273   /**
274    * Type: #GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED
275    */
276   struct GNUNET_MessageHeader header;
277
278   /**
279    * ID of the packet (hop by hop).
280    */
281   uint32_t pid GNUNET_PACKED;
282
283   /**
284    * ID of the connection.
285    */
286   struct GNUNET_CADET_Hash cid;
287
288   /**
289    * MAC of the encrypted message, used to verify message integrity.
290    * Everything after this value  will be encrypted with the header key
291    * and authenticated.
292    */
293   struct GNUNET_CADET_Hash hmac;
294
295   /**************** AX_HEADER start ****************/
296
297   /**
298    * Number of messages sent with the current ratchet key.
299    */
300   uint32_t Ns GNUNET_PACKED;
301
302   /**
303    * Number of messages sent with the previous ratchet key.
304    */
305   uint32_t PNs GNUNET_PACKED;
306
307   /**
308    * Current ratchet key.
309    */
310   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
311
312   /**************** AX_HEADER  end  ****************/
313
314   /**
315    * Encrypted content follows.
316    */
317 };
318
319
320
321 /******************************************************************************/
322 /*******************************   CHANNEL  ***********************************/
323 /******************************************************************************/
324
325 /**
326  * Message to create a Channel.
327  */
328 struct GNUNET_CADET_ChannelCreate
329 {
330   /**
331    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
332    */
333   struct GNUNET_MessageHeader header;
334
335   /**
336    * Channel options.
337    */
338   uint32_t opt GNUNET_PACKED;
339
340   /**
341    * Destination port.
342    */
343   struct GNUNET_HashCode port;
344
345   /**
346    * ID of the channel
347    */
348   CADET_ChannelNumber chid GNUNET_PACKED;
349 };
350
351
352 /**
353  * Message to manage a Channel (ACK, NACK, Destroy).
354  */
355 struct GNUNET_CADET_ChannelManage
356 {
357   /**
358    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
359    */
360   struct GNUNET_MessageHeader header;
361
362   /**
363    * ID of the channel
364    */
365   CADET_ChannelNumber chid GNUNET_PACKED;
366 };
367
368
369 /**
370  * Message for cadet data traffic.
371  */
372 struct GNUNET_CADET_Data
373 {
374   /**
375    * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
376    *       #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
377    */
378   struct GNUNET_MessageHeader header;
379
380   /**
381    * Unique ID of the payload message
382    */
383   uint32_t mid GNUNET_PACKED;
384
385   /**
386    * ID of the channel
387    */
388   CADET_ChannelNumber chid GNUNET_PACKED;
389
390   /**
391    * Payload follows
392    */
393 };
394
395
396 /**
397  * Message to acknowledge end-to-end data.
398  */
399 struct GNUNET_CADET_DataACK
400 {
401   /**
402    * Type: GNUNET_MESSAGE_TYPE_CADET_DATA_ACK
403    */
404   struct GNUNET_MessageHeader header;
405
406   /**
407    * ID of the channel
408    */
409   CADET_ChannelNumber chid GNUNET_PACKED;
410
411   /**
412    * Bitfield of already-received newer messages
413    * pid +  1 @ LSB
414    * pid + 64 @ MSB
415    */
416   uint64_t futures GNUNET_PACKED;
417
418   /**
419    * Last message ID received.
420    */
421   uint32_t mid GNUNET_PACKED;
422 };
423
424
425
426 GNUNET_NETWORK_STRUCT_END
427
428 #if 0                           /* keep Emacsens' auto-indent happy */
429 {
430 #endif
431 #ifdef __cplusplus
432 }
433 #endif
434
435 /* ifndef CADET_PROTOCOL_H */
436 #endif
437 /* end of cadet_protocol.h */