changes
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.c
index d03d186c8749eecde1a4d9f871a98dc9c6008ecc..49d6d0b593f71cb95783b7c87481179dc3e3e99a 100644 (file)
@@ -62,37 +62,86 @@ enum ATS_Mode
   MODE_MLP
 };
 
-
-
-
-
-
+/**
+ * Handle for ATS address component
+ */
 struct GAS_Addresses_Handle
 {
+  /**
+   * A multihashmap to store all addresses
+   */
   struct GNUNET_CONTAINER_MultiHashMap *addresses;
 
+  /**
+   * Configure WAN quota in
+   */
   unsigned long long wan_quota_in;
 
+  /**
+   * Configure WAN quota out
+   */
   unsigned long long wan_quota_out;
 
+  /**
+   * Number of active addresses
+   */
   unsigned int active_addr_count;
 
+  /**
+   * Is ATS addresses running
+   */
   int running;
 
-
+  /**
+   * Configured ATS solver
+   */
   int ats_mode;
-  /* Solver handle */
+
+  /**
+   *  Solver handle
+   */
   void *solver;
 
   /* Solver functions */
+
+  /**
+   * Initialize solver
+   */
   GAS_solver_init s_init;
-  GAS_solver_done s_done;
+
+  /**
+   * Update address in solver
+   */
+  GAS_solver_address_update s_update;
+
+  /**
+   * Get address from solver
+   */
+  GAS_solver_get_preferred_address s_get;
+
+  /**
+   * Delete address in solver
+   */
   GAS_solver_address_delete s_del;
+
+  /**
+   * Change preference for quality in solver
+   */
   GAS_solver_address_change_preference s_pref;
+
+  /**
+   * Shutdown solver
+   */
+  GAS_solver_done s_done;
 };
 
+
+/**
+ * Temporary handle
+ */
 struct GAS_Addresses_Handle *handle;
 
+
 static unsigned int
 assemble_ats_information (struct ATS_Address *aa,  struct GNUNET_ATS_Information **dest)
 {
@@ -412,6 +461,7 @@ lookup_address (const struct GNUNET_PeerIdentity *peer,
 }
 
 
+#if 0
 static int
 compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
@@ -451,7 +501,7 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer,
                                               &compare_address_session_it, &cac);
   return cac.exact_address;
 }
-
+#endif
 
 void
 GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
@@ -579,18 +629,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
     }
 
   /* Tell solver about update */
-  switch (handle->ats_mode)
-  {
-    case MODE_MLP:
-      GAS_mlp_address_update (handle->solver, handle->addresses, old);
-      break;
-    case MODE_SIMPLISTIC:
-      GAS_simplistic_address_update (handle->solver, handle->addresses, old);
-      break;
-    default:
-      GNUNET_break (0);
-      break;
-  }
+  handle->s_update (handle->solver, handle->addresses, old);
 }
 
 
@@ -829,18 +868,8 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer,
   old->used = in_use;
 
   /* Tell solver about update */
-  switch (handle->ats_mode)
-  {
-    case MODE_MLP:
-      GAS_mlp_address_update (handle->solver, handle->addresses, old);
-      break;
-    case MODE_SIMPLISTIC:
-      GAS_simplistic_address_update (handle->solver, handle->addresses, old);
-      break;
-    default:
-      GNUNET_break (0);
-      break;
-  }
+  handle->s_update (handle->solver, handle->addresses, old);
+
   return GNUNET_OK;
 }
 
@@ -969,9 +998,6 @@ GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer)
 }
 
 
-
-// FIXME: this function should likely end up in the LP-subsystem and
-// not with 'addresses' in the future...
 void
 GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
                                  enum GNUNET_ATS_PreferenceKind kind,
@@ -980,20 +1006,8 @@ GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
   if (GNUNET_NO == handle->running)
     return;
 
-
   /* Tell solver about update */
-  switch (handle->ats_mode)
-  {
-    case MODE_MLP:
-      GAS_mlp_address_change_preference (handle->solver, peer, kind, score);
-      break;
-    case MODE_SIMPLISTIC:
-      GAS_simplistic_address_change_preference (handle->solver, peer, kind, score);
-      break;
-    default:
-      GNUNET_break (0);
-      break;
-  }
+  handle->s_pref (handle->solver, peer, kind, score);
 }
 
 
@@ -1074,6 +1088,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid ressource assignment method `%s' configured, using simplistic approch\n", mode_str);
           ah->ats_mode = MODE_SIMPLISTIC;
       }
+      GNUNET_free (mode_str);
   }
   /* Start configured solution method */
   switch (ah->ats_mode)
@@ -1083,6 +1098,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
 #if HAVE_LIBGLPK
       ah->ats_mode = MODE_MLP;
       ah->s_init = &GAS_mlp_init;
+      ah->s_update = &GAS_mlp_address_update;
+      ah->s_get = &GAS_mlp_get_preferred_address;
       ah->s_pref = &GAS_mlp_address_change_preference;
       ah->s_del =  &GAS_mlp_address_delete;
       ah->s_done = &GAS_mlp_done;
@@ -1095,6 +1112,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
       /* Init the simplistic solver with default values */
       ah->ats_mode = MODE_SIMPLISTIC;
       ah->s_init = &GAS_simplistic_init;
+      ah->s_update = &GAS_simplistic_address_update;
+      ah->s_get = &GAS_simplistic_get_preferred_address;
       ah->s_pref = &GAS_simplistic_address_change_preference;
       ah->s_del  = &GAS_simplistic_address_delete;
       ah->s_done = &GAS_simplistic_done;
@@ -1106,6 +1125,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
   }
 
   GNUNET_assert (NULL != ah->s_init);
+  GNUNET_assert (NULL != ah->s_update);
+  GNUNET_assert (NULL != ah->s_get);
   GNUNET_assert (NULL != ah->s_pref);
   GNUNET_assert (NULL != ah->s_del);
   GNUNET_assert (NULL != ah->s_done);