- refactor to check messages from both enc systems
[oweals/gnunet.git] / src / cadet / cadet_protocol.h
1 /*
2      This file is part of GNUnet.
3      Copyright (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 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      * ID of the connection
65      */
66   struct GNUNET_CADET_Hash cid;
67
68     /**
69      * path_length structs defining the *whole* path from the origin [0] to the
70      * final destination [path_length-1].
71      */
72   /* struct GNUNET_PeerIdentity peers[path_length]; */
73 };
74
75 /**
76  * Message for ack'ing a connection
77  */
78 struct GNUNET_CADET_ConnectionACK
79 {
80     /**
81      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK
82      */
83   struct GNUNET_MessageHeader header;
84
85     /**
86      * ID of the connection.
87      */
88   struct GNUNET_CADET_Hash cid;
89
90 };
91
92
93 /**
94  * Message for encapsulation of a Key eXchange message in a connection.
95  */
96 struct GNUNET_CADET_KX
97 {
98     /**
99      * Type: GNUNET_MESSAGE_TYPE_CADET_KX.
100      */
101   struct GNUNET_MessageHeader header;
102
103     /**
104      * ID of the connection.
105      */
106   struct GNUNET_CADET_Hash cid;
107
108   /* Specific KX message follows. */
109 };
110
111
112 /**
113  * Message transmitted with the signed ephemeral key of a peer.  The
114  * session key is then derived from the two ephemeral keys (ECDHE).
115  *
116  * As far as possible, same as CORE's EphemeralKeyMessage.
117  */
118 struct GNUNET_CADET_KX_Ephemeral
119 {
120
121   /**
122    * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL.
123    */
124   struct GNUNET_MessageHeader header;
125
126   /**
127    * Status of the sender (should be in "enum PeerStateMachine"), nbo.
128    */
129   int32_t sender_status GNUNET_PACKED;
130
131   /**
132    * An ECC signature of the 'origin' asserting the validity of
133    * the given ephemeral key.
134    */
135   struct GNUNET_CRYPTO_EddsaSignature signature;
136
137   /**
138    * Information about what is being signed.
139    */
140   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
141
142   /**
143    * At what time was this key created (beginning of validity).
144    */
145   struct GNUNET_TIME_AbsoluteNBO creation_time;
146
147   /**
148    * When does the given ephemeral key expire (end of validity).
149    */
150   struct GNUNET_TIME_AbsoluteNBO expiration_time;
151
152   /**
153    * Ephemeral public ECC key (always for NIST P-521) encoded in a format
154    * suitable for network transmission as created using 'gcry_sexp_sprint'.
155    */
156   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
157
158   /**
159    * Public key of the signing peer
160    * (persistent version, not the ephemeral public key).
161    */
162   struct GNUNET_PeerIdentity origin_identity;
163
164   /**
165    * Seed for the IV of nonce.
166    */
167   uint32_t iv GNUNET_PACKED;
168
169   /**
170    * Nonce to check liveness of peer.
171    */
172   uint32_t nonce GNUNET_PACKED;
173 };
174
175
176 /**
177  * Response to a PING.  Includes data from the original PING.
178  */
179 struct GNUNET_CADET_KX_Pong
180 {
181   /**
182    * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_PONG.
183    */
184   struct GNUNET_MessageHeader header;
185
186   /**
187    * Seed for the IV
188    */
189   uint32_t iv GNUNET_PACKED;
190
191   /**
192    * Same nonce as in the reve.
193    */
194   uint32_t nonce GNUNET_PACKED;
195 };
196
197
198 /**
199  * Tunnel(ed) message.
200  */
201 struct GNUNET_CADET_Encrypted
202 {
203   /**
204    * Type: GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED
205    */
206   struct GNUNET_MessageHeader header;
207
208   /**
209    * ID of the connection.
210    */
211   struct GNUNET_CADET_Hash cid;
212
213   /**
214    * ID of the packet (hop by hop).
215    */
216   uint32_t pid GNUNET_PACKED;
217
218   /**
219    * Number of hops to live.
220    */
221   uint32_t ttl GNUNET_PACKED;
222
223   /**
224    * Initialization Vector for payload encryption.
225    */
226   uint32_t iv GNUNET_PACKED;
227
228   /**
229    * MAC of the encrypted message, used to verify message integrity.
230    * Everything after this value  will be encrypted and authenticated.
231    */
232   struct GNUNET_CADET_Hash hmac;
233
234   /**
235    * Encrypted content follows.
236    */
237 };
238
239
240 /**
241  * Axolotl tunnel message.
242  */
243 struct GNUNET_CADET_AX
244 {
245   /**
246    * Type: GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
247    */
248   struct GNUNET_MessageHeader header;
249
250   /**
251    * ID of the connection.
252    */
253   struct GNUNET_CADET_Hash cid;
254
255   /**
256    * ID of the packet (hop by hop).
257    */
258   uint32_t pid GNUNET_PACKED;
259
260   /**
261    * Number of hops to live.
262    */
263   uint32_t ttl GNUNET_PACKED;
264
265   /**
266    * Initialization Vector for payload encryption.
267    */
268   uint32_t iv GNUNET_PACKED;
269
270   /**
271    * MAC of the encrypted message, used to verify message integrity.
272    * Everything after this value  will be encrypted and authenticated.
273    */
274   struct GNUNET_CADET_Hash hmac;
275
276   /**
277    * Encrypted content follows.
278    */
279 };
280
281
282 /**
283  * Message to create a Channel.
284  */
285 struct GNUNET_CADET_ChannelCreate
286 {
287   /**
288    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
289    */
290   struct GNUNET_MessageHeader header;
291
292   /**
293    * ID of the channel
294    */
295   CADET_ChannelNumber chid GNUNET_PACKED;
296
297   /**
298    * Destination port.
299    */
300   uint32_t port GNUNET_PACKED;
301
302   /**
303    * Channel options.
304    */
305   uint32_t opt GNUNET_PACKED;
306 };
307
308
309 /**
310  * Message to manage a Channel (ACK, NACK, Destroy).
311  */
312 struct GNUNET_CADET_ChannelManage
313 {
314   /**
315    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
316    */
317   struct GNUNET_MessageHeader header;
318
319   /**
320    * ID of the channel
321    */
322   CADET_ChannelNumber chid GNUNET_PACKED;
323 };
324
325
326 /**
327  * Message for cadet data traffic.
328  */
329 struct GNUNET_CADET_Data
330 {
331     /**
332      * Type: GNUNET_MESSAGE_TYPE_CADET_UNICAST,
333      *       GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
334      */
335   struct GNUNET_MessageHeader header;
336
337     /**
338      * Unique ID of the payload message
339      */
340   uint32_t mid GNUNET_PACKED;
341
342     /**
343      * ID of the channel
344      */
345   CADET_ChannelNumber chid GNUNET_PACKED;
346
347     /**
348      * Payload follows
349      */
350 };
351
352
353 /**
354  * Message to acknowledge end-to-end data.
355  */
356 struct GNUNET_CADET_DataACK
357 {
358   /**
359    * Type: GNUNET_MESSAGE_TYPE_CADET_DATA_ACK
360    */
361   struct GNUNET_MessageHeader header;
362
363   /**
364    * ID of the channel
365    */
366   CADET_ChannelNumber chid GNUNET_PACKED;
367
368   /**
369    * Bitfield of already-received newer messages
370    * pid +  1 @ LSB
371    * pid + 64 @ MSB
372    */
373   uint64_t futures GNUNET_PACKED;
374
375   /**
376    * Last message ID received.
377    */
378   uint32_t mid GNUNET_PACKED;
379 };
380
381
382 /**
383  * Message to acknowledge cadet encrypted traffic.
384  */
385 struct GNUNET_CADET_ACK
386 {
387     /**
388      * Type: GNUNET_MESSAGE_TYPE_CADET_ACK
389      */
390   struct GNUNET_MessageHeader header;
391
392     /**
393      * Maximum packet ID authorized.
394      */
395   uint32_t ack GNUNET_PACKED;
396
397     /**
398      * ID of the connection.
399      */
400   struct GNUNET_CADET_Hash cid;
401 };
402
403
404 /**
405  * Message to query a peer about its Flow Control status regarding a tunnel.
406  */
407 struct GNUNET_CADET_Poll
408 {
409     /**
410      * Type: GNUNET_MESSAGE_TYPE_CADET_POLL
411      */
412   struct GNUNET_MessageHeader header;
413
414     /**
415      * Last packet sent.
416      */
417   uint32_t pid GNUNET_PACKED;
418
419     /**
420      * ID of the connection.
421      */
422   struct GNUNET_CADET_Hash cid;
423
424 };
425
426
427 /**
428  * Message for notifying a disconnection in a path
429  */
430 struct GNUNET_CADET_ConnectionBroken
431 {
432     /**
433      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
434      */
435   struct GNUNET_MessageHeader header;
436
437     /**
438      * ID of the connection.
439      */
440   struct GNUNET_CADET_Hash cid;
441
442     /**
443      * ID of the endpoint
444      */
445   struct GNUNET_PeerIdentity peer1;
446
447     /**
448      * ID of the endpoint
449      */
450   struct GNUNET_PeerIdentity peer2;
451 };
452
453
454 /**
455  * Message to destroy a connection.
456  */
457 struct GNUNET_CADET_ConnectionDestroy
458 {
459     /**
460      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
461      */
462   struct GNUNET_MessageHeader header;
463
464     /**
465      * ID of the connection.
466      */
467   struct GNUNET_CADET_Hash cid;
468 };
469
470
471 GNUNET_NETWORK_STRUCT_END
472
473 #if 0                           /* keep Emacsens' auto-indent happy */
474 {
475 #endif
476 #ifdef __cplusplus
477 }
478 #endif
479
480 /* ifndef CADET_PROTOCOL_H */
481 #endif
482 /* end of cadet_protocol.h */