97620a9b6ab0ad0b0f47dcd91d86cc6efeaea033
[oweals/gnunet.git] / src / transport / transport.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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  * @file transport/transport.h
23  * @brief common internal definitions for transport service
24  * @author Christian Grothoff
25  */
26 #ifndef TRANSPORT_H
27 #define TRANSPORT_H
28
29 #include "gnunet_crypto_lib.h"
30 #include "gnunet_time_lib.h"
31 #include "gnunet_transport_service.h"
32 #include "gnunet_constants.h"
33
34 #define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
35
36 #define DEBUG_TRANSPORT_TIMEOUT GNUNET_EXTRA_LOGGING
37
38 #define DEBUG_TRANSPORT_DISCONNECT GNUNET_EXTRA_LOGGING
39
40 #define DEBUG_TRANSPORT_API GNUNET_EXTRA_LOGGING
41
42 /**
43  * For how long do we allow unused bandwidth
44  * from the past to carry over into the future? (in seconds)
45  */
46 #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
47
48 /**
49  * How often do we (at most) do a full quota
50  * recalculation? (in ms)
51  */
52 #define MIN_QUOTA_REFRESH_TIME 2000
53
54 /**
55  * Maximum frequency for re-evaluating latencies for all transport addresses.
56  */
57 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
58
59 /**
60  * Maximum frequency for re-evaluating latencies for connected addresses.
61  */
62 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
63
64 /**
65  * Message from the transport service to the library
66  * asking to check if both processes agree about this
67  * peers identity.
68  */
69 struct StartMessage
70 {
71
72   /**
73    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
74    */
75   struct GNUNET_MessageHeader header;
76
77   /**
78    * 0: no options
79    * 1: The 'self' field should be checked
80    * 2: this client is interested in payload traffic
81    */
82   uint32_t options;
83
84   /**
85    * Identity we think we have.  If it does not match, the
86    * receiver should print out an error message and disconnect.
87    */
88   struct GNUNET_PeerIdentity self;
89
90 };
91
92
93 /**
94  * Message from the transport service to the library
95  * informing about neighbors.
96  */
97 struct ConnectInfoMessage
98 {
99
100   /**
101    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
102    */
103   struct GNUNET_MessageHeader header;
104
105   /**
106    * Number of ATS key-value pairs that follow this struct
107    * (excluding the 0-terminator).
108    */
109   uint32_t ats_count GNUNET_PACKED;
110
111   /**
112    * Identity of the new neighbour.
113    */
114   struct GNUNET_PeerIdentity id;
115 };
116
117
118 /**
119  * Message from the transport service to the library
120  * informing about disconnects.
121  */
122 struct DisconnectInfoMessage
123 {
124
125   /**
126    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
127    */
128   struct GNUNET_MessageHeader header;
129
130   /**
131    * Reserved, always zero.
132    */
133   uint32_t reserved GNUNET_PACKED;
134
135   /**
136    * Who got disconnected?
137    */
138   struct GNUNET_PeerIdentity peer;
139
140 };
141
142 /**
143  * Message type for sending a request connect message
144  * to the transport service.  Must be done before transport
145  * api will allow messages to be queued/sent to transport
146  * service for transmission to a peer.
147  */
148 struct TransportRequestConnectMessage
149 {
150   /**
151    *  Message header
152    */
153   struct GNUNET_MessageHeader header;
154
155   /**
156    * For alignment.
157    */
158   uint32_t reserved;
159
160   /**
161    * Identity of the peer we would like to connect to.
162    */
163   struct GNUNET_PeerIdentity peer;
164 };
165
166 /**
167  * Message used to set a particular bandwidth quota.  Sent TO the
168  * service to set an incoming quota, sent FROM the service to update
169  * an outgoing quota.
170  */
171 struct QuotaSetMessage
172 {
173
174   /**
175    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
176    */
177   struct GNUNET_MessageHeader header;
178
179   /**
180    * Quota.
181    */
182   struct GNUNET_BANDWIDTH_Value32NBO quota;
183
184   /**
185    * About which peer are we talking here?
186    */
187   struct GNUNET_PeerIdentity peer;
188
189 };
190
191
192 /**
193  * Message used to notify the transport API about a message
194  * received from the network.  The actual message follows.
195  */
196 struct InboundMessage
197 {
198
199   /**
200    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
201    */
202   struct GNUNET_MessageHeader header;
203
204   /**
205    * Number of ATS key-value pairs that follow this struct
206    * (excluding the 0-terminator).
207    */
208   uint32_t ats_count GNUNET_PACKED;
209
210   /**
211    * Which peer sent the message?
212    */
213   struct GNUNET_PeerIdentity peer;
214
215 };
216
217
218 /**
219  * Message used to notify the transport API that it can
220  * send another message to the transport service.
221  */
222 struct SendOkMessage
223 {
224
225   /**
226    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
227    */
228   struct GNUNET_MessageHeader header;
229
230   /**
231    * GNUNET_OK if the transmission succeeded,
232    * GNUNET_SYSERR if it failed (i.e. network disconnect);
233    * in either case, it is now OK for this client to
234    * send us another message for the given peer.
235    */
236   uint32_t success GNUNET_PACKED;
237
238   /**
239    * Latency estimate.
240    */
241   struct GNUNET_TIME_RelativeNBO latency;
242
243   /**
244    * Which peer can send more now?
245    */
246   struct GNUNET_PeerIdentity peer;
247
248 };
249
250
251 /**
252  * Message used to notify the transport service about a message
253  * to be transmitted to another peer.  The actual message follows.
254  */
255 struct OutboundMessage
256 {
257
258   /**
259    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
260    */
261   struct GNUNET_MessageHeader header;
262
263   /**
264    * Message priority.
265    */
266   uint32_t priority GNUNET_PACKED;
267
268   /**
269    * Allowed delay.
270    */
271   struct GNUNET_TIME_RelativeNBO timeout;
272
273   /**
274    * Which peer should receive the message?
275    */
276   struct GNUNET_PeerIdentity peer;
277
278 };
279
280
281 /**
282  * Message from the library to the transport service
283  * asking for converting a transport address to a
284  * human-readable UTF-8 string.
285  */
286 struct AddressLookupMessage
287 {
288
289   /**
290    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP
291    */
292   struct GNUNET_MessageHeader header;
293
294   /**
295    * Should the conversion use numeric IP addresses (otherwise
296    * a reverse DNS lookup is OK -- if applicable).
297    */
298   int32_t numeric_only GNUNET_PACKED;
299
300   /**
301    * timeout to give up.
302    */
303   struct GNUNET_TIME_RelativeNBO timeout;
304
305   /**
306    * Length of the (binary) address in bytes, in big-endian.
307    */
308   uint32_t addrlen GNUNET_PACKED;
309
310   /* followed by 'addrlen' bytes of the actual address, then
311    * followed by the 0-terminated name of the transport */
312 };
313
314
315 /**
316  * Message from the library to the transport service
317  * asking for human readable addresses known for a peer.
318  */
319 struct PeerAddressLookupMessage
320 {
321   /**
322    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP
323    */
324   struct GNUNET_MessageHeader header;
325
326   /**
327    * For alignment.
328    */
329   uint32_t reserved;
330
331   /**
332    * timeout to give up.  FIXME: remove in the future.
333    */
334   struct GNUNET_TIME_RelativeNBO timeout;
335
336   /**
337    * The identity of the peer to look up.
338    */
339   struct GNUNET_PeerIdentity peer;
340 };
341
342
343 /**
344  * Message from the library to the transport service
345  * asking for binary addresses known for a peer.
346  */
347 struct AddressIterateMessage
348 {
349   /**
350    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE
351    */
352   struct GNUNET_MessageHeader header;
353
354   /**
355    * For alignment.
356    */
357   uint32_t reserved;
358
359   /**
360    * timeout to give up.  FIXME: remove in the future
361    */
362   struct GNUNET_TIME_AbsoluteNBO timeout;
363
364   /**
365    * The identity of the peer to look up.
366    */
367   struct GNUNET_PeerIdentity peer;
368
369   /**
370    * One shot call or continous replies?
371    */
372   uint32_t one_shot;
373
374 };
375
376 /**
377  * Message from the transport service to the library
378  * containing binary addresses known for a peer.
379  * Memory layout:
380  * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
381  */
382 struct AddressIterateResponseMessage
383 {
384   /**
385    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY
386    */
387   struct GNUNET_MessageHeader header;
388
389   /**
390    * For alignment.
391    */
392   uint32_t reserved;
393
394     /**
395    * Peer identity
396    */
397   struct GNUNET_PeerIdentity peer;
398
399   /**
400    * address length
401    */
402   uint32_t addrlen GNUNET_PACKED;
403
404   /**
405    * length of the plugin name
406    */
407   uint32_t pluginlen GNUNET_PACKED;
408   
409 };
410
411
412 /**
413  * Change in blacklisting (either request or notification,
414  * depending on which direction it is going).
415  */
416 struct BlacklistMessage
417 {
418
419   /**
420    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
421    * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
422    */
423   struct GNUNET_MessageHeader header;
424
425   /**
426    * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed)
427    * for the response.
428    */
429   uint32_t is_allowed GNUNET_PACKED;
430
431   /**
432    * Which peer is being blacklisted or queried?
433    */
434   struct GNUNET_PeerIdentity peer;
435
436 };
437
438
439 /* end of transport.h */
440 #endif