2 This file is part of GNUnet.
3 Copyright (C) 2009-2014 Christian Grothoff (and other contributing authors)
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file transport/transport.h
23 * @brief common internal definitions for transport service
24 * @author Christian Grothoff
29 #include "gnunet_crypto_lib.h"
30 #include "gnunet_time_lib.h"
31 #include "gnunet_transport_service.h"
32 #include "gnunet_constants.h"
34 #define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
38 * For how long do we allow unused bandwidth
39 * from the past to carry over into the future? (in seconds)
41 #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
44 * How often do we (at most) do a full quota
45 * recalculation? (in ms)
47 #define MIN_QUOTA_REFRESH_TIME 2000
50 * What's the maximum number of sockets transport uses for validation and
53 #define DEFAULT_MAX_FDS 256
56 * Maximum frequency for re-evaluating latencies for all transport addresses.
58 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
61 * Maximum frequency for re-evaluating latencies for connected addresses.
63 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
66 * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
67 * included here. These values are not required outside transport_api
70 * @param peer the peer that connected
71 * @param bandwidth_in inbound bandwidth in NBO
72 * @param bandwidth_out outbound bandwidth in NBO
76 (*NotifyConnect) (void *cls,
77 const struct GNUNET_PeerIdentity *peer,
78 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
79 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
82 GNUNET_NETWORK_STRUCT_BEGIN
85 * Message from the transport service to the library
86 * asking to check if both processes agree about this
93 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START
95 struct GNUNET_MessageHeader header;
99 * 1: The 'self' field should be checked
100 * 2: this client is interested in payload traffic
105 * Identity we think we have. If it does not match, the
106 * receiver should print out an error message and disconnect.
108 struct GNUNET_PeerIdentity self;
114 * Message from the transport service to the library
115 * informing about neighbors.
117 struct ConnectInfoMessage
121 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
123 struct GNUNET_MessageHeader header;
126 * Identity of the new neighbour.
128 struct GNUNET_PeerIdentity id;
131 * Current inbound quota for this peer
133 struct GNUNET_BANDWIDTH_Value32NBO quota_in;
136 * Current outbound quota for this peer
138 struct GNUNET_BANDWIDTH_Value32NBO quota_out;
143 * Message from the transport service to the library
144 * informing about disconnects.
146 struct DisconnectInfoMessage
150 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
152 struct GNUNET_MessageHeader header;
155 * Reserved, always zero.
157 uint32_t reserved GNUNET_PACKED;
160 * Who got disconnected?
162 struct GNUNET_PeerIdentity peer;
168 * Message type for sending a request connect message
169 * to the transport service. Must be done before transport
170 * api will allow messages to be queued/sent to transport
171 * service for transmission to a peer.
173 struct TransportRequestConnectMessage
176 * Message header with type #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT
178 struct GNUNET_MessageHeader header;
183 uint32_t reserved GNUNET_PACKED;
186 * Identity of the peer we would like to connect to.
188 struct GNUNET_PeerIdentity peer;
193 * Message used to set a particular bandwidth quota. Sent TO the
194 * service to set an incoming quota, sent FROM the service to update
197 struct QuotaSetMessage
201 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
203 struct GNUNET_MessageHeader header;
208 struct GNUNET_BANDWIDTH_Value32NBO quota;
211 * About which peer are we talking here?
213 struct GNUNET_PeerIdentity peer;
219 * Message used to notify the transport API about a message
220 * received from the network. The actual message follows.
222 struct InboundMessage
226 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
228 struct GNUNET_MessageHeader header;
231 * Which peer sent the message?
233 struct GNUNET_PeerIdentity peer;
239 * Message used to notify the transport API that it can
240 * send another message to the transport service.
246 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
248 struct GNUNET_MessageHeader header;
251 * #GNUNET_OK if the transmission succeeded,
252 * #GNUNET_SYSERR if it failed (i.e. network disconnect);
253 * in either case, it is now OK for this client to
254 * send us another message for the given peer.
256 uint32_t success GNUNET_PACKED;
259 * Size of message sent
261 uint32_t bytes_msg GNUNET_PACKED;
264 * Size of message sent over wire
265 * Includes plugin and protocol specific overhead
267 uint32_t bytes_physical GNUNET_PACKED;
270 * Which peer can send more now?
272 struct GNUNET_PeerIdentity peer;
277 * Message used to notify the transport API about an address to string
278 * conversion. Message is followed by the string with the humand-readable
279 * address. For each lookup, multiple results may be returned. The
280 * last message must have a @e res of #GNUNET_OK and an @e addr_len
283 struct AddressToStringResultMessage
287 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
289 struct GNUNET_MessageHeader header;
292 * #GNUNET_OK if the conversion succeeded,
293 * #GNUNET_SYSERR if it failed
295 uint32_t res GNUNET_PACKED;
298 * Length of the following string, zero if @e is #GNUNET_SYSERR
300 uint32_t addr_len GNUNET_PACKED;
305 * Message used to notify the transport service about a message
306 * to be transmitted to another peer. The actual message follows.
308 struct OutboundMessage
312 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
314 struct GNUNET_MessageHeader header;
319 uint32_t reserved GNUNET_PACKED;
324 struct GNUNET_TIME_RelativeNBO timeout;
327 * Which peer should receive the message?
329 struct GNUNET_PeerIdentity peer;
335 * Message from the library to the transport service
336 * asking for converting a transport address to a
337 * human-readable UTF-8 string.
339 struct AddressLookupMessage
343 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
345 struct GNUNET_MessageHeader header;
348 * Should the conversion use numeric IP addresses (otherwise
349 * a reverse DNS lookup is OK -- if applicable).
351 int16_t numeric_only GNUNET_PACKED;
354 * Length of the (binary) address in bytes, in big-endian.
356 uint16_t addrlen GNUNET_PACKED;
359 * timeout to give up (for DNS resolution timeout mostly)
361 struct GNUNET_TIME_RelativeNBO timeout;
363 /* followed by @e addrlen bytes of the actual address, then
364 * followed by the 0-terminated name of the transport */
369 * Message from the transport service to the library containing information
370 * about a peer. Information contained are:
371 * - current address used to communicate with this peer
376 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
378 struct ValidationIterateResponseMessage
381 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
383 struct GNUNET_MessageHeader header;
393 struct GNUNET_PeerIdentity peer;
396 * Local info about the address
398 uint32_t local_address_info GNUNET_PACKED;
403 uint32_t addrlen GNUNET_PACKED;
406 * Length of the plugin name
408 uint32_t pluginlen GNUNET_PACKED;
413 uint32_t state GNUNET_PACKED;
416 * At what time did we successfully validate the address last.
417 * Will be NEVER if the address failed validation.
419 struct GNUNET_TIME_AbsoluteNBO last_validation;
422 * Until when is the address believed to be valid.
423 * Will be ZERO if the address is not belived to be valid.
425 struct GNUNET_TIME_AbsoluteNBO valid_until;
428 * When will we next try to validate the address (typically
429 * done before @e valid_until happens).
431 struct GNUNET_TIME_AbsoluteNBO next_validation;
435 * Message from the library to the transport service
436 * asking for binary addresses known for a peer.
438 struct ValidationMonitorMessage
441 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
443 struct GNUNET_MessageHeader header;
446 * One shot call or continous replies?
448 uint32_t one_shot GNUNET_PACKED;
451 * The identity of the peer to look up.
453 struct GNUNET_PeerIdentity peer;
459 * Message from the library to the transport service
460 * asking for binary addresses known for a peer.
462 struct PeerMonitorMessage
465 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
467 struct GNUNET_MessageHeader header;
470 * One shot call or continous replies?
472 uint32_t one_shot GNUNET_PACKED;
475 * The identity of the peer to look up.
477 struct GNUNET_PeerIdentity peer;
483 * Message from the library to the transport service
484 * asking for binary addresses known for a peer.
486 struct TrafficMetricMessage
489 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
491 struct GNUNET_MessageHeader header;
496 uint32_t reserved GNUNET_PACKED;
499 * The identity of the peer to look up.
501 struct GNUNET_PeerIdentity peer;
504 * Fake properties to generate.
506 struct GNUNET_ATS_PropertiesNBO properties;
509 * Fake delay to add on inbound traffic.
511 struct GNUNET_TIME_RelativeNBO delay_in;
514 * Fake delay to add on outbound traffic.
516 struct GNUNET_TIME_RelativeNBO delay_out;
521 * Message from the transport service to the library containing information
522 * about a peer. Information contained are:
523 * - current address used to communicate with this peer
528 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
530 struct PeerIterateResponseMessage
533 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
535 struct GNUNET_MessageHeader header;
545 struct GNUNET_PeerIdentity peer;
548 * Timeout for the state this peer is in
550 struct GNUNET_TIME_AbsoluteNBO state_timeout;
553 * Local info about the address
555 uint32_t local_address_info GNUNET_PACKED;
558 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
560 uint32_t state GNUNET_PACKED;
565 uint32_t addrlen GNUNET_PACKED;
568 * Length of the plugin name
570 uint32_t pluginlen GNUNET_PACKED;
576 * Change in blacklisting (either request or notification,
577 * depending on which direction it is going).
579 struct BlacklistMessage
583 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
584 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
586 struct GNUNET_MessageHeader header;
589 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
592 uint32_t is_allowed GNUNET_PACKED;
595 * Which peer is being blacklisted or queried?
597 struct GNUNET_PeerIdentity peer;
603 * Transport-level connection status update.
605 struct TransportPluginMonitorMessage
609 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
611 struct GNUNET_MessageHeader header;
614 * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
616 uint16_t session_state GNUNET_PACKED;
619 * #GNUNET_YES if this is an inbound connection,
620 * #GNUNET_NO if this is an outbound connection,
621 * #GNUNET_SYSERR if connections of this plugin
622 * are so fundamentally bidirectional
623 * that they have no 'initiator'
624 * Value given in NBO.
626 int16_t is_inbound GNUNET_PACKED;
629 * Number of messages waiting transmission.
631 uint32_t msgs_pending GNUNET_PACKED;
634 * Number of bytes waiting for transmission.
636 uint32_t bytes_pending GNUNET_PACKED;
639 * When will this transport plugin session time out?
641 struct GNUNET_TIME_AbsoluteNBO timeout;
644 * Until how long is this plugin currently blocked from reading?
646 struct GNUNET_TIME_AbsoluteNBO delay;
649 * Which peer is this connection for?
651 struct GNUNET_PeerIdentity peer;
654 * Unique identifier for the session.
659 * Length of the plugin name in bytes, including 0-termination.
661 uint16_t plugin_name_len GNUNET_PACKED;
664 * Length of the plugin address in bytes.
666 uint16_t plugin_address_len GNUNET_PACKED;
668 /* followed by 0-terminated plugin name and
669 @e plugin_address_len bytes of plugin address */
674 GNUNET_NETWORK_STRUCT_END
676 /* end of transport.h */