diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/bandwidth.c | 4 | ||||
-rw-r--r-- | src/util/time.c | 26 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index 980af764a..a059fc738 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c | |||
@@ -204,8 +204,8 @@ update_excess (struct GNUNET_BANDWIDTH_Tracker *av) | |||
204 | else | 204 | else |
205 | { | 205 | { |
206 | double factor = 1.0 * left_bytes / (double) av->available_bytes_per_s__; | 206 | double factor = 1.0 * left_bytes / (double) av->available_bytes_per_s__; |
207 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 207 | delay = GNUNET_TIME_relative_saturating_multiply (GNUNET_TIME_UNIT_SECONDS, |
208 | (unsigned long long) factor); | 208 | (unsigned long long) factor); |
209 | } | 209 | } |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
211 | "At %llu bps it will take us %s for %lld bytes to reach excess threshold\n", | 211 | "At %llu bps it will take us %s for %lld bytes to reach excess threshold\n", |
diff --git a/src/util/time.c b/src/util/time.c index eb168d531..89b0c2d44 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -446,6 +446,32 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
446 | 446 | ||
447 | 447 | ||
448 | /** | 448 | /** |
449 | * Saturating multiply relative time by a given factor. | ||
450 | * | ||
451 | * @param rel some duration | ||
452 | * @param factor integer to multiply with | ||
453 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor | ||
454 | */ | ||
455 | struct GNUNET_TIME_Relative | ||
456 | GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, | ||
457 | unsigned long long factor) | ||
458 | { | ||
459 | struct GNUNET_TIME_Relative ret; | ||
460 | |||
461 | if (0 == factor) | ||
462 | return GNUNET_TIME_UNIT_ZERO; | ||
463 | if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | ||
464 | return GNUNET_TIME_UNIT_FOREVER_REL; | ||
465 | ret.rel_value_us = rel.rel_value_us * factor; | ||
466 | if (ret.rel_value_us / factor != rel.rel_value_us) | ||
467 | { | ||
468 | return GNUNET_TIME_UNIT_FOREVER_REL; | ||
469 | } | ||
470 | return ret; | ||
471 | } | ||
472 | |||
473 | |||
474 | /** | ||
449 | * Divide relative time by a given factor. | 475 | * Divide relative time by a given factor. |
450 | * | 476 | * |
451 | * @param rel some duration | 477 | * @param rel some duration |