-log
[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_MeshHash 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      * ID of the connection.
87      */
88   struct GNUNET_MeshHash cid;
89
90 };
91
92
93 /**
94  * Message for encapsulation of a Key eXchange message in a connection.
95  */
96 struct GNUNET_MESH_KX
97 {
98     /**
99      * Type: GNUNET_MESSAGE_TYPE_MESH_KX.
100      */
101   struct GNUNET_MessageHeader header;
102
103     /**
104      * ID of the connection.
105      */
106   struct GNUNET_MeshHash 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_MESH_KX_Ephemeral
119 {
120
121   /**
122    * Message type is GNUNET_MESSAGE_TYPE_MESH_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 suitable
154    * 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 (persistent version, not the ephemeral public key).
160    */
161   struct GNUNET_PeerIdentity origin_identity;
162 };
163
164
165 /**
166  * We're sending an (encrypted) PING to the other peer to check if he
167  * can decrypt.  The other peer should respond with a PONG with the
168  * same content, except this time encrypted with the receiver's key.
169  */
170 struct GNUNET_MESH_KX_Ping
171 {
172   /**
173    * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PING.
174    */
175   struct GNUNET_MessageHeader header;
176
177   /**
178    * Seed for the IV
179    */
180   uint32_t iv GNUNET_PACKED;
181
182   /**
183    * Intended target of the PING, used primarily to check
184    * that decryption actually worked.
185    */
186   struct GNUNET_PeerIdentity target;
187
188   /**
189    * Random number chosen to make reply harder.
190    */
191   uint32_t nonce GNUNET_PACKED;
192 };
193
194
195 /**
196  * Response to a PING.  Includes data from the original PING.
197  */
198 struct GNUNET_MESH_KX_Pong
199 {
200   /**
201    * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PONG.
202    */
203   struct GNUNET_MessageHeader header;
204
205   /**
206    * Seed for the IV
207    */
208   uint32_t iv GNUNET_PACKED;
209
210   /**
211    * Same nonce as in the reve.
212    */
213   uint32_t nonce GNUNET_PACKED;
214 };
215
216
217 /**
218  * Tunnel(ed) message.
219  */
220 struct GNUNET_MESH_Encrypted
221 {
222   /**
223    * Type: GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED
224    */
225   struct GNUNET_MessageHeader header;
226
227   /**
228    * ID of the connection.
229    */
230   struct GNUNET_MeshHash cid;
231
232   /**
233    * ID of the packet (hop by hop).
234    */
235   uint32_t pid GNUNET_PACKED;
236
237   /**
238    * Number of hops to live.
239    */
240   uint32_t ttl GNUNET_PACKED;
241
242   /**
243    * Initialization Vector for payload encryption.
244    */
245   uint32_t iv GNUNET_PACKED;
246
247   /**
248    * MAC of the encrypted message, used to verify message integrity.
249    * Everything after this value  will be encrypted and authenticated.
250    */
251   struct GNUNET_MeshHash hmac;
252
253   /**
254    * Encrypted content follows.
255    */
256 };
257
258
259 /**
260  * Message to create a Channel.
261  */
262 struct GNUNET_MESH_ChannelCreate
263 {
264   /**
265    * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE
266    */
267   struct GNUNET_MessageHeader header;
268
269   /**
270    * ID of the channel
271    */
272   MESH_ChannelNumber chid GNUNET_PACKED;
273
274   /**
275    * Destination port.
276    */
277   uint32_t port GNUNET_PACKED;
278
279   /**
280    * Channel options.
281    */
282   uint32_t opt GNUNET_PACKED;
283 };
284
285
286 /**
287  * Message to manage a Channel (ACK, NACK, Destroy).
288  */
289 struct GNUNET_MESH_ChannelManage
290 {
291   /**
292    * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|NACK|DESTROY}
293    */
294   struct GNUNET_MessageHeader header;
295
296   /**
297    * ID of the channel
298    */
299   MESH_ChannelNumber chid GNUNET_PACKED;
300 };
301
302
303 /**
304  * Message for mesh data traffic.
305  */
306 struct GNUNET_MESH_Data
307 {
308     /**
309      * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST,
310      *       GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
311      */
312   struct GNUNET_MessageHeader header;
313
314     /**
315      * Unique ID of the payload message
316      */
317   uint32_t mid GNUNET_PACKED;
318
319     /**
320      * ID of the channel
321      */
322   MESH_ChannelNumber chid GNUNET_PACKED;
323
324     /**
325      * Payload follows
326      */
327 };
328
329
330 /**
331  * Message to acknowledge end-to-end data.
332  */
333 struct GNUNET_MESH_DataACK
334 {
335   /**
336    * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK
337    */
338   struct GNUNET_MessageHeader header;
339
340   /**
341    * ID of the channel
342    */
343   MESH_ChannelNumber chid GNUNET_PACKED;
344
345   /**
346    * Bitfield of already-received newer messages
347    * pid +  1 @ LSB
348    * pid + 64 @ MSB
349    */
350   uint64_t futures GNUNET_PACKED;
351
352   /**
353    * Last message ID received.
354    */
355   uint32_t mid GNUNET_PACKED;
356 };
357
358
359 /**
360  * Message to acknowledge mesh encrypted traffic.
361  */
362 struct GNUNET_MESH_ACK
363 {
364     /**
365      * Type: GNUNET_MESSAGE_TYPE_MESH_ACK
366      */
367   struct GNUNET_MessageHeader header;
368
369     /**
370      * Maximum packet ID authorized.
371      */
372   uint32_t ack GNUNET_PACKED;
373
374     /**
375      * ID of the connection.
376      */
377   struct GNUNET_MeshHash cid;
378 };
379
380
381 /**
382  * Message to query a peer about its Flow Control status regarding a tunnel.
383  */
384 struct GNUNET_MESH_Poll
385 {
386     /**
387      * Type: GNUNET_MESSAGE_TYPE_MESH_POLL
388      */
389   struct GNUNET_MessageHeader header;
390
391     /**
392      * Last packet sent.
393      */
394   uint32_t pid GNUNET_PACKED;
395
396     /**
397      * ID of the connection.
398      */
399   struct GNUNET_MeshHash cid;
400
401 };
402
403
404 /**
405  * Message for notifying a disconnection in a path
406  */
407 struct GNUNET_MESH_ConnectionBroken
408 {
409     /**
410      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN
411      */
412   struct GNUNET_MessageHeader header;
413
414     /**
415      * ID of the connection.
416      */
417   struct GNUNET_MeshHash cid;
418
419     /**
420      * ID of the endpoint
421      */
422   struct GNUNET_PeerIdentity peer1;
423
424     /**
425      * ID of the endpoint
426      */
427   struct GNUNET_PeerIdentity peer2;
428 };
429
430
431 /**
432  * Message to destroy a connection.
433  */
434 struct GNUNET_MESH_ConnectionDestroy
435 {
436     /**
437      * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY
438      */
439   struct GNUNET_MessageHeader header;
440
441     /**
442      * ID of the connection.
443      */
444   struct GNUNET_MeshHash cid;
445 };
446
447
448 GNUNET_NETWORK_STRUCT_END
449
450 #if 0                           /* keep Emacsens' auto-indent happy */
451 {
452 #endif
453 #ifdef __cplusplus
454 }
455 #endif
456
457 /* ifndef MESH_PROTOCOL_H */
458 #endif
459 /* end of mesh_protocol.h */