diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-01-11 13:38:10 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-01-11 13:38:10 +0000 |
commit | a2f282aad0ee4d5f6113c4ec5fa5ad623f0e3c39 (patch) | |
tree | 18e1ea82677cedcc2f4811897a2406a3d2d2bbdb /src/ats | |
parent | 65fdcf18ec495b818e257ef1716d6270865cc32c (diff) | |
download | gnunet-a2f282aad0ee4d5f6113c4ec5fa5ad623f0e3c39.tar.gz gnunet-a2f282aad0ee4d5f6113c4ec5fa5ad623f0e3c39.zip |
changes
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_simplistic.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c index 5207fcbdb..00dac7168 100644 --- a/src/ats/gnunet-service-ats_addresses_simplistic.c +++ b/src/ats/gnunet-service-ats_addresses_simplistic.c | |||
@@ -55,6 +55,8 @@ | |||
55 | * | 55 | * |
56 | */ | 56 | */ |
57 | 57 | ||
58 | #define DEFAULT_PREFERENCE 1.0 | ||
59 | #define MIN_UPDATE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
58 | 60 | ||
59 | /** | 61 | /** |
60 | * A handle for the simplistic solver | 62 | * A handle for the simplistic solver |
@@ -410,7 +412,7 @@ update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s, | |||
410 | 412 | ||
411 | if (net->active_addresses == 0) | 413 | if (net->active_addresses == 0) |
412 | return; /* no addresses to update */ | 414 | return; /* no addresses to update */ |
413 | #if 0 | 415 | |
414 | /* Idea TODO | 416 | /* Idea TODO |
415 | * | 417 | * |
416 | * Assign every peer in network minimum Bandwidth | 418 | * Assign every peer in network minimum Bandwidth |
@@ -423,20 +425,19 @@ update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s, | |||
423 | unsigned long long quota_in_used = 0; | 425 | unsigned long long quota_in_used = 0; |
424 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 426 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
425 | float total_prefs; | 427 | float total_prefs; |
426 | float cur_pref; | 428 | float cur_pref = 0.0; |
427 | float *t; | 429 | float *t = NULL; |
428 | 430 | ||
429 | remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw); | 431 | remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw); |
430 | remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw); | 432 | remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw); |
431 | total_prefs = 0.0; | 433 | total_prefs = 0.0; |
432 | LOG (GNUNET_ERROR_TYPE_ERROR, | 434 | LOG (GNUNET_ERROR_TYPE_ERROR, "Remaining bandwidth : (in/out): %llu/%llu \n", |
433 | "Remaining: (in/out): %llu/%llu \n", | ||
434 | remaining_quota_in, remaining_quota_out); | 435 | remaining_quota_in, remaining_quota_out); |
435 | for (cur = net->head; NULL != cur; cur = cur->next) | 436 | for (cur = net->head; NULL != cur; cur = cur->next) |
436 | { | 437 | { |
437 | t = GNUNET_CONTAINER_multihashmap_get (s->prefs, &cur->addr->peer.hashPubKey); | 438 | t = GNUNET_CONTAINER_multihashmap_get (s->prefs, &cur->addr->peer.hashPubKey); |
438 | if (NULL == t) | 439 | if (NULL == t) |
439 | total_prefs += 1.0; | 440 | total_prefs += DEFAULT_PREFERENCE; |
440 | else | 441 | else |
441 | total_prefs += (*t); | 442 | total_prefs += (*t); |
442 | } | 443 | } |
@@ -444,16 +445,16 @@ update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s, | |||
444 | { | 445 | { |
445 | t = GNUNET_CONTAINER_multihashmap_get (s->prefs, &cur->addr->peer.hashPubKey); | 446 | t = GNUNET_CONTAINER_multihashmap_get (s->prefs, &cur->addr->peer.hashPubKey); |
446 | if (NULL == t) | 447 | if (NULL == t) |
447 | cur_pref = 1.0; | 448 | cur_pref = DEFAULT_PREFERENCE; |
448 | else | 449 | else |
449 | cur_pref += (*t); | 450 | cur_pref = (*t); |
450 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
451 | "Current pref vs total pref: (in/out): %f/%f \n", | ||
452 | cur_pref, total_prefs); | ||
453 | quota_in = min_bw + (cur_pref / total_prefs) * (float) remaining_quota_in; | 451 | quota_in = min_bw + (cur_pref / total_prefs) * (float) remaining_quota_in; |
454 | quota_out = min_bw + (cur_pref / total_prefs) * (float) remaining_quota_out; | 452 | quota_out = min_bw + (cur_pref / total_prefs) * (float) remaining_quota_out; |
455 | LOG (GNUNET_ERROR_TYPE_ERROR, | 453 | LOG (GNUNET_ERROR_TYPE_ERROR, |
456 | "New quota would be: (in/out): %llu /%llu\n", | 454 | "New quota for peer `%s' with preference (cur/total) %.3f/%.3f (in/out): %llu /%llu\n", |
455 | GNUNET_i2s (&cur->addr->peer), | ||
456 | cur_pref, | ||
457 | total_prefs, | ||
457 | quota_in, | 458 | quota_in, |
458 | quota_out); | 459 | quota_out); |
459 | quota_in_used += quota_in; | 460 | quota_in_used += quota_in; |
@@ -468,10 +469,6 @@ update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s, | |||
468 | "New quota would be: (in/out): %llu /%llu\n", | 469 | "New quota would be: (in/out): %llu /%llu\n", |
469 | quota_in_used, | 470 | quota_in_used, |
470 | quota_out_used); | 471 | quota_out_used); |
471 | /* End TODO */ | ||
472 | #endif | ||
473 | quota_in = net->total_quota_in / net->active_addresses; | ||
474 | quota_out = net->total_quota_out / net->active_addresses; | ||
475 | 472 | ||
476 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 473 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
477 | "New per address quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", | 474 | "New per address quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", |
@@ -1134,7 +1131,7 @@ GAS_simplistic_address_change_preference (void *solver, | |||
1134 | * No value set, so absolute preference 0 */ | 1131 | * No value set, so absolute preference 0 */ |
1135 | p->f[i] = 0.0; | 1132 | p->f[i] = 0.0; |
1136 | /* Default value per peer relative preference for a quality: 1.0 */ | 1133 | /* Default value per peer relative preference for a quality: 1.0 */ |
1137 | p->f_rel[i] = 1.0; | 1134 | p->f_rel[i] = DEFAULT_PREFERENCE; |
1138 | } | 1135 | } |
1139 | GNUNET_CONTAINER_DLL_insert (cur->p_head, cur->p_tail, p); | 1136 | GNUNET_CONTAINER_DLL_insert (cur->p_head, cur->p_tail, p); |
1140 | } | 1137 | } |
@@ -1156,17 +1153,17 @@ GAS_simplistic_address_change_preference (void *solver, | |||
1156 | for (p = cur->p_head; NULL != p; p = p->next) | 1153 | for (p = cur->p_head; NULL != p; p = p->next) |
1157 | cur->f_total[kind] += p->f[kind]; | 1154 | cur->f_total[kind] += p->f[kind]; |
1158 | 1155 | ||
1159 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p has total preference for %s of %f\n", | 1156 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p has total preference for %s of %.3f\n", |
1160 | cur->client, | 1157 | cur->client, |
1161 | GNUNET_ATS_print_preference_type (kind), | 1158 | GNUNET_ATS_print_preference_type (kind), |
1162 | cur->f_total[kind]); | 1159 | cur->f_total[kind]); |
1163 | 1160 | ||
1164 | /* Recalcalculate relative preference */ | 1161 | /* Recalcalculate relative preference for all peers */ |
1165 | for (p = cur->p_head; NULL != p; p = p->next) | 1162 | for (p = cur->p_head; NULL != p; p = p->next) |
1166 | { | 1163 | { |
1167 | /* Calculate relative preference for specific kind */ | 1164 | /* Calculate relative preference for specific kind */ |
1168 | p->f_rel[kind] = (cur->f_total[kind] + p->f[kind]) / cur->f_total[kind]; | 1165 | p->f_rel[kind] = (cur->f_total[kind] + p->f[kind]) / cur->f_total[kind]; |
1169 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has relative preference for %s of %f\n", | 1166 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has relative preference for %s of %.3f\n", |
1170 | cur->client, | 1167 | cur->client, |
1171 | GNUNET_i2s (&p->id), | 1168 | GNUNET_i2s (&p->id), |
1172 | GNUNET_ATS_print_preference_type (kind), | 1169 | GNUNET_ATS_print_preference_type (kind), |
@@ -1180,7 +1177,7 @@ GAS_simplistic_address_change_preference (void *solver, | |||
1180 | p->f_rel_total += p->f_rel[i]; | 1177 | p->f_rel_total += p->f_rel[i]; |
1181 | } | 1178 | } |
1182 | p->f_rel_total /= (GNUNET_ATS_PreferenceCount - 1.0); /* -1 due to terminator */ | 1179 | p->f_rel_total /= (GNUNET_ATS_PreferenceCount - 1.0); /* -1 due to terminator */ |
1183 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has total relative preference of %f\n", | 1180 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has total relative preference of %.3f\n", |
1184 | cur->client, | 1181 | cur->client, |
1185 | GNUNET_i2s (&p->id), | 1182 | GNUNET_i2s (&p->id), |
1186 | p->f_rel_total); | 1183 | p->f_rel_total); |
@@ -1201,7 +1198,7 @@ GAS_simplistic_address_change_preference (void *solver, | |||
1201 | } | 1198 | } |
1202 | } | 1199 | } |
1203 | p_rel_global /= clients; | 1200 | p_rel_global /= clients; |
1204 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Global preference value for peer `%s': %f\n", | 1201 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Global preference value for peer `%s': %.3f\n", |
1205 | GNUNET_i2s (peer), p_rel_global); | 1202 | GNUNET_i2s (peer), p_rel_global); |
1206 | 1203 | ||
1207 | /* Update global map */ | 1204 | /* Update global map */ |
@@ -1217,6 +1214,7 @@ GAS_simplistic_address_change_preference (void *solver, | |||
1217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1214 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1218 | } | 1215 | } |
1219 | 1216 | ||
1217 | |||
1220 | } | 1218 | } |
1221 | 1219 | ||
1222 | /* end of gnunet-service-ats_addresses_simplistic.c */ | 1220 | /* end of gnunet-service-ats_addresses_simplistic.c */ |