X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fbandwidth.c;h=6f25abfd523bc23870c59a14a1734adf7c9e6162;hb=bb83cd2d04ff5a3f7a8d05fc9a724b0246e958b6;hp=658f79b20581be63a78a8facb1ada9a1632c026b;hpb=dfe7e1ea4e61cc99e915af38d0f063e0acd52c50;p=oweals%2Fgnunet.git diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index 658f79b20..6f25abfd5 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c @@ -84,10 +84,10 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO b #if DEBUG_BANDWIDTH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bandwidth has %llu bytes available until deadline in %llums\n", - (unsigned long long) ((b * deadline.value + 500LL) / 1000LL), - deadline.value); + (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL), + deadline.rel_value); #endif - return (b * deadline.value + 500LL) / 1000LL; + return (b * deadline.rel_value + 500LL) / 1000LL; } @@ -115,11 +115,11 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, #endif return GNUNET_TIME_UNIT_FOREVER_REL; } - ret.value = size * 1000LL / b; + ret.rel_value = size * 1000LL / b; #if DEBUG_BANDWIDTH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n", - (unsigned long long) ret.value, + (unsigned long long) ret.rel_value, (unsigned long long) size); #endif return ret; @@ -175,7 +175,7 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) uint64_t max_carry; now = GNUNET_TIME_absolute_get (); - delta_time = now.value - av->last_update__.value; + delta_time = now.abs_value - av->last_update__.abs_value; delta_avail = (delta_time * ((unsigned long long) av->available_bytes_per_s__) + 500LL) / 1000LL; av->consumption_since_last_update__ -= delta_avail; av->last_update__ = now; @@ -183,16 +183,21 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) { left_bytes = - av->consumption_since_last_update__; max_carry = av->available_bytes_per_s__ * av->max_carry_s__; + if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE) + max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE; if (max_carry > left_bytes) - av->consumption_since_last_update__ = -max_carry; + av->consumption_since_last_update__ = -left_bytes; + else + av->consumption_since_last_update__ = -max_carry; } #if DEBUG_BANDWIDTH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av, (unsigned int) av->available_bytes_per_s__, - (unsigned long long) (now.value - av->last_update__.value)); + (unsigned long long) delta_time); #endif + } @@ -285,13 +290,13 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, #endif return GNUNET_TIME_UNIT_ZERO; } - ret.value = 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__; + ret.rel_value = 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__; #if DEBUG_BANDWIDTH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n", av, (unsigned int) size, - (unsigned long long) ret.value); + (unsigned long long) ret.rel_value); #endif return ret; } @@ -318,7 +323,7 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av) used = av->consumption_since_last_update__; #if DEBUG_BANDWIDTH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p available bandwith is %lld ms\n", + "Tracker %p available bandwidth is %lld bytes\n", av, (long long) (int64_t) (avail - used)); #endif @@ -342,7 +347,7 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, new_limit = ntohl (bytes_per_second_limit.value__); #if DEBUG_BANDWIDTH GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Tracker %p bandwith changed to %u Bps\n", + "Tracker %p bandwidth changed to %u Bps\n", av, (unsigned int) new_limit); #endif