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
50 * Delay. Time between when the time packet is sent and the packet
51 * arrives. FOREVER if we did not (successfully) measure yet.
53 struct GNUNET_TIME_Relative delay;
56 * Confirmed successful payload on this connection from this peer to
59 * Unit: [bytes/second]
64 * Confirmed useful payload on this connection to this peer from
67 * Unit: [bytes/second]
72 * Actual traffic on this connection from this peer to the other peer.
73 * Includes transport overhead.
75 * Unit: [bytes/second]
77 uint32_t utilization_out;
80 * Actual traffic on this connection from the other peer to this peer.
81 * Includes transport overhead.
83 * Unit: [bytes/second]
85 uint32_t utilization_in;
88 * Distance on network layer (required for distance-vector routing)
89 * in hops. Zero for direct connections (i.e. plain TCP/UDP).
94 * MTU of the network layer, UINT32_MAX for no MTU (stream).
101 * Which network scope does the respective address belong to?
103 enum GNUNET_NetworkType nt;
106 * What characteristics does this communicator have?
108 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
113 /* ******************************** Transport API ***************************** */
116 * Handle to the ATS subsystem for bandwidth/transport transport information.
118 struct GNUNET_ATS_TransportHandle;
121 * Opaque session handle, to be defined by transport. Contents not known to ATS.
123 struct GNUNET_ATS_Session;
127 * Signature of a function called by ATS with the current bandwidth
128 * allocation to be used as determined by ATS.
131 * @param session session this is about
132 * @param bandwidth_out assigned outbound bandwidth for the connection,
133 * 0 to signal disconnect
134 * @param bandwidth_in assigned inbound bandwidth for the connection,
135 * 0 to signal disconnect
138 (*GNUNET_ATS_AllocationCallback) (void *cls,
139 struct GNUNET_ATS_Session *session,
140 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
141 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
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 */