- improved error logging
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.c
index a5480e50e0220c514b72acded4e88a2a0b279985..06eee9fb39040d55cae982e562eb51e576092391 100644 (file)
 
 enum ATS_Mode
 {
-       SIMPLE,
-       MLP
+  /**
+   * Assign each peer an equal amount of bandwidth (bw)
+   *
+   * bw_per_peer = bw_total / #active addresses
+   */
+  SIMPLE,
+
+  /**
+   * Use MLP solver to assign bandwidth
+   */
+  MLP
 };
 
 static struct GNUNET_CONTAINER_MultiHashMap *addresses;
 
+#if HAVE_LIBGLPK
+static struct GAS_MLP_Handle *mlp;
+#endif
+
 static unsigned long long wan_quota_in;
 
 static unsigned long long wan_quota_out;
@@ -51,6 +64,7 @@ static unsigned int active_addr_count;
 
 static int ats_mode;
 
+
 /**
  * Update a bandwidth assignment for a peer.  This trivial method currently
  * simply assigns the same share to all active connections.
@@ -65,6 +79,8 @@ update_bw_it (void *cls, const GNUNET_HashCode * key, void *value)
 {
   struct ATS_Address *aa = value;
 
+
+  /* Simple method */
   if (GNUNET_YES != aa->active)
     return GNUNET_OK;
   GNUNET_assert (active_addr_count > 0);
@@ -159,6 +175,12 @@ destroy_address (struct ATS_Address *addr)
                  GNUNET_CONTAINER_multihashmap_remove (addresses,
                                                        &addr->peer.hashPubKey,
                                                        addr));
+
+#if HAVE_LIBGLPK
+  if (ats_mode == MLP)
+    GAS_mlp_address_delete (mlp, addresses, addr);
+#endif
+
   if (GNUNET_YES == addr->active)
   {
     active_addr_count--;
@@ -299,7 +321,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
     }
 #if HAVE_LIBGLPK
   if (ats_mode == MLP)
-    GAS_mlp_address_update (addresses, old);
+    GAS_mlp_address_update (mlp, addresses, old);
 #endif
 }
 
@@ -354,12 +376,21 @@ destroy_by_session_id (void *cls, const GNUNET_HashCode * key, void *value)
 
   /* session == 0 and addrlen == 0 : destroy address */
   if (aa->addr_len == 0)
+  {
     (void) destroy_address (aa);
+  }
+  else
+  {
+    /* session was set to 0, update address */
+#if HAVE_LIBGLPK
+  if (ats_mode == MLP)
+    GAS_mlp_address_update (mlp, addresses, aa);
+#endif
+  }
 
   return GNUNET_OK;
 }
 
-
 void
 GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
                        const char *plugin_name, const void *plugin_addr,
@@ -447,7 +478,7 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer,
 
 #if HAVE_LIBGLPK
   if (ats_mode == MLP)
-     GAS_mlp_address_update (addresses, old);
+     GAS_mlp_address_update (mlp, addresses, old);
 #endif
 }
 
@@ -514,8 +545,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                       "WAN_QUOTA_OUT",
                                                       &wan_quota_out));
 
-
-
   switch (GNUNET_CONFIGURATION_get_value_yesno (cfg, "ats", "MLP"))
   {
        /* MLP = YES */
@@ -523,9 +552,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
 #if HAVE_LIBGLPK
           ats_mode = MLP;
           /* Init the MLP solver with default values */
-          GAS_mlp_init (stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+          mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
           break;
 #else
+
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode");
           ats_mode = SIMPLE;
           break;
@@ -585,7 +615,7 @@ GAS_addresses_done ()
 #if HAVE_LIBGLPK
   if (ats_mode == MLP)
   {
-    GAS_mlp_done ();
+    GAS_mlp_done (mlp);
   }
 #endif