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