2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 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 * Bandwidth allocation API for the transport service
24 * @author Christian Grothoff
25 * @author Matthias Wachs
27 * @defgroup ats ATS service
28 * Bandwidth allocation for transport service
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
34 #ifndef GNUNET_ATS_TRANSPORT_SERVICE_H
35 #define GNUNET_ATS_TRANSPORT_SERVICE_H
37 #include "gnunet_constants.h"
38 #include "gnunet_util_lib.h"
39 #include "gnunet_nt_lib.h"
40 #include "gnunet_transport_communication_service.h"
44 * ATS performance characteristics for a session.
46 struct GNUNET_ATS_Properties
49 * Delay. Time between when the time packet is sent and the packet
50 * arrives. FOREVER if we did not (successfully) measure yet.
52 struct GNUNET_TIME_Relative delay;
55 * Confirmed successful payload on this connection from this peer to
58 * Unit: [bytes/second]
63 * Confirmed useful payload on this connection to this peer from
66 * Unit: [bytes/second]
71 * Actual traffic on this connection from this peer to the other peer.
72 * Includes transport overhead.
74 * Unit: [bytes/second]
76 uint32_t utilization_out;
79 * Actual traffic on this connection from the other peer to this peer.
80 * Includes transport overhead.
82 * Unit: [bytes/second]
84 uint32_t utilization_in;
87 * Distance on network layer (required for distance-vector routing)
88 * in hops. Zero for direct connections (i.e. plain TCP/UDP).
93 * MTU of the network layer, UINT32_MAX for no MTU (stream).
100 * Which network scope does the respective address belong to?
102 enum GNUNET_NetworkType nt;
105 * What characteristics does this communicator have?
107 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
111 /* ******************************** Transport API ***************************** */
114 * Handle to the ATS subsystem for bandwidth/transport transport information.
116 struct GNUNET_ATS_TransportHandle;
119 * Opaque session handle, to be defined by transport. Contents not known to ATS.
121 struct GNUNET_ATS_Session;
125 * Signature of a function called by ATS with the current bandwidth
126 * allocation to be used as determined by ATS.
129 * @param session session this is about
130 * @param bandwidth_out assigned outbound bandwidth for the connection,
131 * 0 to signal disconnect
132 * @param bandwidth_in assigned inbound bandwidth for the connection,
133 * 0 to signal disconnect
136 (*GNUNET_ATS_AllocationCallback) (void *cls,
137 struct GNUNET_ATS_Session *session,
138 struct GNUNET_BANDWIDTH_Value32NBO
140 struct GNUNET_BANDWIDTH_Value32NBO
145 * Signature of a function called by ATS suggesting transport to
146 * try connecting with a particular address.
149 * @param pid target peer
150 * @param address the address to try
153 (*GNUNET_ATS_SuggestionCallback) (void *cls,
154 const struct GNUNET_PeerIdentity *pid,
155 const char *address);
159 * Initialize the ATS transport subsystem.
161 * @param cfg configuration to use
162 * @param alloc_cb notification to call whenever the allocation changed
163 * @param alloc_cb_cls closure for @a alloc_cb
164 * @param suggest_cb notification to call whenever the suggestation is made
165 * @param suggest_cb_cls closure for @a suggest_cb
166 * @return ats context
168 struct GNUNET_ATS_TransportHandle *
169 GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
170 GNUNET_ATS_AllocationCallback alloc_cb,
172 GNUNET_ATS_SuggestionCallback suggest_cb,
173 void *suggest_cb_cls);
177 * Client is done with ATS transport, release resources.
179 * @param ath handle to release
182 GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath);
186 * Handle used within ATS to track an session.
188 struct GNUNET_ATS_SessionRecord;
192 * We have a new session ATS should know. Sessiones have to be added with this
193 * function before they can be: updated, set in use and destroyed
196 * @param pid peer we connected to
197 * @param address the address (human readable version),
198 * @param session transport-internal handle for the session/queue, NULL if
199 * the session is inbound-only
200 * @param prop performance data for the session
201 * @return handle to the session representation inside ATS, NULL
202 * on error (i.e. ATS knows this exact session already, or
203 * session is invalid)
205 struct GNUNET_ATS_SessionRecord *
206 GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
207 const struct GNUNET_PeerIdentity *pid,
209 struct GNUNET_ATS_Session *session,
210 const struct GNUNET_ATS_Properties *prop);
214 * We have updated performance statistics for a given session. Based
215 * on the information provided, ATS may update bandwidth assignments.
217 * @param ar session record to update information for
218 * @param prop performance data for the session
221 GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
222 const struct GNUNET_ATS_Properties *prop);
226 * A session was destroyed, ATS should now schedule and
227 * allocate under the assumption that this @a ar is no
230 * @param ar session record to drop
233 GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar);
238 /** @} */ /* end of group */
240 /* end of file gnunet-service-transport_ats.h */