- verboser log, faster start
[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
37 /**
38  * For how long do we allow unused bandwidth
39  * from the past to carry over into the future? (in seconds)
40  */
41 #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
42
43 /**
44  * How often do we (at most) do a full quota
45  * recalculation? (in ms)
46  */
47 #define MIN_QUOTA_REFRESH_TIME 2000
48
49 /**
50  * What's the maximum number of sockets transport uses for validation and
51  * neighbors
52  */
53 #define DEFAULT_MAX_FDS 256
54
55 /**
56  * Maximum frequency for re-evaluating latencies for all transport addresses.
57  */
58 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
59
60 /**
61  * Maximum frequency for re-evaluating latencies for connected addresses.
62  */
63 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
64
65 /**
66  * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
67  * included here. These values are not required outside transport_api
68  *
69  * @param cls closure
70  * @param peer the peer that connected
71  * @param ats performance data
72  * @param ats_count number of entries in ats (excluding 0-termination)
73  * @param bandwidth_in inbound bandwidth in NBO
74  * @param bandwidth_out outbound bandwidth in NBO
75  *
76  */
77
78 typedef void (*NotifyConnect) (void *cls,
79                               const struct GNUNET_PeerIdentity *peer,
80                               const struct GNUNET_ATS_Information *ats,
81                               uint32_t ats_count,
82                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
83                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
84
85 GNUNET_NETWORK_STRUCT_BEGIN
86
87 /**
88  * Message from the transport service to the library
89  * asking to check if both processes agree about this
90  * peers identity.
91  */
92 struct StartMessage
93 {
94
95   /**
96    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
97    */
98   struct GNUNET_MessageHeader header;
99
100   /**
101    * 0: no options
102    * 1: The 'self' field should be checked
103    * 2: this client is interested in payload traffic
104    */
105   uint32_t options;
106
107   /**
108    * Identity we think we have.  If it does not match, the
109    * receiver should print out an error message and disconnect.
110    */
111   struct GNUNET_PeerIdentity self;
112
113 };
114
115
116 /**
117  * Message from the transport service to the library
118  * informing about neighbors.
119  */
120 struct ConnectInfoMessage
121 {
122
123   /**
124    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
125    */
126   struct GNUNET_MessageHeader header;
127
128   /**
129    * Number of ATS key-value pairs that follow this struct
130    * (excluding the 0-terminator).
131    */
132   uint32_t ats_count GNUNET_PACKED;
133
134   /**
135    * Identity of the new neighbour.
136    */
137   struct GNUNET_PeerIdentity id;
138
139   /**
140    * Current inbound quota for this peer
141    */
142   struct GNUNET_BANDWIDTH_Value32NBO quota_in;
143
144   /**
145    * Current outbound quota for this peer
146    */
147   struct GNUNET_BANDWIDTH_Value32NBO quota_out;
148 };
149
150
151 /**
152  * Message from the transport service to the library
153  * informing about disconnects.
154  */
155 struct DisconnectInfoMessage
156 {
157
158   /**
159    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
160    */
161   struct GNUNET_MessageHeader header;
162
163   /**
164    * Reserved, always zero.
165    */
166   uint32_t reserved GNUNET_PACKED;
167
168   /**
169    * Who got disconnected?
170    */
171   struct GNUNET_PeerIdentity peer;
172
173 };
174
175 /**
176  * Message type for sending a request connect message
177  * to the transport service.  Must be done before transport
178  * api will allow messages to be queued/sent to transport
179  * service for transmission to a peer.
180  */
181 struct TransportRequestConnectMessage
182 {
183   /**
184    *  Message header
185    */
186   struct GNUNET_MessageHeader header;
187
188   /**
189    * For alignment.
190    */
191   uint32_t reserved;
192
193   /**
194    * Identity of the peer we would like to connect to.
195    */
196   struct GNUNET_PeerIdentity peer;
197 };
198
199 /**
200  * Message used to set a particular bandwidth quota.  Sent TO the
201  * service to set an incoming quota, sent FROM the service to update
202  * an outgoing quota.
203  */
204 struct QuotaSetMessage
205 {
206
207   /**
208    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
209    */
210   struct GNUNET_MessageHeader header;
211
212   /**
213    * Quota.
214    */
215   struct GNUNET_BANDWIDTH_Value32NBO quota;
216
217   /**
218    * About which peer are we talking here?
219    */
220   struct GNUNET_PeerIdentity peer;
221
222 };
223
224
225 /**
226  * Message used to notify the transport API about a message
227  * received from the network.  The actual message follows.
228  */
229 struct InboundMessage
230 {
231
232   /**
233    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
234    */
235   struct GNUNET_MessageHeader header;
236
237   /**
238    * Number of ATS key-value pairs that follow this struct
239    * (excluding the 0-terminator).
240    */
241   uint32_t ats_count GNUNET_PACKED;
242
243   /**
244    * Which peer sent the message?
245    */
246   struct GNUNET_PeerIdentity peer;
247
248 };
249
250
251 /**
252  * Message used to notify the transport API that it can
253  * send another message to the transport service.
254  */
255 struct SendOkMessage
256 {
257
258   /**
259    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
260    */
261   struct GNUNET_MessageHeader header;
262
263   /**
264    * GNUNET_OK if the transmission succeeded,
265    * GNUNET_SYSERR if it failed (i.e. network disconnect);
266    * in either case, it is now OK for this client to
267    * send us another message for the given peer.
268    */
269   uint32_t success GNUNET_PACKED;
270
271
272   /**
273    * Size of message sent
274    */
275   uint32_t bytes_msg GNUNET_PACKED;
276
277   /**
278    * Size of message sent over wire
279    * Includes plugin and protocol specific overhead
280    */
281   uint32_t bytes_physical GNUNET_PACKED;
282
283   /**
284    * Latency estimate.
285    */
286   struct GNUNET_TIME_RelativeNBO latency;
287
288   /**
289    * Which peer can send more now?
290    */
291   struct GNUNET_PeerIdentity peer;
292
293 };
294
295
296 /**
297  * Message used to notify the transport service about a message
298  * to be transmitted to another peer.  The actual message follows.
299  */
300 struct OutboundMessage
301 {
302
303   /**
304    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
305    */
306   struct GNUNET_MessageHeader header;
307
308   /**
309    * Message priority.
310    */
311   uint32_t priority GNUNET_PACKED;
312
313   /**
314    * Allowed delay.
315    */
316   struct GNUNET_TIME_RelativeNBO timeout;
317
318   /**
319    * Which peer should receive the message?
320    */
321   struct GNUNET_PeerIdentity peer;
322
323 };
324
325
326 /**
327  * Message from the library to the transport service
328  * asking for converting a transport address to a
329  * human-readable UTF-8 string.
330  */
331 struct AddressLookupMessage
332 {
333
334   /**
335    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
336    */
337   struct GNUNET_MessageHeader header;
338
339   /**
340    * Should the conversion use numeric IP addresses (otherwise
341    * a reverse DNS lookup is OK -- if applicable).
342    */
343   int16_t numeric_only GNUNET_PACKED;
344
345   /**
346    * Length of the (binary) address in bytes, in big-endian.
347    */
348   uint16_t addrlen GNUNET_PACKED;
349
350   /**
351    * timeout to give up.
352    */
353   struct GNUNET_TIME_RelativeNBO timeout;
354
355   /* followed by 'addrlen' bytes of the actual address, then
356    * followed by the 0-terminated name of the transport */
357 };
358
359
360 /**
361  * Message from the library to the transport service
362  * asking for human readable addresses known for a peer.
363  */
364 struct PeerAddressLookupMessage
365 {
366   /**
367    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP
368    */
369   struct GNUNET_MessageHeader header;
370
371   /**
372    * For alignment.
373    */
374   uint32_t reserved;
375
376   /**
377    * timeout to give up.  FIXME: remove in the future.
378    */
379   struct GNUNET_TIME_RelativeNBO timeout;
380
381   /**
382    * The identity of the peer to look up.
383    */
384   struct GNUNET_PeerIdentity peer;
385 };
386
387
388 /**
389  * Message from the library to the transport service
390  * asking for binary addresses known for a peer.
391  */
392 struct AddressIterateMessage
393 {
394   /**
395    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE
396    */
397   struct GNUNET_MessageHeader header;
398
399   /**
400    * One shot call or continous replies?
401    */
402   uint32_t one_shot;
403
404   /**
405    * timeout to give up.  FIXME: remove in the future
406    */
407   struct GNUNET_TIME_AbsoluteNBO timeout;
408
409   /**
410    * The identity of the peer to look up.
411    */
412   struct GNUNET_PeerIdentity peer;
413
414 };
415
416
417 /**
418  * Message from the library to the transport service
419  * asking for binary addresses known for a peer.
420  */
421 struct TrafficMetricMessage
422 {
423   /**
424    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
425    */
426   struct GNUNET_MessageHeader header;
427
428   /**
429    * SEND, RECEIVE or BOTH?
430    */
431   uint16_t direction;
432
433   /**
434    * Traffic metrics count
435    */
436   uint16_t ats_count;
437
438   /**
439    * The identity of the peer to look up.
440    */
441   struct GNUNET_PeerIdentity peer;
442 };
443
444
445 /**
446  * Message from the transport service to the library
447  * containing binary addresses known for a peer.
448  * Memory layout:
449  * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
450  */
451 struct AddressIterateResponseMessage
452 {
453   /**
454    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE
455    */
456   struct GNUNET_MessageHeader header;
457
458   /**
459    * For alignment.
460    */
461   uint32_t reserved;
462
463     /**
464    * Peer identity
465    */
466   struct GNUNET_PeerIdentity peer;
467
468   /**
469    * address length
470    */
471   uint32_t addrlen GNUNET_PACKED;
472
473   /**
474    * length of the plugin name
475    */
476   uint32_t pluginlen GNUNET_PACKED;
477
478 };
479
480
481 /**
482  * Change in blacklisting (either request or notification,
483  * depending on which direction it is going).
484  */
485 struct BlacklistMessage
486 {
487
488   /**
489    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
490    * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
491    */
492   struct GNUNET_MessageHeader header;
493
494   /**
495    * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed)
496    * for the response.
497    */
498   uint32_t is_allowed GNUNET_PACKED;
499
500   /**
501    * Which peer is being blacklisted or queried?
502    */
503   struct GNUNET_PeerIdentity peer;
504
505 };
506 GNUNET_NETWORK_STRUCT_END
507
508 /* end of transport.h */
509 #endif