X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fbandwidth.c;h=6f25abfd523bc23870c59a14a1734adf7c9e6162;hb=bb83cd2d04ff5a3f7a8d05fc9a724b0246e958b6;hp=a08bb1f43611f5af847bac4890550dd468410768;hpb=b9b331a978f134af77c64011d17593ed4c6e8382;p=oweals%2Fgnunet.git diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index a08bb1f43..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,24 +175,29 @@ 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; if (av->consumption_since_last_update__ < 0) { 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 - av->last_update__ = now; + } @@ -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; }