- add underlay api implementation
[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  * 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    * Same nonce as in the reve.
224    */
225   uint32_t nonce GNUNET_PACKED;
226 };
227
228
229 /**
230  * Tunnel(ed) message.
231  */
232 struct GNUNET_MESH_Encrypted
233 {
234   /**
235    * Type: GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED
236    */
237   struct GNUNET_MessageHeader header;
238
239   /**
240    * Initialization Vector for payload encryption.
241    */
242   uint32_t iv GNUNET_PACKED;
243
244   /**
245    * ID of the connection.
246    */
247   struct GNUNET_HashCode cid;
248
249   /**
250    * ID of the packet (hop by hop).
251    */
252   uint32_t pid GNUNET_PACKED;
253
254   /**
255    * Number of hops to live.
256    */
257   uint32_t ttl GNUNET_PACKED;
258
259   /**
260    * Encrypted content follows.
261    */
262 };
263
264 struct GNUNET_MESH_ChannelCreate
265 {
266   /**
267    * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE
268    */
269   struct GNUNET_MessageHeader header;
270
271   /**
272    * ID of the channel
273    */
274   MESH_ChannelNumber chid GNUNET_PACKED;
275
276   /**
277    * Destination port.
278    */
279   uint32_t port GNUNET_PACKED;
280
281   /**
282    * Channel options.
283    */
284   uint32_t opt GNUNET_PACKED;
285 };
286
287 struct GNUNET_MESH_ChannelManage
288 {
289   /**
290    * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|NACK|DESTROY}
291    */
292   struct GNUNET_MessageHeader header;
293
294   /**
295    * ID of the channel
296    */
297   MESH_ChannelNumber chid GNUNET_PACKED;
298 };
299
300 /**
301  * Message for mesh data traffic.
302  */
303 struct GNUNET_MESH_Data
304 {
305     /**
306      * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST,
307      *       GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
308      */
309   struct GNUNET_MessageHeader header;
310
311     /**
312      * Unique ID of the payload message
313      */
314   uint32_t mid GNUNET_PACKED;
315
316     /**
317      * ID of the channel
318      */
319   MESH_ChannelNumber chid GNUNET_PACKED;
320
321     /**
322      * Payload follows
323      */
324 };
325
326
327 /**
328  * Message to acknowledge end-to-end data.
329  */
330 struct GNUNET_MESH_DataACK
331 {
332   /**
333    * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK
334    */
335   struct GNUNET_MessageHeader header;
336
337   /**
338    * ID of the channel
339    */
340   MESH_ChannelNumber chid GNUNET_PACKED;
341
342   /**
343    * Bitfield of already-received newer messages
344    * pid +  1 @ LSB
345    * pid + 64 @ MSB
346    */
347   uint64_t futures GNUNET_PACKED;
348
349   /**
350    * Last message ID received.
351    */
352   uint32_t mid GNUNET_PACKED;
353 };
354
355
356 /**
357  * Message to acknowledge mesh encrypted traffic.
358  */
359 struct GNUNET_MESH_ACK
360 {
361     /**
362      * Type: GNUNET_MESSAGE_TYPE_MESH_ACK
363      */
364   struct GNUNET_MessageHeader header;
365
366     /**
367      * Maximum packet ID authorized.
368      */
369   uint32_t ack GNUNET_PACKED;
370
371     /**
372      * ID of the connection.
373      */
374   struct GNUNET_HashCode cid;
375 };
376
377
378 /**
379  * Message to query a peer about its Flow Control status regarding a tunnel.
380  */
381 struct GNUNET_MESH_Poll
382 {
383   /**
384    * Type: GNUNET_MESSAGE_TYPE_MESH_POLL
385    */
386   struct GNUNET_MessageHeader header;
387
388   /**
389    * Last packet sent.
390    */
391   uint32_t pid GNUNET_PACKED;
392
393     /**
394      * ID of the connection.
395      */
396   struct GNUNET_HashCode cid;
397
398 };
399
400
401 /**
402  * Message for notifying a disconnection in a path
403  */
404 struct GNUNET_MESH_ConnectionBroken
405 {
406     /**
407      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN
408      */
409   struct GNUNET_MessageHeader header;
410
411     /**
412      * Always 0.
413      */
414   uint32_t reserved GNUNET_PACKED;
415
416     /**
417      * ID of the connection.
418      */
419   struct GNUNET_HashCode cid;
420
421     /**
422      * ID of the endpoint
423      */
424   struct GNUNET_PeerIdentity peer1;
425
426     /**
427      * ID of the endpoint
428      */
429   struct GNUNET_PeerIdentity peer2;
430
431   /* TODO: signature */
432 };
433
434
435 /**
436  * Message to destroy a connection.
437  */
438 struct GNUNET_MESH_ConnectionDestroy
439 {
440     /**
441      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY
442      */
443   struct GNUNET_MessageHeader header;
444
445     /**
446      * Always 0.
447      */
448   uint32_t reserved GNUNET_PACKED;
449
450     /**
451      * ID of the connection.
452      */
453   struct GNUNET_HashCode cid;
454
455   /* TODO: signature */
456 };
457
458
459 /**
460  * Message to keep a connection alive.
461  */
462 struct GNUNET_MESH_ConnectionKeepAlive
463 {
464   /**
465    * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE
466    */
467   struct GNUNET_MessageHeader header;
468
469   /**
470    * Always 0.
471    */
472   uint32_t reserved GNUNET_PACKED;
473
474   /**
475    * ID of the connection.
476    */
477   struct GNUNET_HashCode cid;
478 };
479
480
481
482 GNUNET_NETWORK_STRUCT_END
483
484 #if 0                           /* keep Emacsens' auto-indent happy */
485 {
486 #endif
487 #ifdef __cplusplus
488 }
489 #endif
490
491 /* ifndef MESH_PROTOCOL_H */
492 #endif
493 /* end of mesh_protocol.h */