- delayed requests correctly when in 'begin' round
[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  * Init the proportional problem solver
54  *
55  * Quotas:
56  * network[i] contains the network type as type GNUNET_ATS_NetworkType[i]
57  * out_quota[i] contains outbound quota for network type i
58  * in_quota[i] contains inbound quota for network type i
59  *
60  * Example
61  * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
62  * network[2]   == GNUNET_ATS_NET_LAN
63  * out_quota[2] == 65353
64  * in_quota[2]  == 65353
65  *
66  * @param cfg configuration handle
67  * @param stats the GNUNET_STATISTICS handle
68  * @param network array of GNUNET_ATS_NetworkType with length dest_length
69  * @param addresses hashmap containing all addresses
70  * @param out_quota array of outbound quotas
71  * @param in_quota array of outbound quota
72  * @param dest_length array length for quota arrays
73  * @param bw_changed_cb callback for changed bandwidth amounts
74  * @param bw_changed_cb_cls cls for callback
75  * @param get_preference callback to get relative preferences for a peer
76  * @param get_preference_cls cls for callback to get relative preferences
77  * @param get_properties_cls for callback to get relative properties
78  * @param get_properties_cls cls for callback to get relative properties
79  * @return handle for the solver on success, NULL on fail
80  */
81 void *
82 GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
83                      const struct GNUNET_STATISTICS_Handle *stats,
84                      const struct GNUNET_CONTAINER_MultiHashMap *addresses,
85                      int *network,
86                      unsigned long long *out_quota,
87                      unsigned long long *in_quota,
88                      int dest_length,
89                      GAS_bandwidth_changed_cb bw_changed_cb,
90                      void *bw_changed_cb_cls,
91                      GAS_get_preferences get_preference,
92                      void *get_preference_cls,
93                      GAS_get_properties get_properties,
94                      void *get_properties_cls);
95
96 /**
97  * Shutdown the proportional problem solver
98  *
99  * @param solver the respective handle to shutdown
100  */
101 void
102 GAS_proportional_done (void * solver);
103
104
105 /**
106  * Add a single address within a network to the solver
107  *
108  * @param solver the solver Handle
109  * @param address the address to add
110  * @param network network type of this address
111  */
112 void
113 GAS_proportional_address_add (void *solver,
114                                                         struct ATS_Address *address,
115                                                         uint32_t network);
116
117
118 /**
119  * Transport properties for this address have changed
120  *
121  * @param solver solver handle
122  * @param address the address
123  * @param type the ATSI type in HBO
124  * @param abs_value the absolute value of the property
125  * @param rel_value the normalized value
126  */
127 void
128 GAS_proportional_address_property_changed (void *solver,
129                                                                                                                         struct ATS_Address *address,
130                                                                                                                         uint32_t type,
131                                                                                                                         uint32_t abs_value,
132                                                                                                                         double rel_value);
133
134
135 /**
136  * Transport session for this address has changed
137  *
138  * NOTE: values in addresses are already updated
139  *
140  * @param solver solver handle
141  * @param address the address
142  * @param cur_session the current session
143  * @param new_session the new session
144  */
145 void
146 GAS_proportional_address_session_changed (void *solver,
147                                                                                                                         struct ATS_Address *address,
148                                                                                                                         uint32_t cur_session,
149                                                                                                                         uint32_t new_session);
150
151
152 /**
153  * Usage 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 in_use usage state
160  */
161 void
162 GAS_proportional_address_inuse_changed (void *solver,
163                                                                                                                         struct ATS_Address *address,
164                                                                                                                         int in_use);
165
166 /**
167  * Network scope for this address has changed
168  *
169  * NOTE: values in addresses are already updated
170  *
171  * @param solver solver handle
172  * @param address the address
173  * @param current_network the current network
174  * @param new_network the new network
175  */
176 void
177 GAS_proportional_address_change_network (void *solver,
178                                                                                                                                            struct ATS_Address *address,
179                                                                                                                                            uint32_t current_network,
180                                                                                                                                            uint32_t new_network);
181
182 /**
183  * Remove an address from the solver
184  *
185  * @param solver the solver handle
186  * @param address the address to remove
187  * @param session_only delete only session not whole address
188  */
189 void
190 GAS_proportional_address_delete (void *solver,
191     struct ATS_Address *address, int session_only);
192
193
194 /**
195  * Start a bulk operation
196  *
197  * @param solver the solver
198  */
199 void
200 GAS_proportional_bulk_start (void *solver);
201
202
203 /**
204  * Bulk operation done
205  */
206 void
207 GAS_proportional_bulk_stop (void *solver);
208
209 /**
210  * Stop notifying about address and bandwidth changes for this peer
211  *
212  * @param solver the proportional handle
213  * @param peer the peer
214  */
215 void
216 GAS_proportional_stop_get_preferred_address (void *solver,
217                                      const struct GNUNET_PeerIdentity *peer);
218
219
220 /**
221  * Get the prefered address for a specific peer
222  *
223  * @param solver the solver handle
224  * @param peer the identity of the peer
225  */
226 const struct ATS_Address *
227 GAS_proportional_get_preferred_address (void *solver,
228                                const struct GNUNET_PeerIdentity *peer);
229
230 /* end of gnunet-service-ats-solver_proportional.c */