aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-08 22:18:16 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-08 22:18:16 +0000
commit6468625abca41bd7ded392bd46aba352a8643721 (patch)
treefbe5c7e7e3fa279d5b8c8d1f35f7954b655b609b /src
parent8913155539cdac83e11f126498f589db7b51bda7 (diff)
downloadgnunet-6468625abca41bd7ded392bd46aba352a8643721.tar.gz
gnunet-6468625abca41bd7ded392bd46aba352a8643721.zip
-further simplify
Diffstat (limited to 'src')
-rw-r--r--src/ats/plugin_ats_proportional.c109
1 files changed, 97 insertions, 12 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index dd6acabfb..4a9dbd3ce 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -375,14 +375,20 @@ struct GAS_PROPORTIONAL_Handle
375 * Test if bandwidth is available in this network to add an additional address. 375 * Test if bandwidth is available in this network to add an additional address.
376 * 376 *
377 * @param net the network type to check 377 * @param net the network type to check
378 * @param extra for how many extra addresses do we check?
378 * @return #GNUNET_YES or #GNUNET_NO 379 * @return #GNUNET_YES or #GNUNET_NO
379 */ 380 */
380static int 381static int
381is_bandwidth_available_in_network (struct Network *net) 382is_bandwidth_available_in_network (struct Network *net,
383 int extra)
382{ 384{
383 unsigned int na = net->active_addresses + 1; 385 unsigned int na;
384 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 386 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
385 387
388 GNUNET_assert (net->active_addresses + extra >= 0);
389 na = net->active_addresses + extra;
390 if (0 == na)
391 return GNUNET_YES;
386 if ( ((net->total_quota_in / na) > min_bw) && 392 if ( ((net->total_quota_in / na) > min_bw) &&
387 ((net->total_quota_out / na) > min_bw) ) 393 ((net->total_quota_out / na) > min_bw) )
388 return GNUNET_YES; 394 return GNUNET_YES;
@@ -391,6 +397,31 @@ is_bandwidth_available_in_network (struct Network *net)
391 397
392 398
393/** 399/**
400 * Test if all peers in this network require connectivity at level at
401 * least @a con.
402 *
403 * @param s the solver handle
404 * @param net the network type to check
405 * @param con connection return value threshold to check
406 * @return #GNUNET_YES or #GNUNET_NO
407 */
408static int
409all_require_connectivity (struct GAS_PROPORTIONAL_Handle *s,
410 struct Network *net,
411 unsigned int con)
412{
413 struct AddressWrapper *aw;
414
415 for (aw = net->head; NULL != aw; aw = aw->next)
416 if (con >
417 s->env->get_connectivity (s->env->cls,
418 &aw->addr->peer))
419 return GNUNET_NO;
420 return GNUNET_YES;
421}
422
423
424/**
394 * Update bandwidth assigned to peers in this network 425 * Update bandwidth assigned to peers in this network
395 * 426 *
396 * @param s the solver handle 427 * @param s the solver handle
@@ -426,14 +457,12 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
426 net->total_quota_in, 457 net->total_quota_in,
427 net->total_quota_in); 458 net->total_quota_in);
428 459
429 if (net->active_addresses == 0) 460 if (0 == net->active_addresses)
430 {
431 return; /* no addresses to update */ 461 return; /* no addresses to update */
432 }
433 462
434 /* Idea 463 /* Idea:
435 * Assign every peer in network minimum Bandwidth 464 * Assign every peer in network minimum Bandwidth
436 * Distribute bandwidth left according to preference 465 * Distribute remaining bandwidth proportional to preferences.
437 */ 466 */
438 467
439 if ((net->active_addresses * min_bw) > net->total_quota_in) 468 if ((net->active_addresses * min_bw) > net->total_quota_in)
@@ -725,12 +754,37 @@ find_best_address_it (void *cls,
725 double cur_delay; 754 double cur_delay;
726 double cur_distance; 755 double cur_distance;
727 int index; 756 int index;
728 757 unsigned int con;
729 if (GNUNET_NO == 758 int bw_available;
730 is_bandwidth_available_in_network (asi->network)) 759 int need;
760
761 /* we need +1 slot if 'current' is not yet active */
762 need = (GNUNET_YES == current->active) ? 0 : 1;
763 /* we save -1 slot if 'best' is active and belongs
764 to the same network (as we would replace it) */
765 if ( (NULL == ctx->best) &&
766 (GNUNET_YES == ctx->best->active) &&
767 (((struct AddressWrapper *) ctx->best->solver_information)->network ==
768 asi->network) )
769 need--;
770 /* we can gain -1 slot if this peers connectivity
771 requirement is higher than that of another peer
772 in that network scope */
773 con = ctx->s->env->get_connectivity (ctx->s->env->cls,
774 key);
775 if (GNUNET_YES !=
776 all_require_connectivity (ctx->s,
777 asi->network,
778 con))
779 need--;
780 /* test if minimum bandwidth for 'current' would be available */
781 bw_available
782 = is_bandwidth_available_in_network (asi->network,
783 need);
784 if (! bw_available)
731 { 785 {
732 /* There's no bandwidth available in this network, 786 /* Bandwidth for this address is unavailable, so we cannot use
733 so we cannot use this address. */ 787 it. */
734 return GNUNET_OK; 788 return GNUNET_OK;
735 } 789 }
736 if (GNUNET_YES == current->active) 790 if (GNUNET_YES == current->active)
@@ -908,6 +962,10 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
908 struct ATS_Address *best_address; 962 struct ATS_Address *best_address;
909 struct AddressWrapper *asi_cur; 963 struct AddressWrapper *asi_cur;
910 struct AddressWrapper *asi_best; 964 struct AddressWrapper *asi_best;
965 struct AddressWrapper *aw;
966 struct AddressWrapper *aw_min;
967 unsigned int a_con;
968 unsigned int con_min;
911 969
912 best_address = get_best_address (s, 970 best_address = get_best_address (s,
913 s->env->addresses, 971 s->env->addresses,
@@ -982,6 +1040,33 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
982 "Address %p for peer `%s' is now active\n", 1040 "Address %p for peer `%s' is now active\n",
983 best_address, 1041 best_address,
984 GNUNET_i2s (peer)); 1042 GNUNET_i2s (peer));
1043
1044
1045 if (GNUNET_NO ==
1046 is_bandwidth_available_in_network (asi_best->network,
1047 0))
1048 {
1049 /* we went over the maximum number of addresses for
1050 this scope; remove the address with the smallest
1051 connectivity requirement */
1052 con_min = UINT32_MAX;
1053 aw_min = NULL;
1054 for (aw = asi_best->network->head; NULL != aw; aw = aw->next)
1055 {
1056 if (con_min >
1057 (a_con = s->env->get_connectivity (s->env->cls,
1058 &aw->addr->peer)))
1059 {
1060 aw_min = aw;
1061 con_min = a_con;
1062 if (0 == con_min)
1063 break;
1064 }
1065 }
1066 update_active_address (s,
1067 aw_con->addr,
1068 &aw->addr->peer);
1069 }
985 distribute_bandwidth_in_network (s, 1070 distribute_bandwidth_in_network (s,
986 asi_best->network); 1071 asi_best->network);
987} 1072}