commit for mantis: 0002729
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 11 Jan 2013 09:51:47 +0000 (09:51 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 11 Jan 2013 09:51:47 +0000 (09:51 +0000)
quota load: support "unlimited", fancy strings and integer values (set by gnunet setup)

src/ats/gnunet-service-ats_addresses.c

index 55eee1af3319b6254f96eb4c9c8ed01914451a1a..6650c7b019e96c0fdb02ee4a6587b038919dbd8a 100644 (file)
@@ -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, &quota_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, &quota_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);