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 * Current outbound quota for this peer
126 struct GNUNET_BANDWIDTH_Value32NBO quota_out;
129 * Identity of the new neighbour.
131 struct GNUNET_PeerIdentity id;
136 * Message from the transport service to the library
137 * informing about disconnects.
139 struct DisconnectInfoMessage
143 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
145 struct GNUNET_MessageHeader header;
148 * Reserved, always zero.
150 uint32_t reserved GNUNET_PACKED;
153 * Who got disconnected?
155 struct GNUNET_PeerIdentity peer;
161 * Message used to set a particular bandwidth quota. Sent TO the
162 * service to set an incoming quota, sent FROM the service to update
165 struct QuotaSetMessage
169 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
171 struct GNUNET_MessageHeader header;
176 struct GNUNET_BANDWIDTH_Value32NBO quota;
179 * About which peer are we talking here?
181 struct GNUNET_PeerIdentity peer;
187 * Message used to notify the transport API about a message
188 * received from the network. The actual message follows.
190 struct InboundMessage
194 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
196 struct GNUNET_MessageHeader header;
199 * Which peer sent the message?
201 struct GNUNET_PeerIdentity peer;
207 * Message used to notify the transport API that it can
208 * send another message to the transport service.
214 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
216 struct GNUNET_MessageHeader header;
219 * #GNUNET_OK if the transmission succeeded,
220 * #GNUNET_SYSERR if it failed (i.e. network disconnect);
221 * in either case, it is now OK for this client to
222 * send us another message for the given peer.
224 uint32_t success GNUNET_PACKED;
227 * Size of message sent
229 uint32_t bytes_msg GNUNET_PACKED;
232 * Size of message sent over wire
233 * Includes plugin and protocol specific overhead
235 uint32_t bytes_physical GNUNET_PACKED;
238 * Which peer can send more now?
240 struct GNUNET_PeerIdentity peer;
245 * Message used to notify the transport API about an address to string
246 * conversion. Message is followed by the string with the humand-readable
247 * address. For each lookup, multiple results may be returned. The
248 * last message must have a @e res of #GNUNET_OK and an @e addr_len
251 struct AddressToStringResultMessage
255 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
257 struct GNUNET_MessageHeader header;
260 * #GNUNET_OK if the conversion succeeded,
261 * #GNUNET_SYSERR if it failed
263 uint32_t res GNUNET_PACKED;
266 * Length of the following string, zero if @e is #GNUNET_SYSERR
268 uint32_t addr_len GNUNET_PACKED;
273 * Message used to notify the transport service about a message
274 * to be transmitted to another peer. The actual message follows.
276 struct OutboundMessage
280 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
282 struct GNUNET_MessageHeader header;
287 uint32_t reserved GNUNET_PACKED;
292 struct GNUNET_TIME_RelativeNBO timeout;
295 * Which peer should receive the message?
297 struct GNUNET_PeerIdentity peer;
303 * Message from the library to the transport service
304 * asking for converting a transport address to a
305 * human-readable UTF-8 string.
307 struct AddressLookupMessage
311 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
313 struct GNUNET_MessageHeader header;
316 * Should the conversion use numeric IP addresses (otherwise
317 * a reverse DNS lookup is OK -- if applicable).
319 int16_t numeric_only GNUNET_PACKED;
322 * Length of the (binary) address in bytes, in big-endian.
324 uint16_t addrlen GNUNET_PACKED;
327 * timeout to give up (for DNS resolution timeout mostly)
329 struct GNUNET_TIME_RelativeNBO timeout;
331 /* followed by @e addrlen bytes of the actual address, then
332 * followed by the 0-terminated name of the transport */
337 * Message from the transport service to the library containing information
338 * about a peer. Information contained are:
339 * - current address used to communicate with this peer
344 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
346 struct ValidationIterateResponseMessage
349 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
351 struct GNUNET_MessageHeader header;
361 struct GNUNET_PeerIdentity peer;
364 * Local info about the address
366 uint32_t local_address_info GNUNET_PACKED;
371 uint32_t addrlen GNUNET_PACKED;
374 * Length of the plugin name
376 uint32_t pluginlen GNUNET_PACKED;
381 uint32_t state GNUNET_PACKED;
384 * At what time did we successfully validate the address last.
385 * Will be NEVER if the address failed validation.
387 struct GNUNET_TIME_AbsoluteNBO last_validation;
390 * Until when is the address believed to be valid.
391 * Will be ZERO if the address is not belived to be valid.
393 struct GNUNET_TIME_AbsoluteNBO valid_until;
396 * When will we next try to validate the address (typically
397 * done before @e valid_until happens).
399 struct GNUNET_TIME_AbsoluteNBO next_validation;
404 * Message from the library to the transport service
405 * asking for binary addresses known for a peer.
407 struct ValidationMonitorMessage
410 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
412 struct GNUNET_MessageHeader header;
415 * One shot call or continous replies?
417 uint32_t one_shot GNUNET_PACKED;
420 * The identity of the peer to look up.
422 struct GNUNET_PeerIdentity peer;
428 * Message from the library to the transport service
429 * asking for binary addresses known for a peer.
431 struct PeerMonitorMessage
434 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
436 struct GNUNET_MessageHeader header;
439 * One shot call or continous replies?
441 uint32_t one_shot GNUNET_PACKED;
444 * The identity of the peer to look up.
446 struct GNUNET_PeerIdentity peer;
452 * Message from the library to the transport service
453 * asking for binary addresses known for a peer.
455 struct TrafficMetricMessage
458 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
460 struct GNUNET_MessageHeader header;
465 uint32_t reserved GNUNET_PACKED;
468 * The identity of the peer to look up.
470 struct GNUNET_PeerIdentity peer;
473 * Fake properties to generate.
475 struct GNUNET_ATS_PropertiesNBO properties;
478 * Fake delay to add on inbound traffic.
480 struct GNUNET_TIME_RelativeNBO delay_in;
483 * Fake delay to add on outbound traffic.
485 struct GNUNET_TIME_RelativeNBO delay_out;
490 * Message from the transport service to the library containing information
491 * about a peer. Information contained are:
492 * - current address used to communicate with this peer
497 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
499 struct PeerIterateResponseMessage
502 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
504 struct GNUNET_MessageHeader header;
514 struct GNUNET_PeerIdentity peer;
517 * Timeout for the state this peer is in
519 struct GNUNET_TIME_AbsoluteNBO state_timeout;
522 * Local info about the address
524 uint32_t local_address_info GNUNET_PACKED;
527 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
529 uint32_t state GNUNET_PACKED;
534 uint32_t addrlen GNUNET_PACKED;
537 * Length of the plugin name
539 uint32_t pluginlen GNUNET_PACKED;
545 * Change in blacklisting (either request or notification,
546 * depending on which direction it is going).
548 struct BlacklistMessage
552 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
553 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
555 struct GNUNET_MessageHeader header;
558 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
561 uint32_t is_allowed GNUNET_PACKED;
564 * Which peer is being blacklisted or queried?
566 struct GNUNET_PeerIdentity peer;
572 * Transport-level connection status update.
574 struct TransportPluginMonitorMessage
578 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
580 struct GNUNET_MessageHeader header;
583 * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
585 uint16_t session_state GNUNET_PACKED;
588 * #GNUNET_YES if this is an inbound connection,
589 * #GNUNET_NO if this is an outbound connection,
590 * #GNUNET_SYSERR if connections of this plugin
591 * are so fundamentally bidirectional
592 * that they have no 'initiator'
593 * Value given in NBO.
595 int16_t is_inbound GNUNET_PACKED;
598 * Number of messages waiting transmission.
600 uint32_t msgs_pending GNUNET_PACKED;
603 * Number of bytes waiting for transmission.
605 uint32_t bytes_pending GNUNET_PACKED;
608 * When will this transport plugin session time out?
610 struct GNUNET_TIME_AbsoluteNBO timeout;
613 * Until how long is this plugin currently blocked from reading?
615 struct GNUNET_TIME_AbsoluteNBO delay;
618 * Which peer is this connection for?
620 struct GNUNET_PeerIdentity peer;
623 * Unique identifier for the session.
628 * Length of the plugin name in bytes, including 0-termination.
630 uint16_t plugin_name_len GNUNET_PACKED;
633 * Length of the plugin address in bytes.
635 uint16_t plugin_address_len GNUNET_PACKED;
637 /* followed by 0-terminated plugin name and
638 @e plugin_address_len bytes of plugin address */
650 /* *********************** TNG messages ***************** */
653 * Communicator goes online. Note which addresses it can
656 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage
660 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR.
662 struct GNUNET_MessageHeader header;
664 /* Followed by the address prefix of the communicator */
669 * Add address to the list.
671 struct GNUNET_TRANSPORT_AddAddressMessage
675 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS.
677 struct GNUNET_MessageHeader header;
680 * Address identifier (used during deletion).
682 uint32_t aid GNUNET_PACKED;
685 * When does the address expire?
687 struct GNUNET_TIME_RelativeNBO expiration;
690 * An `enum GNUNET_ATS_Network_Type` in NBO.
694 /* followed by UTF-8 encoded, 0-terminated human-readable address */
699 * Remove address from the list.
701 struct GNUNET_TRANSPORT_DelAddressMessage
705 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS.
707 struct GNUNET_MessageHeader header;
710 * Address identifier.
712 uint32_t aid GNUNET_PACKED;
718 * Inform transport about an incoming message.
720 struct GNUNET_TRANSPORT_IncomingMessage
724 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG.
726 struct GNUNET_MessageHeader header;
729 * Do we use flow control or not?
731 uint32_t fc_on GNUNET_PACKED;
734 * 64-bit number to identify the matching ACK.
736 uint64_t fc_id GNUNET_PACKED;
741 struct GNUNET_PeerIdentity sender;
743 /* followed by the message */
748 * Transport informs us about being done with an incoming message.
749 * (only sent if fc_on was set).
751 struct GNUNET_TRANSPORT_IncomingMessageAck
755 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
757 struct GNUNET_MessageHeader header;
762 uint32_t reserved GNUNET_PACKED;
765 * Which message is being ACKed?
767 uint64_t fc_id GNUNET_PACKED;
770 * Sender identifier of the original message.
772 struct GNUNET_PeerIdentity sender;
778 * Add queue to the transport
780 struct GNUNET_TRANSPORT_AddQueueMessage
784 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
786 struct GNUNET_MessageHeader header;
789 * Queue identifier (used to identify the queue).
791 uint32_t qid GNUNET_PACKED;
794 * Receiver that can be addressed via the queue.
796 struct GNUNET_PeerIdentity receiver;
799 * An `enum GNUNET_ATS_Network_Type` in NBO.
805 /* followed by UTF-8 encoded, 0-terminated human-readable address */
810 * Remove queue, it is no longer available.
812 struct GNUNET_TRANSPORT_DelQueueMessage
816 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN.
818 struct GNUNET_MessageHeader header;
821 * Address identifier.
823 uint32_t qid GNUNET_PACKED;
826 * Receiver that can be addressed via the queue.
828 struct GNUNET_PeerIdentity receiver;
834 * Transport tells communicator that it wants a new queue.
836 struct GNUNET_TRANSPORT_CreateQueue
840 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
842 struct GNUNET_MessageHeader header;
845 * Unique ID for the request.
847 uint32_t request_id GNUNET_PACKED;
850 * Receiver that can be addressed via the queue.
852 struct GNUNET_PeerIdentity receiver;
854 /* followed by UTF-8 encoded, 0-terminated human-readable address */
859 * Transport tells communicator that it wants a new queue.
861 struct GNUNET_TRANSPORT_CreateQueueResponse
865 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL.
867 struct GNUNET_MessageHeader header;
870 * Unique ID for the request.
872 uint32_t request_id GNUNET_PACKED;
877 * Inform communicator about transport's desire to send a message.
879 struct GNUNET_TRANSPORT_SendMessageTo
883 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
885 struct GNUNET_MessageHeader header;
888 * Which queue should we use?
890 uint32_t qid GNUNET_PACKED;
893 * Message ID, used for flow control.
895 uint64_t mid GNUNET_PACKED;
898 * Receiver identifier.
900 struct GNUNET_PeerIdentity receiver;
902 /* followed by the message */
907 * Inform transport that message was sent.
909 struct GNUNET_TRANSPORT_SendMessageToAck
913 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
915 struct GNUNET_MessageHeader header;
918 * Success (#GNUNET_OK), failure (#GNUNET_SYSERR).
920 uint32_t status GNUNET_PACKED;
923 * Message ID of the original message.
925 uint64_t mid GNUNET_PACKED;
928 * Receiver identifier.
930 struct GNUNET_PeerIdentity receiver;
938 * Request to start monitoring.
940 struct GNUNET_TRANSPORT_MonitorStart
944 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START.
946 struct GNUNET_MessageHeader header;
949 * #GNUNET_YES for one-shot montoring, #GNUNET_NO for continuous monitoring.
954 * Target identifier to monitor, all zeros for "all peers".
956 struct GNUNET_PeerIdentity peer;
964 struct GNUNET_TRANSPORT_MonitorData
968 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA.
970 struct GNUNET_MessageHeader header;
973 * Network type (an `enum GNUNET_ATS_Network_Type` in NBO).
975 uint32_t nt GNUNET_PACKED;
980 struct GNUNET_PeerIdentity peer;
983 * @deprecated To be discussed if we keep these...
985 struct GNUNET_TIME_AbsoluteNBO last_validation;
986 struct GNUNET_TIME_AbsoluteNBO valid_until;
987 struct GNUNET_TIME_AbsoluteNBO next_validation;
990 * Current round-trip time estimate.
992 struct GNUNET_TIME_RelativeNBO rtt;
995 * Is inbound (in NBO).
997 uint32_t is_inbound GNUNET_PACKED;
1000 * Messages pending (in NBO).
1002 uint32_t num_msg_pending GNUNET_PACKED;
1005 * Bytes pending (in NBO).
1007 uint32_t num_bytes_pending GNUNET_PACKED;
1009 /* Followed by 0-terminated address of the peer
1010 (TODO: do we allow no address? If so,
1011 adjust transport_api2_monitor!) */
1019 GNUNET_NETWORK_STRUCT_END
1021 /* end of transport.h */