- fixes
[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 #include "mesh_enc.h"
32
33 #ifdef __cplusplus
34
35 struct GNUNET_MESH_TunnelMessage;
36 extern "C"
37 {
38 #if 0
39   /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 /******************************************************************************/
45 /********************      MESH NETWORK MESSAGES     **************************/
46 /******************************************************************************/
47
48 GNUNET_NETWORK_STRUCT_BEGIN
49
50 /**
51  * Message for mesh connection creation.
52  * TODO onionify path, add random tunnel ID
53  */
54 struct GNUNET_MESH_ConnectionCreate
55 {
56     /**
57      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE
58      *
59      * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
60      *              path_length * sizeof (struct GNUNET_PeerIdentity)
61      */
62   struct GNUNET_MessageHeader header;
63
64     /**
65      * ID of the connection
66      */
67   struct GNUNET_HashCode cid;
68
69     /**
70      * path_length structs defining the *whole* path from the origin [0] to the
71      * final destination [path_length-1].
72      */
73   /* struct GNUNET_PeerIdentity peers[path_length]; */
74 };
75
76 /**
77  * Message for ack'ing a connection
78  */
79 struct GNUNET_MESH_ConnectionACK
80 {
81     /**
82      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK
83      */
84   struct GNUNET_MessageHeader header;
85
86     /**
87      * Always 0.
88      */
89   uint32_t reserved GNUNET_PACKED;
90
91     /**
92      * ID of the connection.
93      */
94   struct GNUNET_HashCode cid;
95
96   /* TODO: signature */
97 };
98
99
100 /**
101  * Message for encapsulation of a Key eXchange message in a connection.
102  */
103 struct GNUNET_MESH_KX
104 {
105     /**
106      * Type: GNUNET_MESSAGE_TYPE_MESH_KX.
107      */
108   struct GNUNET_MessageHeader header;
109
110     /**
111      * Always 0.
112      */
113   uint32_t reserved GNUNET_PACKED;
114
115     /**
116      * ID of the connection.
117      */
118   struct GNUNET_HashCode cid;
119
120   /* Specific KX message follows. */
121 };
122
123
124 /**
125  * Message transmitted with the signed ephemeral key of a peer.  The
126  * session key is then derived from the two ephemeral keys (ECDHE).
127  *
128  * As far as possible, same as CORE's EphemeralKeyMessage.
129  */
130 struct GNUNET_MESH_KX_Ephemeral
131 {
132
133   /**
134    * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_EPHEMERAL.
135    */
136   struct GNUNET_MessageHeader header;
137
138   /**
139    * Status of the sender (should be in "enum PeerStateMachine"), nbo.
140    */
141   int32_t sender_status GNUNET_PACKED;
142
143   /**
144    * An ECC signature of the 'origin' asserting the validity of
145    * the given ephemeral key.
146    */
147   struct GNUNET_CRYPTO_EddsaSignature signature;
148
149   /**
150    * Information about what is being signed.
151    */
152   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
153
154   /**
155    * At what time was this key created (beginning of validity).
156    */
157   struct GNUNET_TIME_AbsoluteNBO creation_time;
158
159   /**
160    * When does the given ephemeral key expire (end of validity).
161    */
162   struct GNUNET_TIME_AbsoluteNBO expiration_time;
163
164   /**
165    * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable
166    * for network transmission as created using 'gcry_sexp_sprint'.
167    */
168   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
169
170   /**
171    * Public key of the signing peer (persistent version, not the ephemeral public key).
172    */
173   struct GNUNET_PeerIdentity origin_identity;
174 };
175
176
177 /**
178  * We're sending an (encrypted) PING to the other peer to check if he
179  * can decrypt.  The other peer should respond with a PONG with the
180  * same content, except this time encrypted with the receiver's key.
181  */
182 struct GNUNET_MESH_KX_Ping
183 {
184   /**
185    * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PING.
186    */
187   struct GNUNET_MessageHeader header;
188
189   /**
190    * Seed for the IV
191    */
192   uint32_t iv GNUNET_PACKED;
193
194   /**
195    * Intended target of the PING, used primarily to check
196    * that decryption actually worked.
197    */
198   struct GNUNET_PeerIdentity target;
199
200   /**
201    * Random number chosen to make reply harder.
202    */
203   uint32_t nonce GNUNET_PACKED;
204 };
205
206
207 /**
208  * Response to a PING.  Includes data from the original PING.
209  */
210 struct GNUNET_MESH_KX_Pong
211 {
212   /**
213    * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PONG.
214    */
215   struct GNUNET_MessageHeader header;
216
217   /**
218    * Seed for the IV
219    */
220   uint32_t iv GNUNET_PACKED;
221
222   /**
223    * Intended target of the PING, used primarily to check
224    * that decryption actually worked.
225    */
226   struct GNUNET_PeerIdentity target;
227
228   /**
229    * Same nonce as in the reve.
230    */
231   uint32_t nonce GNUNET_PACKED;
232 };
233
234
235 /**
236  * Tunnel(ed) message.
237  */
238 struct GNUNET_MESH_Encrypted
239 {
240   /**
241    * Type: GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED
242    */
243   struct GNUNET_MessageHeader header;
244
245   /**
246    * Initialization Vector for payload encryption.
247    */
248   uint32_t iv GNUNET_PACKED;
249
250   /**
251    * ID of the connection.
252    */
253   struct GNUNET_HashCode 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    * Encrypted content follows.
267    */
268 };
269
270 struct GNUNET_MESH_ChannelCreate
271 {
272   /**
273    * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE
274    */
275   struct GNUNET_MessageHeader header;
276
277   /**
278    * ID of the channel
279    */
280   MESH_ChannelNumber chid GNUNET_PACKED;
281
282   /**
283    * Destination port.
284    */
285   uint32_t port GNUNET_PACKED;
286
287   /**
288    * Channel options.
289    */
290   uint32_t opt GNUNET_PACKED;
291 };
292
293 struct GNUNET_MESH_ChannelManage
294 {
295   /**
296    * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|DESTROY}
297    */
298   struct GNUNET_MessageHeader header;
299
300   /**
301    * ID of the channel
302    */
303   MESH_ChannelNumber chid GNUNET_PACKED;
304 };
305
306 /**
307  * Message for mesh data traffic.
308  */
309 struct GNUNET_MESH_Data
310 {
311     /**
312      * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST,
313      *       GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
314      */
315   struct GNUNET_MessageHeader header;
316
317     /**
318      * Unique ID of the payload message
319      */
320   uint32_t mid GNUNET_PACKED;
321
322     /**
323      * ID of the channel
324      */
325   MESH_ChannelNumber chid GNUNET_PACKED;
326
327     /**
328      * Payload follows
329      */
330 };
331
332
333 /**
334  * Message to acknowledge end-to-end data.
335  */
336 struct GNUNET_MESH_DataACK
337 {
338   /**
339    * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK
340    */
341   struct GNUNET_MessageHeader header;
342
343   /**
344    * ID of the channel
345    */
346   MESH_ChannelNumber chid GNUNET_PACKED;
347
348   /**
349    * Bitfield of already-received newer messages
350    * pid +  1 @ LSB
351    * pid + 64 @ MSB
352    */
353   uint64_t futures GNUNET_PACKED;
354
355   /**
356    * Last message ID received.
357    */
358   uint32_t mid GNUNET_PACKED;
359 };
360
361
362 /**
363  * Message to acknowledge mesh encrypted traffic.
364  */
365 struct GNUNET_MESH_ACK
366 {
367     /**
368      * Type: GNUNET_MESSAGE_TYPE_MESH_ACK
369      */
370   struct GNUNET_MessageHeader header;
371
372     /**
373      * Maximum packet ID authorized.
374      */
375   uint32_t ack GNUNET_PACKED;
376
377     /**
378      * ID of the connection.
379      */
380   struct GNUNET_HashCode cid;
381 };
382
383
384 /**
385  * Message to query a peer about its Flow Control status regarding a tunnel.
386  */
387 struct GNUNET_MESH_Poll
388 {
389   /**
390    * Type: GNUNET_MESSAGE_TYPE_MESH_POLL
391    */
392   struct GNUNET_MessageHeader header;
393
394   /**
395    * Last packet sent.
396    */
397   uint32_t pid GNUNET_PACKED;
398
399     /**
400      * ID of the connection.
401      */
402   struct GNUNET_HashCode cid;
403
404 };
405
406
407 /**
408  * Message for notifying a disconnection in a path
409  */
410 struct GNUNET_MESH_ConnectionBroken
411 {
412     /**
413      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN
414      */
415   struct GNUNET_MessageHeader header;
416
417     /**
418      * Always 0.
419      */
420   uint32_t reserved GNUNET_PACKED;
421
422     /**
423      * ID of the connection.
424      */
425   struct GNUNET_HashCode cid;
426
427     /**
428      * ID of the endpoint
429      */
430   struct GNUNET_PeerIdentity peer1;
431
432     /**
433      * ID of the endpoint
434      */
435   struct GNUNET_PeerIdentity peer2;
436
437   /* TODO: signature */
438 };
439
440
441 /**
442  * Message to destroy a connection.
443  */
444 struct GNUNET_MESH_ConnectionDestroy
445 {
446     /**
447      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY
448      */
449   struct GNUNET_MessageHeader header;
450
451     /**
452      * Always 0.
453      */
454   uint32_t reserved GNUNET_PACKED;
455
456     /**
457      * ID of the connection.
458      */
459   struct GNUNET_HashCode cid;
460
461   /* TODO: signature */
462 };
463
464
465 /**
466  * Message to keep a connection alive.
467  */
468 struct GNUNET_MESH_ConnectionKeepAlive
469 {
470   /**
471    * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE
472    */
473   struct GNUNET_MessageHeader header;
474
475   /**
476    * Always 0.
477    */
478   uint32_t reserved GNUNET_PACKED;
479
480   /**
481    * ID of the connection.
482    */
483   struct GNUNET_HashCode cid;
484 };
485
486
487
488 GNUNET_NETWORK_STRUCT_END
489
490 #if 0                           /* keep Emacsens' auto-indent happy */
491 {
492 #endif
493 #ifdef __cplusplus
494 }
495 #endif
496
497 /* ifndef MESH_PROTOCOL_H */
498 #endif
499 /* end of mesh_protocol.h */