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.
17 * @file transport/transport.h
18 * @brief common internal definitions for transport service
19 * @author Christian Grothoff
24 #include "gnunet_crypto_lib.h"
25 #include "gnunet_time_lib.h"
26 #include "gnunet_transport_service.h"
27 #include "gnunet_constants.h"
29 #define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
33 * For how long do we allow unused bandwidth
34 * from the past to carry over into the future? (in seconds)
36 #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
39 * How often do we (at most) do a full quota
40 * recalculation? (in ms)
42 #define MIN_QUOTA_REFRESH_TIME 2000
45 * What's the maximum number of sockets transport uses for validation and
48 #define DEFAULT_MAX_FDS 256
51 * Maximum frequency for re-evaluating latencies for all transport addresses.
53 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
56 * Maximum frequency for re-evaluating latencies for connected addresses.
58 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
61 * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
62 * included here. These values are not required outside transport_api
65 * @param peer the peer that connected
66 * @param bandwidth_in inbound bandwidth in NBO
67 * @param bandwidth_out outbound bandwidth in NBO
71 (*NotifyConnect) (void *cls,
72 const struct GNUNET_PeerIdentity *peer,
73 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
77 GNUNET_NETWORK_STRUCT_BEGIN
80 * Message from the transport service to the library
81 * asking to check if both processes agree about this
88 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START
90 struct GNUNET_MessageHeader header;
94 * 1: The 'self' field should be checked
95 * 2: this client is interested in payload traffic
100 * Identity we think we have. If it does not match, the
101 * receiver should print out an error message and disconnect.
103 struct GNUNET_PeerIdentity self;
109 * Message from the transport service to the library
110 * informing about neighbors.
112 struct ConnectInfoMessage
116 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
118 struct GNUNET_MessageHeader header;
121 * Identity of the new neighbour.
123 struct GNUNET_PeerIdentity id;
126 * Current inbound quota for this peer
128 struct GNUNET_BANDWIDTH_Value32NBO quota_in;
131 * Current outbound quota for this peer
133 struct GNUNET_BANDWIDTH_Value32NBO quota_out;
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 uint32_t success GNUNET_PACKED;
229 * Size of message sent
231 uint32_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;
247 * Message used to notify the transport API about an address to string
248 * conversion. Message is followed by the string with the humand-readable
249 * address. For each lookup, multiple results may be returned. The
250 * last message must have a @e res of #GNUNET_OK and an @e addr_len
253 struct AddressToStringResultMessage
257 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
259 struct GNUNET_MessageHeader header;
262 * #GNUNET_OK if the conversion succeeded,
263 * #GNUNET_SYSERR if it failed
265 uint32_t res GNUNET_PACKED;
268 * Length of the following string, zero if @e is #GNUNET_SYSERR
270 uint32_t addr_len GNUNET_PACKED;
275 * Message used to notify the transport service about a message
276 * to be transmitted to another peer. The actual message follows.
278 struct OutboundMessage
282 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
284 struct GNUNET_MessageHeader header;
289 uint32_t reserved GNUNET_PACKED;
294 struct GNUNET_TIME_RelativeNBO timeout;
297 * Which peer should receive the message?
299 struct GNUNET_PeerIdentity peer;
305 * Message from the library to the transport service
306 * asking for converting a transport address to a
307 * human-readable UTF-8 string.
309 struct AddressLookupMessage
313 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
315 struct GNUNET_MessageHeader header;
318 * Should the conversion use numeric IP addresses (otherwise
319 * a reverse DNS lookup is OK -- if applicable).
321 int16_t numeric_only GNUNET_PACKED;
324 * Length of the (binary) address in bytes, in big-endian.
326 uint16_t addrlen GNUNET_PACKED;
329 * timeout to give up (for DNS resolution timeout mostly)
331 struct GNUNET_TIME_RelativeNBO timeout;
333 /* followed by @e addrlen bytes of the actual address, then
334 * followed by the 0-terminated name of the transport */
339 * Message from the transport service to the library containing information
340 * about a peer. Information contained are:
341 * - current address used to communicate with this peer
346 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
348 struct ValidationIterateResponseMessage
351 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
353 struct GNUNET_MessageHeader header;
363 struct GNUNET_PeerIdentity peer;
366 * Local info about the address
368 uint32_t local_address_info GNUNET_PACKED;
373 uint32_t addrlen GNUNET_PACKED;
376 * Length of the plugin name
378 uint32_t pluginlen GNUNET_PACKED;
383 uint32_t state GNUNET_PACKED;
386 * At what time did we successfully validate the address last.
387 * Will be NEVER if the address failed validation.
389 struct GNUNET_TIME_AbsoluteNBO last_validation;
392 * Until when is the address believed to be valid.
393 * Will be ZERO if the address is not belived to be valid.
395 struct GNUNET_TIME_AbsoluteNBO valid_until;
398 * When will we next try to validate the address (typically
399 * done before @e valid_until happens).
401 struct GNUNET_TIME_AbsoluteNBO next_validation;
405 * Message from the library to the transport service
406 * asking for binary addresses known for a peer.
408 struct ValidationMonitorMessage
411 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
413 struct GNUNET_MessageHeader header;
416 * One shot call or continous replies?
418 uint32_t one_shot GNUNET_PACKED;
421 * The identity of the peer to look up.
423 struct GNUNET_PeerIdentity peer;
429 * Message from the library to the transport service
430 * asking for binary addresses known for a peer.
432 struct PeerMonitorMessage
435 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
437 struct GNUNET_MessageHeader header;
440 * One shot call or continous replies?
442 uint32_t one_shot GNUNET_PACKED;
445 * The identity of the peer to look up.
447 struct GNUNET_PeerIdentity peer;
453 * Message from the library to the transport service
454 * asking for binary addresses known for a peer.
456 struct TrafficMetricMessage
459 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
461 struct GNUNET_MessageHeader header;
466 uint32_t reserved GNUNET_PACKED;
469 * The identity of the peer to look up.
471 struct GNUNET_PeerIdentity peer;
474 * Fake properties to generate.
476 struct GNUNET_ATS_PropertiesNBO properties;
479 * Fake delay to add on inbound traffic.
481 struct GNUNET_TIME_RelativeNBO delay_in;
484 * Fake delay to add on outbound traffic.
486 struct GNUNET_TIME_RelativeNBO delay_out;
491 * Message from the transport service to the library containing information
492 * about a peer. Information contained are:
493 * - current address used to communicate with this peer
498 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
500 struct PeerIterateResponseMessage
503 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
505 struct GNUNET_MessageHeader header;
515 struct GNUNET_PeerIdentity peer;
518 * Timeout for the state this peer is in
520 struct GNUNET_TIME_AbsoluteNBO state_timeout;
523 * Local info about the address
525 uint32_t local_address_info GNUNET_PACKED;
528 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
530 uint32_t state GNUNET_PACKED;
535 uint32_t addrlen GNUNET_PACKED;
538 * Length of the plugin name
540 uint32_t pluginlen GNUNET_PACKED;
546 * Change in blacklisting (either request or notification,
547 * depending on which direction it is going).
549 struct BlacklistMessage
553 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
554 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
556 struct GNUNET_MessageHeader header;
559 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
562 uint32_t is_allowed GNUNET_PACKED;
565 * Which peer is being blacklisted or queried?
567 struct GNUNET_PeerIdentity peer;
573 * Transport-level connection status update.
575 struct TransportPluginMonitorMessage
579 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
581 struct GNUNET_MessageHeader header;
584 * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
586 uint16_t session_state GNUNET_PACKED;
589 * #GNUNET_YES if this is an inbound connection,
590 * #GNUNET_NO if this is an outbound connection,
591 * #GNUNET_SYSERR if connections of this plugin
592 * are so fundamentally bidirectional
593 * that they have no 'initiator'
594 * Value given in NBO.
596 int16_t is_inbound GNUNET_PACKED;
599 * Number of messages waiting transmission.
601 uint32_t msgs_pending GNUNET_PACKED;
604 * Number of bytes waiting for transmission.
606 uint32_t bytes_pending GNUNET_PACKED;
609 * When will this transport plugin session time out?
611 struct GNUNET_TIME_AbsoluteNBO timeout;
614 * Until how long is this plugin currently blocked from reading?
616 struct GNUNET_TIME_AbsoluteNBO delay;
619 * Which peer is this connection for?
621 struct GNUNET_PeerIdentity peer;
624 * Unique identifier for the session.
629 * Length of the plugin name in bytes, including 0-termination.
631 uint16_t plugin_name_len GNUNET_PACKED;
634 * Length of the plugin address in bytes.
636 uint16_t plugin_address_len GNUNET_PACKED;
638 /* followed by 0-terminated plugin name and
639 @e plugin_address_len bytes of plugin address */
644 GNUNET_NETWORK_STRUCT_END
646 /* end of transport.h */