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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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_constants.h"
33 #define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
37 * For how long do we allow unused bandwidth
38 * from the past to carry over into the future? (in seconds)
40 #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
43 * How often do we (at most) do a full quota
44 * recalculation? (in ms)
46 #define MIN_QUOTA_REFRESH_TIME 2000
49 * What's the maximum number of sockets transport uses for validation and
52 #define DEFAULT_MAX_FDS 256
55 * Maximum frequency for re-evaluating latencies for all transport addresses.
57 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
60 * Maximum frequency for re-evaluating latencies for connected addresses.
62 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
65 * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
66 * included here. These values are not required outside transport_api
69 * @param peer the peer that connected
70 * @param bandwidth_in inbound bandwidth in NBO
71 * @param bandwidth_out outbound bandwidth in NBO
75 (*NotifyConnect) (void *cls,
76 const struct GNUNET_PeerIdentity *peer,
77 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
78 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
81 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 @e 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 * Current outbound quota for this peer
128 struct GNUNET_BANDWIDTH_Value32NBO quota_out;
131 * Identity of the new neighbour.
133 struct GNUNET_PeerIdentity id;
138 * Message from the transport service to the library
139 * informing about disconnects.
141 struct DisconnectInfoMessage
145 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
147 struct GNUNET_MessageHeader header;
150 * Reserved, always zero.
152 uint32_t reserved GNUNET_PACKED;
155 * Who got disconnected?
157 struct GNUNET_PeerIdentity peer;
163 * Message used to set a particular bandwidth quota. Sent TO the
164 * service to set an incoming quota, sent FROM the service to update
167 struct QuotaSetMessage
171 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
173 struct GNUNET_MessageHeader header;
178 struct GNUNET_BANDWIDTH_Value32NBO quota;
181 * About which peer are we talking here?
183 struct GNUNET_PeerIdentity peer;
189 * Message used to notify the transport API about a message
190 * received from the network. The actual message follows.
192 struct InboundMessage
196 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
198 struct GNUNET_MessageHeader header;
201 * Which peer sent the message?
203 struct GNUNET_PeerIdentity peer;
209 * Message used to notify the transport API that it can
210 * send another message to the transport service.
216 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
218 struct GNUNET_MessageHeader header;
221 * #GNUNET_OK if the transmission succeeded,
222 * #GNUNET_SYSERR if it failed (i.e. network disconnect);
223 * in either case, it is now OK for this client to
224 * send us another message for the given peer.
226 uint16_t success GNUNET_PACKED;
229 * Size of message sent
231 uint16_t bytes_msg GNUNET_PACKED;
234 * Size of message sent over wire
235 * Includes plugin and protocol specific overhead
237 uint32_t bytes_physical GNUNET_PACKED;
240 * Which peer can send more now?
242 struct GNUNET_PeerIdentity peer;
248 * Message used to notify the transport service about a message
249 * to be transmitted to another peer. The actual message follows.
251 struct OutboundMessage
255 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
257 struct GNUNET_MessageHeader header;
262 uint32_t reserved GNUNET_PACKED;
267 struct GNUNET_TIME_RelativeNBO timeout;
270 * Which peer should receive the message?
272 struct GNUNET_PeerIdentity peer;
279 #if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION)||defined(GNUNET_TRANSPORT_CORE_VERSION))
283 * Message used to notify the transport API about an address to string
284 * conversion. Message is followed by the string with the humand-readable
285 * address. For each lookup, multiple results may be returned. The
286 * last message must have a @e res of #GNUNET_OK and an @e addr_len
289 struct AddressToStringResultMessage
293 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
295 struct GNUNET_MessageHeader header;
298 * #GNUNET_OK if the conversion succeeded,
299 * #GNUNET_SYSERR if it failed
301 uint32_t res GNUNET_PACKED;
304 * Length of the following string, zero if @e is #GNUNET_SYSERR
306 uint32_t addr_len GNUNET_PACKED;
311 * Message from the library to the transport service
312 * asking for converting a transport address to a
313 * human-readable UTF-8 string.
315 struct AddressLookupMessage
319 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
321 struct GNUNET_MessageHeader header;
324 * Should the conversion use numeric IP addresses (otherwise
325 * a reverse DNS lookup is OK -- if applicable).
327 int16_t numeric_only GNUNET_PACKED;
330 * Length of the (binary) address in bytes, in big-endian.
332 uint16_t addrlen GNUNET_PACKED;
335 * timeout to give up (for DNS resolution timeout mostly)
337 struct GNUNET_TIME_RelativeNBO timeout;
339 /* followed by @e addrlen bytes of the actual address, then
340 * followed by the 0-terminated name of the transport */
345 * Message from the transport service to the library containing information
346 * about a peer. Information contained are:
347 * - current address used to communicate with this peer
352 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
354 struct ValidationIterateResponseMessage
357 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
359 struct GNUNET_MessageHeader header;
369 struct GNUNET_PeerIdentity peer;
372 * Local info about the address
374 uint32_t local_address_info GNUNET_PACKED;
379 uint32_t addrlen GNUNET_PACKED;
382 * Length of the plugin name
384 uint32_t pluginlen GNUNET_PACKED;
389 uint32_t state GNUNET_PACKED;
392 * At what time did we successfully validate the address last.
393 * Will be NEVER if the address failed validation.
395 struct GNUNET_TIME_AbsoluteNBO last_validation;
398 * Until when is the address believed to be valid.
399 * Will be ZERO if the address is not belived to be valid.
401 struct GNUNET_TIME_AbsoluteNBO valid_until;
404 * When will we next try to validate the address (typically
405 * done before @e valid_until happens).
407 struct GNUNET_TIME_AbsoluteNBO next_validation;
412 * Message from the library to the transport service
413 * asking for binary addresses known for a peer.
415 struct ValidationMonitorMessage
418 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
420 struct GNUNET_MessageHeader header;
423 * One shot call or continous replies?
425 uint32_t one_shot GNUNET_PACKED;
428 * The identity of the peer to look up.
430 struct GNUNET_PeerIdentity peer;
436 * Message from the library to the transport service
437 * asking for binary addresses known for a peer.
439 struct PeerMonitorMessage
442 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
444 struct GNUNET_MessageHeader header;
447 * One shot call or continous replies?
449 uint32_t one_shot GNUNET_PACKED;
452 * The identity of the peer to look up.
454 struct GNUNET_PeerIdentity peer;
460 * Message from the library to the transport service
461 * asking for binary addresses known for a peer.
463 struct TrafficMetricMessage
466 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
468 struct GNUNET_MessageHeader header;
473 uint32_t reserved GNUNET_PACKED;
476 * The identity of the peer to look up.
478 struct GNUNET_PeerIdentity peer;
481 * Fake properties to generate.
483 struct GNUNET_ATS_PropertiesNBO properties;
486 * Fake delay to add on inbound traffic.
488 struct GNUNET_TIME_RelativeNBO delay_in;
491 * Fake delay to add on outbound traffic.
493 struct GNUNET_TIME_RelativeNBO delay_out;
498 * Message from the transport service to the library containing information
499 * about a peer. Information contained are:
500 * - current address used to communicate with this peer
505 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
507 struct PeerIterateResponseMessage
510 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
512 struct GNUNET_MessageHeader header;
522 struct GNUNET_PeerIdentity peer;
525 * Timeout for the state this peer is in
527 struct GNUNET_TIME_AbsoluteNBO state_timeout;
530 * Local info about the address
532 uint32_t local_address_info GNUNET_PACKED;
535 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
537 uint32_t state GNUNET_PACKED;
542 uint32_t addrlen GNUNET_PACKED;
545 * Length of the plugin name
547 uint32_t pluginlen GNUNET_PACKED;
553 * Change in blacklisting (either request or notification,
554 * depending on which direction it is going).
556 struct BlacklistMessage
560 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
561 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
563 struct GNUNET_MessageHeader header;
566 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
569 uint32_t is_allowed GNUNET_PACKED;
572 * Which peer is being blacklisted or queried?
574 struct GNUNET_PeerIdentity peer;
580 * Transport-level connection status update.
582 struct TransportPluginMonitorMessage
586 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
588 struct GNUNET_MessageHeader header;
591 * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
593 uint16_t session_state GNUNET_PACKED;
596 * #GNUNET_YES if this is an inbound connection,
597 * #GNUNET_NO if this is an outbound connection,
598 * #GNUNET_SYSERR if connections of this plugin
599 * are so fundamentally bidirectional
600 * that they have no 'initiator'
601 * Value given in NBO.
603 int16_t is_inbound GNUNET_PACKED;
606 * Number of messages waiting transmission.
608 uint32_t msgs_pending GNUNET_PACKED;
611 * Number of bytes waiting for transmission.
613 uint32_t bytes_pending GNUNET_PACKED;
616 * When will this transport plugin session time out?
618 struct GNUNET_TIME_AbsoluteNBO timeout;
621 * Until how long is this plugin currently blocked from reading?
623 struct GNUNET_TIME_AbsoluteNBO delay;
626 * Which peer is this connection for?
628 struct GNUNET_PeerIdentity peer;
631 * Unique identifier for the session.
636 * Length of the plugin name in bytes, including 0-termination.
638 uint16_t plugin_name_len GNUNET_PACKED;
641 * Length of the plugin address in bytes.
643 uint16_t plugin_address_len GNUNET_PACKED;
645 /* followed by 0-terminated plugin name and
646 @e plugin_address_len bytes of plugin address */
652 /* *********************** TNG messages ***************** */
655 * Communicator goes online. Note which addresses it can
658 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage
662 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR.
664 struct GNUNET_MessageHeader header;
667 * NBO encoding of `enum GNUNET_TRANSPORT_CommunicatorCharacteristics`
671 /* Followed by the address prefix of the communicator */
676 * Add address to the list.
678 struct GNUNET_TRANSPORT_AddAddressMessage
682 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS.
684 struct GNUNET_MessageHeader header;
687 * Address identifier (used during deletion).
689 uint32_t aid GNUNET_PACKED;
692 * When does the address expire?
694 struct GNUNET_TIME_RelativeNBO expiration;
697 * An `enum GNUNET_NetworkType` in NBO.
701 /* followed by UTF-8 encoded, 0-terminated human-readable address */
706 * Remove address from the list.
708 struct GNUNET_TRANSPORT_DelAddressMessage
712 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS.
714 struct GNUNET_MessageHeader header;
717 * Address identifier.
719 uint32_t aid GNUNET_PACKED;
725 * Inform transport about an incoming message.
727 struct GNUNET_TRANSPORT_IncomingMessage
731 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG.
733 struct GNUNET_MessageHeader header;
736 * Do we use flow control or not?
738 uint32_t fc_on GNUNET_PACKED;
741 * 64-bit number to identify the matching ACK.
743 uint64_t fc_id GNUNET_PACKED;
746 * How long does the communicator believe the address on which
747 * the message was received to remain valid?
749 struct GNUNET_TIME_RelativeNBO expected_address_validity;
754 struct GNUNET_PeerIdentity sender;
756 /* followed by the message */
761 * Transport informs us about being done with an incoming message.
762 * (only sent if fc_on was set).
764 struct GNUNET_TRANSPORT_IncomingMessageAck
768 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
770 struct GNUNET_MessageHeader header;
775 uint32_t reserved GNUNET_PACKED;
778 * Which message is being ACKed?
780 uint64_t fc_id GNUNET_PACKED;
783 * Sender identifier of the original message.
785 struct GNUNET_PeerIdentity sender;
791 * Add queue to the transport
793 struct GNUNET_TRANSPORT_AddQueueMessage
797 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
799 struct GNUNET_MessageHeader header;
802 * Queue identifier (used to identify the queue).
804 uint32_t qid GNUNET_PACKED;
807 * Receiver that can be addressed via the queue.
809 struct GNUNET_PeerIdentity receiver;
812 * An `enum GNUNET_NetworkType` in NBO.
817 * Maximum transmission unit, in NBO. UINT32_MAX for unlimited.
822 * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
826 /* followed by UTF-8 encoded, 0-terminated human-readable address */
831 * Remove queue, it is no longer available.
833 struct GNUNET_TRANSPORT_DelQueueMessage
837 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN.
839 struct GNUNET_MessageHeader header;
842 * Address identifier.
844 uint32_t qid GNUNET_PACKED;
847 * Receiver that can be addressed via the queue.
849 struct GNUNET_PeerIdentity receiver;
855 * Transport tells communicator that it wants a new queue.
857 struct GNUNET_TRANSPORT_CreateQueue
861 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
863 struct GNUNET_MessageHeader header;
866 * Unique ID for the request.
868 uint32_t request_id GNUNET_PACKED;
871 * Receiver that can be addressed via the queue.
873 struct GNUNET_PeerIdentity receiver;
875 /* followed by UTF-8 encoded, 0-terminated human-readable address */
880 * Communicator tells transport how queue creation went down.
882 struct GNUNET_TRANSPORT_CreateQueueResponse
886 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL.
888 struct GNUNET_MessageHeader header;
891 * Unique ID for the request.
893 uint32_t request_id GNUNET_PACKED;
898 * Inform communicator about transport's desire to send a message.
900 struct GNUNET_TRANSPORT_SendMessageTo
904 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
906 struct GNUNET_MessageHeader header;
909 * Which queue should we use?
911 uint32_t qid GNUNET_PACKED;
914 * Message ID, used for flow control.
916 uint64_t mid GNUNET_PACKED;
919 * Receiver identifier.
921 struct GNUNET_PeerIdentity receiver;
923 /* followed by the message */
928 * Inform transport that message was sent.
930 struct GNUNET_TRANSPORT_SendMessageToAck
934 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
936 struct GNUNET_MessageHeader header;
939 * Success (#GNUNET_OK), failure (#GNUNET_SYSERR).
941 uint32_t status GNUNET_PACKED;
944 * Message ID of the original message.
946 uint64_t mid GNUNET_PACKED;
949 * Receiver identifier.
951 struct GNUNET_PeerIdentity receiver;
957 * Message from communicator to transport service asking for
958 * transmission of a backchannel message with the given peer @e pid
961 struct GNUNET_TRANSPORT_CommunicatorBackchannel
964 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
966 struct GNUNET_MessageHeader header;
969 * Always zero, for alignment.
976 struct GNUNET_PeerIdentity pid;
978 /* Followed by a `struct GNUNET_MessageHeader` with the encapsulated
979 message to the communicator */
981 /* Followed by the 0-terminated string specifying the desired
982 communicator at the target (@e pid) peer */
987 * Message from transport to communicator passing along a backchannel
988 * message from the given peer @e pid.
990 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming
993 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
995 struct GNUNET_MessageHeader header;
998 * Always zero, for alignment.
1005 struct GNUNET_PeerIdentity pid;
1007 /* Followed by a `struct GNUNET_MessageHeader` with the encapsulated
1008 message to the communicator */
1015 * Request to start monitoring.
1017 struct GNUNET_TRANSPORT_MonitorStart
1021 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START.
1023 struct GNUNET_MessageHeader header;
1026 * #GNUNET_YES for one-shot montoring, #GNUNET_NO for continuous monitoring.
1031 * Target identifier to monitor, all zeros for "all peers".
1033 struct GNUNET_PeerIdentity peer;
1041 struct GNUNET_TRANSPORT_MonitorData
1045 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA.
1047 struct GNUNET_MessageHeader header;
1050 * Network type (an `enum GNUNET_NetworkType` in NBO).
1052 uint32_t nt GNUNET_PACKED;
1055 * Target identifier.
1057 struct GNUNET_PeerIdentity peer;
1060 * @deprecated To be discussed if we keep these...
1062 struct GNUNET_TIME_AbsoluteNBO last_validation;
1063 struct GNUNET_TIME_AbsoluteNBO valid_until;
1064 struct GNUNET_TIME_AbsoluteNBO next_validation;
1067 * Current round-trip time estimate.
1069 struct GNUNET_TIME_RelativeNBO rtt;
1072 * Connection status (in NBO).
1074 uint32_t cs GNUNET_PACKED;
1077 * Messages pending (in NBO).
1079 uint32_t num_msg_pending GNUNET_PACKED;
1082 * Bytes pending (in NBO).
1084 uint32_t num_bytes_pending GNUNET_PACKED;
1086 /* Followed by 0-terminated address of the peer */
1092 * Request to verify address.
1094 struct GNUNET_TRANSPORT_AddressToVerify
1098 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY.
1100 struct GNUNET_MessageHeader header;
1108 * Peer the address is from.
1110 struct GNUNET_PeerIdentity peer;
1112 /* followed by variable-size raw address */
1117 * Application client to TRANSPORT service: we would like to have
1118 * address suggestions for this peer.
1120 struct ExpressPreferenceMessage
1123 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST or
1124 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL to stop
1127 struct GNUNET_MessageHeader header;
1130 * What type of performance preference does the client have?
1131 * A `enum GNUNET_MQ_PreferenceKind` in NBO.
1133 uint32_t pk GNUNET_PACKED;
1136 * Peer to get address suggestions for.
1138 struct GNUNET_PeerIdentity peer;
1141 * How much bandwidth in bytes/second does the application expect?
1143 struct GNUNET_BANDWIDTH_Value32NBO bw;
1149 * We got an address of another peer, TRANSPORT service
1150 * should validate it. There is no response.
1152 struct RequestHelloValidationMessage
1156 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION.
1158 struct GNUNET_MessageHeader header;
1161 * What type of network does the other peer claim this is?
1162 * A `enum GNUNET_NetworkType` in NBO.
1164 uint32_t nt GNUNET_PACKED;
1167 * Peer to the address is presumably for.
1169 struct GNUNET_PeerIdentity peer;
1172 * When does the address expire?
1174 struct GNUNET_TIME_AbsoluteNBO expiration;
1176 /* followed by 0-terminated address to validate */
1181 GNUNET_NETWORK_STRUCT_END
1183 /* end of transport.h */