diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-14 09:28:38 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-14 09:28:38 +0000 |
commit | 96c9cc1b75506e4e93864c9b55413c1a86df2560 (patch) | |
tree | 71357e65efd8b3fd9cae50c2fe383070cb7eb6a2 /src/ats-tool | |
parent | 26805033dca64c1b6f3a2ac66067e81b6e53844a (diff) | |
download | gnunet-96c9cc1b75506e4e93864c9b55413c1a86df2560.tar.gz gnunet-96c9cc1b75506e4e93864c9b55413c1a86df2560.zip |
new switch -q to print configured quotas
Diffstat (limited to 'src/ats-tool')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 848168138..5adb1ff21 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -30,6 +30,8 @@ | |||
30 | 30 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
32 | 32 | ||
33 | #define BIG_M_STRING "unlimited" | ||
34 | |||
33 | /** | 35 | /** |
34 | * Final status code. | 36 | * Final status code. |
35 | */ | 37 | */ |
@@ -68,6 +70,11 @@ static int op_list_all; | |||
68 | static int op_set_pref; | 70 | static int op_set_pref; |
69 | 71 | ||
70 | /** | 72 | /** |
73 | * Print quotas configured | ||
74 | */ | ||
75 | static int op_print_quotas; | ||
76 | |||
77 | /** | ||
71 | * Monitor addresses used | 78 | * Monitor addresses used |
72 | */ | 79 | */ |
73 | static int op_monitor; | 80 | static int op_monitor; |
@@ -261,6 +268,67 @@ void ats_perf_cb (void *cls, | |||
261 | } | 268 | } |
262 | } | 269 | } |
263 | 270 | ||
271 | static unsigned int | ||
272 | print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
273 | { | ||
274 | char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; | ||
275 | char * entry_in = NULL; | ||
276 | char * entry_out = NULL; | ||
277 | char * quota_out_str; | ||
278 | char * quota_in_str; | ||
279 | unsigned long long int quota_out; | ||
280 | unsigned long long int quota_in; | ||
281 | int c; | ||
282 | |||
283 | for (c = 0; (c < GNUNET_ATS_NetworkTypeCount); c++) | ||
284 | { | ||
285 | |||
286 | GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]); | ||
287 | GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); | ||
288 | |||
289 | /* quota out */ | ||
290 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | ||
291 | { | ||
292 | if (0 == strcmp(quota_out_str, BIG_M_STRING) || | ||
293 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, "a_out))) | ||
294 | quota_out = UINT32_MAX; | ||
295 | |||
296 | GNUNET_free (quota_out_str); | ||
297 | GNUNET_asprintf ("a_out_str, "%llu", quota_out); | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | fprintf (stderr, "Outbound quota for network `%11s' not configured!\n", | ||
302 | network_str[c]); | ||
303 | GNUNET_asprintf ("a_out_str, "-"); | ||
304 | } | ||
305 | GNUNET_free (entry_out); | ||
306 | |||
307 | /* quota in */ | ||
308 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | ||
309 | { | ||
310 | if (0 == strcmp(quota_in_str, BIG_M_STRING) || | ||
311 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, "a_in))) | ||
312 | quota_in = UINT32_MAX; | ||
313 | GNUNET_free (quota_in_str); | ||
314 | GNUNET_asprintf ("a_in_str, "%llu", quota_in); | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | fprintf (stderr, "Inbound quota for network `%11s' not configured!\n", | ||
319 | network_str[c]); | ||
320 | GNUNET_asprintf ("a_in_str, "-"); | ||
321 | } | ||
322 | GNUNET_free (entry_in); | ||
323 | |||
324 | fprintf (stderr, _("Quota for network `%11s' (in/out): %10s / %10s\n"), network_str[c], quota_in_str, quota_out_str ); | ||
325 | GNUNET_free (quota_out_str); | ||
326 | GNUNET_free (quota_in_str); | ||
327 | } | ||
328 | return GNUNET_ATS_NetworkTypeCount; | ||
329 | } | ||
330 | |||
331 | |||
264 | 332 | ||
265 | void testservice_ats (void *cls, | 333 | void testservice_ats (void *cls, |
266 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 334 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -290,14 +358,17 @@ void testservice_ats (void *cls, | |||
290 | c = op_list_all + op_list_used + op_monitor + op_set_pref; | 358 | c = op_list_all + op_list_used + op_monitor + op_set_pref; |
291 | if ((1 < c)) | 359 | if ((1 < c)) |
292 | { | 360 | { |
293 | FPRINTF (stderr, _("Please select one operation : %s or %s or %s or %s\n"), | 361 | FPRINTF (stderr, _("Please select one operation : %s or %s or %s or %s or %s\n"), |
294 | "--used", "--all", "--monitor", "--preference"); | 362 | "--used", "--all", "--monitor", "--preference", "--quotas"); |
295 | return; | 363 | return; |
296 | } | 364 | } |
297 | if ((0 == c)) | 365 | if ((0 == c)) |
298 | op_list_used = GNUNET_YES; /* set default */ | 366 | op_list_used = GNUNET_YES; /* set default */ |
299 | 367 | if (op_print_quotas) | |
300 | 368 | { | |
369 | ret = print_quotas (cfg); | ||
370 | return; | ||
371 | } | ||
301 | if (op_list_all) | 372 | if (op_list_all) |
302 | { | 373 | { |
303 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 374 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); |
@@ -428,6 +499,9 @@ main (int argc, char *const *argv) | |||
428 | {'p', "preference", NULL, | 499 | {'p', "preference", NULL, |
429 | gettext_noop ("set preference for the given peer"), | 500 | gettext_noop ("set preference for the given peer"), |
430 | 0, &GNUNET_GETOPT_set_one, &op_set_pref}, | 501 | 0, &GNUNET_GETOPT_set_one, &op_set_pref}, |
502 | {'q', "quotas", NULL, | ||
503 | gettext_noop ("print all configured quotas"), | ||
504 | 0, &GNUNET_GETOPT_set_one, &op_print_quotas}, | ||
431 | {'i', "id", "TYPE", | 505 | {'i', "id", "TYPE", |
432 | gettext_noop ("peer id"), | 506 | gettext_noop ("peer id"), |
433 | 1, &GNUNET_GETOPT_set_string, &pid_str}, | 507 | 1, &GNUNET_GETOPT_set_string, &pid_str}, |