From 913b6faffd0ff1711db0675e69382ba9edec4ae0 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 11 Jan 2013 09:51:47 +0000 Subject: commit for mantis: 0002729 quota load: support "unlimited", fancy strings and integer values (set by gnunet setup) --- src/ats/gnunet-service-ats_addresses.c | 52 +++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 55eee1af3..6650c7b01 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -965,36 +965,45 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long * char * quota_out_str; char * quota_in_str; int c; + int res; for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++) { in_dest[c] = 0; out_dest[c] = 0; - GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]); GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); - /* quota out */ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) { + res = GNUNET_NO; if (0 == strcmp(quota_out_str, BIG_M_STRING)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for network `%s' is unlimited (%llu)\n"), - network_str[c], GNUNET_ATS_MaxBandwidth); out_dest[c] = GNUNET_ATS_MaxBandwidth; + res = GNUNET_YES; + } + if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) + res = GNUNET_YES; + if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c]))) + res = GNUNET_YES; + + if (GNUNET_NO == res) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), + network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth); + out_dest[c] = GNUNET_ATS_DefaultBandwidth; } - else if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])) + else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not convert quota configure for network `%s': `%s', assigning default bandwidth %llu\n"), - network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth); - out_dest[c] = GNUNET_ATS_DefaultBandwidth; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for network `%s' is %llu\n"), + network_str[c], out_dest[c]); } GNUNET_free (quota_out_str); } else { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), network_str[c], GNUNET_ATS_DefaultBandwidth); out_dest[c] = GNUNET_ATS_DefaultBandwidth; } @@ -1002,26 +1011,35 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long * /* quota in */ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) { + res = GNUNET_NO; if (0 == strcmp(quota_in_str, BIG_M_STRING)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configure for network `%s' is unlimited (%llu)\n"), - network_str[c], GNUNET_ATS_MaxBandwidth); in_dest[c] = GNUNET_ATS_MaxBandwidth; + res = GNUNET_YES; } + if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) + res = GNUNET_YES; + if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c]))) + res = GNUNET_YES; - else if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])) + if (GNUNET_NO == res) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), + network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth); + in_dest[c] = GNUNET_ATS_DefaultBandwidth; + } + else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not convert quota configure for network `%s': `%s', assigning default bandwidth %llu\n"), - network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth); - in_dest[c] = GNUNET_ATS_DefaultBandwidth; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configured for network `%s' is %llu\n"), + network_str[c], in_dest[c]); } GNUNET_free (quota_in_str); } else { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No inbound quota configure for network `%s', assigning default bandwidth %llu\n"), + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), network_str[c], GNUNET_ATS_DefaultBandwidth); - in_dest[c] = GNUNET_ATS_DefaultBandwidth; + out_dest[c] = GNUNET_ATS_DefaultBandwidth; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]); GNUNET_free (entry_out); -- cgit v1.2.3