diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/Makefile.am | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.c | 21 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.h | 4 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 19 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 8 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 15 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 8 |
7 files changed, 59 insertions, 18 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 964af06dbc..4b48238889 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -17,7 +17,7 @@ endif if HAVE_LIBGLPK GN_LIBGLPK = -lglpk - GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h + GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h GN_MLP_TEST = test_ats_mlp GN_MLP_TEST_UPDATE = test_ats_mlp_update GN_MLP_TEST_AVG = test_ats_mlp_averaging diff --git a/src/ats/gnunet-service-ats-solver_proportional.c b/src/ats/gnunet-service-ats-solver_proportional.c index 1bcd42e041..30a3b060d0 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.c +++ b/src/ats/gnunet-service-ats-solver_proportional.c @@ -27,7 +27,6 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet-service-ats_addresses.h" -#include "gnunet-service-ats_normalization.h" #include "gnunet_statistics_service.h" #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) @@ -255,6 +254,16 @@ struct GAS_PROPORTIONAL_Handle */ 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; + struct GNUNET_CONTAINER_MultiHashMap *prefs; struct PreferenceClient *pc_head; @@ -432,7 +441,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, { if (GNUNET_YES == cur->addr->active) { - GNUNET_assert (NULL != (t = GAS_normalization_get_preferences (&cur->addr->peer))); + GNUNET_assert (NULL != (t = s->get_preferences (s->get_preferences_cls, &cur->addr->peer))); peer_prefs = 0.0; for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) @@ -451,7 +460,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, if (GNUNET_YES == cur->addr->active) { cur_pref = 0.0; - GNUNET_assert (NULL != (t = GAS_normalization_get_preferences (&cur->addr->peer))); + GNUNET_assert (NULL != (t = s->get_preferences (s->get_preferences_cls, &cur->addr->peer))); for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) { @@ -1226,7 +1235,9 @@ GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *in_quota, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, - void *bw_changed_cb_cls) + void *bw_changed_cb_cls, + GAS_get_preferences get_preference, + void *get_preference_cls) { int c; struct GAS_PROPORTIONAL_Handle *s = GNUNET_malloc (sizeof (struct GAS_PROPORTIONAL_Handle)); @@ -1237,6 +1248,8 @@ GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, s->stats = (struct GNUNET_STATISTICS_Handle *) stats; s->bw_changed = bw_changed_cb; s->bw_changed_cls = bw_changed_cb_cls; + s->get_preferences = get_preference; + s->get_preferences_cls = get_preference_cls; s->networks = dest_length; s->network_entries = GNUNET_malloc (dest_length * sizeof (struct Network)); s->active_addresses = 0; diff --git a/src/ats/gnunet-service-ats-solver_proportional.h b/src/ats/gnunet-service-ats-solver_proportional.h index 0417c526ba..960580b3dc 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.h +++ b/src/ats/gnunet-service-ats-solver_proportional.h @@ -83,7 +83,9 @@ GAS_proportional_init (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *in_quota, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, - void *bw_changed_cb_cls); + void *bw_changed_cb_cls, + GAS_get_preferences get_preference, + void *get_preference_cls); /** diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 6da979d739..baf49dfccd 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -739,6 +739,8 @@ get_performance_info (struct ATS_Address *address, uint32_t type) } + + /** * Add a new address for a peer. * @@ -1297,9 +1299,9 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, static void normalized_preference_changed_cb (void *cls, - 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) { GNUNET_assert (NULL != cls); struct GAS_Addresses_Handle *handle = cls; @@ -1307,6 +1309,12 @@ normalized_preference_changed_cb (void *cls, handle->s_pref (handle->solver, handle->addresses, peer, kind, pref_rel); } +const double * +get_preferences_cb (void *cls, struct GNUNET_PeerIdentity *id) +{ + return GAS_normalization_get_preferences (id); +} + /** * Change the preference for a peer @@ -1610,7 +1618,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, GAS_normalization_start (&normalized_preference_changed_cb, ah); 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, ah); + ah->solver = ah->s_init (cfg, stats, + quotas, quotas_in, quotas_out, quota_count, + &bandwidth_changed_cb, ah, + &get_preferences_cb, NULL); if (NULL == ah->solver) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize solver!\n"); diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 5e713883b7..e62f733155 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -354,6 +354,10 @@ struct ATS_Address typedef void (*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address); +typedef const double * + (*GAS_get_preferences) (void *cls, struct GNUNET_PeerIdentity *id); + + /* * Solver API * ---------- @@ -389,7 +393,9 @@ typedef void * unsigned long long *in_quota, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, - void *bw_changed_cb_cls); + void *bw_changed_cb_cls, + GAS_get_preferences get_preference, + void *get_preference_cls); /** diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 1becd76bde..38c7c00193 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -27,7 +27,6 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet-service-ats_addresses.h" -#include "gnunet-service-ats_normalization.h" #include "gnunet-service-ats_addresses_mlp.h" #include "gnunet_statistics_service.h" #include "glpk.h" @@ -1438,12 +1437,12 @@ mlp_get_preferred_address_it (void *cls, const struct GNUNET_HashCode * key, voi } -static double get_peer_pref_value (const struct GNUNET_PeerIdentity *peer) +static double get_peer_pref_value (struct GAS_MLP_Handle *mlp, struct GNUNET_PeerIdentity *peer) { double res; const double *preferences = NULL; int c; - preferences = GAS_normalization_get_preferences ((struct GNUNET_PeerIdentity *) peer); + preferences = mlp->get_preferences (mlp->get_preferences_cls, peer); res = 0.0; for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) @@ -1491,7 +1490,7 @@ GAS_mlp_get_preferred_address (void *solver, p = GNUNET_malloc (sizeof (struct ATS_Peer)); p->id = (*peer); - p->f = get_peer_pref_value (peer);; + p->f = get_peer_pref_value (mlp, peer); GNUNET_CONTAINER_multihashmap_put (mlp->peers, &peer->hashPubKey, p, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); /* Added new peer, we have to rebuild problem before solving */ @@ -1570,7 +1569,7 @@ GAS_mlp_address_change_preference (void *solver, LOG (GNUNET_ERROR_TYPE_ERROR, "Updating preference for unknown peer `%s' \n", GNUNET_i2s(peer)); return; } - p->f = get_peer_pref_value (peer); + p->f = get_peer_pref_value (mlp, peer); mlp_create_problem_set_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__); @@ -1642,7 +1641,9 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *in_dest, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, - void *bw_changed_cb_cls) + void *bw_changed_cb_cls, + GAS_get_preferences get_preference, + void *get_preference_cls) { struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); @@ -1846,6 +1847,8 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; mlp->bw_changed_cb = bw_changed_cb; mlp->bw_changed_cb_cls = bw_changed_cb_cls; + mlp->get_preferences = get_preference; + mlp->get_preferences_cls = get_preference_cls; /* Setting MLP Input variables */ mlp->pv.co_D = D; mlp->pv.co_R = R; diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index daf5ed4e9f..e7464ca96c 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -228,6 +228,10 @@ struct GAS_MLP_Handle */ void *bw_changed_cb_cls; + GAS_get_preferences get_preferences; + + void *get_preferences_cls; + struct MLP_Problem p; struct MLP_Variables pv; @@ -359,7 +363,9 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *in_dest, int dest_length, GAS_bandwidth_changed_cb bw_changed_cb, - void *bw_changed_cb_cls); + void *bw_changed_cb_cls, + GAS_get_preferences get_preference, + void *get_preference_cls); /** |