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 {
48 * Delay. Time between when the time packet is sent and the packet
49 * arrives. FOREVER if we did not (successfully) measure yet.
51 struct GNUNET_TIME_Relative delay;
54 * Confirmed successful payload on this connection from this peer to
57 * Unit: [bytes/second]
62 * Confirmed useful payload on this connection to this peer from
65 * Unit: [bytes/second]
70 * Actual traffic on this connection from this peer to the other peer.
71 * Includes transport overhead.
73 * Unit: [bytes/second]
75 uint32_t utilization_out;
78 * Actual traffic on this connection from the other peer to this peer.
79 * Includes transport overhead.
81 * Unit: [bytes/second]
83 uint32_t utilization_in;
86 * Distance on network layer (required for distance-vector routing)
87 * in hops. Zero for direct connections (i.e. plain TCP/UDP).
92 * MTU of the network layer, UINT32_MAX for no MTU (stream).
99 * Which network scope does the respective address belong to?
101 enum GNUNET_NetworkType nt;
104 * What characteristics does this communicator have?
106 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
110 /* ******************************** Transport API ***************************** */
113 * Handle to the ATS subsystem for bandwidth/transport transport information.
115 struct GNUNET_ATS_TransportHandle;
118 * Opaque session handle, to be defined by transport. Contents not known to ATS.
120 struct GNUNET_ATS_Session;
124 * Signature of a function called by ATS with the current bandwidth
125 * allocation to be used as determined by ATS.
128 * @param session session this is about
129 * @param bandwidth_out assigned outbound bandwidth for the connection,
130 * 0 to signal disconnect
131 * @param bandwidth_in assigned inbound bandwidth for the connection,
132 * 0 to signal disconnect
135 (*GNUNET_ATS_AllocationCallback) (void *cls,
136 struct GNUNET_ATS_Session *session,
137 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
138 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
142 * Signature of a function called by ATS suggesting transport to
143 * try connecting with a particular address.
146 * @param pid target peer
147 * @param address the address to try
150 (*GNUNET_ATS_SuggestionCallback) (void *cls,
151 const struct GNUNET_PeerIdentity *pid,
152 const char *address);
156 * Initialize the ATS transport subsystem.
158 * @param cfg configuration to use
159 * @param alloc_cb notification to call whenever the allocation changed
160 * @param alloc_cb_cls closure for @a alloc_cb
161 * @param suggest_cb notification to call whenever the suggestation is made
162 * @param suggest_cb_cls closure for @a suggest_cb
163 * @return ats context
165 struct GNUNET_ATS_TransportHandle *
166 GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
167 GNUNET_ATS_AllocationCallback alloc_cb,
169 GNUNET_ATS_SuggestionCallback suggest_cb,
170 void *suggest_cb_cls);
174 * Client is done with ATS transport, release resources.
176 * @param ath handle to release
179 GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath);
183 * Handle used within ATS to track an session.
185 struct GNUNET_ATS_SessionRecord;
189 * We have a new session ATS should know. Sessiones have to be added with this
190 * function before they can be: updated, set in use and destroyed
193 * @param pid peer we connected to
194 * @param address the address (human readable version),
195 * @param session transport-internal handle for the session/queue, NULL if
196 * the session is inbound-only
197 * @param prop performance data for the session
198 * @return handle to the session representation inside ATS, NULL
199 * on error (i.e. ATS knows this exact session already, or
200 * session is invalid)
202 struct GNUNET_ATS_SessionRecord *
203 GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath,
204 const struct GNUNET_PeerIdentity *pid,
206 struct GNUNET_ATS_Session *session,
207 const struct GNUNET_ATS_Properties *prop);
211 * We have updated performance statistics for a given session. Based
212 * on the information provided, ATS may update bandwidth assignments.
214 * @param ar session record to update information for
215 * @param prop performance data for the session
218 GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar,
219 const struct GNUNET_ATS_Properties *prop);
223 * A session was destroyed, ATS should now schedule and
224 * allocate under the assumption that this @a ar is no
227 * @param ar session record to drop
230 GNUNET_ATS_session_del(struct GNUNET_ATS_SessionRecord *ar);
235 /** @} */ /* end of group */
237 /* end of file gnunet-service-transport_ats.h */