summaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_plugins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_plugins.c')
-rw-r--r--src/ats/gnunet-service-ats_plugins.c574
1 files changed, 295 insertions, 279 deletions
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c
index 0b0e5ec4b..274f89e7a 100644
--- a/src/ats/gnunet-service-ats_plugins.c
+++ b/src/ats/gnunet-service-ats_plugins.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2014 GNUnet e.V. 3 Copyright (C) 2011-2014 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 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, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -59,14 +59,14 @@ static char *plugin;
59 * @param pref_rel the new relative preference value 59 * @param pref_rel the new relative preference value
60 */ 60 */
61void 61void
62GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, 62GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer,
63 enum GNUNET_ATS_PreferenceKind kind, 63 enum GNUNET_ATS_PreferenceKind kind,
64 double pref_rel) 64 double pref_rel)
65{ 65{
66 sf->s_pref (sf->cls, 66 sf->s_pref(sf->cls,
67 peer, 67 peer,
68 kind, 68 kind,
69 pref_rel); 69 pref_rel);
70} 70}
71 71
72 72
@@ -76,10 +76,10 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer,
76 * @param address the peer for which a property changed 76 * @param address the peer for which a property changed
77 */ 77 */
78void 78void
79GAS_plugin_notify_property_changed (struct ATS_Address *address) 79GAS_plugin_notify_property_changed(struct ATS_Address *address)
80{ 80{
81 sf->s_address_update_property (sf->cls, 81 sf->s_address_update_property(sf->cls,
82 address); 82 address);
83} 83}
84 84
85 85
@@ -92,100 +92,116 @@ GAS_plugin_notify_property_changed (struct ATS_Address *address)
92 * @param add additional information 92 * @param add additional information
93 */ 93 */
94static void 94static void
95solver_info_cb (void *cls, 95solver_info_cb(void *cls,
96 enum GAS_Solver_Operation op, 96 enum GAS_Solver_Operation op,
97 enum GAS_Solver_Status status, 97 enum GAS_Solver_Status status,
98 enum GAS_Solver_Additional_Information add) 98 enum GAS_Solver_Additional_Information add)
99{ 99{
100 const char *add_info; 100 const char *add_info;
101 101
102 switch (add) { 102 switch (add)
103 {
103 case GAS_INFO_NONE: 104 case GAS_INFO_NONE:
104 add_info = "GAS_INFO_NONE"; 105 add_info = "GAS_INFO_NONE";
105 break; 106 break;
107
106 case GAS_INFO_FULL: 108 case GAS_INFO_FULL:
107 add_info = "GAS_INFO_MLP_FULL"; 109 add_info = "GAS_INFO_MLP_FULL";
108 break; 110 break;
111
109 case GAS_INFO_UPDATED: 112 case GAS_INFO_UPDATED:
110 add_info = "GAS_INFO_MLP_UPDATED"; 113 add_info = "GAS_INFO_MLP_UPDATED";
111 break; 114 break;
115
112 case GAS_INFO_PROP_ALL: 116 case GAS_INFO_PROP_ALL:
113 add_info = "GAS_INFO_PROP_ALL"; 117 add_info = "GAS_INFO_PROP_ALL";
114 break; 118 break;
119
115 case GAS_INFO_PROP_SINGLE: 120 case GAS_INFO_PROP_SINGLE:
116 add_info = "GAS_INFO_PROP_SINGLE"; 121 add_info = "GAS_INFO_PROP_SINGLE";
117 break; 122 break;
123
118 default: 124 default:
119 add_info = "INVALID"; 125 add_info = "INVALID";
120 break; 126 break;
121 } 127 }
122 switch (op) 128 switch (op)
123 { 129 {
124 case GAS_OP_SOLVE_START: 130 case GAS_OP_SOLVE_START:
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
126 "Solver notifies `%s' with result `%s' `%s'\n", 132 "Solver notifies `%s' with result `%s' `%s'\n",
127 "GAS_OP_SOLVE_START", 133 "GAS_OP_SOLVE_START",
128 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL", 134 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL",
129 add_info); 135 add_info);
130 return; 136 return;
131 case GAS_OP_SOLVE_STOP: 137
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 138 case GAS_OP_SOLVE_STOP:
133 "Solver notifies `%s' with result `%s'\n", 139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
134 "GAS_OP_SOLVE_STOP", 140 "Solver notifies `%s' with result `%s'\n",
135 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 141 "GAS_OP_SOLVE_STOP",
136 return; 142 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
137 case GAS_OP_SOLVE_SETUP_START: 143 return;
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 144
139 "Solver notifies `%s' with result `%s'\n", 145 case GAS_OP_SOLVE_SETUP_START:
140 "GAS_OP_SOLVE_SETUP_START", 146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
141 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 147 "Solver notifies `%s' with result `%s'\n",
142 return; 148 "GAS_OP_SOLVE_SETUP_START",
143 case GAS_OP_SOLVE_SETUP_STOP: 149 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 150 return;
145 "Solver notifies `%s' with result `%s'\n", 151
146 "GAS_OP_SOLVE_SETUP_STOP", 152 case GAS_OP_SOLVE_SETUP_STOP:
147 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 153 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
148 return; 154 "Solver notifies `%s' with result `%s'\n",
149 case GAS_OP_SOLVE_MLP_LP_START: 155 "GAS_OP_SOLVE_SETUP_STOP",
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 156 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
151 "Solver notifies `%s' with result `%s'\n", 157 return;
152 "GAS_OP_SOLVE_LP_START", 158
153 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 159 case GAS_OP_SOLVE_MLP_LP_START:
154 return; 160 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
155 case GAS_OP_SOLVE_MLP_LP_STOP: 161 "Solver notifies `%s' with result `%s'\n",
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 "GAS_OP_SOLVE_LP_START",
157 "Solver notifies `%s' with result `%s'\n", 163 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
158 "GAS_OP_SOLVE_LP_STOP", 164 return;
159 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 165
160 return; 166 case GAS_OP_SOLVE_MLP_LP_STOP:
161 case GAS_OP_SOLVE_MLP_MLP_START: 167 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 168 "Solver notifies `%s' with result `%s'\n",
163 "Solver notifies `%s' with result `%s'\n", 169 "GAS_OP_SOLVE_LP_STOP",
164 "GAS_OP_SOLVE_MLP_START", 170 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
165 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 171 return;
166 return; 172
167 case GAS_OP_SOLVE_MLP_MLP_STOP: 173 case GAS_OP_SOLVE_MLP_MLP_START:
168 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 174 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
169 "Solver notifies `%s' with result `%s'\n", 175 "Solver notifies `%s' with result `%s'\n",
170 "GAS_OP_SOLVE_MLP_STOP", 176 "GAS_OP_SOLVE_MLP_START",
171 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 177 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
172 return; 178 return;
173 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: 179
174 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 180 case GAS_OP_SOLVE_MLP_MLP_STOP:
175 "Solver notifies `%s' with result `%s'\n", 181 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
176 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", 182 "Solver notifies `%s' with result `%s'\n",
177 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 183 "GAS_OP_SOLVE_MLP_STOP",
178 return; 184 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
179 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: 185 return;
180 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 186
181 "Solver notifies `%s' with result `%s'\n", 187 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
182 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", 188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
183 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 189 "Solver notifies `%s' with result `%s'\n",
184 return; 190 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
185 default: 191 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
186 GNUNET_break (0); 192 return;
187 break; 193
188 } 194 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
196 "Solver notifies `%s' with result `%s'\n",
197 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
198 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
199 return;
200
201 default:
202 GNUNET_break(0);
203 break;
204 }
189} 205}
190 206
191 207
@@ -196,69 +212,69 @@ solver_info_cb (void *cls,
196 * @param address the address with changes 212 * @param address the address with changes
197 */ 213 */
198static void 214static void
199bandwidth_changed_cb (void *cls, 215bandwidth_changed_cb(void *cls,
200 struct ATS_Address *address) 216 struct ATS_Address *address)
201{ 217{
202 long long diff_out; 218 long long diff_out;
203 long long diff_in; 219 long long diff_in;
204 220
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
206 "Bandwidth assignment changed for peer %s to %u/%u\n", 222 "Bandwidth assignment changed for peer %s to %u/%u\n",
207 GNUNET_i2s (&address->peer), 223 GNUNET_i2s(&address->peer),
208 (unsigned int) address->assigned_bw_in, 224 (unsigned int)address->assigned_bw_in,
209 (unsigned int) address->assigned_bw_out); 225 (unsigned int)address->assigned_bw_out);
210 GAS_reservations_set_bandwidth (&address->peer, 226 GAS_reservations_set_bandwidth(&address->peer,
211 GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); 227 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in));
212 /* Notify performance clients about changes to address */ 228 /* Notify performance clients about changes to address */
213 GAS_performance_notify_all_clients (&address->peer, 229 GAS_performance_notify_all_clients(&address->peer,
214 address->plugin, 230 address->plugin,
215 address->addr, 231 address->addr,
216 address->addr_len, 232 address->addr_len,
217 address->active, 233 address->active,
218 &address->properties, 234 &address->properties,
219 address->local_address_info, 235 address->local_address_info,
220 GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), 236 GNUNET_BANDWIDTH_value_init(address->assigned_bw_out),
221 GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); 237 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in));
222 238
223 if ( (0 == address->assigned_bw_in) && 239 if ((0 == address->assigned_bw_in) &&
224 (0 == address->assigned_bw_out) ) 240 (0 == address->assigned_bw_out))
225 { 241 {
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
227 "Telling transport to disconnect peer `%s'\n", 243 "Telling transport to disconnect peer `%s'\n",
228 GNUNET_i2s (&address->peer)); 244 GNUNET_i2s(&address->peer));
229 245
230 /* Notify scheduling clients about suggestion */ 246 /* Notify scheduling clients about suggestion */
231 GAS_scheduling_transmit_address_suggestion (&address->peer, 247 GAS_scheduling_transmit_address_suggestion(&address->peer,
232 address->session_id, 248 address->session_id,
233 GNUNET_BANDWIDTH_ZERO, 249 GNUNET_BANDWIDTH_ZERO,
234 GNUNET_BANDWIDTH_ZERO); 250 GNUNET_BANDWIDTH_ZERO);
235 return; 251 return;
236 } 252 }
237 253
238 /* Do bandwidth stability check */ 254 /* Do bandwidth stability check */
239 diff_out = llabs ((long long) address->assigned_bw_out - 255 diff_out = llabs((long long)address->assigned_bw_out -
240 (long long) address->last_notified_bw_out); 256 (long long)address->last_notified_bw_out);
241 diff_in = llabs ((long long) address->assigned_bw_in - 257 diff_in = llabs((long long)address->assigned_bw_in -
242 (long long) address->last_notified_bw_in); 258 (long long)address->last_notified_bw_in);
243 if ( (diff_out < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) && 259 if ((diff_out < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) &&
244 (diff_in < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) ) 260 (diff_in < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)))
245 { 261 {
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
247 "Bandwidth change too small, not notifying client\n"); 263 "Bandwidth change too small, not notifying client\n");
248 return; 264 return;
249 } 265 }
250 266
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 267 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
252 "Sending bandwidth update for peer `%s': %u/%u\n", 268 "Sending bandwidth update for peer `%s': %u/%u\n",
253 GNUNET_i2s (&address->peer), 269 GNUNET_i2s(&address->peer),
254 address->assigned_bw_out, 270 address->assigned_bw_out,
255 address->assigned_bw_out); 271 address->assigned_bw_out);
256 272
257 /* *Notify scheduling clients about suggestion */ 273 /* *Notify scheduling clients about suggestion */
258 GAS_scheduling_transmit_address_suggestion (&address->peer, 274 GAS_scheduling_transmit_address_suggestion(&address->peer,
259 address->session_id, 275 address->session_id,
260 GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), 276 GNUNET_BANDWIDTH_value_init(address->assigned_bw_out),
261 GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); 277 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in));
262 278
263 address->last_notified_bw_out = address->assigned_bw_out; 279 address->last_notified_bw_out = address->assigned_bw_out;
264 address->last_notified_bw_in = address->assigned_bw_in; 280 address->last_notified_bw_in = address->assigned_bw_in;
@@ -274,48 +290,48 @@ bandwidth_changed_cb (void *cls,
274 * @return numeric quota value to use 290 * @return numeric quota value to use
275 */ 291 */
276static unsigned long long 292static unsigned long long
277parse_quota (const char *quota_str, 293parse_quota(const char *quota_str,
278 const char *direction, 294 const char *direction,
279 enum GNUNET_NetworkType network) 295 enum GNUNET_NetworkType network)
280{ 296{
281 int res; 297 int res;
282 unsigned long long ret; 298 unsigned long long ret;
283 299
284 res = GNUNET_NO; 300 res = GNUNET_NO;
285 if (0 == strcmp (quota_str, GNUNET_ATS_MaxBandwidthString)) 301 if (0 == strcmp(quota_str, GNUNET_ATS_MaxBandwidthString))
286 { 302 {
287 ret = GNUNET_ATS_MaxBandwidth; 303 ret = GNUNET_ATS_MaxBandwidth;
288 res = GNUNET_YES; 304 res = GNUNET_YES;
289 } 305 }
290 if ((GNUNET_NO == res) && 306 if ((GNUNET_NO == res) &&
291 (GNUNET_OK == 307 (GNUNET_OK ==
292 GNUNET_STRINGS_fancy_size_to_bytes (quota_str, 308 GNUNET_STRINGS_fancy_size_to_bytes(quota_str,
293 &ret))) 309 &ret)))
294 res = GNUNET_YES; 310 res = GNUNET_YES;
295 if ((GNUNET_NO == res) && 311 if ((GNUNET_NO == res) &&
296 (1 == 312 (1 ==
297 sscanf (quota_str, 313 sscanf(quota_str,
298 "%llu", 314 "%llu",
299 &ret))) 315 &ret)))
300 res = GNUNET_YES; 316 res = GNUNET_YES;
301 if (GNUNET_NO == res) 317 if (GNUNET_NO == res)
302 { 318 {
303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 319 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
304 _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"), 320 _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
305 direction, 321 direction,
306 GNUNET_NT_to_string (network), 322 GNUNET_NT_to_string(network),
307 quota_str, 323 quota_str,
308 (unsigned long long) GNUNET_ATS_DefaultBandwidth); 324 (unsigned long long)GNUNET_ATS_DefaultBandwidth);
309 ret = GNUNET_ATS_DefaultBandwidth; 325 ret = GNUNET_ATS_DefaultBandwidth;
310 } 326 }
311 else 327 else
312 { 328 {
313 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 329 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
314 _("%s quota configured for network `%s' is %llu\n"), 330 _("%s quota configured for network `%s' is %llu\n"),
315 direction, 331 direction,
316 GNUNET_NT_to_string (network), 332 GNUNET_NT_to_string(network),
317 ret); 333 ret);
318 } 334 }
319 return ret; 335 return ret;
320} 336}
321 337
@@ -330,39 +346,39 @@ parse_quota (const char *quota_str,
330 * @return quota to apply 346 * @return quota to apply
331 */ 347 */
332static unsigned long long 348static unsigned long long
333load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg, 349load_quota(const struct GNUNET_CONFIGURATION_Handle *cfg,
334 enum GNUNET_NetworkType type, 350 enum GNUNET_NetworkType type,
335 const char *direction) 351 const char *direction)
336{ 352{
337 char *entry; 353 char *entry;
338 char *quota_str; 354 char *quota_str;
339 unsigned long long ret; 355 unsigned long long ret;
340 356
341 GNUNET_asprintf (&entry, 357 GNUNET_asprintf(&entry,
342 "%s_QUOTA_%s", 358 "%s_QUOTA_%s",
343 GNUNET_NT_to_string (type), 359 GNUNET_NT_to_string(type),
344 direction); 360 direction);
345 if (GNUNET_OK == 361 if (GNUNET_OK ==
346 GNUNET_CONFIGURATION_get_value_string (cfg, 362 GNUNET_CONFIGURATION_get_value_string(cfg,
347 "ats", 363 "ats",
348 entry, 364 entry,
349 &quota_str)) 365 &quota_str))
350 { 366 {
351 ret = parse_quota (quota_str, 367 ret = parse_quota(quota_str,
352 direction, 368 direction,
353 type); 369 type);
354 GNUNET_free (quota_str); 370 GNUNET_free(quota_str);
355 } 371 }
356 else 372 else
357 { 373 {
358 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 374 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
359 _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"), 375 _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"),
360 direction, 376 direction,
361 GNUNET_NT_to_string (type), 377 GNUNET_NT_to_string(type),
362 (unsigned long long) GNUNET_ATS_DefaultBandwidth); 378 (unsigned long long)GNUNET_ATS_DefaultBandwidth);
363 ret = GNUNET_ATS_DefaultBandwidth; 379 ret = GNUNET_ATS_DefaultBandwidth;
364 } 380 }
365 GNUNET_free (entry); 381 GNUNET_free(entry);
366 return ret; 382 return ret;
367} 383}
368 384
@@ -377,27 +393,27 @@ load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg,
377 * @return number of networks loaded 393 * @return number of networks loaded
378 */ 394 */
379static unsigned int 395static unsigned int
380load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, 396load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg,
381 unsigned long long *out_dest, 397 unsigned long long *out_dest,
382 unsigned long long *in_dest, 398 unsigned long long *in_dest,
383 int dest_length) 399 int dest_length)
384{ 400{
385 unsigned int c; 401 unsigned int c;
386 402
387 for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) 403 for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++)
388 { 404 {
389 in_dest[c] = load_quota (cfg, 405 in_dest[c] = load_quota(cfg,
390 c,
391 "out");
392 out_dest[c] = load_quota (cfg,
393 c, 406 c,
394 "in"); 407 "out");
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 408 out_dest[c] = load_quota(cfg,
396 "Loaded quota for network `%s' (in/out): %llu %llu\n", 409 c,
397 GNUNET_NT_to_string (c), 410 "in");
398 in_dest[c], 411 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
399 out_dest[c]); 412 "Loaded quota for network `%s' (in/out): %llu %llu\n",
400 } 413 GNUNET_NT_to_string(c),
414 in_dest[c],
415 out_dest[c]);
416 }
401 return c; 417 return c;
402} 418}
403 419
@@ -410,21 +426,21 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
410 * solver plugin) 426 * solver plugin)
411 */ 427 */
412int 428int
413GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg) 429GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
414{ 430{
415 char *mode_str; 431 char *mode_str;
416 432
417 /* Figure out configured solution method */ 433 /* Figure out configured solution method */
418 if (GNUNET_SYSERR == 434 if (GNUNET_SYSERR ==
419 GNUNET_CONFIGURATION_get_value_string (cfg, 435 GNUNET_CONFIGURATION_get_value_string(cfg,
420 "ats", 436 "ats",
421 "MODE", 437 "MODE",
422 &mode_str)) 438 &mode_str))
423 { 439 {
424 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 440 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
425 "No resource assignment method configured, using proportional approach\n"); 441 "No resource assignment method configured, using proportional approach\n");
426 mode_str = GNUNET_strdup ("proportional"); 442 mode_str = GNUNET_strdup("proportional");
427 } 443 }
428 env.cls = NULL; 444 env.cls = NULL;
429 env.info_cb = &solver_info_cb; 445 env.info_cb = &solver_info_cb;
430 env.bandwidth_changed_cb = &bandwidth_changed_cb; 446 env.bandwidth_changed_cb = &bandwidth_changed_cb;
@@ -434,24 +450,24 @@ GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
434 env.stats = GSA_stats; 450 env.stats = GSA_stats;
435 env.addresses = GSA_addresses; 451 env.addresses = GSA_addresses;
436 env.network_count = GNUNET_NT_COUNT; 452 env.network_count = GNUNET_NT_COUNT;
437 load_quotas (cfg, 453 load_quotas(cfg,
438 env.out_quota, 454 env.out_quota,
439 env.in_quota, 455 env.in_quota,
440 GNUNET_NT_COUNT); 456 GNUNET_NT_COUNT);
441 GNUNET_asprintf (&plugin, 457 GNUNET_asprintf(&plugin,
442 "libgnunet_plugin_ats_%s", 458 "libgnunet_plugin_ats_%s",
443 mode_str); 459 mode_str);
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 460 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
445 "Initializing solver `%s'\n", 461 "Initializing solver `%s'\n",
446 mode_str); 462 mode_str);
447 GNUNET_free (mode_str); 463 GNUNET_free(mode_str);
448 if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env))) 464 if (NULL == (sf = GNUNET_PLUGIN_load(plugin, &env)))
449 { 465 {
450 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 466 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
451 _("Failed to initialize solver `%s'!\n"), 467 _("Failed to initialize solver `%s'!\n"),
452 plugin); 468 plugin);
453 return GNUNET_SYSERR; 469 return GNUNET_SYSERR;
454 } 470 }
455 return GNUNET_OK; 471 return GNUNET_OK;
456} 472}
457 473
@@ -460,12 +476,12 @@ GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
460 * Shutdown address subsystem. 476 * Shutdown address subsystem.
461 */ 477 */
462void 478void
463GAS_plugin_done () 479GAS_plugin_done()
464{ 480{
465 GNUNET_PLUGIN_unload (plugin, 481 GNUNET_PLUGIN_unload(plugin,
466 sf); 482 sf);
467 sf = NULL; 483 sf = NULL;
468 GNUNET_free (plugin); 484 GNUNET_free(plugin);
469 plugin = NULL; 485 plugin = NULL;
470} 486}
471 487
@@ -477,11 +493,11 @@ GAS_plugin_done ()
477 * @param new_address the new address 493 * @param new_address the new address
478 */ 494 */
479void 495void
480GAS_plugin_new_address (struct ATS_Address *new_address) 496GAS_plugin_new_address(struct ATS_Address *new_address)
481{ 497{
482 sf->s_add (sf->cls, 498 sf->s_add(sf->cls,
483 new_address, 499 new_address,
484 new_address->properties.scope); /* FIXME: remove 3rd arg here! */ 500 new_address->properties.scope); /* FIXME: remove 3rd arg here! */
485} 501}
486 502
487 503
@@ -492,10 +508,10 @@ GAS_plugin_new_address (struct ATS_Address *new_address)
492 * @param address address that was deleted 508 * @param address address that was deleted
493 */ 509 */
494void 510void
495GAS_plugin_delete_address (struct ATS_Address *address) 511GAS_plugin_delete_address(struct ATS_Address *address)
496{ 512{
497 sf->s_del (sf->cls, 513 sf->s_del(sf->cls,
498 address); 514 address);
499} 515}
500 516
501 517
@@ -510,18 +526,18 @@ GAS_plugin_delete_address (struct ATS_Address *address)
510 * @param score_abs degree of the appreciation 526 * @param score_abs degree of the appreciation
511 */ 527 */
512void 528void
513GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, 529GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application,
514 const struct GNUNET_PeerIdentity *peer, 530 const struct GNUNET_PeerIdentity *peer,
515 const struct GNUNET_TIME_Relative scope, 531 const struct GNUNET_TIME_Relative scope,
516 enum GNUNET_ATS_PreferenceKind kind, 532 enum GNUNET_ATS_PreferenceKind kind,
517 float score_abs) 533 float score_abs)
518{ 534{
519 sf->s_feedback (sf->cls, 535 sf->s_feedback(sf->cls,
520 application, 536 application,
521 peer, 537 peer,
522 scope, 538 scope,
523 kind, 539 kind,
524 score_abs); 540 score_abs);
525} 541}
526 542
527 543
@@ -530,9 +546,9 @@ GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application,
530 * happening in bulk right now. 546 * happening in bulk right now.
531 */ 547 */
532void 548void
533GAS_plugin_solver_lock () 549GAS_plugin_solver_lock()
534{ 550{
535 sf->s_bulk_start (sf->cls); 551 sf->s_bulk_start(sf->cls);
536} 552}
537 553
538 554
@@ -540,9 +556,9 @@ GAS_plugin_solver_lock ()
540 * Resume instant solving, we are done with the bulk state updates. 556 * Resume instant solving, we are done with the bulk state updates.
541 */ 557 */
542void 558void
543GAS_plugin_solver_unlock () 559GAS_plugin_solver_unlock()
544{ 560{
545 sf->s_bulk_stop (sf->cls); 561 sf->s_bulk_stop(sf->cls);
546} 562}
547 563
548 564
@@ -553,10 +569,10 @@ GAS_plugin_solver_unlock ()
553 * @param pid identity of peer we now care about 569 * @param pid identity of peer we now care about
554 */ 570 */
555void 571void
556GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid) 572GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid)
557{ 573{
558 sf->s_get (sf->cls, 574 sf->s_get(sf->cls,
559 pid); 575 pid);
560} 576}
561 577
562 578
@@ -567,10 +583,10 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
567 * @param pid identity of peer we care now less about 583 * @param pid identity of peer we care now less about
568 */ 584 */
569void 585void
570GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid) 586GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid)
571{ 587{
572 sf->s_get_stop (sf->cls, 588 sf->s_get_stop(sf->cls,
573 pid); 589 pid);
574} 590}
575 591
576 592