uncrustify as demanded.
[oweals/gnunet.git] / src / include / gnunet_ats_plugin.h
1 /*
2    This file is part of GNUnet
3    Copyright (C) 2009-2015 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * API for the ATS solvers.
26  *
27  * @defgroup ats-plugin  ATS service plugin API
28  * Plugin API for the ATS service.
29  *
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
33  * NULL pointer.
34  *
35  * @{
36  */
37 #ifndef PLUGIN_ATS_H
38 #define PLUGIN_ATS_H
39
40 #include "gnunet_ats_service.h"
41 #include "gnunet_statistics_service.h"
42
43 /**
44  * Representation of an address the plugin can choose from.
45  */
46 struct ATS_Address;
47
48 /**
49  * Change the preference for a peer
50  *
51  * @param handle the solver handle
52  * @param client the client sending this request
53  * @param peer the peer id
54  * @param kind the preference kind to change
55  * @param score the new preference score
56  * @param pref_rel the normalized preference value for this kind over all clients
57  */
58 typedef void
59 (*GAS_solver_address_change_preference) (void *solver,
60                                          const struct GNUNET_PeerIdentity *peer,
61                                          enum GNUNET_ATS_PreferenceKind kind,
62                                          double pref_rel);
63
64
65 /**
66  * Give feedback about the current assignment
67  *
68  * @param handle the solver handle
69  * @param application the application sending this request
70  * @param peer the peer id
71  * @param scope the time interval for this feedback: [now - scope .. now]
72  * @param kind the preference kind for this feedback
73  * @param score the feedback score
74  */
75 typedef void
76 (*GAS_solver_address_feedback_preference) (void *solver,
77                                            struct GNUNET_SERVICE_Client *application,
78                                            const struct GNUNET_PeerIdentity *peer,
79                                            const struct GNUNET_TIME_Relative scope,
80                                            enum GNUNET_ATS_PreferenceKind kind,
81                                            double score);
82
83 /**
84  * Notify the solver about a bulk operation changing possibly a lot of values
85  * Solver will not resolve until all bulk operations are marked as done
86  *
87  * @param solver the solver
88  */
89 typedef void
90 (*GAS_solver_bulk_start) (void *solver);
91
92
93 /**
94  * Mark a bulk operation as done
95  * Solver will resolve if values have changed
96  *
97  * @param solver the solver
98  */
99 typedef void
100 (*GAS_solver_bulk_stop) (void *solver);
101
102
103 /**
104  * Add a single address within a network to the solver
105  *
106  * @param solver the solver Handle
107  * @param address the address to add
108  * @param network network type of this address
109  */
110 typedef void
111 (*GAS_solver_address_add) (void *solver,
112                            struct ATS_Address *address,
113                            uint32_t network);
114
115
116 /**
117  * Delete an address or just the session from the solver
118  *
119  * @param solver the solver Handle
120  * @param address the address to delete
121  */
122 typedef void
123 (*GAS_solver_address_delete) (void *solver,
124                               struct ATS_Address *address);
125
126
127 /**
128  * Transport properties for this address have changed
129  *
130  * @param solver solver handle
131  * @param address the address
132  */
133 typedef void
134 (*GAS_solver_address_property_changed) (void *solver,
135                                         struct ATS_Address *address);
136
137
138 /**
139  * Get the prefered address for a peer from solver
140  *
141  * @param solver the solver to use
142  * @param peer the peer
143  */
144 typedef void
145 (*GAS_solver_get_preferred_address) (void *solver,
146                                      const struct GNUNET_PeerIdentity *peer);
147
148
149 /**
150  * Stop getting the prefered address for a peer from solver
151  *
152  * @param solver the solver to use
153  * @param peer the peer
154  */
155 typedef void
156 (*GAS_solver_stop_get_preferred_address) (void *solver,
157                                           const struct GNUNET_PeerIdentity *peer);
158
159
160 /**
161  * Solver functions.
162  *
163  * Each solver is required to set up and return an instance
164  * of this struct during initialization.
165  */
166 struct GNUNET_ATS_SolverFunctions {
167   /**
168    * Closure to pass to all solver functions in this struct.
169    */
170   void *cls;
171
172   /**
173    * Add a new address for a peer to the solver
174    *
175    * The address is already contained in the addresses hashmap!
176    */
177   GAS_solver_address_add s_add;
178
179   /**
180    * Update the properties of an address in the solver
181    */
182   GAS_solver_address_property_changed s_address_update_property;
183
184   /**
185    * Tell solver to notify ATS if the address to use changes for a specific
186    * peer using the bandwidth changed callback
187    *
188    * The solver must only notify about changes for peers with pending address
189    * requests!
190    */
191   GAS_solver_get_preferred_address s_get;
192
193   /**
194    * Tell solver stop notifying ATS about changes for this peers
195    *
196    * The solver must only notify about changes for peers with pending address
197    * requests!
198    */
199   GAS_solver_stop_get_preferred_address s_get_stop;
200
201   /**
202    * Delete an address in the solver
203    *
204    * The address is not contained in the address hashmap anymore!
205    */
206   GAS_solver_address_delete s_del;
207
208   /**
209    * Change relative preference for quality in solver
210    */
211   GAS_solver_address_change_preference s_pref;
212
213   /**
214    * Give feedback about the current assignment
215    */
216   GAS_solver_address_feedback_preference s_feedback;
217
218   /**
219    * Start a bulk operation
220    *
221    * Used if many values have to be updated at the same time.
222    * When a bulk operation is pending the solver does not have to resolve
223    * the problem since more updates will follow anyway
224    *
225    * For each call to bulk_start, a call to bulk_stop is required!
226    */
227   GAS_solver_bulk_start s_bulk_start;
228
229   /**
230    * Bulk operation done
231    *
232    * If no more bulk operations are pending, the solver can solve the problem
233    * with the updated values
234    */
235   GAS_solver_bulk_stop s_bulk_stop;
236 };
237
238
239 /**
240  * Operation codes for solver information callback
241  *
242  * Order of calls is expected to be:
243  * #GAS_OP_SOLVE_START
244  * #GAS_OP_SOLVE_STOP
245  * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
246  * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
247  *
248  */
249 enum GAS_Solver_Operation {
250   /**
251    * A solution iteration has been started
252    */
253   GAS_OP_SOLVE_START,
254
255   /**
256    * A solution iteration has been finished
257    */
258   GAS_OP_SOLVE_STOP,
259
260   /**
261    * The setup of the problem as a preparation to solve it was started
262    */
263   GAS_OP_SOLVE_SETUP_START,
264
265   /**
266    * The setup of the problem as a preparation to solve is finished
267    */
268   GAS_OP_SOLVE_SETUP_STOP,
269
270   /**
271    * Solving of the LP problem was started
272    * MLP solver only
273    */
274   GAS_OP_SOLVE_MLP_LP_START,
275
276   /**
277    * Solving of the LP problem is done
278    * MLP solver only
279    */
280   GAS_OP_SOLVE_MLP_LP_STOP,
281
282   /**
283    * Solving of the MLP problem was started
284    * MLP solver only
285    */
286   GAS_OP_SOLVE_MLP_MLP_START,
287
288   /**
289    * Solving of the MLP problem is done
290    * MLP solver only
291    */
292   GAS_OP_SOLVE_MLP_MLP_STOP,
293
294   /**
295    * After the problem was finished, start notifications about changes
296    * to addresses
297    */
298   GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
299
300   /**
301    * After the problem was finished, notifications about changes to addresses
302    * are done
303    */
304   GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
305 };
306
307
308 /**
309  * Status of a GAS_Solver_Operation operation
310  */
311 enum GAS_Solver_Status {
312   /**
313    * Success
314    */
315   GAS_STAT_SUCCESS,
316
317   /**
318    * Failure
319    */
320   GAS_STAT_FAIL
321 };
322
323
324 /**
325  * Status of the operation
326  */
327 enum GAS_Solver_Additional_Information {
328   /**
329    * No more specific information
330    */
331   GAS_INFO_NONE,
332
333   /**
334    * A full solution process is performed
335    * Quite specific to the MLP solver
336    */
337   GAS_INFO_FULL,
338
339   /**
340    * An existing solution was reused
341    * Quite specific to the MLP solver
342    */
343   GAS_INFO_UPDATED,
344
345   /**
346    * The proportional solver had to recalculate for a single network
347    */
348   GAS_INFO_PROP_SINGLE,
349
350   /**
351    * The proportional solver had to recalculate for all networks
352    */
353   GAS_INFO_PROP_ALL
354 };
355
356
357 /**
358  * Callback to call with additional information
359  * Used for measurement
360  *
361  * @param cls the closure
362  * @param op the operation
363  */
364 typedef void
365 (*GAS_solver_information_callback) (void *cls,
366                                     enum GAS_Solver_Operation op,
367                                     enum GAS_Solver_Status stat,
368                                     enum GAS_Solver_Additional_Information);
369
370
371 /**
372  * Callback to call from solver when bandwidth for address has changed
373  *
374  * @param address the with changed bandwidth assigned
375  */
376 typedef void
377 (*GAS_bandwidth_changed_cb) (void *cls,
378                              struct ATS_Address *address);
379
380
381 /**
382  * Callback to call from solver to obtain application preference
383  * values for a peer.
384  *
385  * @param cls the cls
386  * @param id the peer id
387  * @return carry of double values containing the preferences with
388  *      GNUNET_ATS_PreferenceCount elements
389  */
390 typedef const double *
391 (*GAS_get_preferences) (void *cls,
392                         const struct GNUNET_PeerIdentity *id);
393
394
395 /**
396  * Callback to call from solver to obtain application connectivity
397  * preferences for a peer.
398  *
399  * @param cls the cls
400  * @param id the peer id
401  * @return 0 if connectivity is not desired, non-null if address
402  *      suggestions are requested
403  */
404 typedef unsigned int
405 (*GAS_get_connectivity) (void *cls,
406                          const struct GNUNET_PeerIdentity *id);
407
408
409 /**
410  * The ATS plugin will pass a pointer to a struct
411  * of this type as to the initialization function
412  * of the ATS plugins.
413  */
414 struct GNUNET_ATS_PluginEnvironment {
415   /**
416    * Configuration handle to be used by the solver
417    */
418   const struct GNUNET_CONFIGURATION_Handle *cfg;
419
420   /**
421    * Statistics handle to be used by the solver
422    */
423   struct GNUNET_STATISTICS_Handle *stats;
424
425   /**
426    * Closure to pass to all callbacks in this struct.
427    */
428   void *cls;
429
430   /**
431    * Hashmap containing all addresses available
432    */
433   struct GNUNET_CONTAINER_MultiPeerMap *addresses;
434
435   /**
436    * ATS addresses callback to be notified about bandwidth assignment changes
437    */
438   GAS_bandwidth_changed_cb bandwidth_changed_cb;
439
440   /**
441    * ATS addresses function to obtain preference values
442    */
443   GAS_get_preferences get_preferences;
444
445   /**
446    * ATS addresses function to obtain preference values
447    */
448   GAS_get_connectivity get_connectivity;
449
450   /**
451    * Callback for solver to call with status information,
452    * can be NULL
453    */
454   GAS_solver_information_callback info_cb;
455
456   /**
457    * Number of networks available, size of the @e out_quota
458    * and @e in_quota arrays.
459    */
460   unsigned int network_count;
461
462   /**
463    * Array of configured outbound quotas
464    * Order according to networks in network array
465    */
466   unsigned long long out_quota[GNUNET_NT_COUNT];
467
468   /**
469    * Array of configured inbound quotas
470    * Order according to networks in network array
471    */
472   unsigned long long in_quota[GNUNET_NT_COUNT];
473 };
474
475 #endif
476
477 /** @} */  /* end of group */