+struct GAS_Addresses_Handle *
+GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_STATISTICS_Handle *stats)
+{
+ struct GAS_Addresses_Handle *ah;
+ int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+ unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
+ unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
+ int quota_count;
+ char *mode_str;
+ int c;
+
+ ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle));
+ handle = ah;
+ handle->running = GNUNET_NO;
+
+ /* Initialize the addresses database */
+ ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
+ GNUNET_assert (NULL != ah->addresses);
+
+ /* Figure out configured solution method */
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No ressource assignment method configured, using simplistic approch\n");
+ ah->ats_mode = MODE_SIMPLISTIC;
+ }
+ else
+ {
+ for (c = 0; c < strlen (mode_str); c++)
+ mode_str[c] = toupper (mode_str[c]);
+ if (0 == strcmp (mode_str, "SIMPLISTIC"))
+ {
+ ah->ats_mode = MODE_SIMPLISTIC;
+ }
+ else if (0 == strcmp (mode_str, "MLP"))
+ {
+ ah->ats_mode = MODE_MLP;
+#if !HAVE_LIBGLPK
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Assignment method `%s' configured, but GLPK is not availabe, please install \n", mode_str);
+ ah->ats_mode = MODE_SIMPLISTIC;
+#endif
+ }
+ else
+ {
+ 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)
+ {
+ case MODE_MLP:
+ /* Init the MLP solver with default values */
+#if HAVE_LIBGLPK
+ ah->ats_mode = MODE_MLP;
+ ah->s_init = &GAS_mlp_init;
+ ah->s_add = &GAS_mlp_address_add;
+ 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;
+#else
+ GNUNET_free (ah);
+ return NULL;
+#endif
+ break;
+ case MODE_SIMPLISTIC:
+ /* Init the simplistic solver with default values */
+ ah->ats_mode = MODE_SIMPLISTIC;
+ ah->s_init = &GAS_simplistic_init;
+ ah->s_add = &GAS_simplistic_address_add;
+ 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;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "SIMPLISTIC");
+ break;
+ default:
+ return NULL;
+ break;
+ }
+
+ GNUNET_assert (NULL != ah->s_init);
+ GNUNET_assert (NULL != ah->s_add);
+ 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);
+
+ quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount);
+
+ ah->solver = ah->s_init (cfg, stats, quotas, quotas_in, quotas_out, quota_count, &bandwidth_changed_cb);
+ if (NULL == ah->solver)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize solver!\n");
+ GNUNET_free (ah);
+ return NULL;
+ }
+
+ /* up and running */
+ ah->running = GNUNET_YES;
+ return ah;