aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ats/Makefile.am12
-rw-r--r--src/ats/gnunet-service-ats-solver_proportional.c21
-rw-r--r--src/ats/gnunet-service-ats_addresses.c10
-rw-r--r--src/ats/gnunet-service-ats_normalization.c48
-rw-r--r--src/ats/gnunet-service-ats_normalization.h8
5 files changed, 65 insertions, 34 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index d592367eee..4b48238889 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -71,10 +71,10 @@ check_PROGRAMS = \
test_ats_api_scheduling_destroy_session \
test_ats_api_scheduling_destroy_inbound_connection \
test_ats_api_scheduling_block_and_reset \
+ test_ats_change_preference \
test_ats_simplistic \
test_ats_simplistic_switch_networks \
test_ats_simplistic_change_preference \
- test_ats_simplistic_pref_aging \
test_ats_api_performance_list_addresses \
test_ats_api_performance_address_info \
$(GN_MLP_TEST) $(GN_MLP_PERF) $(GN_MLP_TEST_UPDATE)
@@ -198,13 +198,13 @@ test_ats_simplistic_change_preference_LDADD = \
$(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/ats/libgnunetats.la
-test_ats_simplistic_pref_aging_SOURCES = \
- test_ats_simplistic_pref_aging.c test_ats_api_common.c
-test_ats_simplistic_pref_aging_LDADD = \
+test_ats_change_preference_SOURCES = \
+ test_ats_change_preference.c test_ats_api_common.c
+test_ats_change_preference_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/ats/libgnunetats.la
-
+ $(top_builddir)/src/ats/libgnunetats.la
+
if HAVE_LIBGLPK
test_ats_mlp_SOURCES = \
$(GN_MLP_SRC) test_ats_mlp.c test_ats_api_common.c
diff --git a/src/ats/gnunet-service-ats-solver_proportional.c b/src/ats/gnunet-service-ats-solver_proportional.c
index 0da9fdc33f..1590493c4a 100644
--- a/src/ats/gnunet-service-ats-solver_proportional.c
+++ b/src/ats/gnunet-service-ats-solver_proportional.c
@@ -434,12 +434,20 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
{
t = GAS_normalization_get_preferences (&cur->addr->peer);
if (NULL == t)
+ {
total_prefs += DEFAULT_REL_PREFERENCE;
+ }
else
{
peer_prefs = 0.0;
- for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
- peer_prefs += t[c];
+ for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+ {
+ if (c != GNUNET_ATS_PREFERENCE_END)
+ {
+ //fprintf (stderr, "VALUE[%u] %s %.3f \n", c, GNUNET_i2s (&cur->addr->peer), t[c]);
+ peer_prefs += t[c];
+ }
+ }
total_prefs += (peer_prefs / (GNUNET_ATS_PreferenceCount -1));
}
}
@@ -452,12 +460,17 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
t = GAS_normalization_get_preferences (&cur->addr->peer);
if (NULL != t)
{
- for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
- cur_pref += t[c];
+ for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+ {
+ if (c != GNUNET_ATS_PREFERENCE_END)
+ cur_pref += t[c];
+ }
cur_pref /= 2;
}
else
+ {
cur_pref = DEFAULT_REL_PREFERENCE;
+ }
assigned_quota_in = min_bw + ((cur_pref / total_prefs) * remaining_quota_in);
assigned_quota_out = min_bw + ((cur_pref / total_prefs) * remaining_quota_out);
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 7858fc661b..1e930c466e 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -1295,6 +1295,14 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
NULL));
}
+static void
+normalized_preference_changed_cb (const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double pref_rel)
+{
+ GNUNET_break (0);
+}
+
/**
* Change the preference for a peer
@@ -1597,7 +1605,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_assert (NULL != ah->s_del);
GNUNET_assert (NULL != ah->s_done);
- GAS_normalization_start();
+ GAS_normalization_start (&normalized_preference_changed_cb);
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);
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index 2d5c075201..ccc67f5f69 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -129,7 +129,7 @@ struct PeerRelative
struct GNUNET_PeerIdentity id;
};
-
+GAS_Normalization_preference_changed_cb pref_changed_cb;
struct GNUNET_CONTAINER_MultiHashMap *peers;
struct PreferenceClient *pc_head;
struct PreferenceClient *pc_tail;
@@ -144,6 +144,7 @@ update_peers (struct GNUNET_PeerIdentity *id,
struct PreferencePeer *p_cur;
struct PeerRelative *rp;
double f_rel_total;
+ double backup;
unsigned int count;
f_rel_total = 0.0;
@@ -166,33 +167,35 @@ update_peers (struct GNUNET_PeerIdentity *id,
}
}
- if (0 < count)
+ /* Find a client */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u clients have a total relative preference for peer `%s''s `%s' of %.3f\n",
+ count,
+ GNUNET_i2s (id),
+ GNUNET_ATS_print_preference_type (kind),
+ f_rel_total);
+ if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey)))
{
- /* Find a client */
- f_rel_total /= count;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u clients have a total relative preference for peer `%s''s%s is %.3f\n",
- count,
- GNUNET_i2s (id),
- GNUNET_ATS_print_preference_type (kind),
- f_rel_total);
- if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey)))
+ backup = rp->f_rel[kind];
+ if (0 < count)
{
- rp->f_rel[kind] = f_rel_total;
+ rp->f_rel[kind] = f_rel_total / count;
}
- return f_rel_total;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No clients have a total relative preference for peer `%s''s%s\n",
- count,
- GNUNET_i2s (id),
- GNUNET_ATS_print_preference_type (kind));
- if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey)))
+ else
{
rp->f_rel[kind] = DEFAULT_REL_PREFERENCE;
}
+ }
+ else
+ {
return DEFAULT_REL_PREFERENCE;
}
+
+ if ((backup != rp->f_rel[kind]) && (NULL != pref_changed_cb))
+ {
+ pref_changed_cb (&rp->id, kind, rp->f_rel[kind]);
+ }
+
+ return rp->f_rel[kind];
}
/**
@@ -426,12 +429,13 @@ GAS_normalization_get_preferences (struct GNUNET_PeerIdentity *id)
return rp->f_rel;
}
+
void
-GAS_normalization_start ()
+GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb)
{
int i;
peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
-
+ pref_changed_cb = pref_ch_cb;
for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE;
return;
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h
index 6e6e4e00b1..ab37da7969 100644
--- a/src/ats/gnunet-service-ats_normalization.h
+++ b/src/ats/gnunet-service-ats_normalization.h
@@ -33,6 +33,12 @@
#define DEFAULT_REL_PREFERENCE 1.0
#define DEFAULT_ABS_PREFERENCE 0.0
+
+typedef void
+(*GAS_Normalization_preference_changed_cb) (const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double pref_rel);
+
/**
* Get the normalized preference values for a specific peer
*
@@ -58,7 +64,7 @@ GAS_normalization_change_preference (void *src,
float score_abs);
void
-GAS_normalization_start ();
+GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb);
void
GAS_normalization_stop ();