struct GNUNET_PeerIdentity id;
};
+ /**
+ * Pending Address suggestion requests
+ */
+ struct GAS_Addresses_Preference_Clients
+ {
+ /**
+ * Next in DLL
+ */
+ struct GAS_Addresses_Preference_Clients *next;
+
+ /**
+ * Previous in DLL
+ */
+ struct GAS_Addresses_Preference_Clients *prev;
+
+ /**
+ * Peer ID
+ */
+ void *client;
+ };
+
/**
* Handle for ATS address component
*/
*/
int running;
+ /**
+ * Preferences clients
+ */
+ int pref_clients;
+
/**
* Configured ATS solver
*/
*/
struct GAS_Addresses_Suggestion_Requests *pending_requests_tail;
+ /**
+ * Address suggestion requests DLL head
+ */
+ struct GAS_Addresses_Preference_Clients *preference_clients_head;
+
+ /**
+ * Address suggestion requests DLL head
+ */
+ struct GAS_Addresses_Preference_Clients *preference_clients_tail;
+
/**
* Solver functions
*/
const double *
get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
{
- return GAS_normalization_get_preferences (id);
+ return GAS_normalization_get_preferences_by_peer (id);
}
/**
return GNUNET_YES;
}
+
/**
* Summary context
*/
struct GAS_Addresses_Handle *ah;
};
-
static int
-eval_preference_relativity (void *cls, const struct GNUNET_PeerIdentity *id, void *obj)
+find_active_address (void *cls, const struct GNUNET_PeerIdentity *id, void *obj)
{
- struct RelativityContext *rc = cls;
+ struct ATS_Address **res = cls;
struct ATS_Address *addr = obj;
- int prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceType ;
- int c;
- const double *preferences;
if (GNUNET_YES == addr->active)
- {
- preferences = get_preferences_cb (rc->ah->env.get_preference_cls, id);
- for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
- {
- if (prefs[c] == GNUNET_ATS_PREFERENCE_END)
- continue;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preference for peer `%s' type %s: %f\n",
- GNUNET_i2s (id), GNUNET_ATS_print_preference_type(prefs[c]),
- preferences[c]);
- }
- }
+ (*res) = addr;
- return GNUNET_OK;
+ if (NULL != (*res))
+ return GNUNET_NO;
+ else
+ return GNUNET_YES;
}
-
/**
* Evaluate current bandwidth assignment
*
GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah)
{
struct GAS_Addresses_Suggestion_Requests *cur;
+ struct GAS_Addresses_Preference_Clients *pcur;
int c;
float quality_requests_fulfilled = 0.0;
/* Variable related to utilization */
struct SummaryContext sum;
+ struct ATS_Address *active_address;
int network_count;
+ /* Variables for preferences */
+ int prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceType;
+ double pref_val;
+ double prop_val;
+ const double *norm_values;
+ double prefs_fulfill[GNUNET_ATS_PreferenceCount];
+ int prefs_clients[GNUNET_ATS_PreferenceCount];
+ int rels;
+
GNUNET_assert (NULL != ah);
GNUNET_assert (NULL != ah->addresses);
if (GNUNET_YES == request_active)
requests_fulfilled ++;
requests_pending ++;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer `%s': pending requests, %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': %u pending requests, %s\n",
GNUNET_i2s (&cur->id),
+ requests_pending,
(GNUNET_YES == request_active) ? "active adress" : "no active address");
}
quality_requests_fulfilled = 0.0;
include_requests = GNUNET_NO;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u pending requests, %u requests fullfilled\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u pending requests, %u requests fullfilled\n",
requests_pending, requests_fulfilled);
/* 2) How well is bandwidth utilized? */
quality_bandwidth_utilization[c] = (((float)sum.bandwidth_out_assigned[c] / ah->env.out_quota[c]) +
((float)sum.bandwidth_in_assigned[c] / ah->env.in_quota[c])) / 2;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Utilization for network `%s': %f\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Utilization for network `%s': %f\n",
GNUNET_ATS_print_network_type(ah->env.networks[c]),
quality_bandwidth_utilization[c]);
if (sum.addresses_in_network[c] > 0)
}
/* 3) How well does selection match application requirements */
- for (cur = ah->pending_requests_head; NULL != cur; cur = cur->next)
+ include_requirements = GNUNET_NO;
+ if (0 == ah->pref_clients)
{
- GNUNET_CONTAINER_multipeermap_get_multiple (ah->addresses,
- &cur->id, &eval_preference_relativity, ah);
include_requirements = GNUNET_NO;
}
+ else
+ {
+ for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+ {
+ prefs_fulfill[c] = 0.0;
+ prefs_clients[c] = 0;
+ }
+
+ for (cur = ah->pending_requests_head; NULL != cur; cur = cur->next)
+ {
+ active_address = NULL;
+ GNUNET_CONTAINER_multipeermap_get_multiple (ah->addresses,
+ &cur->id, &find_active_address, &active_address);
+
+ for (pcur = ah->preference_clients_head; NULL != pcur; pcur = pcur->next)
+ {
+ for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+ {
+ if (prefs[c] == GNUNET_ATS_PREFERENCE_END)
+ continue;
+ pref_val = -1.0;
+ pref_val = GAS_normalization_get_preferences_by_client (pcur->client, &cur->id, prefs[c]);
+ if (-1.0 == pref_val)
+ {
+ GNUNET_break (0);
+ continue;
+ }
+
+ if (DEFAULT_REL_PREFERENCE == pref_val)
+ {
+ /* Default preference value */
+ continue;
+ }
+
+ if (NULL != active_address)
+ {
+ norm_values = GAS_normalization_get_properties (active_address);
+ prop_val = norm_values[c];
+ if ((norm_values[c] <= 1.0) || (norm_values[c] >= 2.0))
+ prop_val = DEFAULT_REL_QUALITY;
+ }
+ else
+ {
+ prop_val = DEFAULT_REL_QUALITY;
+ }
+
+ /* We now have preference values [1..2] and properties [1..2] */
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u Client %p, Peer %s Property %s: pref: %.3f prop %.3f \n",
+ c,
+ pcur->client,
+ GNUNET_i2s (&cur->id),
+ GNUNET_ATS_print_preference_type(prefs[c]),
+ pref_val,
+ prop_val);
+
+ prefs_fulfill[c] += (pref_val * prop_val) / 2;
+ prefs_clients[c] ++;
+ }
+ }
+ }
+ rels = 0;
+ for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+ {
+ if (0 < prefs_clients[c])
+ {
+ prefs_fulfill[c] /= prefs_clients[c];
+ rels ++;
+ quality_application_requirements += prefs_fulfill[c];
+ }
+ }
+ if (rels > 0)
+ quality_application_requirements /= rels;
+ else
+ quality_application_requirements = 0.0;
+
+ include_requirements = GNUNET_YES;
+ }
/* GUQ */
if (include_requests + include_utilization + include_requirements > 0)
else
guq = 0.0;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requests fulfilled %.3f bandwidth utilized %.3f application preferences met %.3f => %.3f\n",
quality_requests_fulfilled,
quality_bandwidth_utilization_total,
ah->env.sf.s_address_update_property (ah->solver, address, type, 0, prop_rel);
}
+static struct GAS_Addresses_Preference_Clients *
+find_preference_client (struct GAS_Addresses_Handle *handle, void *client)
+{
+ struct GAS_Addresses_Preference_Clients *cur;
+
+ for (cur = handle->preference_clients_head; NULL != cur; cur = cur->next)
+ {
+ if (cur->client == client)
+ return cur;
+ }
+ return NULL;
+}
+
+/**
+ * A performance client disconnected
+ *
+ * @param handle address handle
+ * @param client the client
+ */
+void
+GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle,
+ void *client)
+{
+ struct GAS_Addresses_Preference_Clients * pc;
+ if (NULL != (pc = find_preference_client (handle, client)))
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head,
+ handle->preference_clients_tail, pc);
+ GNUNET_free (pc);
+ GNUNET_assert (handle->pref_clients > 0);
+ handle->pref_clients --;
+ GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO);
+ }
+ GAS_normalization_preference_client_disconnect (client);
+}
/**
* Change the preference for a peer
* @param score_abs the new preference score
*/
void
-GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
+GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
void *client, const struct GNUNET_PeerIdentity *peer,
enum GNUNET_ATS_PreferenceKind kind, float score_abs)
{
+ struct GAS_Addresses_Preference_Clients * pc;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' for peer `%s' for client %p\n", "CHANGE PREFERENCE",
GNUNET_i2s (peer), client);
return;
}
+ if (NULL == find_preference_client (handle, client))
+ {
+ pc = GNUNET_malloc (sizeof (struct GAS_Addresses_Preference_Clients));
+ pc->client = client;
+ GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head,
+ handle->preference_clients_tail, pc);
+ handle->pref_clients ++;
+ GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO);
+ }
+
handle->env.sf.s_bulk_start (handle->solver);
/* Tell normalization about change, normalization will call callback if preference changed */
GAS_normalization_normalize_preference (client, peer, kind, score_abs);
ah->stat = (struct GNUNET_STATISTICS_Handle *) stats;
/* Initialize the addresses database */
ah->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
+ ah->pref_clients = 0;
GNUNET_assert(NULL != ah->addresses);
/* Figure out configured solution method */
GNUNET_free(mode_str);
}
- load_quotas (cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount);
+ load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount);
ah->env.info_cb = &solver_info_cb;
ah->env.info_cb_cls = ah;
ah->env.bandwidth_changed_cb = &bandwidth_changed_cb;
GAS_addresses_done (struct GAS_Addresses_Handle *handle)
{
struct GAS_Addresses_Suggestion_Requests *cur;
+ struct GAS_Addresses_Preference_Clients *pcur;
GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Shutting down addresses\n");
GNUNET_assert(NULL != handle);
GNUNET_free(cur);
}
+ while (NULL != (pcur = handle->preference_clients_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head,
+ handle->preference_clients_tail, pcur);
+ GNUNET_assert (handle->pref_clients > 0);
+ handle->pref_clients --;
+ GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO);
+ GNUNET_free (pcur);
+ }
+
GNUNET_PLUGIN_unload (handle->plugin, handle->solver);
GNUNET_free (handle->plugin);
GNUNET_free(handle);