}
}
-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)
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);
+ sh->sf->s_bulk_stop (sh->sf->cls);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
&set_prop_task, pg);
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);
+ sh->sf->s_bulk_start (sh->sf->cls);
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);
+ sh->sf->s_bulk_stop (sh->sf->cls);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
set_pref_task, pg);
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
*
}
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.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++)
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 ()
{
/**
* Solver handle
*/
- void *solver;
+ struct GNUNET_ATS_SolverFunctions *sf;
/**
* Address hashmap
static int ats_mode;
/**
- * Solver handle. FIXME: TYPE!?
+ * Solver handle.
*/
-static void *solver;
+static struct GNUNET_ATS_SolverFunctions *sf;
/**
- * Solver functions. FIXME.
+ * Solver environment.
*/
static struct GNUNET_ATS_PluginEnvironment env;
double pref_rel)
{
/* Tell solver about update */
- env.sf.s_pref (solver, peer, kind, pref_rel);
+ sf->s_pref (sf->cls, peer, kind, pref_rel);
}
GNUNET_ATS_print_property_type (type),
GNUNET_i2s (&address->peer),
prop_rel);
- env.sf.s_address_update_property (solver,
- address,
- type,
- 0,
- prop_rel);
+ sf->s_address_update_property (sf->cls,
+ address,
+ type,
+ 0,
+ prop_rel);
}
}
load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount);
+ env.cls = NULL;
env.info_cb = &solver_info_cb;
- env.info_cb_cls = NULL;
env.bandwidth_changed_cb = &bandwidth_changed_cb;
- env.bw_changed_cb_cls = NULL;
env.get_preferences = &GAS_normalization_get_preferences_by_peer;
- env.get_preference_cls = NULL;
env.get_property = &GAS_normalization_get_properties;
- env.get_property_cls = NULL;
env.cfg = cfg;
env.stats = GSA_stats;
env.addresses = GSA_addresses;
"Initializing solver `%s '`%s'\n",
plugin_short,
plugin);
- if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env)))
+ if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Failed to initialize solver `%s'!\n"),
plugin);
return GNUNET_SYSERR;
}
-
-
- GNUNET_assert (NULL != env.sf.s_add);
- GNUNET_assert (NULL != env.sf.s_address_update_property);
- GNUNET_assert (NULL != env.sf.s_get);
- GNUNET_assert (NULL != env.sf.s_get_stop);
- GNUNET_assert (NULL != env.sf.s_pref);
- GNUNET_assert (NULL != env.sf.s_feedback);
- GNUNET_assert (NULL != env.sf.s_del);
- GNUNET_assert (NULL != env.sf.s_bulk_start);
- GNUNET_assert (NULL != env.sf.s_bulk_stop);
-
- if (NULL == solver)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to initialize solver!\n"));
- return GNUNET_SYSERR;
- }
return GNUNET_OK;
}
GAS_plugins_done ()
{
GNUNET_PLUGIN_unload (plugin,
- solver);
- solver = NULL;
+ sf);
+ sf = NULL;
GNUNET_free (plugin);
plugin = NULL;
}
const struct GNUNET_ATS_Information *atsi,
uint32_t atsi_count)
{
- env.sf.s_add (solver, new_address, addr_net);
- env.sf.s_bulk_start (solver);
+ sf->s_add (sf->cls, new_address, addr_net);
+ sf->s_bulk_start (sf->cls);
GAS_normalization_normalize_property (new_address,
atsi,
atsi_count);
- env.sf.s_bulk_stop (solver);
+ sf->s_bulk_stop (sf->cls);
}
const struct GNUNET_ATS_Information *atsi,
uint32_t atsi_count)
{
- env.sf.s_bulk_start (solver);
+ sf->s_bulk_start (sf->cls);
GAS_normalization_normalize_property (address,
atsi,
atsi_count);
- env.sf.s_bulk_stop (solver);
+ sf->s_bulk_stop (sf->cls);
}
void
GAS_plugin_delete_address (struct ATS_Address *address)
{
- env.sf.s_del (solver, address, GNUNET_NO);
+ sf->s_del (sf->cls, address, GNUNET_NO);
}
enum GNUNET_ATS_PreferenceKind kind,
float score_abs)
{
- env.sf.s_bulk_start (solver);
+ sf->s_bulk_start (sf->cls);
/* Tell normalization about change, normalization will call callback if preference changed */
GAS_normalization_normalize_preference (client, peer, kind, score_abs);
- env.sf.s_bulk_stop (solver);
+ sf->s_bulk_stop (sf->cls);
}
enum GNUNET_ATS_PreferenceKind kind,
float score_abs)
{
- env.sf.s_feedback (solver,
+ sf->s_feedback (sf->cls,
application,
peer,
scope,
void
GAS_plugin_solver_lock ()
{
- env.sf.s_bulk_start (solver);
+ sf->s_bulk_start (sf->cls);
}
void
GAS_plugin_solver_unlock ()
{
- env.sf.s_bulk_start (solver);
+ sf->s_bulk_start (sf->cls);
}
{
const struct ATS_Address *aa;
- aa = env.sf.s_get (solver, pid);
+ aa = sf->s_get (sf->cls, pid);
if (NULL == aa)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
void
GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid)
{
- env.sf.s_get_stop (solver, pid);
+ sf->s_get_stop (sf->cls, pid);
}
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_plugins.h"
#include "gnunet-service-ats_normalization.h"
+#include "gnunet-service-ats_preferences.h"
#include "gnunet_ats_service.h"
#include "gnunet_ats_plugin.h"
#include "test_ats_api_common.h"
/**
* Solver handle
*/
- void *solver;
+ struct GNUNET_ATS_SolverFunctions *sf;
/**
* Statistics stat;
GNUNET_i2s (&cur->peer), cur,
"GNUNET_ATS_QUALITY_NET_DELAY",
abs_val, rel_val);
- ph.env.sf.s_address_update_property (ph.solver, cur,
+ ph.sf->s_address_update_property (ph.sf->cls, cur,
GNUNET_ATS_QUALITY_NET_DELAY,
abs_val, rel_val);
break;
"Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
abs_val, rel_val);
- ph.env.sf.s_address_update_property (ph.solver, cur,
+ ph.sf->s_address_update_property (ph.sf->cls, cur,
GNUNET_ATS_QUALITY_NET_DISTANCE,
abs_val, rel_val);
break;
const double *
get_property_cb (void *cls, const struct ATS_Address *address)
{
- return GAS_normalization_get_properties (NULL,
+ return GAS_normalization_get_properties (NULL,
address);
}
static void
-perf_address_initial_update (void *solver,
+perf_address_initial_update (void *dead,
struct GNUNET_CONTAINER_MultiPeerMap * addresses,
struct ATS_Address *address)
{
double distance;
uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
delay = (100 + (double) random) / 100;
- ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
+ ph.sf->s_address_update_property (ph.sf->cls,
+ address, GNUNET_ATS_QUALITY_NET_DELAY,
100, delay);
random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
distance = (100 + (double) random) / 100;
- ph.env.sf.s_address_update_property (solver, address,
- GNUNET_ATS_QUALITY_NET_DISTANCE, 10, distance);
+ ph.sf->s_address_update_property (ph.sf->cls, address,
+ GNUNET_ATS_QUALITY_NET_DISTANCE,
+ 10, distance);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Initial update address %p : %.2f %.2f\n", address, delay, distance);
+ "Initial update address %p : %.2f %.2f\n",
+ address, delay, distance);
}
+
+struct DUA_Ctx
+{
+ int r;
+ int c_cur_a;
+};
+
+
+static int
+do_update_address (void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ void *value)
+{
+ struct DUA_Ctx *ctx = cls;
+ struct ATS_Address *addr = value;
+
+ if (ctx->c_cur_a == ctx->r)
+ perf_update_address (addr);
+ ctx->c_cur_a++;
+ return GNUNET_OK;
+}
+
+
/**
* Update a certain percentage of peers
*
* @param ca the current number of addresses
* @param percentage_peers the percentage of peers to update
*/
-
static void
perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
{
- struct ATS_Address *cur_address;
int c_peer;
int c_select;
int c_cur_p;
- int c_cur_a;
int r;
int count;
unsigned int m[cp];
+ struct DUA_Ctx dua_ctx;
count = cp * ((double) percentage_peers / 100);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
{
r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Updating peer [%u] address [%u]\n", c_cur_p, r);
-
- c_cur_a = 0;
- for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next)
- {
- if (c_cur_a == r)
- perf_update_address (cur_address);
- c_cur_a ++;
- }
+ "Updating peer [%u] address [%u]\n", c_cur_p, r);
+
+ dua_ctx.c_cur_a = 0;
+ dua_ctx.r = r;
+ GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
+ &ph.peers[c_cur_p].id,
+ &do_update_address,
+ &dua_ctx);
}
}
}
perf_create_address (int cp, int ca)
{
struct ATS_Address *a;
+
a = create_address (&ph.peers[cp].id,
"Test 1", "test 1", strlen ("test 1") + 1, 0);
- GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
return a;
GNUNET_free_non_null (data_fn_update);
}
+
+static int
+do_delete_address (void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ void *value)
+{
+ struct ATS_Address *cur = value;
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting addresses for peer %u\n",
+ pid);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
+ pid,
+ cur));
+ ph.sf->s_del (ph.sf->cls, cur, GNUNET_NO);
+ GNUNET_free_non_null (cur->atsi);
+ GNUNET_free (cur);
+ return GNUNET_OK;
+}
+
+
/**
* Run a performance iteration
*/
-
static void
perf_run_iteration (void)
{
- struct ATS_Address *cur;
- struct ATS_Address *next;
int cp;
int ca;
int count_p = ph.N_peers_end;
if (GNUNET_NO == ph.bulk_running)
{
ph.bulk_running = GNUNET_YES;
- ph.env.sf.s_bulk_start (ph.solver);
+ ph.sf->s_bulk_start (ph.sf->cls);
}
ph.current_p = cp + 1;
for (ca = 0; ca < count_a; ca++)
cur_addr->atsi_count = 1;
cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
cur_addr->atsi[0].value = htonl (net);
- ph.env.sf.s_add (ph.solver, cur_addr, net);
+ ph.sf->s_add (ph.sf->cls, cur_addr, net);
ph.current_a = ca + 1;
- perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
+ perf_address_initial_update (NULL, ph.addresses, cur_addr);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
"Adding address for peer %u address %u in network %s\n", cp, ca,
GNUNET_ATS_print_network_type(net));
}
/* Notify solver about request */
- ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
+ ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
if (cp + 1 >= ph.N_peers_start)
{
{
ph.expecting_solution = GNUNET_YES;
ph.bulk_running = GNUNET_NO;
- ph.env.sf.s_bulk_stop (ph.solver);
+ ph.sf->s_bulk_stop (ph.sf->cls);
}
else
GNUNET_break (0);
if (GNUNET_NO == ph.bulk_running)
{
ph.bulk_running = GNUNET_YES;
- ph.env.sf.s_bulk_start (ph.solver);
+ ph.sf->s_bulk_start (ph.sf->cls);
}
perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
ph.bulk_running = GNUNET_NO;
- ph.env.sf.s_bulk_stop (ph.solver);
+ ph.sf->s_bulk_stop (ph.sf->cls);
/* Problem is solved by the solver here due to unlocking */
ph.performed_update = GNUNET_NO;
ph.expecting_solution = GNUNET_NO;
"Done, cleaning up addresses\n");
if (GNUNET_NO == ph.bulk_running)
{
- ph.env.sf.s_bulk_start (ph.solver);
+ ph.sf->s_bulk_start (ph.sf->cls);
ph.bulk_running = GNUNET_YES;
}
for (cp = 0; cp < count_p; cp++)
{
- for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Deleting addresses for peer %u\n", cp);
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
- &ph.peers[cp].id, cur));
- ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
- next = cur->next;
- GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
- GNUNET_free_non_null (cur->atsi);
- GNUNET_free (cur);
- }
+ GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
+ &ph.peers[cp].id,
+ &do_delete_address,
+ NULL);
}
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
ph.env.get_property = &get_property_cb;
ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
ph.env.info_cb = &solver_info_cb;
- ph.env.info_cb_cls = NULL;
int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
- if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
+ if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to initialize solver `%s'!\n"), plugin);
ret = 1;
return;
}
/* Unload solver*/
GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
- GNUNET_PLUGIN_unload (plugin, ph.solver);
+ GNUNET_PLUGIN_unload (plugin, ph.sf);
+ ph.sf = NULL;
GNUNET_free (plugin);
for (c = 0; c < ph.total_iterations; c++ )
{
GNUNET_CONFIGURATION_destroy (solver_cfg);
GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
- ph.solver = NULL;
}
/**
{
struct GNUNET_ATS_PluginEnvironment *env;
- /**
- * Statistics handle
- */
- struct GNUNET_STATISTICS_Handle *stats;
-
/**
* Address hashmap for lookups
*/
const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
- /**
- * Addresses' bandwidth changed callback
- */
- GAS_bandwidth_changed_cb bw_changed_cb;
-
- /**
- * Addresses' bandwidth changed callback closure
- */
- void *bw_changed_cb_cls;
-
- /**
- * ATS function to get preferences
- */
- GAS_get_preferences get_preferences;
-
- /**
- * Closure for ATS function to get preferences
- */
- void *get_preferences_cls;
-
- /**
- * ATS function to get properties
- */
- GAS_get_properties get_properties;
-
- /**
- * Closure for ATS function to get properties
- */
- void *get_properties_cls;
-
/**
* Exclude peer from next result propagation
*/
/**
* Bulk lock
*/
-
int stat_bulk_lock;
/**
struct MLP_information
{
- /* Bandwidth assigned outbound */
+ /**
+ * Bandwidth assigned outbound
+ */
uint32_t b_out;
- /* Bandwidth assigned inbound */
+ /**
+ * Bandwidth assigned inbound
+ */
uint32_t b_in;
- /* Address selected */
+ /**
+ * Address selected
+ */
int n;
- /* bandwidth column index */
+ /**
+ * bandwidth column index
+ */
signed int c_b;
- /* address usage column */
+ /**
+ * address usage column
+ */
signed int c_n;
/* row indexes */
- /* constraint 1: bandwidth capping */
+ /**
+ * constraint 1: bandwidth capping
+ */
unsigned int r_c1;
- /* constraint 3: minimum bandwidth */
+ /**
+ * constraint 3: minimum bandwidth
+ */
unsigned int r_c3;
};
* @param cls not used
* @param key the key
* @param value ATS_Peer
- * @return GNUNET_OK
+ * @return #GNUNET_OK
*/
static int
reset_peers (void *cls,
/* For all quality metrics, set quality of this address */
if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
{
- props = mlp->get_properties (mlp->get_properties_cls, address);
+ props = mlp->env->get_property (mlp->env->cls, address);
for (c = 0; c < mlp->pv.m_q; c++)
{
if ((props[c] < 1.0) && (props[c] > 2.0))
address->assigned_bw_out = mlp_bw_out;
mlpi->b_out = mlp_bw_out;
if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
- mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+ mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
return GNUNET_OK;
}
else if (GNUNET_YES == address->active)
address->assigned_bw_out = mlp_bw_out;
mlpi->b_out = mlp_bw_out;
if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
- mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+ mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
return GNUNET_OK;
}
}
enum GAS_Solver_Additional_Information add)
{
if (NULL != mlp->env->info_cb)
- mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add);
+ mlp->env->info_cb (mlp->env->cls, op, stat, add);
}
double res;
const double *preferences = NULL;
int c;
- preferences = mlp->get_preferences (mlp->get_preferences_cls, peer);
+ preferences = mlp->env->get_preferences (mlp->env->cls, peer);
res = 0.0;
for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
{
if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer))
{
/* No alternative address, disconnecting peer */
- mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+ mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
}
}
struct GAS_MLP_Handle *mlp = solver;
struct ATS_Peer *p;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing preference for address for peer `%s' to %.2f\n",
- GNUNET_i2s(peer), pref_rel);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Changing preference for address for peer `%s' to %.2f\n",
+ GNUNET_i2s(peer),
+ pref_rel);
- GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (mlp->env->stats,
+ "# LP address preference changes", 1, GNUNET_NO);
/* Update the constraints with changed preferences */
/* Update relativity constraint c9 */
if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer)))
{
- LOG (GNUNET_ERROR_TYPE_INFO, "Updating preference for unknown peer `%s'\n", GNUNET_i2s(peer));
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Updating preference for unknown peer `%s'\n",
+ GNUNET_i2s(peer));
return;
}
if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
{
p->f = get_peer_pref_value (mlp, peer);
- mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__);
+ mlp_create_problem_update_value (&mlp->p,
+ p->r_c9,
+ mlp->p.c_r,
+ - p->f,
+ __LINE__);
/* Problem size changed: new address for peer with pending request */
mlp->stat_mlp_prob_updated = GNUNET_YES;
*/
static void
GAS_mlp_address_preference_feedback (void *solver,
- void *application,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind,
- double score)
+ struct GNUNET_SERVER_Client *application,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double score)
{
struct GAS_PROPORTIONAL_Handle *s = solver;
+
GNUNET_assert (NULL != solver);
GNUNET_assert (NULL != peer);
-
GNUNET_assert (NULL != s);
}
void *
libgnunet_plugin_ats_mlp_done (void *cls)
{
- struct GAS_MLP_Handle *mlp = cls;
- GNUNET_assert (mlp != NULL);
+ struct GNUNET_ATS_SolverFunctions *sf = cls;
+ struct GAS_MLP_Handle *mlp = sf->cls;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down mlp solver\n");
mlp_delete_problem (mlp);
-
GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
&mlp_free_peers,
mlp->requested_peers);
void *
libgnunet_plugin_ats_mlp_init (void *cls)
{
+ static struct GNUNET_ATS_SolverFunctions sf;
struct GNUNET_ATS_PluginEnvironment *env = cls;
struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle);
}
}
mlp->env = env;
- env->sf.s_add = &GAS_mlp_address_add;
- env->sf.s_address_update_property = &GAS_mlp_address_property_changed;
- env->sf.s_get = &GAS_mlp_get_preferred_address;
- env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address;
- env->sf.s_pref = &GAS_mlp_address_change_preference;
- env->sf.s_feedback = &GAS_mlp_address_preference_feedback;
- env->sf.s_del = &GAS_mlp_address_delete;
- env->sf.s_bulk_start = &GAS_mlp_bulk_start;
- env->sf.s_bulk_stop = &GAS_mlp_bulk_stop;
-
-
- /* Assign options to handle */
- mlp->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
- mlp->addresses = env->addresses;
- mlp->bw_changed_cb = env->bandwidth_changed_cb;
- mlp->bw_changed_cb_cls = env->bw_changed_cb_cls;
- mlp->get_preferences = env->get_preferences;
- mlp->get_preferences_cls = env->get_preference_cls;
- mlp->get_properties = env->get_property;
- mlp->get_properties_cls = env->get_property_cls;
- /* Setting MLP Input variables */
+ sf.cls = mlp;
+ sf.s_add = &GAS_mlp_address_add;
+ sf.s_address_update_property = &GAS_mlp_address_property_changed;
+ sf.s_get = &GAS_mlp_get_preferred_address;
+ sf.s_get_stop = &GAS_mlp_stop_get_preferred_address;
+ sf.s_pref = &GAS_mlp_address_change_preference;
+ sf.s_feedback = &GAS_mlp_address_preference_feedback;
+ sf.s_del = &GAS_mlp_address_delete;
+ sf.s_bulk_start = &GAS_mlp_bulk_start;
+ sf.s_bulk_stop = &GAS_mlp_bulk_stop;
+ /* Setting MLP Input variables */
mlp->pv.b_min = b_min;
mlp->pv.n_min = n_min;
mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
- return mlp;
+ return &sf;
}
/* end of plugin_ats_mlp.c */
*/
struct GAS_PROPORTIONAL_Handle
{
- struct GNUNET_ATS_PluginEnvironment *env;
/**
- * Statistics handle
+ * Our execution environment.
*/
- struct GNUNET_STATISTICS_Handle *stats;
+ struct GNUNET_ATS_PluginEnvironment *env;
/**
* Hashmap containing all valid addresses
*/
struct GNUNET_CONTAINER_MultiPeerMap *requests;
- /**
- * Bandwidth changed callback
- */
- GAS_bandwidth_changed_cb bw_changed;
-
- /**
- * Bandwidth changed callback cls
- */
- void *bw_changed_cls;
-
- /**
- * ATS function to get preferences
- */
- GAS_get_preferences get_preferences;
-
- /**
- * Closure for ATS function to get preferences
- */
- void *get_preferences_cls;
-
- /**
- * ATS function to get properties
- */
- GAS_get_properties get_properties;
-
- /**
- * Closure for ATS function to get properties
- */
- void *get_properties_cls;
-
/**
* Bulk lock
*/
void *
libgnunet_plugin_ats_proportional_done (void *cls)
{
- struct GAS_PROPORTIONAL_Handle *s = cls;
+ struct GNUNET_ATS_SolverFunctions *sf = cls;
+ struct GAS_PROPORTIONAL_Handle *s = sf->cls;
struct AddressWrapper *cur;
struct AddressWrapper *next;
int c;
if (GNUNET_YES != cur_address->addr->active)
continue;
- GNUNET_assert( NULL != (peer_relative_prefs = s->get_preferences (s->get_preferences_cls,
- &cur_address->addr->peer)));
+ GNUNET_assert( NULL != (peer_relative_prefs = s->env->get_preferences (s->env->cls,
+ &cur_address->addr->peer)));
relative_peer_prefence = 0.0;
relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
sum_relative_peer_prefences += relative_peer_prefence;
if (GNUNET_YES == cur_address->addr->active)
{
GNUNET_assert( NULL != (peer_relative_prefs =
- s->get_preferences (s->get_preferences_cls, &cur_address->addr->peer)));
+ s->env->get_preferences (s->env->cls,
+ &cur_address->addr->peer)));
cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
total_weight = net->active_addresses +
}
/* Now compare ATS information */
- norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls,
- (const struct ATS_Address *) current);
+ norm_prop_cur = ctx->s->env->get_property (ctx->s->env->cls,
+ current);
index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
cur_distance = norm_prop_cur[index];
index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
cur_delay = norm_prop_cur[index];
- norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls,
- (const struct ATS_Address *) ctx->best);
+ norm_prop_best = ctx->s->env->get_property (ctx->s->env->cls,
+ ctx->best);
index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
best_distance = norm_prop_best[index];
index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
{
s->total_addresses++;
net->total_addresses++;
- GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", 1, GNUNET_NO);
- GNUNET_STATISTICS_update (s->stats, net->stat_total, 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (s->env->stats,
+ "# ATS addresses total", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (s->env->stats,
+ net->stat_total, 1, GNUNET_NO);
}
if (GNUNET_YES == active)
{
net->active_addresses++;
s->active_addresses++;
- GNUNET_STATISTICS_update (s->stats, "# ATS active addresses total", 1,
+ GNUNET_STATISTICS_update (s->env->stats,
+ "# ATS active addresses total", 1,
GNUNET_NO);
- GNUNET_STATISTICS_update (s->stats, net->stat_active, 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (s->env->stats,
+ net->stat_active, 1, GNUNET_NO);
}
}
else
{
s->total_addresses--;
- GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1,
+ GNUNET_STATISTICS_update (s->env->stats,
+ "# ATS addresses total", -1,
GNUNET_NO);
}
if (net->total_addresses < 1)
else
{
net->total_addresses--;
- GNUNET_STATISTICS_update (s->stats, net->stat_total, -1, GNUNET_NO);
+ GNUNET_STATISTICS_update (s->env->stats,
+ net->stat_total, -1, GNUNET_NO);
}
}
else
{
net->active_addresses--;
- GNUNET_STATISTICS_update (s->stats, net->stat_active, -1, GNUNET_NO);
+ GNUNET_STATISTICS_update (s->env->stats,
+ net->stat_active, -1, GNUNET_NO);
}
if (s->active_addresses < 1)
{
else
{
s->active_addresses--;
- GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1,
+ GNUNET_STATISTICS_update (s->env->stats,
+ "# ATS addresses total", -1,
GNUNET_NO);
}
}
{
struct AddressWrapper *cur;
struct AddressSolverInformation *asi;
+
for (cur = net->head; NULL != cur; cur = cur->next)
{
asi = cur->addr->solver_information;
/* Notify on change */
if ((GNUNET_YES == cur->addr->active))
{
- s->bw_changed (s->bw_changed_cls, cur->addr);
+ s->env->bandwidth_changed_cb (s->env->cls,
+ cur->addr);
}
}
}
n->active_addresses, n->total_addresses);
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
/* Distribute */
distribute_bandwidth(s, n);
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
/* Do propagation */
propagate_bandwidth (s, n);
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
}
else
{
int i;
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
for (i = 0; i < s->network_count; i++)
{
}
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
for (i = 0; i < s->network_count; i++)
{
propagate_bandwidth(s, &s->network_entries[i]);
}
if (NULL != s->env->info_cb)
- s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
+ s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
}
}
"Disconnecting peer `%s' with previous address %p\n",
GNUNET_i2s (peer),
current_address);
- s->bw_changed (s->bw_changed_cls,
- current_address);
+ s->env->bandwidth_changed_cb (s->env->cls,
+ current_address);
}
}
if (NULL == best_address)
*/
static void
GAS_proportional_address_preference_feedback (void *solver,
- void *application,
+ struct GNUNET_SERVER_Client *application,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TIME_Relative scope,
enum GNUNET_ATS_PreferenceKind kind,
"Disconnecting peer `%s' after deleting previous address %p\n",
GNUNET_i2s (&address->peer),
address);
- s->bw_changed (s->bw_changed_cls,
- address);
+ s->env->bandwidth_changed_cb (s->env->cls,
+ address);
}
}
if (GNUNET_NO == session_only)
void *
libgnunet_plugin_ats_proportional_init (void *cls)
{
+ static struct GNUNET_ATS_SolverFunctions sf;
struct GNUNET_ATS_PluginEnvironment *env = cls;
struct GAS_PROPORTIONAL_Handle *s;
struct Network * cur;
s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
s->env = env;
- env->sf.s_add = &GAS_proportional_address_add;
- env->sf.s_address_update_property = &GAS_proportional_address_property_changed;
- env->sf.s_get = &GAS_proportional_get_preferred_address;
- env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
- env->sf.s_pref = &GAS_proportional_address_change_preference;
- env->sf.s_feedback = &GAS_proportional_address_preference_feedback;
- env->sf.s_del = &GAS_proportional_address_delete;
- env->sf.s_bulk_start = &GAS_proportional_bulk_start;
- env->sf.s_bulk_stop = &GAS_proportional_bulk_stop;
-
- s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
- s->bw_changed = env->bandwidth_changed_cb;
- s->bw_changed_cls = env->bw_changed_cb_cls;
- s->get_preferences = env->get_preferences;
- s->get_preferences_cls = env->get_preference_cls;
- s->get_properties = env->get_property;
- s->get_properties_cls = env->get_property_cls;
- s->network_count = env->network_count;
+ sf.cls = s;
+ sf.s_add = &GAS_proportional_address_add;
+ sf.s_address_update_property = &GAS_proportional_address_property_changed;
+ sf.s_get = &GAS_proportional_get_preferred_address;
+ sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
+ sf.s_pref = &GAS_proportional_address_change_preference;
+ sf.s_feedback = &GAS_proportional_address_preference_feedback;
+ sf.s_del = &GAS_proportional_address_delete;
+ sf.s_bulk_start = &GAS_proportional_bulk_start;
+ sf.s_bulk_stop = &GAS_proportional_bulk_stop;
+
s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network));
/* Init */
cur->total_quota_in,
cur->total_quota_out);
}
- return s;
+ return &sf;
}
/**
* The solver-plugin environment of the solver-plugin API
*/
- struct GNUNET_ATS_PluginEnvironment *plugin_envi;
-
- /**
- * Statistics handle
- */
- struct GNUNET_STATISTICS_Handle *stats;
+ struct GNUNET_ATS_PluginEnvironment *env;
/**
* Number of performed steps
enum GAS_Solver_Operation op,
enum GAS_Solver_Status stat)
{
- if (NULL != solver->plugin_envi->info_cb)
- solver->plugin_envi->info_cb (solver->plugin_envi->info_cb_cls, op, stat, GAS_INFO_NONE);
+ if (NULL != solver->env->info_cb)
+ solver->env->info_cb (solver->env->cls, op, stat, GAS_INFO_NONE);
}
/**
double delay_norm;
double pref_match;
- preferences = agent->envi->plugin_envi->get_preferences (agent->envi->plugin_envi->get_preference_cls,
- &agent->peer);
+ preferences = agent->envi->env->get_preferences (agent->envi->env->cls,
+ &agent->peer);
delay_atsi = (double) ril_get_atsi (agent->address_inuse, GNUNET_ATS_QUALITY_NET_DELAY);
delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001);
for (cur = solver->agents_head; NULL != cur; cur = cur->next)
{
if (cur->suggestion_issue) {
- solver->plugin_envi->bandwidth_changed_cb(solver->plugin_envi->bw_changed_cb_cls, cur->suggestion_address);
+ solver->env->bandwidth_changed_cb(solver->env->cls, cur->suggestion_address);
cur->suggestion_issue = GNUNET_NO;
}
}
*/
static void
GAS_ril_address_preference_feedback (void *solver,
- void *application,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind,
- double score)
+ struct GNUNET_SERVER_Client *application,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double score)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
- "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
- GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
+ "preference %s for %d seconds\n",
+ GNUNET_i2s (peer),
+ "UNKNOWN",
+ GNUNET_ATS_print_preference_type (kind),
+ scope.rel_value_us / 1000000);
}
void *
libgnunet_plugin_ats_ril_init (void *cls)
{
+ static struct GNUNET_ATS_SolverFunctions sf;
struct GNUNET_ATS_PluginEnvironment *env = cls;
struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
struct RIL_Scope * cur;
solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
}
- env->sf.s_add = &GAS_ril_address_add;
- env->sf.s_address_update_property = &GAS_ril_address_property_changed;
- env->sf.s_get = &GAS_ril_get_preferred_address;
- env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
- env->sf.s_pref = &GAS_ril_address_change_preference;
- env->sf.s_feedback = &GAS_ril_address_preference_feedback;
- env->sf.s_del = &GAS_ril_address_delete;
- env->sf.s_bulk_start = &GAS_ril_bulk_start;
- env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
+ solver->env = env;
+ sf.cls = solver;
+ sf.s_add = &GAS_ril_address_add;
+ sf.s_address_update_property = &GAS_ril_address_property_changed;
+ sf.s_get = &GAS_ril_get_preferred_address;
+ sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
+ sf.s_pref = &GAS_ril_address_change_preference;
+ sf.s_feedback = &GAS_ril_address_preference_feedback;
+ sf.s_del = &GAS_ril_address_delete;
+ sf.s_bulk_start = &GAS_ril_bulk_start;
+ sf.s_bulk_stop = &GAS_ril_bulk_stop;
- solver->plugin_envi = env;
solver->networks_count = env->network_count;
solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
solver->step_count = 0;
LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
solver->parameters.rbf_divisor);
- return solver;
+ return &sf;
}
void *
libgnunet_plugin_ats_ril_done (void *cls)
{
- struct GAS_RIL_Handle *s = cls;
+ struct GNUNET_ATS_SolverFunctions *sf = cls;
+ struct GAS_RIL_Handle *s = sf->cls;
struct RIL_Peer_Agent *cur_agent;
struct RIL_Peer_Agent *next_agent;
/*
This file is part of GNUnet
- (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+ (C) 2009-2015 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
*/
typedef void
(*GAS_solver_address_change_preference) (void *solver,
- const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel);
+ const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double pref_rel);
+
/**
* Give feedback about the current assignment
* @param score the feedback score
*/
typedef void
-(*GAS_solver_address_feedback_preference) (void *solver, void *application,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind, double score);
+(*GAS_solver_address_feedback_preference) (void *solver,
+ struct GNUNET_SERVER_Client *application,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double score);
/**
* Notify the solver about a bulk operation changing possibly a lot of values
typedef void
(*GAS_solver_bulk_start) (void *solver);
+
/**
* Mark a bulk operation as done
* Solver will resolve if values have changed
typedef void
(*GAS_solver_bulk_stop) (void *solver);
+
/**
* Add a single address within a network to the solver
*
* @param solver the solver Handle
- * @param addresses the address hashmap containing all addresses
* @param address the address to add
* @param network network type of this address
*/
typedef void
-(*GAS_solver_address_add) (void *solver, struct ATS_Address *address,
- uint32_t network);
+(*GAS_solver_address_add) (void *solver,
+ struct ATS_Address *address,
+ uint32_t network);
+
/**
* Delete an address or just the session from the solver
*
* @param solver the solver Handle
- * @param addresses the address hashmap containing all addresses
* @param address the address to delete
* @param session_only remove address or just session
*/
typedef void
-(*GAS_solver_address_delete) (void *solver, struct ATS_Address *address,
- int session_only);
+(*GAS_solver_address_delete) (void *solver,
+ struct ATS_Address *address,
+ int session_only);
+
/**
* Transport properties for this address have changed
*/
typedef void
(*GAS_solver_address_property_changed) (void *solver,
- struct ATS_Address *address, uint32_t type, uint32_t abs_value,
- double rel_value);
+ struct ATS_Address *address,
+ uint32_t type,
+ uint32_t abs_value,
+ double rel_value);
/**
* Get the prefered address for a peer from solver
*
* @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
* @param peer the peer
*/
typedef const struct ATS_Address *
(*GAS_solver_get_preferred_address) (void *solver,
- const struct GNUNET_PeerIdentity *peer);
+ const struct GNUNET_PeerIdentity *peer);
+
/**
* Stop getting the prefered address for a peer from solver
*
* @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
* @param peer the peer
*/
typedef void
(*GAS_solver_stop_get_preferred_address) (void *solver,
- const struct GNUNET_PeerIdentity *peer);
+ const struct GNUNET_PeerIdentity *peer);
+
/**
- * Solver functions
+ * Solver functions.
*
- * Each solver is required to set up this struct contained in the plugin
- * environment struct in during startup
+ * Each solver is required to set up and return an instance
+ * of this struct during initialization.
*/
struct GNUNET_ATS_SolverFunctions
{
+ /**
+ * Closure to pass to all solver functions in this struct.
+ */
+ void *cls;
+
/**
* Add a new address for a peer to the solver
*
GAS_solver_bulk_stop s_bulk_stop;
};
+
/**
* Operation codes for solver information callback
*
* Order of calls is expected to be:
- * GAS_OP_SOLVE_START
- *
- * GAS_OP_SOLVE_STOP
- * GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
- * GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
+ * #GAS_OP_SOLVE_START
+ * #GAS_OP_SOLVE_STOP
+ * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
+ * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
*
*/
enum GAS_Solver_Operation
GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
};
+
/**
* Status of a GAS_Solver_Operation operation
*/
GAS_STAT_FAIL
};
+
/**
* Status of the operation
*/
GAS_INFO_PROP_ALL
};
+
/**
* Callback to call with additional information
* Used for measurement
*
* @param cls the closure
* @param op the operation
- * @param peer the peer id
- * @param kind the preference kind to change
- * @param score the new preference score
- * @param pref_rel the normalized preference value for this kind over all clients
*/
typedef void
-(*GAS_solver_information_callback) (void *cls, enum GAS_Solver_Operation op,
- enum GAS_Solver_Status stat, enum GAS_Solver_Additional_Information);
+(*GAS_solver_information_callback) (void *cls,
+ enum GAS_Solver_Operation op,
+ enum GAS_Solver_Status stat,
+ enum GAS_Solver_Additional_Information);
+
/**
* Callback to call from solver when bandwidth for address has changed
* @param address the with changed bandwidth assigned
*/
typedef void
-(*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address);
+(*GAS_bandwidth_changed_cb) (void *cls,
+ struct ATS_Address *address);
+
/**
* Callback to call from solver to obtain application preference values for a
* GNUNET_ATS_PreferenceCount elements
*/
typedef const double *
-(*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id);
+(*GAS_get_preferences) (void *cls,
+ const struct GNUNET_PeerIdentity *id);
+
/**
* Callback to call from solver to obtain transport properties for an
* GNUNET_ATS_PreferenceCount elements
*/
typedef const double *
-(*GAS_get_properties) (void *cls, const struct ATS_Address *address);
+(*GAS_get_properties) (void *cls,
+ const struct ATS_Address *address);
+
/**
- * The ATS service will pass a pointer to a struct
- * of this type as the first and only argument to the
- * entry point of each ATS solver.
+ * The ATS plugin will pass a pointer to a struct
+ * of this type as to the initialization function
+ * of the ATS plugins.
*/
struct GNUNET_ATS_PluginEnvironment
{
/**
* Statistics handle to be used by the solver
*/
- const struct GNUNET_STATISTICS_Handle *stats;
+ struct GNUNET_STATISTICS_Handle *stats;
+
+ /**
+ * Closure to pass to all callbacks in this struct.
+ */
+ void *cls;
/**
* Hashmap containing all addresses available
*/
GAS_bandwidth_changed_cb bandwidth_changed_cb;
- /**
- * ATS addresses closure to be notified about bandwidth assignment changes
- */
- void *bw_changed_cb_cls;
-
/**
* ATS addresses function to obtain preference values
*/
GAS_get_preferences get_preferences;
- /**
- * ATS addresses function closure to obtain preference values
- */
- void *get_preference_cls;
-
/**
* ATS addresses function to obtain property values
*/
GAS_get_properties get_property;
- /**
- * ATS addresses function closure to obtain property values
- */
- void *get_property_cls;
-
/**
* Callback for solver to call with status information,
* can be NULL
*/
GAS_solver_information_callback info_cb;
- /**
- * Closure for information callback,
- * can be NULL
- */
- void *info_cb_cls;
-
- /**
- * The ATS solver plugin functions to call
- */
- struct GNUNET_ATS_SolverFunctions sf;
-
/**
* Available networks
*/