/*
This file is part of GNUnet.
- (C) 2011-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
};
+enum QualityMetrics
+{
+ RQ_QUALITY_METRIC_DELAY = 0,
+ RQ_QUALITY_METRIC_DISTANCE = 1,
+ RQ_QUALITY_METRIC_COUNT = 2
+};
+
+
+static const char *
+print_quality_type (enum QualityMetrics qm)
+{
+ switch (qm){
+ case RQ_QUALITY_METRIC_DELAY:
+ return "delay";
+ case RQ_QUALITY_METRIC_DISTANCE:
+ return "distance";
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
+}
+
+
struct MLP_Solution
{
int lp_res;
/* Row index constraint 9: relativity*/
unsigned int r_c9;
/* Row indices quality metrics */
- int r_q[GNUNET_ATS_QualityPropertiesCount];
+ int r_q[RQ_QUALITY_METRIC_COUNT];
/* Row indices ATS network quotas */
int r_quota[GNUNET_ATS_NetworkTypeCount];
/* Column index Proportionality (R) column */
int c_r;
/* Column index quality metrics */
- int c_q[GNUNET_ATS_QualityPropertiesCount];
+ int c_q[RQ_QUALITY_METRIC_COUNT];
/* Problem matrix */
/* Current index */
/* LP MIP Gap */
double lp_mip_gap;
- /* ATS Quality metrics
- *
- * Array with GNUNET_ATS_QualityPropertiesCount elements
- * contains mapping to GNUNET_ATS_Property*/
- int q[GNUNET_ATS_QualityPropertiesCount];
-
- /* Number of quality metrics */
+ /* Number of quality metrics @deprecated, use RQ_QUALITY_METRIC_COUNT */
int m_q;
/* Number of quality metrics */
int m_rc;
/* Quality metric coefficients*/
- double co_Q[GNUNET_ATS_QualityPropertiesCount];
+ double co_Q[RQ_QUALITY_METRIC_COUNT];
/* Ressource costs coefficients*/
- double co_RC[GNUNET_ATS_QualityPropertiesCount];
+ double co_RC[RQ_QUALITY_METRIC_COUNT];
/* Diversity coefficient */
double co_D;
* array with GNUNET_ATS_QualityPropertiesCount elements
* contains mapping to GNUNET_ATS_Property
* */
- int rc[GNUNET_ATS_QualityPropertiesCount];
+ int rc[RQ_QUALITY_METRIC_COUNT];
};
{
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,
mlp->p.r_c4 = MLP_UNDEFINED;
mlp->p.r_c6 = MLP_UNDEFINED;
mlp->p.r_c9 = MLP_UNDEFINED;
- for (c = 0; c < mlp->pv.m_q ; c ++)
+ for (c = 0; c < RQ_QUALITY_METRIC_COUNT ; c ++)
mlp->p.r_q[c] = MLP_UNDEFINED;
for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++)
mlp->p.r_quota[c] = MLP_UNDEFINED;
}
-/**
- * Translate ATS properties to text
- * Just intended for debugging
- *
- * @param ats_index the ATS index
- * @return string with result
- */
-static const char *
-mlp_ats_to_string (int ats_index)
-{
- switch (ats_index) {
- case GNUNET_ATS_ARRAY_TERMINATOR:
- return "GNUNET_ATS_ARRAY_TERMINATOR";
- case GNUNET_ATS_UTILIZATION_OUT:
- return "GNUNET_ATS_UTILIZATION_OUT";
- case GNUNET_ATS_UTILIZATION_IN:
- return "GNUNET_ATS_UTILIZATION_IN";
- case GNUNET_ATS_UTILIZATION_PAYLOAD_OUT:
- return "GNUNET_ATS_UTILIZATION_PAYLOAD_OUT";
- case GNUNET_ATS_UTILIZATION_PAYLOAD_IN:
- return "GNUNET_ATS_UTILIZATION_PAYLOAD_IN";
- case GNUNET_ATS_COST_LAN:
- return "GNUNET_ATS_COST_LAN";
- case GNUNET_ATS_COST_WAN:
- return "GNUNET_ATS_COST_LAN";
- case GNUNET_ATS_COST_WLAN:
- return "GNUNET_ATS_COST_WLAN";
- case GNUNET_ATS_NETWORK_TYPE:
- return "GNUNET_ATS_NETWORK_TYPE";
- case GNUNET_ATS_QUALITY_NET_DELAY:
- return "GNUNET_ATS_QUALITY_NET_DELAY";
- case GNUNET_ATS_QUALITY_NET_DISTANCE:
- return "GNUNET_ATS_QUALITY_NET_DISTANCE";
- default:
- GNUNET_break (0);
- return "unknown";
- }
-}
-
/**
* Translate glpk status error codes to text
* @param retcode return code
}
}
-/**
- * Extract an ATS performance info from an address
- *
- * @param address the address
- * @param type the type to extract in HBO
- * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist
- */
-static uint32_t
-get_performance_info (struct ATS_Address *address, uint32_t type)
-{
- int c1;
- GNUNET_assert (NULL != address);
-
- if ((NULL == address->atsi) || (0 == address->atsi_count))
- return GNUNET_ATS_VALUE_UNDEFINED;
-
- for (c1 = 0; c1 < address->atsi_count; c1++)
- {
- if (ntohl (address->atsi[c1].type) == type)
- return ntohl (address->atsi[c1].value);
- }
- return GNUNET_ATS_VALUE_UNDEFINED;
-}
-
struct CountContext
{
double *val_array;
int *ind_array;
- GNUNET_assert (NULL != p);
GNUNET_assert (NULL != p->prob);
/* Get number of columns and prepare data structure */
struct ATS_Peer *peer;
struct MLP_information *mlpi;
char *name;
- const double *props;
double cur_bigm;
-
uint32_t addr_net;
uint32_t addr_net_index;
unsigned long long max_quota;
return GNUNET_OK;
}
- addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE);
+ addr_net = address->properties.scope;
for (addr_net_index = 0; addr_net_index < GNUNET_ATS_NetworkTypeCount; addr_net_index++)
{
if (mlp->pv.quota_index[addr_net_index] == addr_net)
/* 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);
- for (c = 0; c < mlp->pv.m_q; c++)
- {
- if ((props[c] < 1.0) && (props[c] > 2.0))
- {
- fprintf (stderr, "PROP == %.3f \t ", props[c]);
- GNUNET_break (0);
- }
- mlp_create_problem_set_value (p, p->r_q[c], mlpi->c_b, props[c], __LINE__);
- }
+ mlp_create_problem_set_value (p,
+ p->r_q[RQ_QUALITY_METRIC_DELAY],
+ mlpi->c_b,
+ address->norm_delay.norm,
+ __LINE__);
+ mlp_create_problem_set_value (p,
+ p->r_q[RQ_QUALITY_METRIC_DISTANCE],
+ mlpi->c_b,
+ address->norm_distance.norm,
+ __LINE__);
}
}
{
for (c = 0; c < mlp->pv.m_q; c++)
{
- GNUNET_asprintf(&name, "c7_q%i_%s", c, mlp_ats_to_string(mlp->pv.q[c]));
+ GNUNET_asprintf (&name,
+ "c7_q%i_%s", c,
+ print_quality_type (c));
p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0);
GNUNET_free (name);
- mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1, __LINE__);
+ mlp_create_problem_set_value (p,
+ p->r_q[c],
+ p->c_q[c], -1, __LINE__);
}
}
}
{
for (c = 0; c < mlp->pv.m_q; c++)
{
- GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]);
+ GNUNET_asprintf (&name, "q_%u", c);
p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]);
GNUNET_free (name);
}
/* create the glpk problem */
p->prob = glp_create_prob ();
GNUNET_assert (NULL != p->prob);
- p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->addresses);
- p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, mlp->addresses);
+ p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->env->addresses);
+ p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers,
+ mlp->env->addresses);
/* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */
p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses +
mlp_create_problem_add_invariant_rows (mlp, p);
/* Adding address dependent columns constraint rows */
- GNUNET_CONTAINER_multipeermap_iterate (mlp->addresses,
+ GNUNET_CONTAINER_multipeermap_iterate (mlp->env->addresses,
&mlp_create_problem_add_address_information,
mlp);
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_Status stat,
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);
}
notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
return GNUNET_OK; /* No pending requests */
}
- if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->addresses))
+ if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->env->addresses))
{
notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
return GNUNET_OK; /* No addresses available */
{
LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n");
notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL);
- mlp_delete_problem(mlp);
- if (GNUNET_SYSERR == mlp_create_problem(mlp))
+ mlp_delete_problem (mlp);
+ if (GNUNET_SYSERR == mlp_create_problem (mlp))
{
notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL);
return GNUNET_SYSERR;
GAS_INFO_NONE);
if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res))
{
- GNUNET_CONTAINER_multipeermap_iterate(mlp->addresses,
+ GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses,
&mlp_propagate_results, mlp);
}
notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
{
struct GAS_MLP_Handle *mlp = solver;
- GNUNET_assert (NULL != solver);
- GNUNET_assert (NULL != address);
-
if (GNUNET_ATS_NetworkTypeCount <= network)
{
- GNUNET_break (0);
- return;
+ GNUNET_break (0);
+ return;
}
if (NULL == address->solver_information)
*
* @param solver solver handle
* @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
*/
static void
GAS_mlp_address_property_changed (void *solver,
- struct ATS_Address *address,
- uint32_t type,
- uint32_t abs_value,
- double rel_value)
+ struct ATS_Address *address)
{
struct MLP_information *mlpi = address->solver_information;
struct GAS_MLP_Handle *mlp = solver;
- int c1;
- int type_index;
- GNUNET_assert (NULL != solver);
- GNUNET_assert (NULL != address);
+ if (NULL == mlp->p.prob)
+ return; /* There is no MLP problem to update yet */
if (NULL == mlpi)
{
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Updating address property `%s' for peer `%s' %p not added before\n"),
- GNUNET_ATS_print_property_type (type),
- GNUNET_i2s(&address->peer),
- address);
- GNUNET_break (0);
- return;
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Updating address property for peer `%s' %p not added before\n"),
+ GNUNET_i2s (&address->peer),
+ address);
+ GNUNET_break (0);
+ return;
}
-
if (NULL ==
GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
&address->peer))
/* Peer is not requested, so no need to update problem */
return;
}
- LOG (GNUNET_ERROR_TYPE_INFO, "Updating property `%s' address for peer `%s' to abs %llu rel %.3f\n",
- GNUNET_ATS_print_property_type (type),
- GNUNET_i2s(&address->peer),
- abs_value,
- rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Updating properties for peer `%s'\n",
+ GNUNET_i2s(&address->peer));
if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
return;
- /* Find row index */
- type_index = -1;
- for (c1 = 0; c1 < mlp->pv.m_q; c1++)
- {
- if (type == mlp->pv.q[c1])
- {
- type_index = c1;
- break;
- }
- }
- if (-1 == type_index)
- {
- GNUNET_break (0);
- return; /* quality index not found */
- }
-
/* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */
- if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p,
- mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__))
+ if ( (GNUNET_YES ==
+ mlp_create_problem_update_value (&mlp->p,
+ mlp->p.r_q[RQ_QUALITY_METRIC_DELAY],
+ mlpi->c_b,
+ address->norm_delay.norm,
+ __LINE__)) ||
+ (GNUNET_YES ==
+ mlp_create_problem_update_value (&mlp->p,
+ mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE],
+ mlpi->c_b,
+ address->norm_distance.norm,
+ __LINE__)) )
{
mlp->stat_mlp_prob_updated = GNUNET_YES;
if (GNUNET_YES == mlp->opt_mlp_auto_solve)
}
-/**
- * Transport session for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param cur_session the current session
- * @param new_session the new session
- */
-static void
-GAS_mlp_address_session_changed (void *solver,
- struct ATS_Address *address,
- uint32_t cur_session,
- uint32_t new_session)
-{
- /* Nothing to do here */
- return;
-}
-
-
-/**
- * Network scope for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param current_network the current network
- * @param new_network the new network
- */
-static void
-GAS_mlp_address_change_network (void *solver,
- struct ATS_Address *address,
- uint32_t current_network,
- uint32_t new_network)
-{
- struct MLP_information *mlpi = address->solver_information;
- struct GAS_MLP_Handle *mlp = solver;
- int nets_avail[] = GNUNET_ATS_NetworkType;
- int c1;
-
- GNUNET_assert (NULL != solver);
- GNUNET_assert (NULL != address);
-
- if (GNUNET_ATS_NetworkTypeCount <= new_network)
- {
- GNUNET_break (0);
- return;
- }
-
- if (NULL == mlpi)
- {
- GNUNET_break (0);
- return;
- }
-
- if (mlpi->c_b == MLP_UNDEFINED)
- return; /* This address is not yet in the matrix*/
-
- if (NULL ==
- GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
- &address->peer))
- {
- /* Peer is not requested, so no need to update problem */
- GNUNET_break (0);
- return;
- }
-
- if (current_network == new_network)
- {
- GNUNET_break (0);
- return;
- }
-
- for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount ; c1 ++)
- {
- if (nets_avail[c1] == new_network)
- break;
- }
-
- if (GNUNET_ATS_NetworkTypeCount == c1)
- {
- /* Invalid network */
- GNUNET_break (0);
- return;
- }
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating network for peer `%s' from `%s' to `%s'\n",
- GNUNET_i2s (&address->peer),
- GNUNET_ATS_print_network_type(current_network),
- GNUNET_ATS_print_network_type(new_network));
-
- for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount; c1++)
- {
- if (mlp->pv.quota_index[c1] == current_network)
- {
- /* Remove from old network */
- mlp_create_problem_update_value (&mlp->p,
- mlp->p.r_quota[c1],
- mlpi->c_b, 0.0, __LINE__);
- break;
- }
- }
-
- for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount; c1++)
- {
- if (mlp->pv.quota_index[c1] == new_network)
- {
- /* Remove from old network */
- if (GNUNET_SYSERR == mlp_create_problem_update_value (&mlp->p,
- mlp->p.r_quota[c1],
- mlpi->c_b, 1.0, __LINE__))
- {
- /* This quota did not exist in the problem, recreate */
- GNUNET_break (0);
- }
- break;
- }
- }
-
- mlp->stat_mlp_prob_changed = GNUNET_YES;
-}
-
-
/**
* Find the active address in the set of addresses of a peer
* @param cls destination
const struct GNUNET_PeerIdentity *peer)
{
double res;
- const double *preferences = NULL;
+ const double *preferences;
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++)
+ for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
{
- if (c != GNUNET_ATS_PREFERENCE_END)
- {
- /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
- * c, GNUNET_i2s (&cur->addr->peer), t[c]); */
- res += preferences[c];
- }
+ /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
+ * c, GNUNET_i2s (&cur->addr->peer), t[c]); */
+ res += preferences[c];
}
- res /= (GNUNET_ATS_PreferenceCount -1);
+ res /= GNUNET_ATS_PREFERENCE_END;
res += 1.0;
LOG (GNUNET_ERROR_TYPE_DEBUG,
*
* @param solver the MLP Handle
* @param peer the peer
- * @return suggested address
*/
-static const struct ATS_Address *
+static void
GAS_mlp_get_preferred_address (void *solver,
const struct GNUNET_PeerIdentity *peer)
{
struct ATS_Peer *p;
struct ATS_Address *res;
- GNUNET_assert (NULL != solver);
- GNUNET_assert (NULL != peer);
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n",
- GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting preferred address for `%s'\n",
+ GNUNET_i2s (peer));
/* Is this peer included in the problem? */
if (NULL ==
mlp->stat_mlp_prob_changed = GNUNET_YES;
if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&&
- (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->addresses,
+ (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses,
peer)))
{
mlp->exclude_peer = peer;
}
/* Get prefered address */
res = NULL;
- GNUNET_CONTAINER_multipeermap_get_multiple (mlp->addresses, peer,
+ GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, peer,
&mlp_get_preferred_address_it, &res);
- return res;
+ if (NULL != res)
+ mlp->env->bandwidth_changed_cb (mlp->env->cls,
+ res);
}
*
* @param solver the MLP Handle
* @param address the address to delete
- * @param session_only delete only session not whole address
*/
static void
GAS_mlp_address_delete (void *solver,
- struct ATS_Address *address,
- int session_only)
+ struct ATS_Address *address)
{
struct GAS_MLP_Handle *mlp = solver;
struct MLP_information *mlpi;
+ struct ATS_Address *res;
int was_active;
- GNUNET_assert (NULL != solver);
- GNUNET_assert (NULL != address);
-
mlpi = address->solver_information;
- if ((GNUNET_NO == session_only) && (NULL != mlpi))
+ if (NULL != mlpi)
{
/* Remove full address */
GNUNET_free (mlpi);
&address->peer))
{
LOG (GNUNET_ERROR_TYPE_INFO,
- "Deleting %s for peer `%s' without address request \n",
- (session_only == GNUNET_YES) ? "session" : "address",
+ "Deleting address for peer `%s' without address request \n",
GNUNET_i2s(&address->peer));
return;
}
- LOG (GNUNET_ERROR_TYPE_INFO, "Deleting %s for peer `%s' with address request \n",
- (session_only == GNUNET_YES) ? "session" : "address",
- GNUNET_i2s(&address->peer));
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Deleting address for peer `%s' with address request \n",
+ GNUNET_i2s (&address->peer));
/* Problem size changed: new address for peer with pending request */
mlp->stat_mlp_prob_changed = GNUNET_YES;
}
if (GNUNET_YES == was_active)
{
- if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer))
+ GAS_mlp_get_preferred_address (solver, &address->peer);
+ res = NULL;
+ GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses,
+ &address->peer,
+ &mlp_get_preferred_address_it,
+ &res);
+ if (NULL == res)
{
/* No alternative address, disconnecting peer */
- mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+ mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
}
}
-
- return;
}
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);
-
float f_tmp;
unsigned long long tmp;
unsigned int b_min;
unsigned int n_min;
int c;
- int c2;
- int found;
char *outputformat;
struct GNUNET_TIME_Relative max_duration;
long long unsigned int max_iterations;
- GNUNET_assert (NULL != env->cfg);
- GNUNET_assert (NULL != env->addresses);
- GNUNET_assert (NULL != env->bandwidth_changed_cb);
- GNUNET_assert (NULL != env->get_preferences);
- GNUNET_assert (NULL != env->get_property);
-
/* Init GLPK environment */
int res = glp_init_env();
switch (res) {
}
/* Get quality metric coefficients from configuration */
- int i_delay = MLP_NaN;
- int i_distance = MLP_NaN;
- int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
- for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
+ for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++)
{
/* initialize quality coefficients with default value 1.0 */
- mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
-
- mlp->pv.q[c] = q[c];
- if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY)
- i_delay = c;
- if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE)
- i_distance = c;
+ mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
}
- if ( (i_delay != MLP_NaN) &&
- (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
- "MLP_COEFFICIENT_QUALITY_DELAY", &tmp)) )
- mlp->pv.co_Q[i_delay] = (double) tmp / 100;
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
+ "MLP_COEFFICIENT_QUALITY_DELAY",
+ &tmp))
+ mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100;
else
- mlp->pv.co_Q[i_delay] = MLP_DEFAULT_QUALITY;
+ mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY;
- if ( (i_distance != MLP_NaN) &&
- (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
- "MLP_COEFFICIENT_QUALITY_DISTANCE", &tmp)) )
- mlp->pv.co_Q[i_distance] = (double) tmp / 100;
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
+ "MLP_COEFFICIENT_QUALITY_DISTANCE",
+ &tmp))
+ mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100;
else
- mlp->pv.co_Q[i_distance] = MLP_DEFAULT_QUALITY;
+ mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY;
/* Get minimum bandwidth per used address from configuration */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
n_min = MLP_DEFAULT_MIN_CONNECTIONS;
/* Init network quotas */
- int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
{
- found = GNUNET_NO;
- for (c2 = 0; c2 < env->network_count; c2++)
- {
- if (quotas[c] == env->networks[c2])
- {
- mlp->pv.quota_index[c] = env->networks[c2];
- mlp->pv.quota_out[c] = env->out_quota[c2];
- mlp->pv.quota_in[c] = env->in_quota[c2];
-
- found = GNUNET_YES;
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Quota for network `%s' (in/out) %llu/%llu\n",
- GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
- mlp->pv.quota_out[c],
- mlp->pv.quota_in[c]);
- break;
-
- }
- }
+ mlp->pv.quota_index[c] = c;
+ mlp->pv.quota_out[c] = env->out_quota[c];
+ mlp->pv.quota_in[c] = env->in_quota[c];
- /* Check if defined quota could make problem unsolvable */
- if ((n_min * b_min) > mlp->pv.quota_out[c])
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
- GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
- mlp->pv.quota_out[c],
- (n_min * b_min));
- mlp->pv.quota_out[c] = (n_min * b_min);
- }
- if ((n_min * b_min) > mlp->pv.quota_in[c])
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
- GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
- mlp->pv.quota_in[c],
- (n_min * b_min));
- mlp->pv.quota_in[c] = (n_min * b_min);
- }
-
- /* Check if bandwidth is too big to make problem solvable */
- if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
- GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
- mlp->pv.quota_out[c],
- mlp->pv.BIG_M);
- mlp->pv.quota_out[c] = mlp->pv.BIG_M ;
- }
- if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
- {
- LOG (GNUNET_ERROR_TYPE_INFO, _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
- GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
- mlp->pv.quota_in[c],
- mlp->pv.BIG_M);
- mlp->pv.quota_in[c] = mlp->pv.BIG_M ;
- }
-
- if (GNUNET_NO == found)
- {
- mlp->pv.quota_in[c] = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
- mlp->pv.quota_out[c] = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
- LOG (GNUNET_ERROR_TYPE_INFO, _("Using default quota configuration for network `%s' (in/out) %llu/%llu\n"),
- GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
- mlp->pv.quota_in[c],
- mlp->pv.quota_out[c]);
- }
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Quota for network `%s' (in/out) %llu/%llu\n",
+ GNUNET_ATS_print_network_type (c),
+ mlp->pv.quota_out[c],
+ mlp->pv.quota_in[c]);
+ /* Check if defined quota could make problem unsolvable */
+ if ((n_min * b_min) > mlp->pv.quota_out[c])
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
+ GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+ mlp->pv.quota_out[c],
+ (n_min * b_min));
+ mlp->pv.quota_out[c] = (n_min * b_min);
+ }
+ if ((n_min * b_min) > mlp->pv.quota_in[c])
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
+ GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+ mlp->pv.quota_in[c],
+ (n_min * b_min));
+ mlp->pv.quota_in[c] = (n_min * b_min);
+ }
+ /* Check if bandwidth is too big to make problem solvable */
+ if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
+ GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+ mlp->pv.quota_out[c],
+ mlp->pv.BIG_M);
+ mlp->pv.quota_out[c] = mlp->pv.BIG_M ;
+ }
+ if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
+ GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+ mlp->pv.quota_in[c],
+ mlp->pv.BIG_M);
+ mlp->pv.quota_in[c] = mlp->pv.BIG_M ;
+ }
}
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_address_update_session = &GAS_mlp_address_session_changed;
- env->sf.s_address_update_network = &GAS_mlp_address_change_network;
- 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;
+ mlp->pv.m_q = RQ_QUALITY_METRIC_COUNT;
mlp->stat_mlp_prob_changed = GNUNET_NO;
mlp->stat_mlp_prob_updated = GNUNET_NO;
mlp->opt_mlp_auto_solve = GNUNET_YES;
LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
- return mlp;
+ return &sf;
}
/* end of plugin_ats_mlp.c */