ceeaf9c0daeaa3384e7723cdeabcc882aa55bc0a
[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 bandwidth_in inbound bandwidth in NBO
72  * @param bandwidth_out outbound bandwidth in NBO
73  *
74  */
75
76 typedef void (*NotifyConnect) (void *cls,
77                               const struct GNUNET_PeerIdentity *peer,
78                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
79                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
80
81 GNUNET_NETWORK_STRUCT_BEGIN
82
83 /**
84  * Message from the transport service to the library
85  * asking to check if both processes agree about this
86  * peers identity.
87  */
88 struct StartMessage
89 {
90
91   /**
92    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
93    */
94   struct GNUNET_MessageHeader header;
95
96   /**
97    * 0: no options
98    * 1: The 'self' field should be checked
99    * 2: this client is interested in payload traffic
100    */
101   uint32_t options;
102
103   /**
104    * Identity we think we have.  If it does not match, the
105    * receiver should print out an error message and disconnect.
106    */
107   struct GNUNET_PeerIdentity self;
108
109 };
110
111
112 /**
113  * Message from the transport service to the library
114  * informing about neighbors.
115  */
116 struct ConnectInfoMessage
117 {
118
119   /**
120    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
121    */
122   struct GNUNET_MessageHeader header;
123
124   /**
125    * Identity of the new neighbour.
126    */
127   struct GNUNET_PeerIdentity id;
128
129   /**
130    * Current inbound quota for this peer
131    */
132   struct GNUNET_BANDWIDTH_Value32NBO quota_in;
133
134   /**
135    * Current outbound quota for this peer
136    */
137   struct GNUNET_BANDWIDTH_Value32NBO quota_out;
138 };
139
140
141 /**
142  * Message from the transport service to the library
143  * informing about disconnects.
144  */
145 struct DisconnectInfoMessage
146 {
147
148   /**
149    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
150    */
151   struct GNUNET_MessageHeader header;
152
153   /**
154    * Reserved, always zero.
155    */
156   uint32_t reserved GNUNET_PACKED;
157
158   /**
159    * Who got disconnected?
160    */
161   struct GNUNET_PeerIdentity peer;
162
163 };
164
165 /**
166  * Message type for sending a request connect message
167  * to the transport service.  Must be done before transport
168  * api will allow messages to be queued/sent to transport
169  * service for transmission to a peer.
170  */
171 struct TransportRequestConnectMessage
172 {
173   /**
174    *  Message header
175    */
176   struct GNUNET_MessageHeader header;
177
178   /**
179    * Connect (GNUNET_YES) or connect (GNUNET_NO).
180    */
181   uint32_t connect;
182
183   /**
184    * Identity of the peer we would like to connect to.
185    */
186   struct GNUNET_PeerIdentity peer;
187 };
188
189 /**
190  * Message used to set a particular bandwidth quota.  Sent TO the
191  * service to set an incoming quota, sent FROM the service to update
192  * an outgoing quota.
193  */
194 struct QuotaSetMessage
195 {
196
197   /**
198    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
199    */
200   struct GNUNET_MessageHeader header;
201
202   /**
203    * Quota.
204    */
205   struct GNUNET_BANDWIDTH_Value32NBO quota;
206
207   /**
208    * About which peer are we talking here?
209    */
210   struct GNUNET_PeerIdentity peer;
211
212 };
213
214
215 /**
216  * Message used to notify the transport API about a message
217  * received from the network.  The actual message follows.
218  */
219 struct InboundMessage
220 {
221
222   /**
223    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
224    */
225   struct GNUNET_MessageHeader header;
226
227   /**
228    * Which peer sent the message?
229    */
230   struct GNUNET_PeerIdentity peer;
231
232 };
233
234
235 /**
236  * Message used to notify the transport API that it can
237  * send another message to the transport service.
238  */
239 struct SendOkMessage
240 {
241
242   /**
243    * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
244    */
245   struct GNUNET_MessageHeader header;
246
247   /**
248    * GNUNET_OK if the transmission succeeded,
249    * GNUNET_SYSERR if it failed (i.e. network disconnect);
250    * in either case, it is now OK for this client to
251    * send us another message for the given peer.
252    */
253   uint32_t success GNUNET_PACKED;
254
255
256   /**
257    * Size of message sent
258    */
259   uint32_t bytes_msg GNUNET_PACKED;
260
261   /**
262    * Size of message sent over wire
263    * Includes plugin and protocol specific overhead
264    */
265   uint32_t bytes_physical GNUNET_PACKED;
266
267   /**
268    * Latency estimate.
269    */
270   struct GNUNET_TIME_RelativeNBO latency;
271
272   /**
273    * Which peer can send more now?
274    */
275   struct GNUNET_PeerIdentity peer;
276
277 };
278
279 /**
280  * Message used to notify the transport API about an address to string
281  * conversion. Message is followed by the string with the humand-readable
282  * address.  For each lookup, multiple results may be returned.  The
283  * last message must have a @e res of #GNUNET_OK and an @e addr_len
284  * of zero.
285  */
286 struct AddressToStringResultMessage
287 {
288
289   /**
290    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
291    */
292   struct GNUNET_MessageHeader header;
293
294   /**
295    * #GNUNET_OK if the conversion succeeded,
296    * #GNUNET_SYSERR if it failed
297    */
298   uint32_t res GNUNET_PACKED;
299
300   /**
301    * Length of the following string, zero if @e is #GNUNET_SYSERR
302    */
303   uint32_t addr_len GNUNET_PACKED;
304 };
305
306
307 /**
308  * Message used to notify the transport service about a message
309  * to be transmitted to another peer.  The actual message follows.
310  */
311 struct OutboundMessage
312 {
313
314   /**
315    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
316    */
317   struct GNUNET_MessageHeader header;
318
319   /**
320    * Always zero.
321    */
322   uint32_t reserved GNUNET_PACKED;
323
324   /**
325    * Allowed delay.
326    */
327   struct GNUNET_TIME_RelativeNBO timeout;
328
329   /**
330    * Which peer should receive the message?
331    */
332   struct GNUNET_PeerIdentity peer;
333
334 };
335
336
337 /**
338  * Message from the library to the transport service
339  * asking for converting a transport address to a
340  * human-readable UTF-8 string.
341  */
342 struct AddressLookupMessage
343 {
344
345   /**
346    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
347    */
348   struct GNUNET_MessageHeader header;
349
350   /**
351    * Should the conversion use numeric IP addresses (otherwise
352    * a reverse DNS lookup is OK -- if applicable).
353    */
354   int16_t numeric_only GNUNET_PACKED;
355
356   /**
357    * Length of the (binary) address in bytes, in big-endian.
358    */
359   uint16_t addrlen GNUNET_PACKED;
360
361   /**
362    * timeout to give up (for DNS resolution timeout mostly)
363    */
364   struct GNUNET_TIME_RelativeNBO timeout;
365
366   /* followed by @e addrlen bytes of the actual address, then
367    * followed by the 0-terminated name of the transport */
368 };
369
370
371 /**
372  * Message from the transport service to the library containing information
373  * about a peer. Information contained are:
374  * - current address used to communicate with this peer
375  * - state
376  * - state timeout
377  *
378  * Memory layout:
379  * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
380  */
381 struct ValidationIterateResponseMessage
382 {
383   /**
384    * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
385    */
386   struct GNUNET_MessageHeader header;
387
388   /**
389    * For alignment.
390    */
391   uint32_t reserved;
392
393   /**
394    * Peer identity
395    */
396   struct GNUNET_PeerIdentity peer;
397
398   /**
399    * Local info about the address
400    */
401   uint32_t local_address_info GNUNET_PACKED;
402
403   /**
404    * Address length
405    */
406   uint32_t addrlen GNUNET_PACKED;
407
408   /**
409    * Length of the plugin name
410    */
411   uint32_t pluginlen GNUNET_PACKED;
412
413   /**
414    * State
415    */
416   uint32_t state GNUNET_PACKED;
417
418   /**
419    * At what time did we successfully validate the address last.
420    * Will be NEVER if the address failed validation.
421    */
422   struct GNUNET_TIME_AbsoluteNBO last_validation;
423
424   /**
425    * Until when is the address believed to be valid.
426    * Will be ZERO if the address is not belived to be valid.
427    */
428   struct GNUNET_TIME_AbsoluteNBO valid_until;
429
430   /**
431    * When will we next try to validate the address (typically
432    * done before @e valid_until happens).
433    */
434   struct GNUNET_TIME_AbsoluteNBO next_validation;
435 };
436
437 /**
438  * Message from the library to the transport service
439  * asking for binary addresses known for a peer.
440  */
441 struct ValidationMonitorMessage
442 {
443   /**
444    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
445    */
446   struct GNUNET_MessageHeader header;
447
448   /**
449    * One shot call or continous replies?
450    */
451   uint32_t one_shot;
452
453   /**
454    * The identity of the peer to look up.
455    */
456   struct GNUNET_PeerIdentity peer;
457
458 };
459
460
461 /**
462  * Message from the library to the transport service
463  * asking for binary addresses known for a peer.
464  */
465 struct PeerMonitorMessage
466 {
467   /**
468    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
469    */
470   struct GNUNET_MessageHeader header;
471
472   /**
473    * One shot call or continous replies?
474    */
475   uint32_t one_shot;
476
477   /**
478    * The identity of the peer to look up.
479    */
480   struct GNUNET_PeerIdentity peer;
481
482 };
483
484
485 /**
486  * Message from the library to the transport service
487  * asking for binary addresses known for a peer.
488  */
489 struct TrafficMetricMessage
490 {
491   /**
492    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
493    */
494   struct GNUNET_MessageHeader header;
495
496   /**
497    * SEND, RECEIVE or BOTH?
498    */
499   uint16_t direction;
500
501   /**
502    * Traffic metrics count
503    */
504   uint16_t ats_count;
505
506   /**
507    * The identity of the peer to look up.
508    */
509   struct GNUNET_PeerIdentity peer;
510 };
511
512
513 /**
514  * Message from the transport service to the library containing information
515  * about a peer. Information contained are:
516  * - current address used to communicate with this peer
517  * - state
518  * - state timeout
519  *
520  * Memory layout:
521  * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
522  */
523 struct PeerIterateResponseMessage
524 {
525   /**
526    * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
527    */
528   struct GNUNET_MessageHeader header;
529
530   /**
531    * For alignment.
532    */
533   uint32_t reserved;
534
535   /**
536    * Peer identity
537    */
538   struct GNUNET_PeerIdentity peer;
539
540   /**
541    * Timeout for the state this peer is in
542    */
543   struct GNUNET_TIME_AbsoluteNBO state_timeout;
544
545   /**
546    * Local info about the address
547    */
548   uint32_t local_address_info GNUNET_PACKED;
549
550   /**
551    * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
552    */
553   uint32_t state GNUNET_PACKED;
554
555   /**
556    * Address length
557    */
558   uint32_t addrlen GNUNET_PACKED;
559
560   /**
561    * Length of the plugin name
562    */
563   uint32_t pluginlen GNUNET_PACKED;
564
565 };
566
567
568 /**
569  * Change in blacklisting (either request or notification,
570  * depending on which direction it is going).
571  */
572 struct BlacklistMessage
573 {
574
575   /**
576    * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
577    * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
578    */
579   struct GNUNET_MessageHeader header;
580
581   /**
582    * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
583    * for the response.
584    */
585   uint32_t is_allowed GNUNET_PACKED;
586
587   /**
588    * Which peer is being blacklisted or queried?
589    */
590   struct GNUNET_PeerIdentity peer;
591
592 };
593 GNUNET_NETWORK_STRUCT_END
594
595 /* end of transport.h */
596 #endif