ATS service calls solver with feedback
[oweals/gnunet.git] / src / ats / gnunet-service-ats-solver_proportional.h
1 /*
2      This file is part of GNUnet.
3      (C) 2011 Christian Grothoff (and other contributing authors)
4
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.
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      General Public License for more details.
14
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.
19 */
20
21 /**
22  * @file ats/gnunet-service-ats-solver_proportional.h
23  * @brief ATS proportional solver
24  * @author Matthias Wachs
25  * @author Christian Grothoff
26  */
27 #include "platform.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet-service-ats_addresses.h"
30
31 /**
32  * ATS proportional solver
33  *
34  * General description
35  */
36
37 /**
38  * Changes the preferences for a peer in the problem
39  *
40  * @param solver the solver handle
41  * @param peer the peer to change the preference for
42  * @param kind the kind to change the preference
43  * @param pref_rel the normalized preference value for this kind over all clients
44  */
45 void
46 GAS_proportional_address_change_preference (void *solver,
47                                                                                         const struct GNUNET_PeerIdentity *peer,
48                                                                                         enum GNUNET_ATS_PreferenceKind kind,
49                                                                                         double pref_rel);
50
51
52 /**
53  * Get application feedback for a peer
54  *
55  * @param solver the solver handle
56  * @param application the application
57  * @param peer the peer to change the preference for
58  * @param kind the kind to change the preference
59  * @param score the score
60  */
61 void
62 GAS_proportional_address_preference_feedback (void *solver,
63                                                                                         void *application,
64                                                                                         const struct GNUNET_PeerIdentity *peer,
65                                                                                         enum GNUNET_ATS_PreferenceKind kind,
66                                                                                         double score);
67
68
69 /**
70  * Init the proportional problem solver
71  *
72  * Quotas:
73  * network[i] contains the network type as type GNUNET_ATS_NetworkType[i]
74  * out_quota[i] contains outbound quota for network type i
75  * in_quota[i] contains inbound quota for network type i
76  *
77  * Example
78  * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
79  * network[2]   == GNUNET_ATS_NET_LAN
80  * out_quota[2] == 65353
81  * in_quota[2]  == 65353
82  *
83  * @param cfg configuration handle
84  * @param stats the GNUNET_STATISTICS handle
85  * @param network array of GNUNET_ATS_NetworkType with length dest_length
86  * @param addresses hashmap containing all addresses
87  * @param out_quota array of outbound quotas
88  * @param in_quota array of outbound quota
89  * @param dest_length array length for quota arrays
90  * @param bw_changed_cb callback for changed bandwidth amounts
91  * @param bw_changed_cb_cls cls for callback
92  * @param get_preference callback to get relative preferences for a peer
93  * @param get_preference_cls cls for callback to get relative preferences
94  * @param get_properties_cls for callback to get relative properties
95  * @param get_properties_cls cls for callback to get relative properties
96  * @return handle for the solver on success, NULL on fail
97  */
98 void *
99 GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
100                      const struct GNUNET_STATISTICS_Handle *stats,
101                      const struct GNUNET_CONTAINER_MultiHashMap *addresses,
102                      int *network,
103                      unsigned long long *out_quota,
104                      unsigned long long *in_quota,
105                      int dest_length,
106                      GAS_bandwidth_changed_cb bw_changed_cb,
107                      void *bw_changed_cb_cls,
108                      GAS_get_preferences get_preference,
109                      void *get_preference_cls,
110                      GAS_get_properties get_properties,
111                      void *get_properties_cls);
112
113 /**
114  * Shutdown the proportional problem solver
115  *
116  * @param solver the respective handle to shutdown
117  */
118 void
119 GAS_proportional_done (void * solver);
120
121
122 /**
123  * Add a single address within a network to the solver
124  *
125  * @param solver the solver Handle
126  * @param address the address to add
127  * @param network network type of this address
128  */
129 void
130 GAS_proportional_address_add (void *solver,
131                                                         struct ATS_Address *address,
132                                                         uint32_t network);
133
134
135 /**
136  * Transport properties for this address have changed
137  *
138  * @param solver solver handle
139  * @param address the address
140  * @param type the ATSI type in HBO
141  * @param abs_value the absolute value of the property
142  * @param rel_value the normalized value
143  */
144 void
145 GAS_proportional_address_property_changed (void *solver,
146                                                                                                                         struct ATS_Address *address,
147                                                                                                                         uint32_t type,
148                                                                                                                         uint32_t abs_value,
149                                                                                                                         double rel_value);
150
151
152 /**
153  * Transport session for this address has changed
154  *
155  * NOTE: values in addresses are already updated
156  *
157  * @param solver solver handle
158  * @param address the address
159  * @param cur_session the current session
160  * @param new_session the new session
161  */
162 void
163 GAS_proportional_address_session_changed (void *solver,
164                                                                                                                         struct ATS_Address *address,
165                                                                                                                         uint32_t cur_session,
166                                                                                                                         uint32_t new_session);
167
168
169 /**
170  * Usage for this address has changed
171  *
172  * NOTE: values in addresses are already updated
173  *
174  * @param solver solver handle
175  * @param address the address
176  * @param in_use usage state
177  */
178 void
179 GAS_proportional_address_inuse_changed (void *solver,
180                                                                                                                         struct ATS_Address *address,
181                                                                                                                         int in_use);
182
183 /**
184  * Network scope for this address has changed
185  *
186  * NOTE: values in addresses are already updated
187  *
188  * @param solver solver handle
189  * @param address the address
190  * @param current_network the current network
191  * @param new_network the new network
192  */
193 void
194 GAS_proportional_address_change_network (void *solver,
195                                                                                                                                            struct ATS_Address *address,
196                                                                                                                                            uint32_t current_network,
197                                                                                                                                            uint32_t new_network);
198
199 /**
200  * Remove an address from the solver
201  *
202  * @param solver the solver handle
203  * @param address the address to remove
204  * @param session_only delete only session not whole address
205  */
206 void
207 GAS_proportional_address_delete (void *solver,
208     struct ATS_Address *address, int session_only);
209
210
211 /**
212  * Start a bulk operation
213  *
214  * @param solver the solver
215  */
216 void
217 GAS_proportional_bulk_start (void *solver);
218
219
220 /**
221  * Bulk operation done
222  */
223 void
224 GAS_proportional_bulk_stop (void *solver);
225
226 /**
227  * Stop notifying about address and bandwidth changes for this peer
228  *
229  * @param solver the proportional handle
230  * @param peer the peer
231  */
232 void
233 GAS_proportional_stop_get_preferred_address (void *solver,
234                                      const struct GNUNET_PeerIdentity *peer);
235
236
237 /**
238  * Get the prefered address for a specific peer
239  *
240  * @param solver the solver handle
241  * @param peer the identity of the peer
242  */
243 const struct ATS_Address *
244 GAS_proportional_get_preferred_address (void *solver,
245                                const struct GNUNET_PeerIdentity *peer);
246
247 /* end of gnunet-service-ats-solver_proportional.c */