major change to solver api: split _update function since it combined 3 different...
[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 addresses the address hashmap
42  * @param peer the peer to change the preference for
43  * @param kind the kind to change the preference
44  * @param pref_rel the normalized preference value for this kind over all clients
45  */
46 void
47 GAS_proportional_address_change_preference (void *solver,
48                                                                                         const struct GNUNET_PeerIdentity *peer,
49                                                                                         enum GNUNET_ATS_PreferenceKind kind,
50                                                                                         double pref_rel);
51
52
53 /**
54  * Init the proportional problem solver
55  *
56  * Quotas:
57  * network[i] contains the network type as type GNUNET_ATS_NetworkType[i]
58  * out_quota[i] contains outbound quota for network type i
59  * in_quota[i] contains inbound quota for network type i
60  *
61  * Example
62  * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
63  * network[2]   == GNUNET_ATS_NET_LAN
64  * out_quota[2] == 65353
65  * in_quota[2]  == 65353
66  *
67  * @param cfg configuration handle
68  * @param stats the GNUNET_STATISTICS handle
69  * @param network array of GNUNET_ATS_NetworkType with length dest_length
70  * @param addresses hashmap containing all addresses
71  * @param out_quota array of outbound quotas
72  * @param in_quota array of outbound quota
73  * @param dest_length array length for quota arrays
74  * @param bw_changed_cb callback for changed bandwidth amounts
75  * @param bw_changed_cb_cls cls for callback
76  * @param get_preference callback to get relative preferences for a peer
77  * @param get_preference_cls cls for callback to get relative preferences
78  * @return handle for the solver on success, NULL on fail
79  */
80 void *
81 GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
82                      const struct GNUNET_STATISTICS_Handle *stats,
83                      const struct GNUNET_CONTAINER_MultiHashMap *addresses,
84                      int *network,
85                      unsigned long long *out_quota,
86                      unsigned long long *in_quota,
87                      int dest_length,
88                      GAS_bandwidth_changed_cb bw_changed_cb,
89                      void *bw_changed_cb_cls,
90                      GAS_get_preferences get_preference,
91                      void *get_preference_cls,
92                      GAS_get_properties get_properties,
93                      void *get_properties_cls);
94
95 /**
96  * Shutdown the proportional problem solver
97  *
98  * @param solver the respective handle to shutdown
99  */
100 void
101 GAS_proportional_done (void * solver);
102
103
104 /**
105  * Add a single address within a network to the solver
106  *
107  * @param solver the solver Handle
108  * @param addresses the address hashmap containing all addresses
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 void
118 GAS_proportional_address_property_changed (void *solver,
119                                                                                                                         struct ATS_Address *address,
120                                                                                                                         uint32_t type,
121                                                                                                                         uint32_t abs_value,
122                                                                                                                         double rel_value);
123
124
125 void
126 GAS_proportional_address_session_changed (void *solver,
127                                                                                                                         struct ATS_Address *address,
128                                                                                                                         uint32_t cur_session,
129                                                                                                                         uint32_t new_session);
130
131 void
132 GAS_proportional_address_inuse_changed (void *solver,
133                                                                                                                         struct ATS_Address *address,
134                                                                                                                         uint32_t session,
135                                                                                                                         int in_use);
136
137 void
138 GAS_proportional_address_change_network (void *solver,
139                                                                                                                                            struct ATS_Address *address,
140                                                                                                                                            uint32_t current_network,
141                                                                                                                                            uint32_t new_network);
142
143 /**
144  * Remove an address from the solver
145  *
146  * @param solver the solver handle
147  * @param addresses the address hashmap containing all addresses
148  * @param address the address to remove
149  * @param session_only delete only session not whole address
150  */
151 void
152 GAS_proportional_address_delete (void *solver,
153     struct ATS_Address *address, int session_only);
154
155
156 /**
157  * Start a bulk operation
158  *
159  * @param solver the solver
160  */
161 void
162 GAS_proportional_bulk_start (void *solver);
163
164
165 /**
166  * Bulk operation done
167  */
168 void
169 GAS_proportional_bulk_stop (void *solver);
170
171 /**
172  * Stop notifying about address and bandwidth changes for this peer
173  *
174  * @param solver the proportional handle
175  * @param addresses address hashmap
176  * @param peer the peer
177  */
178 void
179 GAS_proportional_stop_get_preferred_address (void *solver,
180                                      const struct GNUNET_PeerIdentity *peer);
181
182
183 /**
184  * Get the prefered address for a specific peer
185  *
186  * @param solver the solver handle
187  * @param addresses the address hashmap containing all addresses
188  * @param peer the identity of the peer
189  */
190 const struct ATS_Address *
191 GAS_proportional_get_preferred_address (void *solver,
192                                const struct GNUNET_PeerIdentity *peer);
193
194 /* end of gnunet-service-ats-solver_proportional.c */