aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_proportional.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r--src/ats/plugin_ats_proportional.c120
1 files changed, 69 insertions, 51 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index 5798fd82e..7badd3491 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -203,12 +203,7 @@
203 * 203 *
204 */ 204 */
205 205
206#define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 206#define PROPORTIONALITY_FACTOR 2.0
207#define PREF_AGING_FACTOR 0.95
208
209#define DEFAULT_REL_PREFERENCE 1.0
210#define DEFAULT_ABS_PREFERENCE 0.0
211#define MIN_UPDATE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
212 207
213/** 208/**
214 * A handle for the proportional solver 209 * A handle for the proportional solver
@@ -292,6 +287,10 @@ struct GAS_PROPORTIONAL_Handle
292 */ 287 */
293 unsigned int network_count; 288 unsigned int network_count;
294 289
290 /**
291 * Proportionality factor
292 */
293 double prop_factor;
295}; 294};
296 295
297/** 296/**
@@ -400,6 +399,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
400 struct GAS_PROPORTIONAL_Handle *s; 399 struct GAS_PROPORTIONAL_Handle *s;
401 struct Network * cur; 400 struct Network * cur;
402 char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; 401 char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
402 unsigned long long prop_factor;
403 int c; 403 int c;
404 404
405 GNUNET_assert (NULL != env); 405 GNUNET_assert (NULL != env);
@@ -440,6 +440,23 @@ libgnunet_plugin_ats_proportional_init (void *cls)
440 s->addresses = env->addresses; 440 s->addresses = env->addresses;
441 s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 441 s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
442 442
443 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number(s->env->cfg, "ats",
444 "PROP_PROPORTIONALITY_FACTOR", &prop_factor))
445 {
446 if (prop_factor > 1)
447 s->prop_factor = (double) prop_factor;
448 else
449 {
450 GNUNET_break (0);
451 s->prop_factor = PROPORTIONALITY_FACTOR;
452 }
453 }
454 else
455 s->prop_factor = PROPORTIONALITY_FACTOR;
456 LOG (GNUNET_ERROR_TYPE_ERROR, "Using proportionality factor %.0f\n",
457 s->prop_factor);
458
459
443 for (c = 0; c < env->network_count; c++) 460 for (c = 0; c < env->network_count; c++)
444 { 461 {
445 cur = &s->network_entries[c]; 462 cur = &s->network_entries[c];
@@ -557,18 +574,21 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
557 struct Network *net, struct ATS_Address *address_except) 574 struct Network *net, struct ATS_Address *address_except)
558{ 575{
559 struct AddressSolverInformation *asi; 576 struct AddressSolverInformation *asi;
560 struct AddressWrapper *cur; 577 struct AddressWrapper *cur_address;
561 578
562 unsigned long long remaining_quota_in = 0; 579 unsigned long long remaining_quota_in = 0;
563 unsigned long long quota_out_used = 0; 580 unsigned long long quota_out_used = 0;
564 unsigned long long remaining_quota_out = 0; 581 unsigned long long remaining_quota_out = 0;
565 unsigned long long quota_in_used = 0; 582 unsigned long long quota_in_used = 0;
583 int count_addresses;
566 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 584 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
567 double peer_prefs; 585 double relative_peer_prefence;
568 double total_prefs; /* Important: has to be double not float due to precision */ 586 double sum_relative_peer_prefences; /* Important: has to be double not float due to precision */
569 double cur_pref; /* Important: has to be double not float due to precision */ 587 double cur_pref; /* Important: has to be double not float due to precision */
570 const double *t = NULL; /* Important: has to be double not float due to precision */ 588 double peer_weight;
571 int c; 589 double total_weight;
590 const double *peer_relative_prefs = NULL; /* Important: has to be double not float due to precision */
591
572 unsigned long long assigned_quota_in = 0; 592 unsigned long long assigned_quota_in = 0;
573 unsigned long long assigned_quota_out = 0; 593 unsigned long long assigned_quota_out = 0;
574 594
@@ -603,49 +623,49 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
603 remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw); 623 remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw);
604 LOG(GNUNET_ERROR_TYPE_DEBUG, "Remaining bandwidth : (in/out): %llu/%llu \n", 624 LOG(GNUNET_ERROR_TYPE_DEBUG, "Remaining bandwidth : (in/out): %llu/%llu \n",
605 remaining_quota_in, remaining_quota_out); 625 remaining_quota_in, remaining_quota_out);
606 total_prefs = 0.0; 626 sum_relative_peer_prefences = 0.0;
607 for (cur = net->head; NULL != cur; cur = cur->next)
608 {
609 if (GNUNET_YES == cur->addr->active)
610 {
611 GNUNET_assert(
612 NULL != (t = s->get_preferences (s->get_preferences_cls, &cur->addr->peer)));
613 627
614 peer_prefs = 0.0; 628 /* Calculate sum of relative preference for active addresses in this network */
615 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) 629 count_addresses = 0;
616 { 630 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next)
617 if (c != GNUNET_ATS_PREFERENCE_END) 631 {
618 { 632 if (GNUNET_YES != cur_address->addr->active)
619 //fprintf (stderr, "VALUE[%u] %s %.3f \n", c, GNUNET_i2s (&cur->addr->peer), t[c]); 633 continue;
620 peer_prefs += t[c]; 634
621 } 635 GNUNET_assert( NULL != (peer_relative_prefs = s->get_preferences (s->get_preferences_cls,
622 } 636 &cur_address->addr->peer)));
623 total_prefs += (peer_prefs / (GNUNET_ATS_PreferenceCount - 1)); 637 relative_peer_prefence = 0.0;
624 } 638 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
639 sum_relative_peer_prefences += relative_peer_prefence;
640 count_addresses ++;
625 } 641 }
626 for (cur = net->head; NULL != cur; cur = cur->next) 642
643 GNUNET_assert (count_addresses == net->active_addresses);
644
645 LOG (GNUNET_ERROR_TYPE_INFO,
646 "Total relative preference %.3f for %u addresses in network %s\n",
647 sum_relative_peer_prefences, net->active_addresses, net->desc);
648
649 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next)
627 { 650 {
628 if (GNUNET_YES == cur->addr->active) 651 if (GNUNET_YES == cur_address->addr->active)
629 { 652 {
630 cur_pref = 0.0; 653 GNUNET_assert( NULL != (peer_relative_prefs =
631 GNUNET_assert( 654 s->get_preferences (s->get_preferences_cls, &cur_address->addr->peer)));
632 NULL != (t = s->get_preferences (s->get_preferences_cls, &cur->addr->peer)));
633 655
634 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) 656 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
635 { 657 total_weight = net->active_addresses +
636 if (c != GNUNET_ATS_PREFERENCE_END) 658 s->prop_factor * sum_relative_peer_prefences;
637 cur_pref += t[c]; 659 peer_weight = (1.0 + (s->prop_factor * cur_pref));
638 }
639 cur_pref /= 2;
640 660
641 assigned_quota_in = min_bw 661 assigned_quota_in = min_bw
642 + ((cur_pref / total_prefs) * remaining_quota_in); 662 + ((peer_weight / total_weight) * remaining_quota_in);
643 assigned_quota_out = min_bw 663 assigned_quota_out = min_bw
644 + ((cur_pref / total_prefs) * remaining_quota_out); 664 + ((peer_weight / total_weight) * remaining_quota_out);
645 665
646 LOG (GNUNET_ERROR_TYPE_INFO, 666 LOG (GNUNET_ERROR_TYPE_INFO,
647 "New quota for peer `%s' with preference (cur/total) %.3f/%.3f (in/out): %llu / %llu\n", 667 "New quota for peer `%s' with weight (cur/total) %.3f/%.3f (in/out): %llu / %llu\n",
648 GNUNET_i2s (&cur->addr->peer), cur_pref, total_prefs, 668 GNUNET_i2s (&cur_address->addr->peer), peer_weight, total_weight,
649 assigned_quota_in, assigned_quota_out); 669 assigned_quota_in, assigned_quota_out);
650 } 670 }
651 else 671 else
@@ -663,7 +683,7 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
663 assigned_quota_out = UINT32_MAX; 683 assigned_quota_out = UINT32_MAX;
664 684
665 /* Compare to current bandwidth assigned */ 685 /* Compare to current bandwidth assigned */
666 asi = cur->addr->solver_information; 686 asi = cur_address->addr->solver_information;
667 asi->calculated_quota_in_NBO = htonl (assigned_quota_in); 687 asi->calculated_quota_in_NBO = htonl (assigned_quota_in);
668 asi->calculated_quota_out_NBO = htonl (assigned_quota_out); 688 asi->calculated_quota_out_NBO = htonl (assigned_quota_out);
669 } 689 }
@@ -1140,13 +1160,11 @@ GAS_proportional_get_preferred_address (void *solver,
1140 GNUNET_assert(peer != NULL); 1160 GNUNET_assert(peer != NULL);
1141 1161
1142 /* Add to list of pending requests */ 1162 /* Add to list of pending requests */
1143 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, 1163 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
1144 peer))
1145 { 1164 {
1146 GNUNET_assert (GNUNET_OK == 1165 GNUNET_assert(
1147 GNUNET_CONTAINER_multipeermap_put (s->requests, 1166 GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (s->requests, peer, NULL,
1148 peer, NULL, 1167 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1149 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1150 } 1168 }
1151 1169
1152 /* Get address with: stick to current address, lower distance, lower latency */ 1170 /* Get address with: stick to current address, lower distance, lower latency */