2 This file is part of GNUnet
3 Copyright (C) 2009-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_ats_plugin.h
23 * @brief API for the ATS solvers. This header
24 * specifies the struct that is given to the plugin's entry
25 * method and the other struct that must be returned.
26 * Note that the destructors of ATS plugins will
27 * be given the value returned by the constructor
28 * and is expected to return a NULL pointer.
29 * @author Christian Grothoff
34 #include "gnunet_ats_service.h"
35 #include "gnunet_statistics_service.h"
38 * Representation of an address the plugin can choose from.
43 * Change the preference for a peer
45 * @param handle the solver handle
46 * @param client the client sending this request
47 * @param peer the peer id
48 * @param kind the preference kind to change
49 * @param score the new preference score
50 * @param pref_rel the normalized preference value for this kind over all clients
53 (*GAS_solver_address_change_preference) (void *solver,
54 const struct GNUNET_PeerIdentity *peer,
55 enum GNUNET_ATS_PreferenceKind kind,
60 * Give feedback about the current assignment
62 * @param handle the solver handle
63 * @param application the application sending this request
64 * @param peer the peer id
65 * @param scope the time interval for this feedback: [now - scope .. now]
66 * @param kind the preference kind for this feedback
67 * @param score the feedback score
70 (*GAS_solver_address_feedback_preference) (void *solver,
71 struct GNUNET_SERVER_Client *application,
72 const struct GNUNET_PeerIdentity *peer,
73 const struct GNUNET_TIME_Relative scope,
74 enum GNUNET_ATS_PreferenceKind kind,
78 * Notify the solver about a bulk operation changing possibly a lot of values
79 * Solver will not resolve until all bulk operations are marked as done
81 * @param solver the solver
84 (*GAS_solver_bulk_start) (void *solver);
88 * Mark a bulk operation as done
89 * Solver will resolve if values have changed
91 * @param solver the solver
94 (*GAS_solver_bulk_stop) (void *solver);
98 * Add a single address within a network to the solver
100 * @param solver the solver Handle
101 * @param address the address to add
102 * @param network network type of this address
105 (*GAS_solver_address_add) (void *solver,
106 struct ATS_Address *address,
111 * Delete an address or just the session from the solver
113 * @param solver the solver Handle
114 * @param address the address to delete
117 (*GAS_solver_address_delete) (void *solver,
118 struct ATS_Address *address);
122 * Transport properties for this address have changed
124 * @param solver solver handle
125 * @param address the address
128 (*GAS_solver_address_property_changed) (void *solver,
129 struct ATS_Address *address);
133 * Get the prefered address for a peer from solver
135 * @param solver the solver to use
136 * @param peer the peer
139 (*GAS_solver_get_preferred_address) (void *solver,
140 const struct GNUNET_PeerIdentity *peer);
144 * Stop getting the prefered address for a peer from solver
146 * @param solver the solver to use
147 * @param peer the peer
150 (*GAS_solver_stop_get_preferred_address) (void *solver,
151 const struct GNUNET_PeerIdentity *peer);
157 * Each solver is required to set up and return an instance
158 * of this struct during initialization.
160 struct GNUNET_ATS_SolverFunctions
164 * Closure to pass to all solver functions in this struct.
169 * Add a new address for a peer to the solver
171 * The address is already contained in the addresses hashmap!
173 GAS_solver_address_add s_add;
176 * Update the properties of an address in the solver
178 GAS_solver_address_property_changed s_address_update_property;
181 * Tell solver to notify ATS if the address to use changes for a specific
182 * peer using the bandwidth changed callback
184 * The solver must only notify about changes for peers with pending address
187 GAS_solver_get_preferred_address s_get;
190 * Tell solver stop notifying ATS about changes for this peers
192 * The solver must only notify about changes for peers with pending address
195 GAS_solver_stop_get_preferred_address s_get_stop;
198 * Delete an address in the solver
200 * The address is not contained in the address hashmap anymore!
202 GAS_solver_address_delete s_del;
205 * Change relative preference for quality in solver
207 GAS_solver_address_change_preference s_pref;
210 * Give feedback about the current assignment
212 GAS_solver_address_feedback_preference s_feedback;
215 * Start a bulk operation
217 * Used if many values have to be updated at the same time.
218 * When a bulk operation is pending the solver does not have to resolve
219 * the problem since more updates will follow anyway
221 * For each call to bulk_start, a call to bulk_stop is required!
223 GAS_solver_bulk_start s_bulk_start;
226 * Bulk operation done
228 * If no more bulk operations are pending, the solver can solve the problem
229 * with the updated values
231 GAS_solver_bulk_stop s_bulk_stop;
236 * Operation codes for solver information callback
238 * Order of calls is expected to be:
239 * #GAS_OP_SOLVE_START
241 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
242 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
245 enum GAS_Solver_Operation
248 * A solution iteration has been started
253 * A solution iteration has been finished
258 * The setup of the problem as a preparation to solve it was started
260 GAS_OP_SOLVE_SETUP_START,
263 * The setup of the problem as a preparation to solve is finished
265 GAS_OP_SOLVE_SETUP_STOP,
268 * Solving of the LP problem was started
271 GAS_OP_SOLVE_MLP_LP_START,
274 * Solving of the LP problem is done
277 GAS_OP_SOLVE_MLP_LP_STOP,
280 * Solving of the MLP problem was started
283 GAS_OP_SOLVE_MLP_MLP_START,
286 * Solving of the MLP problem is done
289 GAS_OP_SOLVE_MLP_MLP_STOP,
292 * After the problem was finished, start notifications about changes
295 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
298 * After the problem was finished, notifications about changes to addresses
301 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
306 * Status of a GAS_Solver_Operation operation
308 enum GAS_Solver_Status
323 * Status of the operation
325 enum GAS_Solver_Additional_Information
328 * No more specific information
333 * A full solution process is performed
334 * Quite specific to the MLP solver
339 * An existing solution was reused
340 * Quite specific to the MLP solver
345 * The proportional solver had to recalculate for a single network
347 GAS_INFO_PROP_SINGLE,
350 * The proportional solver had to recalculate for all networks
357 * Callback to call with additional information
358 * Used for measurement
360 * @param cls the closure
361 * @param op the operation
364 (*GAS_solver_information_callback) (void *cls,
365 enum GAS_Solver_Operation op,
366 enum GAS_Solver_Status stat,
367 enum GAS_Solver_Additional_Information);
371 * Callback to call from solver when bandwidth for address has changed
373 * @param address the with changed bandwidth assigned
376 (*GAS_bandwidth_changed_cb) (void *cls,
377 struct ATS_Address *address);
381 * Callback to call from solver to obtain application preference
385 * @param id the peer id
386 * @return carry of double values containing the preferences with
387 * GNUNET_ATS_PreferenceCount elements
389 typedef const double *
390 (*GAS_get_preferences) (void *cls,
391 const struct GNUNET_PeerIdentity *id);
395 * Callback to call from solver to obtain application connectivity
396 * preferences for a peer.
399 * @param id the peer id
400 * @return 0 if connectivity is not desired, non-null if address
401 * suggestions are requested
404 (*GAS_get_connectivity) (void *cls,
405 const struct GNUNET_PeerIdentity *id);
409 * The ATS plugin will pass a pointer to a struct
410 * of this type as to the initialization function
411 * of the ATS plugins.
413 struct GNUNET_ATS_PluginEnvironment
416 * Configuration handle to be used by the solver
418 const struct GNUNET_CONFIGURATION_Handle *cfg;
421 * Statistics handle to be used by the solver
423 struct GNUNET_STATISTICS_Handle *stats;
426 * Closure to pass to all callbacks in this struct.
431 * Hashmap containing all addresses available
433 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
436 * ATS addresses callback to be notified about bandwidth assignment changes
438 GAS_bandwidth_changed_cb bandwidth_changed_cb;
441 * ATS addresses function to obtain preference values
443 GAS_get_preferences get_preferences;
446 * ATS addresses function to obtain preference values
448 GAS_get_connectivity get_connectivity;
451 * Callback for solver to call with status information,
454 GAS_solver_information_callback info_cb;
457 * Number of networks available, size of the @e out_quota
458 * and @e in_quota arrays.
460 unsigned int network_count;
463 * Array of configured outbound quotas
464 * Order according to networks in network array
466 unsigned long long out_quota[GNUNET_ATS_NetworkTypeCount];
469 * Array of configured inbound quotas
470 * Order according to networks in network array
472 unsigned long long in_quota[GNUNET_ATS_NetworkTypeCount];