2 This file is part of GNUnet.
3 Copyright (C) 2009-2014 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file transport/transport.h
21 * @brief common internal definitions for transport service
22 * @author Christian Grothoff
27 #include "gnunet_crypto_lib.h"
28 #include "gnunet_time_lib.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_constants.h"
32 #define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
36 * For how long do we allow unused bandwidth
37 * from the past to carry over into the future? (in seconds)
39 #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
42 * How often do we (at most) do a full quota
43 * recalculation? (in ms)
45 #define MIN_QUOTA_REFRESH_TIME 2000
48 * What's the maximum number of sockets transport uses for validation and
51 #define DEFAULT_MAX_FDS 256
54 * Maximum frequency for re-evaluating latencies for all transport addresses.
56 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
59 * Maximum frequency for re-evaluating latencies for connected addresses.
61 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
64 * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
65 * included here. These values are not required outside transport_api
68 * @param peer the peer that connected
69 * @param bandwidth_in inbound bandwidth in NBO
70 * @param bandwidth_out outbound bandwidth in NBO
74 (*NotifyConnect) (void *cls,
75 const struct GNUNET_PeerIdentity *peer,
76 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
77 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
80 GNUNET_NETWORK_STRUCT_BEGIN
83 * Message from the transport service to the library
84 * asking to check if both processes agree about this
91 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START
93 struct GNUNET_MessageHeader header;
97 * 1: The @e self field should be checked
98 * 2: this client is interested in payload traffic
103 * Identity we think we have. If it does not match, the
104 * receiver should print out an error message and disconnect.
106 struct GNUNET_PeerIdentity self;
112 * Message from the transport service to the library
113 * informing about neighbors.
115 struct ConnectInfoMessage
119 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
121 struct GNUNET_MessageHeader header;
124 * Identity of the new neighbour.
126 struct GNUNET_PeerIdentity id;
129 * Current inbound quota for this peer
131 struct GNUNET_BANDWIDTH_Value32NBO quota_in;
134 * Current outbound quota for this peer
136 struct GNUNET_BANDWIDTH_Value32NBO quota_out;
141 * Message from the transport service to the library
142 * informing about disconnects.
144 struct DisconnectInfoMessage
148 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
150 struct GNUNET_MessageHeader header;
153 * Reserved, always zero.
155 uint32_t reserved GNUNET_PACKED;
158 * Who got disconnected?
160 struct GNUNET_PeerIdentity peer;
166 * Message used to set a particular bandwidth quota. Sent TO the
167 * service to set an incoming quota, sent FROM the service to update
170 struct QuotaSetMessage
174 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
176 struct GNUNET_MessageHeader header;
181 struct GNUNET_BANDWIDTH_Value32NBO quota;
184 * About which peer are we talking here?
186 struct GNUNET_PeerIdentity peer;
192 * Message used to notify the transport API about a message
193 * received from the network. The actual message follows.
195 struct InboundMessage
199 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
201 struct GNUNET_MessageHeader header;
204 * Which peer sent the message?
206 struct GNUNET_PeerIdentity peer;
212 * Message used to notify the transport API that it can
213 * send another message to the transport service.
219 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
221 struct GNUNET_MessageHeader header;
224 * #GNUNET_OK if the transmission succeeded,
225 * #GNUNET_SYSERR if it failed (i.e. network disconnect);
226 * in either case, it is now OK for this client to
227 * send us another message for the given peer.
229 uint32_t success GNUNET_PACKED;
232 * Size of message sent
234 uint32_t bytes_msg GNUNET_PACKED;
237 * Size of message sent over wire
238 * Includes plugin and protocol specific overhead
240 uint32_t bytes_physical GNUNET_PACKED;
243 * Which peer can send more now?
245 struct GNUNET_PeerIdentity peer;
250 * Message used to notify the transport API about an address to string
251 * conversion. Message is followed by the string with the humand-readable
252 * address. For each lookup, multiple results may be returned. The
253 * last message must have a @e res of #GNUNET_OK and an @e addr_len
256 struct AddressToStringResultMessage
260 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
262 struct GNUNET_MessageHeader header;
265 * #GNUNET_OK if the conversion succeeded,
266 * #GNUNET_SYSERR if it failed
268 uint32_t res GNUNET_PACKED;
271 * Length of the following string, zero if @e is #GNUNET_SYSERR
273 uint32_t addr_len GNUNET_PACKED;
278 * Message used to notify the transport service about a message
279 * to be transmitted to another peer. The actual message follows.
281 struct OutboundMessage
285 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
287 struct GNUNET_MessageHeader header;
292 uint32_t reserved GNUNET_PACKED;
297 struct GNUNET_TIME_RelativeNBO timeout;
300 * Which peer should receive the message?
302 struct GNUNET_PeerIdentity peer;
308 * Message from the library to the transport service
309 * asking for converting a transport address to a
310 * human-readable UTF-8 string.
312 struct AddressLookupMessage
316 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
318 struct GNUNET_MessageHeader header;
321 * Should the conversion use numeric IP addresses (otherwise
322 * a reverse DNS lookup is OK -- if applicable).
324 int16_t numeric_only GNUNET_PACKED;
327 * Length of the (binary) address in bytes, in big-endian.
329 uint16_t addrlen GNUNET_PACKED;
332 * timeout to give up (for DNS resolution timeout mostly)
334 struct GNUNET_TIME_RelativeNBO timeout;
336 /* followed by @e addrlen bytes of the actual address, then
337 * followed by the 0-terminated name of the transport */
342 * Message from the transport service to the library containing information
343 * about a peer. Information contained are:
344 * - current address used to communicate with this peer
349 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
351 struct ValidationIterateResponseMessage
354 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
356 struct GNUNET_MessageHeader header;
366 struct GNUNET_PeerIdentity peer;
369 * Local info about the address
371 uint32_t local_address_info GNUNET_PACKED;
376 uint32_t addrlen GNUNET_PACKED;
379 * Length of the plugin name
381 uint32_t pluginlen GNUNET_PACKED;
386 uint32_t state GNUNET_PACKED;
389 * At what time did we successfully validate the address last.
390 * Will be NEVER if the address failed validation.
392 struct GNUNET_TIME_AbsoluteNBO last_validation;
395 * Until when is the address believed to be valid.
396 * Will be ZERO if the address is not belived to be valid.
398 struct GNUNET_TIME_AbsoluteNBO valid_until;
401 * When will we next try to validate the address (typically
402 * done before @e valid_until happens).
404 struct GNUNET_TIME_AbsoluteNBO next_validation;
409 * Message from the library to the transport service
410 * asking for binary addresses known for a peer.
412 struct ValidationMonitorMessage
415 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
417 struct GNUNET_MessageHeader header;
420 * One shot call or continous replies?
422 uint32_t one_shot GNUNET_PACKED;
425 * The identity of the peer to look up.
427 struct GNUNET_PeerIdentity peer;
433 * Message from the library to the transport service
434 * asking for binary addresses known for a peer.
436 struct PeerMonitorMessage
439 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
441 struct GNUNET_MessageHeader header;
444 * One shot call or continous replies?
446 uint32_t one_shot GNUNET_PACKED;
449 * The identity of the peer to look up.
451 struct GNUNET_PeerIdentity peer;
457 * Message from the library to the transport service
458 * asking for binary addresses known for a peer.
460 struct TrafficMetricMessage
463 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
465 struct GNUNET_MessageHeader header;
470 uint32_t reserved GNUNET_PACKED;
473 * The identity of the peer to look up.
475 struct GNUNET_PeerIdentity peer;
478 * Fake properties to generate.
480 struct GNUNET_ATS_PropertiesNBO properties;
483 * Fake delay to add on inbound traffic.
485 struct GNUNET_TIME_RelativeNBO delay_in;
488 * Fake delay to add on outbound traffic.
490 struct GNUNET_TIME_RelativeNBO delay_out;
495 * Message from the transport service to the library containing information
496 * about a peer. Information contained are:
497 * - current address used to communicate with this peer
502 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
504 struct PeerIterateResponseMessage
507 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
509 struct GNUNET_MessageHeader header;
519 struct GNUNET_PeerIdentity peer;
522 * Timeout for the state this peer is in
524 struct GNUNET_TIME_AbsoluteNBO state_timeout;
527 * Local info about the address
529 uint32_t local_address_info GNUNET_PACKED;
532 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
534 uint32_t state GNUNET_PACKED;
539 uint32_t addrlen GNUNET_PACKED;
542 * Length of the plugin name
544 uint32_t pluginlen GNUNET_PACKED;
550 * Change in blacklisting (either request or notification,
551 * depending on which direction it is going).
553 struct BlacklistMessage
557 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
558 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
560 struct GNUNET_MessageHeader header;
563 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
566 uint32_t is_allowed GNUNET_PACKED;
569 * Which peer is being blacklisted or queried?
571 struct GNUNET_PeerIdentity peer;
577 * Transport-level connection status update.
579 struct TransportPluginMonitorMessage
583 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
585 struct GNUNET_MessageHeader header;
588 * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
590 uint16_t session_state GNUNET_PACKED;
593 * #GNUNET_YES if this is an inbound connection,
594 * #GNUNET_NO if this is an outbound connection,
595 * #GNUNET_SYSERR if connections of this plugin
596 * are so fundamentally bidirectional
597 * that they have no 'initiator'
598 * Value given in NBO.
600 int16_t is_inbound GNUNET_PACKED;
603 * Number of messages waiting transmission.
605 uint32_t msgs_pending GNUNET_PACKED;
608 * Number of bytes waiting for transmission.
610 uint32_t bytes_pending GNUNET_PACKED;
613 * When will this transport plugin session time out?
615 struct GNUNET_TIME_AbsoluteNBO timeout;
618 * Until how long is this plugin currently blocked from reading?
620 struct GNUNET_TIME_AbsoluteNBO delay;
623 * Which peer is this connection for?
625 struct GNUNET_PeerIdentity peer;
628 * Unique identifier for the session.
633 * Length of the plugin name in bytes, including 0-termination.
635 uint16_t plugin_name_len GNUNET_PACKED;
638 * Length of the plugin address in bytes.
640 uint16_t plugin_address_len GNUNET_PACKED;
642 /* followed by 0-terminated plugin name and
643 @e plugin_address_len bytes of plugin address */
655 /* *********************** TNG messages ***************** */
658 * Communicator goes online. Note which addresses it can
661 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage
665 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR.
667 struct GNUNET_MessageHeader header;
669 /* Followed by the address prefix of the communicator */
674 * Add address to the list.
676 struct GNUNET_TRANSPORT_AddAddressMessage
680 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS.
682 struct GNUNET_MessageHeader header;
685 * Address identifier (used during deletion).
687 uint32_t aid GNUNET_PACKED;
690 * When does the address expire?
692 struct GNUNET_TIME_RelativeNBO expiration;
695 * An `enum GNUNET_ATS_Network_Type` in NBO.
699 /* followed by UTF-8 encoded, 0-terminated human-readable address */
704 * Remove address from the list.
706 struct GNUNET_TRANSPORT_DelAddressMessage
710 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS.
712 struct GNUNET_MessageHeader header;
715 * Address identifier.
717 uint32_t aid GNUNET_PACKED;
723 * Inform transport about an incoming message.
725 struct GNUNET_TRANSPORT_IncomingMessage
729 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG.
731 struct GNUNET_MessageHeader header;
734 * Do we use flow control or not?
736 uint32_t fc_on GNUNET_PACKED;
739 * 64-bit number to identify the matching ACK.
741 uint64_t fc_id GNUNET_PACKED;
746 struct GNUNET_PeerIdentity sender;
748 /* followed by the message */
753 * Transport informs us about being done with an incoming message.
754 * (only sent if fc_on was set).
756 struct GNUNET_TRANSPORT_IncomingMessageAck
760 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
762 struct GNUNET_MessageHeader header;
767 uint32_t reserved GNUNET_PACKED;
770 * Which message is being ACKed?
772 uint64_t fc_id GNUNET_PACKED;
775 * Sender identifier of the original message.
777 struct GNUNET_PeerIdentity sender;
783 * Add queue to the transport
785 struct GNUNET_TRANSPORT_AddQueueMessage
789 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
791 struct GNUNET_MessageHeader header;
794 * Queue identifier (used to identify the queue).
796 uint32_t qid GNUNET_PACKED;
799 * Receiver that can be addressed via the queue.
801 struct GNUNET_PeerIdentity receiver;
804 * An `enum GNUNET_ATS_Network_Type` in NBO.
808 /* followed by UTF-8 encoded, 0-terminated human-readable address */
813 * Remove queue, it is no longer available.
815 struct GNUNET_TRANSPORT_DelQueueMessage
819 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN.
821 struct GNUNET_MessageHeader header;
824 * Address identifier.
826 uint32_t qid GNUNET_PACKED;
829 * Receiver that can be addressed via the queue.
831 struct GNUNET_PeerIdentity receiver;
837 * Transport tells communicator that it wants a new queue.
839 struct GNUNET_TRANSPORT_CreateQueue
843 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
845 struct GNUNET_MessageHeader header;
848 * Unique ID for the request.
850 uint32_t request_id GNUNET_PACKED;
853 * Receiver that can be addressed via the queue.
855 struct GNUNET_PeerIdentity receiver;
857 /* followed by UTF-8 encoded, 0-terminated human-readable address */
862 * Transport tells communicator that it wants a new queue.
864 struct GNUNET_TRANSPORT_CreateQueueResponse
868 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL.
870 struct GNUNET_MessageHeader header;
873 * Unique ID for the request.
875 uint32_t request_id GNUNET_PACKED;
880 * Inform communicator about transport's desire to send a message.
882 struct GNUNET_TRANSPORT_SendMessageTo
886 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
888 struct GNUNET_MessageHeader header;
891 * Which queue should we use?
893 uint32_t qid GNUNET_PACKED;
896 * Message ID, used for flow control.
898 uint64_t mid GNUNET_PACKED;
901 * Receiver identifier.
903 struct GNUNET_PeerIdentity receiver;
905 /* followed by the message */
910 * Inform transport that message was sent.
912 struct GNUNET_TRANSPORT_SendMessageToAck
916 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
918 struct GNUNET_MessageHeader header;
921 * Success (#GNUNET_OK), failure (#GNUNET_SYSERR).
923 uint32_t status GNUNET_PACKED;
926 * Message ID of the original message.
928 uint64_t mid GNUNET_PACKED;
931 * Receiver identifier.
933 struct GNUNET_PeerIdentity receiver;
941 * Request to start monitoring.
943 struct GNUNET_TRANSPORT_MonitorStart
947 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START.
949 struct GNUNET_MessageHeader header;
952 * #GNUNET_YES for one-shot montoring, #GNUNET_NO for continuous monitoring.
957 * Target identifier to monitor, all zeros for "all peers".
959 struct GNUNET_PeerIdentity peer;
967 struct GNUNET_TRANSPORT_MonitorData
971 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA.
973 struct GNUNET_MessageHeader header;
976 * Network type (an `enum GNUNET_ATS_Network_Type` in NBO).
978 uint32_t nt GNUNET_PACKED;
983 struct GNUNET_PeerIdentity peer;
986 * @deprecated To be discussed if we keep these...
988 struct GNUNET_TIME_AbsoluteNBO last_validation;
989 struct GNUNET_TIME_AbsoluteNBO valid_until;
990 struct GNUNET_TIME_AbsoluteNBO next_validation;
993 * Current round-trip time estimate.
995 struct GNUNET_TIME_RelativeNBO rtt;
998 * Is inbound (in NBO).
1000 uint32_t is_inbound GNUNET_PACKED;
1003 * Messages pending (in NBO).
1005 uint32_t num_msg_pending GNUNET_PACKED;
1008 * Bytes pending (in NBO).
1010 uint32_t num_bytes_pending GNUNET_PACKED;
1012 /* Followed by 0-terminated address of the peer
1013 (TODO: do we allow no address? If so,
1014 adjust transport_api2_monitor!) */
1022 GNUNET_NETWORK_STRUCT_END
1024 /* end of transport.h */