fixing resource leaks
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.c
index 88e2771d589f3137303938cbd8ddce0059b1a45c..406acf6147430f1c9a4c1dfe48949e2ac108eb47 100644 (file)
@@ -472,12 +472,17 @@ free_address (struct ATS_Address *addr)
  * @param plugin_name plugin
  * @param plugin_addr address
  * @param plugin_addr_len address length
+ * @param local_address_info additional local info for the address
  * @param session_id session
  * @return the ATS_Address
  */
 static struct ATS_Address *
-create_address (const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id)
+create_address (const struct GNUNET_PeerIdentity *peer,
+    const char *plugin_name,
+    const void *plugin_addr,
+    size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id)
 {
   struct ATS_Address *aa = NULL;
   int c1;
@@ -490,6 +495,7 @@ create_address (const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
   memcpy (&aa[1], plugin_addr, plugin_addr_len);
   aa->plugin = GNUNET_strdup (plugin_name);
   aa->session_id = session_id;
+  aa->local_address_info = local_address_info;
   aa->active = GNUNET_NO;
   aa->used = GNUNET_NO;
   aa->solver_information = NULL;
@@ -636,20 +642,25 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle,
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @return an ATS_address or NULL
  */
 
 static struct ATS_Address *
 find_exact_address (struct GAS_Addresses_Handle *handle,
-    const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id)
+    const struct GNUNET_PeerIdentity *peer,
+    const char *plugin_name,
+    const void *plugin_addr,
+    size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id)
 {
   struct ATS_Address *aa;
   struct ATS_Address *ea;
 
   aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len,
-      session_id);
+      local_address_info, session_id);
 
   /* Get existing address or address with session == 0 */
   ea = find_equivalent_address (handle, peer, aa);
@@ -721,15 +732,21 @@ get_performance_info (struct ATS_Address *address, uint32_t type)
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param atsi performance information for this address
  * @param atsi_count number of performance information contained
  */
 void
 GAS_addresses_add (struct GAS_Addresses_Handle *handle,
-    const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id,
-    const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count)
+    const struct GNUNET_PeerIdentity *peer,
+    const char *plugin_name,
+    const void *plugin_addr,
+    size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id,
+    const struct GNUNET_ATS_Information *atsi,
+    uint32_t atsi_count)
 {
   struct ATS_Address *new_address;
   struct ATS_Address *existing_address;
@@ -748,7 +765,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
   GNUNET_assert(NULL != handle->addresses);
 
   new_address = create_address (peer, plugin_name, plugin_addr, plugin_addr_len,
-      session_id);
+      local_address_info, session_id);
   atsi_delta = NULL;
   disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta,
       &atsi_delta_count);
@@ -762,6 +779,8 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
   if (existing_address == NULL )
   {
     /* Add a new address */
+    new_address->t_added = GNUNET_TIME_absolute_get();
+    new_address->t_last_activity = GNUNET_TIME_absolute_get();
     GNUNET_assert(
         GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (handle->addresses,
                                                        peer,
@@ -773,7 +792,9 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
 
     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
         "Adding new address %p for peer `%s', length %u, session id %u, %s\n",
-        new_address, GNUNET_i2s (peer), plugin_addr_len, session_id,
+        new_address,
+        GNUNET_i2s (peer),
+        plugin_addr_len, session_id,
         GNUNET_ATS_print_network_type (addr_net));
 
     /* Tell solver about new address */
@@ -814,6 +835,8 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
       GNUNET_i2s (peer), existing_address, session_id,
       GNUNET_ATS_print_network_type (addr_net));
   /* We have an address without an session, update this address */
+  existing_address->t_added = GNUNET_TIME_absolute_get();
+  existing_address->t_last_activity = GNUNET_TIME_absolute_get();
   atsi_delta = NULL;
   atsi_delta_count = 0;
   if (GNUNET_YES
@@ -833,7 +856,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
           && (addr_net != ntohl (atsi_delta[c1].value)))
       {
         /* Network type changed */
-        GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
             "Address for peer `%s' %p changed from network %s to %s\n",
             GNUNET_i2s (peer), existing_address,
             GNUNET_ATS_print_network_type (addr_net),
@@ -879,15 +902,21 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param atsi performance information for this address
  * @param atsi_count number of performance information contained
  */
 void
 GAS_addresses_update (struct GAS_Addresses_Handle *handle,
-    const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id,
-    const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count)
+    const struct GNUNET_PeerIdentity *peer,
+    const char *plugin_name,
+    const void *plugin_addr,
+    size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id,
+    const struct GNUNET_ATS_Information *atsi,
+    uint32_t atsi_count)
 {
   struct ATS_Address *aa;
   struct GNUNET_ATS_Information *atsi_delta;
@@ -902,27 +931,17 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
 
   /* Get existing address */
   aa = find_exact_address (handle, peer, plugin_name, plugin_addr,
-      plugin_addr_len, session_id);
+      plugin_addr_len, local_address_info, session_id);
   if (aa == NULL )
-  {
-    /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", */
-    /*             GNUNET_i2s (peer), plugin_name, session_id); */
-    /* GNUNET_break (0); */
     return;
-  }
-
   if (NULL == aa->solver_information)
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        "Tried to update unknown address for peer `%s' `%s' session id %u\n",
-        GNUNET_i2s (peer), plugin_name, session_id);
     return;
-  }
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s' address \n",
       "ADDRESS UPDATE", GNUNET_i2s (peer), aa);
 
   /* Update address */
+  aa->t_last_activity = GNUNET_TIME_absolute_get();
   if (session_id != aa->session_id)
   {
     /* Session changed */
@@ -1038,8 +1057,8 @@ destroy_by_session_id (void *cls,
       GNUNET_break(0);
       return GNUNET_OK;
     }
-
-    if (aa->addr_len == 0)
+    if (GNUNET_HELLO_ADDRESS_INFO_INBOUND ==
+        (aa->local_address_info && GNUNET_HELLO_ADDRESS_INFO_INBOUND))
     {
       /* Inbound connection died, delete full address */
       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
@@ -1080,12 +1099,17 @@ destroy_by_session_id (void *cls,
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  */
 void
 GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
-    const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id)
+    const struct GNUNET_PeerIdentity *peer,
+    const char *plugin_name,
+    const void *plugin_addr,
+    size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id)
 {
   struct ATS_Address *ea;
   struct DestroyContext dc;
@@ -1094,23 +1118,23 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
 
   /* Get existing address */
   ea = find_exact_address (handle, peer, plugin_name, plugin_addr,
-      plugin_addr_len, session_id);
+      plugin_addr_len, local_address_info, session_id);
   if (ea == NULL )
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
         "Tried to destroy unknown address for peer `%s' `%s' session id %u\n",
         GNUNET_i2s (peer), plugin_name, session_id);
     return;
   }
 
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
       "Received `%s' for peer `%s' address %p session %u\n", "ADDRESS DESTROY",
       GNUNET_i2s (peer), ea, session_id);
 
   GNUNET_break(0 < strlen (plugin_name));
   dc.handle = handle;
   dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len,
-      session_id);
+      local_address_info, session_id);
 
   GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses,
                                              peer,
@@ -1135,6 +1159,7 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
  * @param plugin_name transport plugin name
  * @param plugin_addr plugin address
  * @param plugin_addr_len length of the plugin address
+ * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param in_use GNUNET_YES if GNUNET_NO
  * @return GNUNET_SYSERR on failure (address unknown ...)
@@ -1142,7 +1167,9 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
 int
 GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
     const struct GNUNET_PeerIdentity *peer, const char *plugin_name,
-    const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id,
+    const void *plugin_addr, size_t plugin_addr_len,
+    uint32_t local_address_info,
+    uint32_t session_id,
     int in_use)
 {
   struct ATS_Address *ea;
@@ -1153,10 +1180,10 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
     return GNUNET_SYSERR;
 
   ea = find_exact_address (handle, peer, plugin_name, plugin_addr,
-      plugin_addr_len, session_id);
+      plugin_addr_len, local_address_info, session_id);
   if (NULL == ea)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
         "Trying to set unknown address `%s' `%s' `%u' to %s \n",
         GNUNET_i2s (peer), plugin_name, session_id,
         (GNUNET_NO == in_use) ? "NO" : "YES");
@@ -1166,7 +1193,7 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
   if (ea->used == in_use)
   {
     GNUNET_break(0);
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
         "Address in use called multiple times for peer `%s': %s -> %s \n",
         GNUNET_i2s (peer), (GNUNET_NO == ea->used) ? "NO" : "YES",
         (GNUNET_NO == in_use) ? "NO" : "YES");
@@ -1175,6 +1202,7 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
 
   /* Tell solver about update */
   ea->used = in_use;
+  ea->t_last_activity = GNUNET_TIME_absolute_get();
   handle->env.sf.s_address_update_inuse (handle->solver, ea, ea->used);
   return GNUNET_OK;
 }
@@ -1203,7 +1231,7 @@ GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle,
 
   if (NULL == cur)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
         "No address requests pending for peer `%s', cannot remove!\n",
         GNUNET_i2s (peer));
     return;
@@ -1230,7 +1258,7 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
   struct GAS_Addresses_Suggestion_Requests *cur = handle->pending_requests_head;
   struct ATS_Address *aa;
 
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received `%s' for peer `%s'\n",
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s'\n",
       "REQUEST ADDRESS", GNUNET_i2s (peer));
 
   if (GNUNET_NO == handle->running)
@@ -1243,7 +1271,7 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
   }
   if (NULL == cur)
   {
-    cur = GNUNET_malloc (sizeof (struct GAS_Addresses_Suggestion_Requests));
+    cur = GNUNET_new (struct GAS_Addresses_Suggestion_Requests);
     cur->id = (*peer);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
         "Adding new address suggestion request for `%s'\n",
@@ -1264,7 +1292,8 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
       aa, GNUNET_i2s (peer));
 
   GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
-      aa->addr_len, aa->session_id, aa->atsi, aa->atsi_count,
+      aa->addr_len, aa->local_address_info, aa->session_id,
+      aa->atsi, aa->atsi_count,
       aa->assigned_bw_out, aa->assigned_bw_in);
 
   aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval,
@@ -1326,9 +1355,10 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
 }
 
 
-
 static int
-eval_count_active_it (void *cls, const struct GNUNET_PeerIdentity *id, void *obj)
+eval_count_active_it (void *cls,
+                      const struct GNUNET_PeerIdentity *id,
+                      void *obj)
 {
   int *request_fulfilled = cls;
   struct ATS_Address *addr = obj;
@@ -1346,7 +1376,8 @@ eval_count_active_it (void *cls, const struct GNUNET_PeerIdentity *id, void *obj
 /**
  * Summary context
  */
-struct SummaryContext {
+struct SummaryContext
+{
   /**
    * Sum of the utilized inbound bandwidth per network
    */
@@ -1367,11 +1398,10 @@ struct SummaryContext {
 static int
 eval_sum_bw_used (void *cls, const struct GNUNET_PeerIdentity *id, void *obj)
 {
+  struct SummaryContext *ctx = cls;
   struct ATS_Address *addr = obj;
   int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
   int net;
-  struct SummaryContext  *ctx = cls;
-
   int c;
 
   if (GNUNET_YES == addr->active)
@@ -1386,22 +1416,26 @@ eval_sum_bw_used (void *cls, const struct GNUNET_PeerIdentity *id, void *obj)
         ctx->bandwidth_out_assigned[c] += ntohl (addr->assigned_bw_out.value__);
       }
     }
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Active address in  %s with (in/out) %llu/%llu Bps\n",
-        GNUNET_ATS_print_network_type(net),
-        ntohl (addr->assigned_bw_in.value__),
-        ntohl (addr->assigned_bw_out.value__));
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Active address in  %s with (in/out) %u/%u Bps\n",
+                GNUNET_ATS_print_network_type (net),
+                (unsigned int) ntohl (addr->assigned_bw_in.value__),
+                (unsigned int) ntohl (addr->assigned_bw_out.value__));
   }
   return GNUNET_OK;
 }
 
+
 /**
  * Summary context
  */
-struct RelativityContext {
+struct RelativityContext
+{
 
   struct GAS_Addresses_Handle *ah;
 };
 
+
 static int
 find_active_address (void *cls, const struct GNUNET_PeerIdentity *id, void *obj)
 {
@@ -1528,10 +1562,9 @@ GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah)
   }
 
   /* 3) How well does selection match application requirements */
-  include_requirements = GNUNET_NO;
   if (0 == ah->pref_clients)
   {
-    include_requirements = GNUNET_NO;
+    include_requirements = 0;
   }
   else
   {
@@ -1553,7 +1586,6 @@ GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah)
         {
           if (prefs[c] == GNUNET_ATS_PREFERENCE_END)
             continue;
-          pref_val = -1.0;
           pref_val = GAS_normalization_get_preferences_by_client (pcur->client, &cur->id, prefs[c]);
           if (-1.0 == pref_val)
           {
@@ -1609,7 +1641,7 @@ GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah)
     else
       quality_application_requirements = 0.0;
 
-    include_requirements = GNUNET_YES;
+    include_requirements = 1;
   }
   /* GUQ */
 
@@ -1833,7 +1865,7 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
       GNUNET_CONTAINER_multipeermap_contains (handle->addresses,
                                              peer))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
         "Received `%s' for unknown peer `%s' from client %p\n",
         "CHANGE PREFERENCE", GNUNET_i2s (peer), client);
     return;
@@ -1841,7 +1873,7 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
 
   if (NULL == find_preference_client (handle, client))
   {
-    pc = GNUNET_malloc (sizeof (struct GAS_Addresses_Preference_Clients));
+    pc = GNUNET_new (struct GAS_Addresses_Preference_Clients);
     pc->client = client;
     GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head,
         handle->preference_clients_tail, pc);
@@ -1882,7 +1914,7 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
       GNUNET_CONTAINER_multipeermap_contains (handle->addresses,
                                              peer))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
         "Received `%s' for unknown peer `%s' from client %p\n",
         "PREFERENCE FEEDBACK", GNUNET_i2s (peer), application);
     return;
@@ -2049,32 +2081,36 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
   }
   if (NULL == cur)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Nobody is interested in peer `%s' :(\n",
-        GNUNET_i2s (&address->peer));
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+               "Nobody is interested in peer `%s' :(\n",
+               GNUNET_i2s (&address->peer));
     return;
   }
 
   if ((0 == ntohl (address->assigned_bw_in.value__))
       && (0 == ntohl (address->assigned_bw_out.value__)))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-        "Telling transport to disconnect peer `%s'\n",
-        GNUNET_i2s (&address->peer));
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               "Telling transport to disconnect peer `%s'\n",
+                GNUNET_i2s (&address->peer));
   }
   else
   {
     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-        "Sending bandwidth update for peer `%s': %llu %llu\n",
-        GNUNET_i2s (&address->peer), address->assigned_bw_out,
-        address->assigned_bw_out);
+               "Sending bandwidth update for peer `%s': %u %u\n",
+               GNUNET_i2s (&address->peer),
+               (unsigned int) ntohl (address->assigned_bw_out.value__),
+               (unsigned int) ntohl (address->assigned_bw_out.value__));
   }
 
   /* *Notify scheduling clients about suggestion */
   GAS_scheduling_transmit_address_suggestion (&address->peer, address->plugin,
-      address->addr, address->addr_len, address->session_id, address->atsi,
+      address->addr, address->addr_len, address->local_address_info,
+      address->session_id, address->atsi,
       address->atsi_count, address->assigned_bw_out, address->assigned_bw_in);
 }
 
+
 /**
  * Initialize address subsystem. The addresses subsystem manages the addresses
  * known and current performance information. It has a solver component
@@ -2096,7 +2132,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
   char *plugin_short;
   int c;
 
-  ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle));
+  ah = GNUNET_new (struct GAS_Addresses_Handle);
   ah->running = GNUNET_NO;
 
   ah->stat = (struct GNUNET_STATISTICS_Handle *) stats;
@@ -2106,7 +2142,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
   GNUNET_assert(NULL != ah->addresses);
 
   /* Figure out configured solution method */
-  plugin_short = NULL;
   if (GNUNET_SYSERR
       == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str))
   {
@@ -2119,39 +2154,30 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
     for (c = 0; c < strlen (mode_str); c++)
       mode_str[c] = toupper (mode_str[c]);
     if (0 == strcmp (mode_str, "PROPORTIONAL"))
-    {
       ah->ats_mode = MODE_PROPORTIONAL;
-      plugin_short = "proportional";
-    }
     else if (0 == strcmp (mode_str, "MLP"))
     {
       ah->ats_mode = MODE_MLP;
-      plugin_short = "mlp";
 #if !HAVE_LIBGLPK
       GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
           "Assignment method `%s' configured, but GLPK is not available, please install \n",
           mode_str);
       ah->ats_mode = MODE_PROPORTIONAL;
-      plugin_short = "proportional";
 #endif
     }
     else if (0 == strcmp (mode_str, "RIL"))
-    {
       ah->ats_mode = MODE_RIL;
-      plugin_short = "ril";
-    }
     else
     {
       GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
           "Invalid resource assignment method `%s' configured, using proportional approach\n",
           mode_str);
       ah->ats_mode = MODE_PROPORTIONAL;
-      plugin_short = "proportional";
     }
     GNUNET_free(mode_str);
   }
 
-  load_quotas (cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount);
+  load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount);
   ah->env.info_cb = &solver_info_cb;
   ah->env.info_cb_cls = ah;
   ah->env.bandwidth_changed_cb = &bandwidth_changed_cb;
@@ -2173,6 +2199,20 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
     ah->env.in_quota[c] = quotas_in[c];
   }
 
+  switch (ah->ats_mode) {
+    case MODE_PROPORTIONAL:
+      plugin_short = "proportional";
+      break;
+    case MODE_MLP:
+      plugin_short = "mlp";
+      break;
+    case MODE_RIL:
+      plugin_short = "ril";
+      break;
+    default:
+      plugin_short = NULL;
+      break;
+  }
   GNUNET_asprintf (&ah->plugin, "libgnunet_plugin_ats_%s", plugin_short);
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s '`%s'\n"), plugin_short, ah->plugin);
   if  (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env)))