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