diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-25 12:35:39 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-25 12:35:39 +0000 |
commit | 19f70ca1812b97f690c85b719b0c4c824d703bd5 (patch) | |
tree | db8152919b91c73bb9ba89241a0b998fbff5b26b | |
parent | 8580234f727560162eabc607d8067c3b221c967f (diff) | |
download | gnunet-19f70ca1812b97f690c85b719b0c4c824d703bd5.tar.gz gnunet-19f70ca1812b97f690c85b719b0c4c824d703bd5.zip |
improved bandwidth distribution and outbound quota compliance
-rw-r--r-- | src/core/gnunet-service-core.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index f28f2001e..27f7a7d1c 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -44,7 +44,7 @@ | |||
44 | 44 | ||
45 | #define DEBUG_HANDSHAKE GNUNET_NO | 45 | #define DEBUG_HANDSHAKE GNUNET_NO |
46 | 46 | ||
47 | #define DEBUG_CORE_QUOTA GNUNET_YES | 47 | #define DEBUG_CORE_QUOTA GNUNET_NO |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Receive and send buffer windows grow over time. For | 50 | * Receive and send buffer windows grow over time. For |
@@ -4026,6 +4026,8 @@ neighbour_quota_update (void *cls, | |||
4026 | { | 4026 | { |
4027 | struct Neighbour *n = cls; | 4027 | struct Neighbour *n = cls; |
4028 | struct GNUNET_BANDWIDTH_Value32NBO q_in; | 4028 | struct GNUNET_BANDWIDTH_Value32NBO q_in; |
4029 | struct GNUNET_BANDWIDTH_Value32NBO q_out; | ||
4030 | struct GNUNET_BANDWIDTH_Value32NBO q_out_min; | ||
4029 | double pref_rel; | 4031 | double pref_rel; |
4030 | double share; | 4032 | double share; |
4031 | unsigned long long distributable; | 4033 | unsigned long long distributable; |
@@ -4053,14 +4055,31 @@ neighbour_quota_update (void *cls, | |||
4053 | need_per_peer = GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER, | 4055 | need_per_peer = GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER, |
4054 | GNUNET_TIME_UNIT_SECONDS); | 4056 | GNUNET_TIME_UNIT_SECONDS); |
4055 | need_per_second = need_per_peer * neighbour_count; | 4057 | need_per_second = need_per_peer * neighbour_count; |
4058 | |||
4059 | /* calculate inbound bandwidth per peer */ | ||
4056 | distributable = 0; | 4060 | distributable = 0; |
4057 | if (bandwidth_target_out_bps > need_per_second) | 4061 | if (bandwidth_target_in_bps > need_per_second) |
4058 | distributable = bandwidth_target_out_bps - need_per_second; | 4062 | distributable = bandwidth_target_in_bps - need_per_second; |
4059 | share = distributable * pref_rel; | 4063 | share = distributable * pref_rel; |
4060 | if (share + need_per_peer > UINT32_MAX) | 4064 | if (share + need_per_peer > UINT32_MAX) |
4061 | q_in = GNUNET_BANDWIDTH_value_init (UINT32_MAX); | 4065 | q_in = GNUNET_BANDWIDTH_value_init (UINT32_MAX); |
4062 | else | 4066 | else |
4063 | q_in = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); | 4067 | q_in = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); |
4068 | |||
4069 | /* calculate outbound bandwidth per peer */ | ||
4070 | distributable = 0; | ||
4071 | if (bandwidth_target_out_bps > need_per_second) | ||
4072 | distributable = bandwidth_target_out_bps - need_per_second; | ||
4073 | share = distributable * pref_rel; | ||
4074 | if (share + need_per_peer > UINT32_MAX) | ||
4075 | q_out = GNUNET_BANDWIDTH_value_init (UINT32_MAX); | ||
4076 | else | ||
4077 | q_out = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); | ||
4078 | n->bw_out_internal_limit = q_out; | ||
4079 | |||
4080 | q_out_min = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, n->bw_out_internal_limit); | ||
4081 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, n->bw_out); | ||
4082 | |||
4064 | /* check if we want to disconnect for good due to inactivity */ | 4083 | /* check if we want to disconnect for good due to inactivity */ |
4065 | if ( (GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value > 0) && | 4084 | if ( (GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value > 0) && |
4066 | (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value > GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) ) | 4085 | (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value > GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) ) |
@@ -4081,10 +4100,13 @@ neighbour_quota_update (void *cls, | |||
4081 | (unsigned int) ntohl (n->bw_in.value__), | 4100 | (unsigned int) ntohl (n->bw_in.value__), |
4082 | (unsigned int) ntohl (n->bw_out.value__), | 4101 | (unsigned int) ntohl (n->bw_out.value__), |
4083 | (unsigned int) ntohl (n->bw_out_internal_limit.value__)); | 4102 | (unsigned int) ntohl (n->bw_out_internal_limit.value__)); |
4084 | #endif | 4103 | #endif |
4085 | if (n->bw_in.value__ != q_in.value__) | 4104 | if ((n->bw_in.value__ != q_in.value__) || (n->bw_out.value__ != q_out_min.value__)) |
4086 | { | 4105 | { |
4087 | n->bw_in = q_in; | 4106 | if (n->bw_in.value__ != q_in.value__) |
4107 | n->bw_in = q_in; | ||
4108 | if (n->bw_out.value__ != q_out_min.value__) | ||
4109 | n->bw_out = q_out_min; | ||
4088 | if (GNUNET_YES == n->is_connected) | 4110 | if (GNUNET_YES == n->is_connected) |
4089 | GNUNET_TRANSPORT_set_quota (transport, | 4111 | GNUNET_TRANSPORT_set_quota (transport, |
4090 | &n->peer, | 4112 | &n->peer, |