* @return GNUNET_OK (continue to iterate)
*/
static int
-update_bw_it (void *cls, const GNUNET_HashCode * key, void *value)
+update_bw_simple_it (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ATS_Address *aa = value;
-
- /* Simple method */
if (GNUNET_YES != aa->active)
return GNUNET_OK;
GNUNET_assert (active_addr_count > 0);
+
+
+ /* Simple method */
aa->assigned_bw_in.value__ = htonl (wan_quota_in / active_addr_count);
aa->assigned_bw_out.value__ = htonl (wan_quota_out / active_addr_count);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
ntohl (aa->assigned_bw_out.value__));
1, GNUNET_NO);
GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count,
GNUNET_NO);
- GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL);
+
+ GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, NULL);
}
/**
struct ATS_Address *aa;
aa = NULL;
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
- &find_address_it, &aa);
- if (aa == NULL)
+
+ if (ats_mode == SIMPLE)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
- return;
+ /* Get address with: stick to current address, lower distance, lower latency */
+ GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ &find_address_it, &aa);
+ if (aa == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
+ return;
+ }
}
+ if (ats_mode == MLP)
+ {
+ /* Get preferred address from MLP */
+ }
+
if (aa->active == GNUNET_NO)
{
aa->active = GNUNET_YES;
mlpi = a->mlp_information;
b = glp_mip_col_val(mlp->prob, mlpi->c_b);
- n = glp_mip_col_val(mlp->prob, mlpi->c_n);
+ mlpi->b = b;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %f %f\n", n, b);
+ n = glp_mip_col_val(mlp->prob, mlpi->c_n);
+ if (n == 1.0)
+ mlpi->n = GNUNET_YES;
+ else
+ mlpi->n = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %s %f\n",
+ (n == 1.0) ? "[x]" : "[ ]", b);
}
}
-
-
-
if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel(mlp->mlp_task);
}
}
+static int
+mlp_get_preferred_address_it (void *cls, const GNUNET_HashCode * key, void *value)
+{
+
+ struct ATS_Address **aa = (struct ATS_Address **)cls;
+ struct ATS_Address *addr = value;
+ struct MLP_information *mlpi = addr->mlp_information;
+ if (mlpi->n == GNUNET_YES)
+ {
+ *aa = addr;
+ return GNUNET_NO;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Get the preferred address for a specific peer
+ *
+ * @param mlp the MLP Handle
+ * @param peer the peer
+ * @return suggested address
+ */
+struct ATS_Address *
+GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp,
+ struct GNUNET_CONTAINER_MultiHashMap * addresses,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ struct ATS_Address * aa = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n", GNUNET_i2s (peer));
+ GNUNET_CONTAINER_multihashmap_get_multiple(addresses, &peer->hashPubKey, mlp_get_preferred_address_it, &aa);
+ return aa;
+}
+
+
/**
* Changes the preferences for a peer in the MLP problem
*
*/
struct MLP_information
{
+ double b;
+
+ int n;
+
/* bandwidth column index */
signed int c_b;
float score);
+/**
+ * Get the preferred address for a specific peer
+ *
+ * @param mlp the MLP Handle
+ * @param peer the peer
+ * @return suggested address
+ */
+struct ATS_Address *
+GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp,
+ struct GNUNET_CONTAINER_MultiHashMap * addresses,
+ const struct GNUNET_PeerIdentity *peer);
+
/**
* Shutdown the MLP problem solving component
*/
struct GAS_MLP_Handle *mlp;
+
static void
create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats)
{
return;
#endif
struct ATS_Address addr[10];
+ struct ATS_Address *res[10];
stats = GNUNET_STATISTICS_create("ats", cfg);
GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp));
+ res[0] = GAS_mlp_get_preferred_address(mlp, addresses, &p[0]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' \n",res[0]->plugin);
+ res[1] = GAS_mlp_get_preferred_address(mlp, addresses, &p[1]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' \n",res[1]->plugin);
+
/* Delete an address */
GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]);
GAS_mlp_address_delete (mlp, addresses, &addr[0]);