2 This file is part of GNUnet
3 Copyright (C) 2009-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 * @author Christian Grothoff
25 * API for the ATS solvers.
27 * @defgroup ats-plugin ATS service plugin API
28 * Plugin API for the ATS service.
30 * Specifies the struct that is given to the plugin's entry method and the other
31 * struct that must be returned. Note that the destructors of ATS plugins will
32 * be given the value returned by the constructor and is expected to return a
40 #include "gnunet_util_lib.h"
41 #include "gnunet_ats_application_service.h"
42 #include "gnunet_ats_transport_service.h"
43 #include "gnunet_statistics_service.h"
47 * Preference being expressed by an application client.
49 struct GNUNET_ATS_Preference {
52 * Peer to get address suggestions for.
54 struct GNUNET_PeerIdentity peer;
57 * How much bandwidth in bytes/second does the application expect?
59 struct GNUNET_BANDWIDTH_Value32NBO bw;
62 * What type of performance preference does the client have?
64 enum GNUNET_MQ_PreferenceKind pk;
69 * Opaque representation of a session the plugin can allocate bandwidth for.
71 struct GNUNET_ATS_Session;
74 * Plugin-relevant information about a session.
76 struct GNUNET_ATS_SessionData {
79 * Peer the session is with.
81 struct GNUNET_PeerIdentity peer;
84 * ATS performance characteristics for a session.
86 struct GNUNET_ATS_Properties prop;
89 * Handle to the session that has the given properties.
91 struct GNUNET_ATS_Session *session;
94 * Is the session inbound only?
101 * Internal representation of a preference by the plugin.
102 * (If desired, plugin may just use NULL.)
104 struct GNUNET_ATS_PreferenceHandle;
107 * Internal representation of a session by the plugin.
108 * (If desired, plugin may just use NULL.)
110 struct GNUNET_ATS_SessionHandle;
116 * Each solver is required to set up and return an instance
117 * of this struct during initialization.
119 struct GNUNET_ATS_SolverFunctions
123 * Closure to pass to all solver functions in this struct.
128 * The plugin should begin to respect a new preference.
130 * @param cls the closure
131 * @param pref the preference to add
132 * @return plugin's internal representation, or NULL
134 struct GNUNET_ATS_PreferenceHandle *
135 (*preference_add)(void *cls,
136 const struct GNUNET_ATS_Preference *pref);
139 * The plugin should end respecting a preference.
141 * @param cls the closure
142 * @param ph whatever @e preference_add returned
143 * @param pref the preference to delete
144 * @return plugin's internal representation, or NULL
147 (*preference_del)(void *cls,
148 struct GNUNET_ATS_PreferenceHandle *ph,
149 const struct GNUNET_ATS_Preference *pref);
152 * Transport established a new session with performance
153 * characteristics given in @a data.
156 * @param data performance characteristics of @a sh
157 * @param address address information (for debugging)
158 * @return handle by which the plugin will identify this session
160 struct GNUNET_ATS_SessionHandle *
161 (*session_add)(void *cls,
162 const struct GNUNET_ATS_SessionData *data,
163 const char *address);
166 * @a data changed for a given @a sh, solver should consider
167 * the updated performance characteristics.
170 * @param sh session this is about
171 * @param data performance characteristics of @a sh
174 (*session_update)(void *cls,
175 struct GNUNET_ATS_SessionHandle *sh,
176 const struct GNUNET_ATS_SessionData *data);
179 * A session went away. Solver should update accordingly.
182 * @param sh session this is about
183 * @param data (last) performance characteristics of @a sh
186 (*session_del)(void *cls,
187 struct GNUNET_ATS_SessionHandle *sh,
188 const struct GNUNET_ATS_SessionData *data);
194 * The ATS plugin will pass a pointer to a struct
195 * of this type as to the initialization function
196 * of the ATS plugins.
198 struct GNUNET_ATS_PluginEnvironment
201 * Configuration handle to be used by the solver
203 const struct GNUNET_CONFIGURATION_Handle *cfg;
206 * Statistics handle to be used by the solver
208 struct GNUNET_STATISTICS_Handle *stats;
211 * Closure to pass to all callbacks in this struct.
216 * Suggest to the transport that it should try establishing
217 * a connection using the given address.
219 * @param cls closure, NULL
220 * @param pid peer this is about
221 * @param address address the transport should try
224 (*suggest_cb) (void *cls,
225 const struct GNUNET_PeerIdentity *pid,
226 const char *address);
229 * Tell the transport that it should allocate the given
230 * bandwidth to the specified session.
232 * @param cls closure, NULL
233 * @param session session this is about
234 * @param peer peer this is about
235 * @param bw_in suggested bandwidth for receiving
236 * @param bw_out suggested bandwidth for transmission
239 (*allocate_cb) (void *cls,
240 struct GNUNET_ATS_Session *session,
241 const struct GNUNET_PeerIdentity *peer,
242 struct GNUNET_BANDWIDTH_Value32NBO bw_in,
243 struct GNUNET_BANDWIDTH_Value32NBO bw_out);
251 /** @} */ /* end of group */