/*
This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2013 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
#include "gnunet_util_lib.h"
#include "gnunet-ats-solver-eval.h"
#include "gnunet-service-ats_normalization.h"
-#include "gnunet-service-ats_preferences.h"
+#include "gnunet-service-ats_preferences.c"
#define BIG_M_STRING "unlimited"
static void
end_now ();
-const double *
-get_property_cb (void *cls, const struct ATS_Address *address);
static char *
print_generator_type (enum GeneratorType g)
}
}
-struct AddressLookupCtx
-{
- struct ATS_Address *res;
- char *plugin;
- char *addr;
-};
-
-
-int find_address_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- struct AddressLookupCtx *ctx = cls;
- struct ATS_Address *addr = value;
-
- if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
- (0 == strcmp (ctx->addr, addr->addr)) )
- {
- ctx->res = addr;
- return GNUNET_NO;
- }
- return GNUNET_YES;
-}
static struct TestPeer *
find_peer_by_id (int id)
}
-static struct TestAddress *
-find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
-{
- struct TestAddress *cur;
- for (cur = p->addr_head; NULL != cur; cur = cur->next)
- if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
- (cur->ats_addr->addr_len == addr->addr_len) &&
- (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
- return cur;
- return NULL;
-}
-
-
/**
* Logging
*/
-
void
GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
{
log_a->aid = cur_addr->aid;
log_a->active = cur_addr->ats_addr->active;
log_a->network = cur_addr->network;
- log_a->used = cur_addr->ats_addr->used;
log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
atsi.value = htonl ((uint32_t) prop_value);
/* set performance here! */
- sh->env.sf.s_bulk_start (sh->solver);
+ sh->sf->s_bulk_start (sh->sf->cls);
if (GNUNET_YES == opt_disable_normalization)
{
a->prop_abs[pg->ats_property] = prop_value;
a->prop_norm[pg->ats_property] = prop_value;
- sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
+ sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
pg->ats_property, prop_value, prop_value);
}
else
- GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 1);
- sh->env.sf.s_bulk_stop (sh->solver);
+ GAS_normalization_update_property (pg->test_address->ats_addr, &atsi, 1);
+ sh->sf->s_bulk_stop (sh->sf->cls);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
&set_prop_task, pg);
-
}
+
/**
* Set ats_property to 0 to find all pgs
*/
-
static struct PropertyGenerator *
find_prop_gen (unsigned int peer, unsigned int address,
uint32_t ats_property)
}
-
/**
* Stop all preferences generators
*/
GNUNET_ATS_print_preference_type (pg->kind),
feedback);
- sh->env.sf.s_feedback (sh->solver, NULL + (pg->client_id), &p->peer_id,
+ sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
pg->feedback_frequency, pg->kind, feedback);
pg->feedback_last = GNUNET_TIME_absolute_get();
pg->peer, NULL + (pg->client_id),
GNUNET_ATS_print_preference_type (pg->kind), pref_value);
- sh->env.sf.s_bulk_start (sh->solver);
if (GNUNET_YES == opt_disable_normalization)
{
p->pref_abs[pg->kind] = pref_value;
p->pref_norm[pg->kind] = pref_value;
- sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
+ sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
}
else
- GAS_normalization_normalize_preference (NULL + (pg->client_id),
- &p->peer_id, pg->kind, pref_value);
- sh->env.sf.s_bulk_stop (sh->solver);
+ normalize_preference (NULL + (pg->client_id),
+ &p->peer_id,
+ pg->kind,
+ pref_value);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
- set_pref_task, pg);
-
+ &set_pref_task,
+ pg);
}
+
static struct PreferenceGenerator *
find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
{
GNUNET_free (pg);
}
-struct TestAddress*
+
+static struct TestAddress*
find_active_address (struct TestPeer *p)
{
struct TestAddress *cur;
return NULL;
}
+
/**
* Generate between the source master and the partner and set property with a
* value depending on the generator.
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
{
struct TestAddress * addr = find_active_address(p);
- const double *properties = get_property_cb (NULL, addr->ats_addr);
pg->last_assigned_bw_in = p->assigned_bw_in;
pg->last_assigned_bw_out = p->assigned_bw_out;
pg->feedback_bw_in_acc = 0;
pg->feedback_bw_out_acc = 0;
-
- pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
+ pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY];
pg->feedback_delay_acc = 0;
pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
/**
* Experiments
*/
-
-const char *
+static const char *
print_op (enum OperationType op)
{
switch (op) {
return "";
}
+
static struct Experiment *
create_experiment ()
{
return e;
}
+
static void
free_experiment (struct Experiment *e)
{
return GNUNET_OK;
}
+
static int
load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
struct Episode *e,
return GNUNET_OK;
}
+
static enum GNUNET_ATS_Property
parse_preference_string (const char * str)
{
if (0 == strcmp(str, props[c]))
return c;
return 0;
-};
+}
+
static int
load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
return GNUNET_OK;
}
+
static int
load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
struct Episode *e,
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 = 0;
- aa->assigned_bw_out = 0;
return aa;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
- sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
+ sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
}
op->address_id,
op->peer_id);
- sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
+ sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO);
if (NULL != l)
{
op->peer_id);
p->is_requested = GNUNET_YES;
- res = sh->env.sf.s_get (sh->solver, &p->peer_id);
+ res = sh->sf->s_get (sh->sf->cls, &p->peer_id);
if (NULL != res)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
p->is_requested = GNUNET_NO;
p->assigned_bw_in = 0;
p->assigned_bw_out = 0;
- sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
+ sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
if (NULL != l)
{
{
GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
GNUNET_NO);
- GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
-
+ GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
+ sh->sf = NULL;
GAS_normalization_stop();
- GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
+ &free_all_it,
+ NULL);
GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
GNUNET_free (sh->plugin);
GNUNET_free (sh);
}
+
/**
* Load quotas for networks from configuration
*
return p->pref_abs;
}
else
- return GAS_normalization_get_preferences_by_peer (NULL,
+ return GAS_preference_get_by_peer (NULL,
id);
}
-const double *
-get_property_cb (void *cls, const struct ATS_Address *address)
-{
- struct TestPeer *p;
- struct TestAddress *a;
-
- if (GNUNET_YES == opt_disable_normalization)
- {
- p = find_peer_by_pid (&address->peer);
- if (NULL == p)
- return NULL;
- a = find_address_by_ats_address (p, address);
- return a->prop_abs;
- }
- return GAS_normalization_get_properties (NULL,
- address);
-}
-
-
struct SolverHandle *
GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
{
struct SolverHandle *sh;
char * solver_str;
- int c;
switch (type) {
case GNUNET_ATS_SOLVER_PROPORTIONAL:
}
sh = GNUNET_new (struct SolverHandle);
- GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
-
+ GNUNET_asprintf (&sh->plugin,
+ "libgnunet_plugin_ats_%s",
+ solver_str);
sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
/* setup environment */
sh->env.addresses = sh->addresses;
sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
sh->env.get_preferences = &get_preferences_cb;
- sh->env.get_property = &get_property_cb;
sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
sh->env.info_cb = &solver_info_cb;
- sh->env.info_cb_cls = NULL;
sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
- int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
- for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
- sh->env.networks[c] = networks[c];
-
/* start normalization */
GAS_normalization_start ();
return NULL;
}
- sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
- if (NULL == sh->solver)
+ sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
+ if (NULL == sh->sf)
{
fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
GNUNET_break(0);
return sh;
}
+
static void
done ()
{