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 '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;
408 * Message from the library to the transport service
409 * asking for binary addresses known for a peer.
411 struct ValidationMonitorMessage
414 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
416 struct GNUNET_MessageHeader header;
419 * One shot call or continous replies?
421 uint32_t one_shot GNUNET_PACKED;
424 * The identity of the peer to look up.
426 struct GNUNET_PeerIdentity peer;
432 * Message from the library to the transport service
433 * asking for binary addresses known for a peer.
435 struct PeerMonitorMessage
438 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
440 struct GNUNET_MessageHeader header;
443 * One shot call or continous replies?
445 uint32_t one_shot GNUNET_PACKED;
448 * The identity of the peer to look up.
450 struct GNUNET_PeerIdentity peer;
456 * Message from the library to the transport service
457 * asking for binary addresses known for a peer.
459 struct TrafficMetricMessage
462 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
464 struct GNUNET_MessageHeader header;
469 uint32_t reserved GNUNET_PACKED;
472 * The identity of the peer to look up.
474 struct GNUNET_PeerIdentity peer;
477 * Fake properties to generate.
479 struct GNUNET_ATS_PropertiesNBO properties;
482 * Fake delay to add on inbound traffic.
484 struct GNUNET_TIME_RelativeNBO delay_in;
487 * Fake delay to add on outbound traffic.
489 struct GNUNET_TIME_RelativeNBO delay_out;
494 * Message from the transport service to the library containing information
495 * about a peer. Information contained are:
496 * - current address used to communicate with this peer
501 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
503 struct PeerIterateResponseMessage
506 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
508 struct GNUNET_MessageHeader header;
518 struct GNUNET_PeerIdentity peer;
521 * Timeout for the state this peer is in
523 struct GNUNET_TIME_AbsoluteNBO state_timeout;
526 * Local info about the address
528 uint32_t local_address_info GNUNET_PACKED;
531 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
533 uint32_t state GNUNET_PACKED;
538 uint32_t addrlen GNUNET_PACKED;
541 * Length of the plugin name
543 uint32_t pluginlen GNUNET_PACKED;
549 * Change in blacklisting (either request or notification,
550 * depending on which direction it is going).
552 struct BlacklistMessage
556 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
557 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
559 struct GNUNET_MessageHeader header;
562 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
565 uint32_t is_allowed GNUNET_PACKED;
568 * Which peer is being blacklisted or queried?
570 struct GNUNET_PeerIdentity peer;
576 * Transport-level connection status update.
578 struct TransportPluginMonitorMessage
582 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
584 struct GNUNET_MessageHeader header;
587 * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
589 uint16_t session_state GNUNET_PACKED;
592 * #GNUNET_YES if this is an inbound connection,
593 * #GNUNET_NO if this is an outbound connection,
594 * #GNUNET_SYSERR if connections of this plugin
595 * are so fundamentally bidirectional
596 * that they have no 'initiator'
597 * Value given in NBO.
599 int16_t is_inbound GNUNET_PACKED;
602 * Number of messages waiting transmission.
604 uint32_t msgs_pending GNUNET_PACKED;
607 * Number of bytes waiting for transmission.
609 uint32_t bytes_pending GNUNET_PACKED;
612 * When will this transport plugin session time out?
614 struct GNUNET_TIME_AbsoluteNBO timeout;
617 * Until how long is this plugin currently blocked from reading?
619 struct GNUNET_TIME_AbsoluteNBO delay;
622 * Which peer is this connection for?
624 struct GNUNET_PeerIdentity peer;
627 * Unique identifier for the session.
632 * Length of the plugin name in bytes, including 0-termination.
634 uint16_t plugin_name_len GNUNET_PACKED;
637 * Length of the plugin address in bytes.
639 uint16_t plugin_address_len GNUNET_PACKED;
641 /* followed by 0-terminated plugin name and
642 @e plugin_address_len bytes of plugin address */
654 /* *********************** TNG messages ***************** */
657 * Add address to the list.
659 struct GNUNET_TRANSPORT_AddAddressMessage
663 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS.
665 struct GNUNET_MessageHeader header;
668 * Address identifier (used during deletion).
670 uint32_t aid GNUNET_PACKED;
673 * When does the address expire?
675 struct GNUNET_TIME_RelativeNBO expiration;
678 * An `enum GNUNET_ATS_Network_Type` in NBO.
682 /* followed by UTF-8 encoded, 0-terminated human-readable address */
687 * Remove address from the list.
689 struct GNUNET_TRANSPORT_DelAddressMessage
693 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS.
695 struct GNUNET_MessageHeader header;
698 * Address identifier.
700 uint32_t aid GNUNET_PACKED;
706 * Inform transport about an incoming message.
708 struct GNUNET_TRANSPORT_IncomingMessage
712 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG.
714 struct GNUNET_MessageHeader header;
717 * Do we use flow control or not?
719 uint32_t fc_on GNUNET_PACKED;
722 * 64-bit number to identify the matching ACK.
724 uint64_t fc_id GNUNET_PACKED;
729 struct GNUNET_PeerIdentity sender GNUNET_PACKED;
731 /* followed by the message */
736 * Transport informs us about being done with an incoming message.
737 * (only sent if fc_on was set).
739 struct GNUNET_TRANSPORT_IncomingMessageAck
743 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
745 struct GNUNET_MessageHeader header;
750 uint32_t reserved GNUNET_PACKED;
753 * Which message is being ACKed?
755 uint64_t fc_id GNUNET_PACKED;
758 * Sender identifier of the original message.
760 struct GNUNET_PeerIdentity sender GNUNET_PACKED;
766 * Add queue to the transport
768 struct GNUNET_TRANSPORT_AddQueueMessage
772 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_QUEUE.
774 struct GNUNET_MessageHeader header;
777 * Queue identifier (used to identify the queue).
779 uint32_t qid GNUNET_PACKED;
782 * Receiver that can be addressed via the queue.
784 struct GNUNET_PeerIdentity receiver GNUNET_PACKED;
787 * An `enum GNUNET_ATS_Network_Type` in NBO.
791 /* followed by UTF-8 encoded, 0-terminated human-readable address */
796 * Remove queue, it is no longer available.
798 struct GNUNET_TRANSPORT_DelQueueMessage
802 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_QUEUE.
804 struct GNUNET_MessageHeader header;
807 * Address identifier.
809 uint32_t qid GNUNET_PACKED;
812 * Receiver that can be addressed via the queue.
814 struct GNUNET_PeerIdentity receiver GNUNET_PACKED;
820 * Transport tells communicator that it wants a new queue.
822 struct GNUNET_TRANSPORT_CreateQueue
826 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
828 struct GNUNET_MessageHeader header;
833 uint32_t reserved GNUNET_PACKED;
836 * Receiver that can be addressed via the queue.
838 struct GNUNET_PeerIdentity receiver GNUNET_PACKED;
840 /* followed by UTF-8 encoded, 0-terminated human-readable address */
845 * Inform communicator about transport's desire to send a message.
847 struct GNUNET_TRANSPORT_SendMessageTo
851 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
853 struct GNUNET_MessageHeader header;
856 * Which queue should we use?
858 uint32_t qid GNUNET_PACKED;
861 * Message ID, used for flow control.
863 uint64_t mid GNUNET_PACKED;
866 * Receiver identifier.
868 struct GNUNET_PeerIdentity receiver GNUNET_PACKED;
870 /* followed by the message */
875 * Inform transport that message was sent.
877 struct GNUNET_TRANSPORT_SendMessageToAck
881 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
883 struct GNUNET_MessageHeader header;
886 * Success (#GNUNET_OK), failure (#GNUNET_SYSERR).
888 uint32_t status GNUNET_PACKED;
891 * Message ID of the original message.
893 uint64_t mid GNUNET_PACKED;
896 * Receiver identifier.
898 struct GNUNET_PeerIdentity receiver GNUNET_PACKED;
904 GNUNET_NETWORK_STRUCT_END
906 /* end of transport.h */