diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-14 10:01:38 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-14 10:01:38 +0000 |
commit | 29e26fe33fa4cdf3d7b6e1ba18077f37924dc4b0 (patch) | |
tree | fffa80b73153356b52be9d8c9840086cd71f0d47 /src/ats | |
parent | 96c9cc1b75506e4e93864c9b55413c1a86df2560 (diff) | |
download | gnunet-29e26fe33fa4cdf3d7b6e1ba18077f37924dc4b0.tar.gz gnunet-29e26fe33fa4cdf3d7b6e1ba18077f37924dc4b0.zip |
improved quota loading
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/ats.conf.in | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 85 |
2 files changed, 41 insertions, 46 deletions
diff --git a/src/ats/ats.conf.in b/src/ats/ats.conf.in index 9c43d9428..bdc064e2f 100644 --- a/src/ats/ats.conf.in +++ b/src/ats/ats.conf.in | |||
@@ -14,6 +14,8 @@ UNIX_MATCH_GID = YES | |||
14 | MODE = simplistic | 14 | MODE = simplistic |
15 | 15 | ||
16 | # Network specific inbound/outbound quotas | 16 | # Network specific inbound/outbound quotas |
17 | UNSPECIFIED_QUOTA_IN = 64 KiB | ||
18 | UNSPECIFIED_QUOTA_OUT = 64 KiB | ||
17 | # LOOPBACK | 19 | # LOOPBACK |
18 | LOOPBACK_QUOTA_IN = unlimited | 20 | LOOPBACK_QUOTA_IN = unlimited |
19 | LOOPBACK_QUOTA_OUT = unlimited | 21 | LOOPBACK_QUOTA_OUT = unlimited |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 36070f999..31d4f6808 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -948,7 +948,7 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | |||
948 | static unsigned int | 948 | static unsigned int |
949 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) | 949 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) |
950 | { | 950 | { |
951 | int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | 951 | char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; |
952 | char * entry_in = NULL; | 952 | char * entry_in = NULL; |
953 | char * entry_out = NULL; | 953 | char * entry_out = NULL; |
954 | char * quota_out_str; | 954 | char * quota_out_str; |
@@ -959,69 +959,62 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long * | |||
959 | { | 959 | { |
960 | in_dest[c] = 0; | 960 | in_dest[c] = 0; |
961 | out_dest[c] = 0; | 961 | out_dest[c] = 0; |
962 | switch (quotas[c]) { | ||
963 | case GNUNET_ATS_NET_UNSPECIFIED: | ||
964 | entry_out = "UNSPECIFIED_QUOTA_OUT"; | ||
965 | entry_in = "UNSPECIFIED_QUOTA_IN"; | ||
966 | break; | ||
967 | case GNUNET_ATS_NET_LOOPBACK: | ||
968 | entry_out = "LOOPBACK_QUOTA_OUT"; | ||
969 | entry_in = "LOOPBACK_QUOTA_IN"; | ||
970 | break; | ||
971 | case GNUNET_ATS_NET_LAN: | ||
972 | entry_out = "LAN_QUOTA_OUT"; | ||
973 | entry_in = "LAN_QUOTA_IN"; | ||
974 | break; | ||
975 | case GNUNET_ATS_NET_WAN: | ||
976 | entry_out = "WAN_QUOTA_OUT"; | ||
977 | entry_in = "WAN_QUOTA_IN"; | ||
978 | break; | ||
979 | case GNUNET_ATS_NET_WLAN: | ||
980 | entry_out = "WLAN_QUOTA_OUT"; | ||
981 | entry_in = "WLAN_QUOTA_IN"; | ||
982 | break; | ||
983 | default: | ||
984 | break; | ||
985 | } | ||
986 | 962 | ||
987 | if ((entry_in == NULL) || (entry_out == NULL)) | 963 | GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]); |
988 | continue; | 964 | GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); |
965 | |||
989 | 966 | ||
990 | /* quota out */ | 967 | /* quota out */ |
991 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | 968 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) |
992 | { | 969 | { |
993 | if (0 == strcmp(quota_out_str, BIG_M_STRING) || | 970 | if (0 == strcmp(quota_out_str, BIG_M_STRING)) |
994 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) | 971 | { |
995 | out_dest[c] = UINT32_MAX; | 972 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for network `%s' is unlimited (%llu)\n"), |
996 | 973 | network_str[c], GNUNET_ATS_MaxBandwidth); | |
974 | out_dest[c] = GNUNET_ATS_MaxBandwidth; | ||
975 | } | ||
976 | else if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])) | ||
977 | { | ||
978 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not convert quota configure for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
979 | network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth); | ||
980 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
981 | } | ||
997 | GNUNET_free (quota_out_str); | 982 | GNUNET_free (quota_out_str); |
998 | quota_out_str = NULL; | ||
999 | } | 983 | } |
1000 | else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c]) | ||
1001 | out_dest[c] = UINT32_MAX; | ||
1002 | else | 984 | else |
1003 | out_dest[c] = UINT32_MAX; | 985 | { |
986 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), | ||
987 | network_str[c], GNUNET_ATS_DefaultBandwidth); | ||
988 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
989 | } | ||
1004 | 990 | ||
1005 | /* quota in */ | 991 | /* quota in */ |
1006 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | 992 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) |
1007 | { | 993 | { |
1008 | if (0 == strcmp(quota_in_str, BIG_M_STRING) || | 994 | if (0 == strcmp(quota_in_str, BIG_M_STRING)) |
1009 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) | 995 | { |
1010 | in_dest[c] = UINT32_MAX; | 996 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configure for network `%s' is unlimited (%llu)\n"), |
997 | network_str[c], GNUNET_ATS_MaxBandwidth); | ||
998 | in_dest[c] = GNUNET_ATS_MaxBandwidth; | ||
999 | } | ||
1011 | 1000 | ||
1001 | else if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])) | ||
1002 | { | ||
1003 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not convert quota configure for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
1004 | network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth); | ||
1005 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
1006 | } | ||
1012 | GNUNET_free (quota_in_str); | 1007 | GNUNET_free (quota_in_str); |
1013 | quota_in_str = NULL; | ||
1014 | } | ||
1015 | else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c]) | ||
1016 | { | ||
1017 | in_dest[c] = UINT32_MAX; | ||
1018 | } | 1008 | } |
1019 | else | 1009 | else |
1020 | { | 1010 | { |
1021 | in_dest[c] = UINT32_MAX; | 1011 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No inbound quota configure for network `%s', assigning default bandwidth %llu\n"), |
1012 | network_str[c], GNUNET_ATS_DefaultBandwidth); | ||
1013 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
1022 | } | 1014 | } |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", entry_in, in_dest[c], entry_out, out_dest[c]); | 1015 | 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]); |
1024 | 1016 | GNUNET_free (entry_out); | |
1017 | GNUNET_free (entry_in); | ||
1025 | } | 1018 | } |
1026 | return GNUNET_ATS_NetworkTypeCount; | 1019 | return GNUNET_ATS_NetworkTypeCount; |
1027 | } | 1020 | } |