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;
748 struct GNUNET_PeerIdentity sender;
750 /* followed by the message */
755 * Transport informs us about being done with an incoming message.
756 * (only sent if fc_on was set).
758 struct GNUNET_TRANSPORT_IncomingMessageAck
762 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
764 struct GNUNET_MessageHeader header;
769 uint32_t reserved GNUNET_PACKED;
772 * Which message is being ACKed?
774 uint64_t fc_id GNUNET_PACKED;
777 * Sender identifier of the original message.
779 struct GNUNET_PeerIdentity sender;
785 * Add queue to the transport
787 struct GNUNET_TRANSPORT_AddQueueMessage
791 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
793 struct GNUNET_MessageHeader header;
796 * Queue identifier (used to identify the queue).
798 uint32_t qid GNUNET_PACKED;
801 * Receiver that can be addressed via the queue.
803 struct GNUNET_PeerIdentity receiver;
806 * An `enum GNUNET_NetworkType` in NBO.
811 * Maximum transmission unit, in NBO. UINT32_MAX for unlimited.
816 * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
820 /* followed by UTF-8 encoded, 0-terminated human-readable address */
825 * Remove queue, it is no longer available.
827 struct GNUNET_TRANSPORT_DelQueueMessage
831 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN.
833 struct GNUNET_MessageHeader header;
836 * Address identifier.
838 uint32_t qid GNUNET_PACKED;
841 * Receiver that can be addressed via the queue.
843 struct GNUNET_PeerIdentity receiver;
849 * Transport tells communicator that it wants a new queue.
851 struct GNUNET_TRANSPORT_CreateQueue
855 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
857 struct GNUNET_MessageHeader header;
860 * Unique ID for the request.
862 uint32_t request_id GNUNET_PACKED;
865 * Receiver that can be addressed via the queue.
867 struct GNUNET_PeerIdentity receiver;
869 /* followed by UTF-8 encoded, 0-terminated human-readable address */
874 * Communicator tells transport how queue creation went down.
876 struct GNUNET_TRANSPORT_CreateQueueResponse
880 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL.
882 struct GNUNET_MessageHeader header;
885 * Unique ID for the request.
887 uint32_t request_id GNUNET_PACKED;
892 * Inform communicator about transport's desire to send a message.
894 struct GNUNET_TRANSPORT_SendMessageTo
898 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
900 struct GNUNET_MessageHeader header;
903 * Which queue should we use?
905 uint32_t qid GNUNET_PACKED;
908 * Message ID, used for flow control.
910 uint64_t mid GNUNET_PACKED;
913 * Receiver identifier.
915 struct GNUNET_PeerIdentity receiver;
917 /* followed by the message */
922 * Inform transport that message was sent.
924 struct GNUNET_TRANSPORT_SendMessageToAck
928 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
930 struct GNUNET_MessageHeader header;
933 * Success (#GNUNET_OK), failure (#GNUNET_SYSERR).
935 uint32_t status GNUNET_PACKED;
938 * Message ID of the original message.
940 uint64_t mid GNUNET_PACKED;
943 * Receiver identifier.
945 struct GNUNET_PeerIdentity receiver;
951 * Message from communicator to transport service asking for
952 * transmission of a backchannel message with the given peer @e pid
955 struct GNUNET_TRANSPORT_CommunicatorBackchannel
958 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
960 struct GNUNET_MessageHeader header;
963 * Always zero, for alignment.
970 struct GNUNET_PeerIdentity pid;
972 /* Followed by a `struct GNUNET_MessageHeader` with the encapsulated
973 message to the communicator */
975 /* Followed by the 0-terminated string specifying the desired
976 communicator at the target (@e pid) peer */
981 * Message from transport to communicator passing along a backchannel
982 * message from the given peer @e pid.
984 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming
987 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
989 struct GNUNET_MessageHeader header;
992 * Always zero, for alignment.
999 struct GNUNET_PeerIdentity pid;
1001 /* Followed by a `struct GNUNET_MessageHeader` with the encapsulated
1002 message to the communicator */
1009 * Request to start monitoring.
1011 struct GNUNET_TRANSPORT_MonitorStart
1015 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START.
1017 struct GNUNET_MessageHeader header;
1020 * #GNUNET_YES for one-shot montoring, #GNUNET_NO for continuous monitoring.
1025 * Target identifier to monitor, all zeros for "all peers".
1027 struct GNUNET_PeerIdentity peer;
1035 struct GNUNET_TRANSPORT_MonitorData
1039 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA.
1041 struct GNUNET_MessageHeader header;
1044 * Network type (an `enum GNUNET_NetworkType` in NBO).
1046 uint32_t nt GNUNET_PACKED;
1049 * Target identifier.
1051 struct GNUNET_PeerIdentity peer;
1054 * @deprecated To be discussed if we keep these...
1056 struct GNUNET_TIME_AbsoluteNBO last_validation;
1057 struct GNUNET_TIME_AbsoluteNBO valid_until;
1058 struct GNUNET_TIME_AbsoluteNBO next_validation;
1061 * Current round-trip time estimate.
1063 struct GNUNET_TIME_RelativeNBO rtt;
1066 * Connection status (in NBO).
1068 uint32_t cs GNUNET_PACKED;
1071 * Messages pending (in NBO).
1073 uint32_t num_msg_pending GNUNET_PACKED;
1076 * Bytes pending (in NBO).
1078 uint32_t num_bytes_pending GNUNET_PACKED;
1080 /* Followed by 0-terminated address of the peer */
1086 GNUNET_NETWORK_STRUCT_END
1088 /* end of transport.h */