2 This file is part of GNUnet
3 (C) 2009, 2010 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"
45 * Change the preference for a peer
47 * @param handle the solver handle
48 * @param client the client sending this request
49 * @param peer the peer id
50 * @param kind the preference kind to change
51 * @param score the new preference score
52 * @param pref_rel the normalized preference value for this kind over all clients
55 (*GAS_solver_address_change_preference) (void *solver,
56 const struct GNUNET_PeerIdentity *peer, 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, void *application,
71 const struct GNUNET_PeerIdentity *peer,
72 const struct GNUNET_TIME_Relative scope,
73 enum GNUNET_ATS_PreferenceKind kind, double score);
76 * Notify the solver about a bulk operation changing possibly a lot of values
77 * Solver will not resolve until all bulk operations are marked as done
79 * @param solver the solver
82 (*GAS_solver_bulk_start) (void *solver);
85 * Mark a bulk operation as done
86 * Solver will resolve if values have changed
88 * @param solver the solver
91 (*GAS_solver_bulk_stop) (void *solver);
94 * Add a single address within a network to the solver
96 * @param solver the solver Handle
97 * @param addresses the address hashmap containing all addresses
98 * @param address the address to add
99 * @param network network type of this address
102 (*GAS_solver_address_add) (void *solver, struct ATS_Address *address,
106 * Delete an address or just the session from the solver
108 * @param solver the solver Handle
109 * @param addresses the address hashmap containing all addresses
110 * @param address the address to delete
111 * @param session_only remove address or just session
114 (*GAS_solver_address_delete) (void *solver, struct ATS_Address *address,
118 * Transport properties for this address have changed
120 * @param solver solver handle
121 * @param address the address
122 * @param type the ATSI type in HBO
123 * @param abs_value the absolute value of the property
124 * @param rel_value the normalized value
127 (*GAS_solver_address_property_changed) (void *solver,
128 struct ATS_Address *address, uint32_t type, uint32_t abs_value,
132 * Transport session for this address has changed
134 * NOTE: values in addresses are already updated
136 * @param solver solver handle
137 * @param address the address
138 * @param cur_session the current session
139 * @param new_session the new session
142 (*GAS_solver_address_session_changed) (void *solver,
143 struct ATS_Address *address, uint32_t cur_session, uint32_t new_session);
147 * Network scope for this address has changed
149 * NOTE: values in addresses are already updated
151 * @param solver solver handle
152 * @param address the address
153 * @param current_network the current network
154 * @param new_network the new network
157 (*GAS_solver_address_network_changed) (void *solver,
158 struct ATS_Address *address, uint32_t current_network, uint32_t new_network);
161 * Get the prefered address for a peer from solver
163 * @param solver the solver to use
164 * @param addresses the address hashmap containing all addresses
165 * @param peer the peer
167 typedef const struct ATS_Address *
168 (*GAS_solver_get_preferred_address) (void *solver,
169 const struct GNUNET_PeerIdentity *peer);
172 * Stop getting the prefered address for a peer from solver
174 * @param solver the solver to use
175 * @param addresses the address hashmap containing all addresses
176 * @param peer the peer
179 (*GAS_solver_stop_get_preferred_address) (void *solver,
180 const struct GNUNET_PeerIdentity *peer);
185 * Each solver is required to set up this struct contained in the plugin
186 * environment struct in during startup
188 struct GNUNET_ATS_SolverFunctions
192 * Add a new address for a peer to the solver
194 * The address is already contained in the addresses hashmap!
196 GAS_solver_address_add s_add;
199 * Update the properties of an address in the solver
201 GAS_solver_address_property_changed s_address_update_property;
204 * Update the session of an address in the solver
206 GAS_solver_address_session_changed s_address_update_session;
209 * Notify solver that the network an address is located in has changed
211 GAS_solver_address_network_changed s_address_update_network;
214 * Tell solver to notify ATS if the address to use changes for a specific
215 * peer using the bandwidth changed callback
217 * The solver must only notify about changes for peers with pending address
220 GAS_solver_get_preferred_address s_get;
223 * Tell solver stop notifying ATS about changes for this peers
225 * The solver must only notify about changes for peers with pending address
228 GAS_solver_stop_get_preferred_address s_get_stop;
231 * Delete an address in the solver
233 * The address is not contained in the address hashmap anymore!
235 GAS_solver_address_delete s_del;
238 * Change relative preference for quality in solver
240 GAS_solver_address_change_preference s_pref;
243 * Give feedback about the current assignment
245 GAS_solver_address_feedback_preference s_feedback;
248 * Start a bulk operation
250 * Used if many values have to be updated at the same time.
251 * When a bulk operation is pending the solver does not have to resolve
252 * the problem since more updates will follow anyway
254 * For each call to bulk_start, a call to bulk_stop is required!
256 GAS_solver_bulk_start s_bulk_start;
259 * Bulk operation done
261 * If no more bulk operations are pending, the solver can solve the problem
262 * with the updated values
264 GAS_solver_bulk_stop s_bulk_stop;
268 * Operation codes for solver information callback
270 * Order of calls is expected to be:
274 * GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
275 * GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
278 enum GAS_Solver_Operation
281 * A solution iteration has been started
286 * A solution iteration has been finished
291 * The setup of the problem as a preparation to solve it was started
293 GAS_OP_SOLVE_SETUP_START,
296 * The setup of the problem as a preparation to solve is finished
298 GAS_OP_SOLVE_SETUP_STOP,
301 * Solving of the LP problem was started
304 GAS_OP_SOLVE_MLP_LP_START,
307 * Solving of the LP problem is done
310 GAS_OP_SOLVE_MLP_LP_STOP,
313 * Solving of the MLP problem was started
316 GAS_OP_SOLVE_MLP_MLP_START,
319 * Solving of the MLP problem is done
322 GAS_OP_SOLVE_MLP_MLP_STOP,
325 * After the problem was finished, start notifications about changes
328 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
331 * After the problem was finished, notifications about changes to addresses
334 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
338 * Status of a GAS_Solver_Operation operation
340 enum GAS_Solver_Status
354 * Status of the operation
356 enum GAS_Solver_Additional_Information
359 * No more specific information
364 * A full solution process is performed
365 * Quite specific to the MLP solver
370 * An existing solution was reused
371 * Quite specific to the MLP solver
376 * The proportional solver had to recalculate for a single network
378 GAS_INFO_PROP_SINGLE,
381 * The proportional solver had to recalculate for all networks
387 * Callback to call with additional information
388 * Used for measurement
390 * @param cls the closure
391 * @param op the operation
392 * @param peer the peer id
393 * @param kind the preference kind to change
394 * @param score the new preference score
395 * @param pref_rel the normalized preference value for this kind over all clients
398 (*GAS_solver_information_callback) (void *cls, enum GAS_Solver_Operation op,
399 enum GAS_Solver_Status stat, enum GAS_Solver_Additional_Information);
402 * Callback to call from solver when bandwidth for address has changed
404 * @param address the with changed bandwidth assigned
407 (*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address);
410 * Callback to call from solver to obtain application preference values for a
414 * @param id the peer id
415 * @return carry of double values containing the preferences with
416 * GNUNET_ATS_PreferenceCount elements
418 typedef const double *
419 (*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id);
422 * Callback to call from solver to obtain transport properties for an
426 * @param address the address
427 * @return carry of double values containing the preferences with
428 * GNUNET_ATS_PreferenceCount elements
430 typedef const double *
431 (*GAS_get_properties) (void *cls, const struct ATS_Address *address);
434 * The ATS service will pass a pointer to a struct
435 * of this type as the first and only argument to the
436 * entry point of each ATS solver.
438 struct GNUNET_ATS_PluginEnvironment
441 * Configuration handle to be used by the solver
443 const struct GNUNET_CONFIGURATION_Handle *cfg;
446 * Statistics handle to be used by the solver
448 const struct GNUNET_STATISTICS_Handle *stats;
451 * Hashmap containing all addresses available
453 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
456 * ATS addresses callback to be notified about bandwidth assignment changes
458 GAS_bandwidth_changed_cb bandwidth_changed_cb;
461 * ATS addresses closure to be notified about bandwidth assignment changes
463 void *bw_changed_cb_cls;
466 * ATS addresses function to obtain preference values
468 GAS_get_preferences get_preferences;
471 * ATS addresses function closure to obtain preference values
473 void *get_preference_cls;
476 * ATS addresses function to obtain property values
478 GAS_get_properties get_property;
481 * ATS addresses function closure to obtain property values
483 void *get_property_cls;
486 * Callback for solver to call with status information,
489 GAS_solver_information_callback info_cb;
492 * Closure for information callback,
498 * The ATS solver plugin functions to call
500 struct GNUNET_ATS_SolverFunctions sf;
505 int networks[GNUNET_ATS_NetworkTypeCount];
508 * Number of networks available
513 * Array of configured outbound quotas
514 * Order according to networks in network array
516 unsigned long long out_quota[GNUNET_ATS_NetworkTypeCount];
519 * Array of configured inbound quotas
520 * Order according to networks in network array
522 unsigned long long in_quota[GNUNET_ATS_NetworkTypeCount];