diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-19 09:46:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-19 09:46:32 +0000 |
commit | fccb457f37724b245c258bbc61145a8072705fe6 (patch) | |
tree | 76d65c4ea0e115313320480779b98d8db4fcecf7 /src/ats | |
parent | d8cda8039015fe11760ae256c43094d046e08cac (diff) | |
download | gnunet-fccb457f37724b245c258bbc61145a8072705fe6.tar.gz gnunet-fccb457f37724b245c258bbc61145a8072705fe6.zip |
- changes
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 5 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 63 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 33 |
3 files changed, 74 insertions, 27 deletions
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, | |||
523 | enum GNUNET_ATS_PreferenceKind kind, | 523 | enum GNUNET_ATS_PreferenceKind kind, |
524 | float score) | 524 | float score) |
525 | { | 525 | { |
526 | // do nothing for now... | 526 | #if HAVE_LIBGLPK |
527 | if (ats_mode == MLP) | ||
528 | GAS_mlp_address_change_preference (mlp, peer, kind, score); | ||
529 | #endif | ||
527 | } | 530 | } |
528 | 531 | ||
529 | 532 | ||
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 | |||
@@ -151,6 +151,24 @@ mlp_status_to_string (int retcode) | |||
151 | } | 151 | } |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * Find a peer in the DLL | ||
155 | * @param the peer to find | ||
156 | * @return the peer struct | ||
157 | */ | ||
158 | static struct ATS_Peer * | ||
159 | mlp_find_peer (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentity *peer) | ||
160 | { | ||
161 | struct ATS_Peer *res = mlp->peer_head; | ||
162 | while (res != NULL) | ||
163 | { | ||
164 | if (0 == memcmp (peer, &res->id, sizeof (struct GNUNET_PeerIdentity))) | ||
165 | break; | ||
166 | res = res->next; | ||
167 | } | ||
168 | return res; | ||
169 | } | ||
170 | |||
171 | /** | ||
154 | * Intercept GLPK terminal output | 172 | * Intercept GLPK terminal output |
155 | * @param info the mlp handle | 173 | * @param info the mlp handle |
156 | * @param s the string to print | 174 | * @param s the string to print |
@@ -492,8 +510,8 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
492 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); | 510 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); |
493 | 511 | ||
494 | /* Quality metric columns */ | 512 | /* Quality metric columns */ |
495 | col = glp_add_cols(mlp->prob, mlp->m); | 513 | col = glp_add_cols(mlp->prob, mlp->m_q); |
496 | for (c = 0; c < mlp->m; c++) | 514 | for (c = 0; c < mlp->m_q; c++) |
497 | { | 515 | { |
498 | mlp->c_q[c] = col + c; | 516 | mlp->c_q[c] = col + c; |
499 | GNUNET_asprintf (&name, "q_%u", mlp->q[c]); | 517 | GNUNET_asprintf (&name, "q_%u", mlp->q[c]); |
@@ -869,7 +887,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
869 | mlp->co_U = U; | 887 | mlp->co_U = U; |
870 | mlp->b_min = b_min; | 888 | mlp->b_min = b_min; |
871 | mlp->n_min = n_min; | 889 | mlp->n_min = n_min; |
872 | mlp->m = GNUNET_ATS_QualityPropertiesCount; | 890 | mlp->m_q = GNUNET_ATS_QualityPropertiesCount; |
873 | 891 | ||
874 | return mlp; | 892 | return mlp; |
875 | } | 893 | } |
@@ -893,6 +911,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
893 | { | 911 | { |
894 | int new; | 912 | int new; |
895 | struct MLP_information *mlpi; | 913 | struct MLP_information *mlpi; |
914 | int c; | ||
896 | 915 | ||
897 | GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); | 916 | GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); |
898 | 917 | ||
@@ -910,13 +929,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
910 | mlp->addr_in_problem ++; | 929 | mlp->addr_in_problem ++; |
911 | 930 | ||
912 | /* Check for and add peer */ | 931 | /* Check for and add peer */ |
913 | struct ATS_Peer *peer = mlp->peer_head; | 932 | struct ATS_Peer *peer = mlp_find_peer (mlp, &address->peer); |
914 | while (peer != NULL) | ||
915 | { | ||
916 | if (0 == memcmp (&address->peer, &peer->id, sizeof (struct GNUNET_PeerIdentity))) | ||
917 | break; | ||
918 | peer = peer->next; | ||
919 | } | ||
920 | if (peer == NULL) | 933 | if (peer == NULL) |
921 | { | 934 | { |
922 | #if DEBUG_ATS | 935 | #if DEBUG_ATS |
@@ -925,6 +938,12 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
925 | peer = GNUNET_malloc (sizeof (struct ATS_Peer)); | 938 | peer = GNUNET_malloc (sizeof (struct ATS_Peer)); |
926 | peer->head = NULL; | 939 | peer->head = NULL; |
927 | peer->tail = NULL; | 940 | peer->tail = NULL; |
941 | |||
942 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) | ||
943 | { | ||
944 | peer->f_q[c] = 1.0; | ||
945 | } | ||
946 | |||
928 | memcpy (&peer->id, &address->peer, sizeof (struct GNUNET_PeerIdentity)); | 947 | memcpy (&peer->id, &address->peer, sizeof (struct GNUNET_PeerIdentity)); |
929 | GNUNET_assert(address->prev == NULL); | 948 | GNUNET_assert(address->prev == NULL); |
930 | GNUNET_assert(address->next == NULL); | 949 | GNUNET_assert(address->next == NULL); |
@@ -978,13 +997,7 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
978 | } | 997 | } |
979 | 998 | ||
980 | /* Remove from peer list */ | 999 | /* Remove from peer list */ |
981 | struct ATS_Peer *head = mlp->peer_head; | 1000 | struct ATS_Peer *head = mlp_find_peer (mlp, &address->peer); |
982 | while (head != NULL) | ||
983 | { | ||
984 | if (0 == memcmp (&address->peer, &head->id, sizeof (struct GNUNET_PeerIdentity))) | ||
985 | break; | ||
986 | head = head->next; | ||
987 | } | ||
988 | GNUNET_assert (head != NULL); | 1001 | GNUNET_assert (head != NULL); |
989 | #if DEBUG_ATS | 1002 | #if DEBUG_ATS |
990 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting address for `%s'\n", GNUNET_i2s (&address->peer)); | 1003 | 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 | |||
1017 | } | 1030 | } |
1018 | 1031 | ||
1019 | /** | 1032 | /** |
1020 | * Deletes a single address in the MLP problem | 1033 | * Changes the preferences for a peer in the MLP problem |
1021 | * | 1034 | * |
1022 | * @param mlp the MLP Handle | 1035 | * @param mlp the MLP Handle |
1023 | * @param addresses the address hashmap | 1036 | * @param peer the peer |
1024 | * @param address the address to change the preference | 1037 | * @param kind the kind to change the preference |
1038 | * @param float the score | ||
1025 | */ | 1039 | */ |
1026 | void | 1040 | void |
1027 | GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) | 1041 | GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, |
1042 | const struct GNUNET_PeerIdentity *peer, | ||
1043 | enum GNUNET_ATS_PreferenceKind kind, | ||
1044 | float score) | ||
1028 | { | 1045 | { |
1029 | GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); | 1046 | GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); |
1047 | |||
1048 | struct ATS_Peer *p = mlp_find_peer (mlp, peer); | ||
1049 | p = p; | ||
1050 | /* Here we have to do the matching */ | ||
1030 | } | 1051 | } |
1031 | 1052 | ||
1032 | /** | 1053 | /** |
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 | |||
47 | 47 | ||
48 | struct GNUNET_PeerIdentity id; | 48 | struct GNUNET_PeerIdentity id; |
49 | 49 | ||
50 | /* Array of quality preferences */ | ||
51 | double f_q[GNUNET_ATS_QualityPropertiesCount]; | ||
52 | |||
50 | struct ATS_Address *head; | 53 | struct ATS_Address *head; |
51 | struct ATS_Address *tail; | 54 | struct ATS_Address *tail; |
52 | }; | 55 | }; |
@@ -179,6 +182,7 @@ struct GAS_MLP_Handle | |||
179 | double co_R; | 182 | double co_R; |
180 | 183 | ||
181 | /* ATS Quality metrics | 184 | /* ATS Quality metrics |
185 | * | ||
182 | * array with GNUNET_ATS_QualityPropertiesCount elements | 186 | * array with GNUNET_ATS_QualityPropertiesCount elements |
183 | * contains mapping to GNUNET_ATS_Property*/ | 187 | * contains mapping to GNUNET_ATS_Property*/ |
184 | int q[GNUNET_ATS_QualityPropertiesCount]; | 188 | int q[GNUNET_ATS_QualityPropertiesCount]; |
@@ -190,7 +194,22 @@ struct GAS_MLP_Handle | |||
190 | double co_Q[GNUNET_ATS_QualityPropertiesCount]; | 194 | double co_Q[GNUNET_ATS_QualityPropertiesCount]; |
191 | 195 | ||
192 | /* number of quality metrics */ | 196 | /* number of quality metrics */ |
193 | int m; | 197 | int m_q; |
198 | |||
199 | /* ATS ressource costs | ||
200 | * | ||
201 | * array with GNUNET_ATS_QualityPropertiesCount elements | ||
202 | * contains mapping to GNUNET_ATS_Property*/ | ||
203 | int rc[GNUNET_ATS_QualityPropertiesCount]; | ||
204 | |||
205 | /* column index ressource costs */ | ||
206 | int c_rc[GNUNET_ATS_QualityPropertiesCount]; | ||
207 | |||
208 | /* ressource costs coefficients*/ | ||
209 | double co_RC[GNUNET_ATS_QualityPropertiesCount]; | ||
210 | |||
211 | /* number of quality metrics */ | ||
212 | int m_rc; | ||
194 | 213 | ||
195 | /* minimum bandwidth assigned to an address */ | 214 | /* minimum bandwidth assigned to an address */ |
196 | unsigned int b_min; | 215 | unsigned int b_min; |
@@ -270,14 +289,18 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
270 | 289 | ||
271 | 290 | ||
272 | /** | 291 | /** |
273 | * Deletes a single address in the MLP problem | 292 | * Changes the preferences for a peer in the MLP problem |
274 | * | 293 | * |
275 | * @param mlp the MLP Handle | 294 | * @param mlp the MLP Handle |
276 | * @param addresses the address hashmap | 295 | * @param peer the peer |
277 | * @param address the address to change the preference | 296 | * @param kind the kind to change the preference |
297 | * @param float the score | ||
278 | */ | 298 | */ |
279 | void | 299 | void |
280 | GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); | 300 | GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, |
301 | const struct GNUNET_PeerIdentity *peer, | ||
302 | enum GNUNET_ATS_PreferenceKind kind, | ||
303 | float score); | ||
281 | 304 | ||
282 | 305 | ||
283 | /** | 306 | /** |