- Always send traffic coming from channel, even overfilling connection buffer. Client...
[oweals/gnunet.git] / src / cadet / cadet_protocol.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 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  * Message to create a Channel.
242  */
243 struct GNUNET_CADET_ChannelCreate
244 {
245   /**
246    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
247    */
248   struct GNUNET_MessageHeader header;
249
250   /**
251    * ID of the channel
252    */
253   CADET_ChannelNumber chid GNUNET_PACKED;
254
255   /**
256    * Destination port.
257    */
258   uint32_t port GNUNET_PACKED;
259
260   /**
261    * Channel options.
262    */
263   uint32_t opt GNUNET_PACKED;
264 };
265
266
267 /**
268  * Message to manage a Channel (ACK, NACK, Destroy).
269  */
270 struct GNUNET_CADET_ChannelManage
271 {
272   /**
273    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
274    */
275   struct GNUNET_MessageHeader header;
276
277   /**
278    * ID of the channel
279    */
280   CADET_ChannelNumber chid GNUNET_PACKED;
281 };
282
283
284 /**
285  * Message for cadet data traffic.
286  */
287 struct GNUNET_CADET_Data
288 {
289     /**
290      * Type: GNUNET_MESSAGE_TYPE_CADET_UNICAST,
291      *       GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
292      */
293   struct GNUNET_MessageHeader header;
294
295     /**
296      * Unique ID of the payload message
297      */
298   uint32_t mid GNUNET_PACKED;
299
300     /**
301      * ID of the channel
302      */
303   CADET_ChannelNumber chid GNUNET_PACKED;
304
305     /**
306      * Payload follows
307      */
308 };
309
310
311 /**
312  * Message to acknowledge end-to-end data.
313  */
314 struct GNUNET_CADET_DataACK
315 {
316   /**
317    * Type: GNUNET_MESSAGE_TYPE_CADET_DATA_ACK
318    */
319   struct GNUNET_MessageHeader header;
320
321   /**
322    * ID of the channel
323    */
324   CADET_ChannelNumber chid GNUNET_PACKED;
325
326   /**
327    * Bitfield of already-received newer messages
328    * pid +  1 @ LSB
329    * pid + 64 @ MSB
330    */
331   uint64_t futures GNUNET_PACKED;
332
333   /**
334    * Last message ID received.
335    */
336   uint32_t mid GNUNET_PACKED;
337 };
338
339
340 /**
341  * Message to acknowledge cadet encrypted traffic.
342  */
343 struct GNUNET_CADET_ACK
344 {
345     /**
346      * Type: GNUNET_MESSAGE_TYPE_CADET_ACK
347      */
348   struct GNUNET_MessageHeader header;
349
350     /**
351      * Maximum packet ID authorized.
352      */
353   uint32_t ack GNUNET_PACKED;
354
355     /**
356      * ID of the connection.
357      */
358   struct GNUNET_CADET_Hash cid;
359 };
360
361
362 /**
363  * Message to query a peer about its Flow Control status regarding a tunnel.
364  */
365 struct GNUNET_CADET_Poll
366 {
367     /**
368      * Type: GNUNET_MESSAGE_TYPE_CADET_POLL
369      */
370   struct GNUNET_MessageHeader header;
371
372     /**
373      * Last packet sent.
374      */
375   uint32_t pid GNUNET_PACKED;
376
377     /**
378      * ID of the connection.
379      */
380   struct GNUNET_CADET_Hash cid;
381
382 };
383
384
385 /**
386  * Message for notifying a disconnection in a path
387  */
388 struct GNUNET_CADET_ConnectionBroken
389 {
390     /**
391      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
392      */
393   struct GNUNET_MessageHeader header;
394
395     /**
396      * ID of the connection.
397      */
398   struct GNUNET_CADET_Hash cid;
399
400     /**
401      * ID of the endpoint
402      */
403   struct GNUNET_PeerIdentity peer1;
404
405     /**
406      * ID of the endpoint
407      */
408   struct GNUNET_PeerIdentity peer2;
409 };
410
411
412 /**
413  * Message to destroy a connection.
414  */
415 struct GNUNET_CADET_ConnectionDestroy
416 {
417     /**
418      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
419      */
420   struct GNUNET_MessageHeader header;
421
422     /**
423      * ID of the connection.
424      */
425   struct GNUNET_CADET_Hash cid;
426 };
427
428
429 GNUNET_NETWORK_STRUCT_END
430
431 #if 0                           /* keep Emacsens' auto-indent happy */
432 {
433 #endif
434 #ifdef __cplusplus
435 }
436 #endif
437
438 /* ifndef CADET_PROTOCOL_H */
439 #endif
440 /* end of cadet_protocol.h */