From: Matthias Wachs Date: Thu, 19 Jan 2012 09:46:32 +0000 (+0000) Subject: - changes X-Git-Tag: initial-import-from-subversion-38251~15226 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fccb457f37724b245c258bbc61145a8072705fe6;p=oweals%2Fgnunet.git - changes --- diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index ae78858e6..1f31b9c5c 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -523,7 +523,10 @@ GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, float score) { - // do nothing for now... +#if HAVE_LIBGLPK + if (ats_mode == MLP) + GAS_mlp_address_change_preference (mlp, peer, kind, score); +#endif } diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index c7b1ee75c..0794401bd 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -150,6 +150,24 @@ mlp_status_to_string (int retcode) return "unknown error"; } +/** + * Find a peer in the DLL + * @param the peer to find + * @return the peer struct + */ +static struct ATS_Peer * +mlp_find_peer (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentity *peer) +{ + struct ATS_Peer *res = mlp->peer_head; + while (res != NULL) + { + if (0 == memcmp (peer, &res->id, sizeof (struct GNUNET_PeerIdentity))) + break; + res = res->next; + } + return res; +} + /** * Intercept GLPK terminal output * @param info the mlp handle @@ -492,8 +510,8 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); /* Quality metric columns */ - col = glp_add_cols(mlp->prob, mlp->m); - for (c = 0; c < mlp->m; c++) + col = glp_add_cols(mlp->prob, mlp->m_q); + for (c = 0; c < mlp->m_q; c++) { mlp->c_q[c] = col + c; GNUNET_asprintf (&name, "q_%u", mlp->q[c]); @@ -869,7 +887,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, mlp->co_U = U; mlp->b_min = b_min; mlp->n_min = n_min; - mlp->m = GNUNET_ATS_QualityPropertiesCount; + mlp->m_q = GNUNET_ATS_QualityPropertiesCount; return mlp; } @@ -893,6 +911,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult { int new; struct MLP_information *mlpi; + int c; GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); @@ -910,13 +929,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult mlp->addr_in_problem ++; /* Check for and add peer */ - struct ATS_Peer *peer = mlp->peer_head; - while (peer != NULL) - { - if (0 == memcmp (&address->peer, &peer->id, sizeof (struct GNUNET_PeerIdentity))) - break; - peer = peer->next; - } + struct ATS_Peer *peer = mlp_find_peer (mlp, &address->peer); if (peer == NULL) { #if DEBUG_ATS @@ -925,6 +938,12 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult peer = GNUNET_malloc (sizeof (struct ATS_Peer)); peer->head = NULL; peer->tail = NULL; + + for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) + { + peer->f_q[c] = 1.0; + } + memcpy (&peer->id, &address->peer, sizeof (struct GNUNET_PeerIdentity)); GNUNET_assert(address->prev == NULL); GNUNET_assert(address->next == NULL); @@ -978,13 +997,7 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult } /* Remove from peer list */ - struct ATS_Peer *head = mlp->peer_head; - while (head != NULL) - { - if (0 == memcmp (&address->peer, &head->id, sizeof (struct GNUNET_PeerIdentity))) - break; - head = head->next; - } + struct ATS_Peer *head = mlp_find_peer (mlp, &address->peer); GNUNET_assert (head != NULL); #if DEBUG_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting address for `%s'\n", GNUNET_i2s (&address->peer)); @@ -1017,16 +1030,24 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult } /** - * Deletes a single address in the MLP problem + * Changes the preferences for a peer in the MLP problem * * @param mlp the MLP Handle - * @param addresses the address hashmap - * @param address the address to change the preference + * @param peer the peer + * @param kind the kind to change the preference + * @param float the score */ void -GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, + const struct GNUNET_PeerIdentity *peer, + enum GNUNET_ATS_PreferenceKind kind, + float score) { GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); + + struct ATS_Peer *p = mlp_find_peer (mlp, peer); + p = p; + /* Here we have to do the matching */ } /** diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index dd26aa837..4d55ff6e1 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -47,6 +47,9 @@ struct ATS_Peer struct GNUNET_PeerIdentity id; + /* Array of quality preferences */ + double f_q[GNUNET_ATS_QualityPropertiesCount]; + struct ATS_Address *head; struct ATS_Address *tail; }; @@ -179,6 +182,7 @@ struct GAS_MLP_Handle double co_R; /* ATS Quality metrics + * * array with GNUNET_ATS_QualityPropertiesCount elements * contains mapping to GNUNET_ATS_Property*/ int q[GNUNET_ATS_QualityPropertiesCount]; @@ -190,7 +194,22 @@ struct GAS_MLP_Handle double co_Q[GNUNET_ATS_QualityPropertiesCount]; /* number of quality metrics */ - int m; + int m_q; + + /* ATS ressource costs + * + * array with GNUNET_ATS_QualityPropertiesCount elements + * contains mapping to GNUNET_ATS_Property*/ + int rc[GNUNET_ATS_QualityPropertiesCount]; + + /* column index ressource costs */ + int c_rc[GNUNET_ATS_QualityPropertiesCount]; + + /* ressource costs coefficients*/ + double co_RC[GNUNET_ATS_QualityPropertiesCount]; + + /* number of quality metrics */ + int m_rc; /* minimum bandwidth assigned to an address */ unsigned int b_min; @@ -270,14 +289,18 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult /** - * Deletes a single address in the MLP problem + * Changes the preferences for a peer in the MLP problem * * @param mlp the MLP Handle - * @param addresses the address hashmap - * @param address the address to change the preference + * @param peer the peer + * @param kind the kind to change the preference + * @param float the score */ void -GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); +GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, + const struct GNUNET_PeerIdentity *peer, + enum GNUNET_ATS_PreferenceKind kind, + float score); /**