-cleaning up bandwidth allocation routine
[oweals/gnunet.git] / src / ats / test_ats_api_common.c
index 44d6274243dad7d5faabefaa3a4477f319d02c6d..2bfebaa6d366fd3eeabaff222ebd4909d4ec2e6e 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010,2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -44,6 +44,7 @@ create_test_address (struct Test_Address *dest, char * plugin, void *session, vo
   dest->addr_len = addrlen;
 }
 
+
 void
 free_test_address (struct Test_Address *dest)
 {
@@ -53,37 +54,46 @@ free_test_address (struct Test_Address *dest)
   dest->addr = NULL;
 }
 
+
 int
-compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1,
-                   const struct GNUNET_HELLO_Address *address2, void *session2)
+compare_addresses (const struct GNUNET_HELLO_Address *address1,
+                   void *session1,
+                   const struct GNUNET_HELLO_Address *address2,
+                   void *session2)
 {
-  if (0 != memcmp (&address1->peer, &address2->peer, sizeof (struct GNUNET_PeerIdentity)))
+  if (0 !=
+      memcmp (&address1->peer,
+              &address2->peer,
+              sizeof (struct GNUNET_PeerIdentity)))
   {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer id'\n");
-      return GNUNET_SYSERR;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Suggestion with invalid peer id'\n");
+    return GNUNET_SYSERR;
   }
   if (0 != strcmp (address1->transport_name, address2->transport_name))
   {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid plugin'\n");
-      return GNUNET_SYSERR;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Suggestion with invalid plugin'\n");
+    return GNUNET_SYSERR;
   }
   if (address1->address_length != address2->address_length)
   {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length\n");
-      return GNUNET_SYSERR;
-
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Suggestion with invalid address length\n");
+    return GNUNET_SYSERR;
   }
-  else if (0 != memcmp (address1->address, address2->address, address2->address_length))
+  if (0 != memcmp (address1->address, address2->address, address2->address_length))
   {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address\n");
-      return GNUNET_SYSERR;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Suggestion with invalid address\n");
+    return GNUNET_SYSERR;
   }
   if (session1 != session2)
   {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid session1 %p vs session2 %p'\n",
-                  session1, session2);
-      return GNUNET_SYSERR;
-
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Suggestion with invalid session1 %p vs session2 %p'\n",
+                session1, session2);
+    return GNUNET_SYSERR;
   }
   return GNUNET_OK;
 }
@@ -95,7 +105,6 @@ compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is,
 {
   unsigned int c_o;
   unsigned int c_i;
-  char *prop[] = GNUNET_ATS_PropertyStrings;
   uint32_t type1;
   uint32_t type2;
   uint32_t val1;
@@ -110,21 +119,24 @@ compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is,
         type2 = ntohl(ats_should[c_i].type);
         if (type1 == type2)
         {
-            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS type `%s'\n",
-                        prop[type1]);
+            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                        "ATS type `%s'\n",
+                        GNUNET_ATS_print_property_type (type1));
             val1 = ntohl(ats_is[c_o].value);
             val2 = ntohl(ats_should[c_i].value);
             if (val1 != val2)
             {
-                GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS value `%s' not equal: %u != %u\n",
-                            prop[type1],
+                GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                            "ATS value `%s' not equal: %u != %u\n",
+                            GNUNET_ATS_print_property_type (type1),
                             val1, val2);
                 res = GNUNET_SYSERR;
             }
             else
             {
-              GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS value `%s' equal: %u == %u\n",
-                          prop[type1],
+              GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                          "ATS value `%s' equal: %u == %u\n",
+                          GNUNET_ATS_print_property_type (type1),
                           val1, val2);
             }
         }
@@ -149,11 +161,10 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                 unsigned long long *in_dest,
                                                 int dest_length)
 {
-  char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
-  char * entry_in = NULL;
-  char * entry_out = NULL;
-  char * quota_out_str;
-  char * quota_in_str;
+  char *entry_in = NULL;
+  char *entry_out = NULL;
+  char *quota_out_str;
+  char *quota_in_str;
   int c;
   int res;
 
@@ -161,8 +172,12 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
   {
     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]);
+    GNUNET_asprintf (&entry_out,
+                     "%s_QUOTA_OUT",
+                     GNUNET_ATS_print_network_type (c));
+    GNUNET_asprintf (&entry_in,
+                     "%s_QUOTA_IN",
+                     GNUNET_ATS_print_network_type (c));
 
     /* quota out */
     if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, &quota_out_str))
@@ -180,21 +195,28 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
       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);
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    _("Could not load quota for network `%s':  `%s', assigning default bandwidth %llu\n"),
+                    GNUNET_ATS_print_network_type (c),
+                    quota_out_str,
+                    GNUNET_ATS_DefaultBandwidth);
           out_dest[c] = GNUNET_ATS_DefaultBandwidth;
       }
       else
       {
-          GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for network `%s' is %llu\n"),
-              network_str[c], out_dest[c]);
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                      "Outbound quota configure for network `%s' is %llu\n",
+                      GNUNET_ATS_print_network_type (c),
+                      out_dest[c]);
       }
       GNUNET_free (quota_out_str);
     }
     else
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
-          network_str[c], GNUNET_ATS_DefaultBandwidth);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
+                  GNUNET_ATS_print_network_type (c),
+                  GNUNET_ATS_DefaultBandwidth);
       out_dest[c] = GNUNET_ATS_DefaultBandwidth;
     }
 
@@ -214,24 +236,35 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
       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);
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      _("Could not load quota for network `%s':  `%s', assigning default bandwidth %llu\n"),
+                      GNUNET_ATS_print_network_type (c),
+                      quota_in_str,
+                      GNUNET_ATS_DefaultBandwidth);
           in_dest[c] = GNUNET_ATS_DefaultBandwidth;
       }
       else
       {
-          GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configured for network `%s' is %llu\n"),
-              network_str[c], in_dest[c]);
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                      "Inbound quota configured for network `%s' is %llu\n",
+                      GNUNET_ATS_print_network_type (c),
+                      in_dest[c]);
       }
       GNUNET_free (quota_in_str);
     }
     else
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
-          network_str[c], GNUNET_ATS_DefaultBandwidth);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
+                  GNUNET_ATS_print_network_type (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_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Loaded quota for network `%s' (in/out): %llu %llu\n",
+                GNUNET_ATS_print_network_type (c),
+                in_dest[c],
+                out_dest[c]);
     GNUNET_free (entry_out);
     GNUNET_free (entry_in);
   }
@@ -263,11 +296,6 @@ create_address (const struct GNUNET_PeerIdentity *peer,
   memcpy (&aa[1], plugin_addr, plugin_addr_len);
   memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
   aa->session_id = session_id;
-  aa->active = GNUNET_NO;
-  aa->used = GNUNET_NO;
-  aa->solver_information = NULL;
-  aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
-  aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
   return aa;
 }