diff options
author | David Barksdale <amatus@amatus.name> | 2016-11-17 23:24:43 -0600 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2016-11-17 23:24:43 -0600 |
commit | 12597da2a33fe196a785a656136cba7675a06e21 (patch) | |
tree | c189c7fb7f2835f8219622400d83c453a91dbb69 | |
parent | cdeb1253bfda209def1ef48b436ff09cf7ab8be6 (diff) | |
download | gnunet-12597da2a33fe196a785a656136cba7675a06e21.tar.gz gnunet-12597da2a33fe196a785a656136cba7675a06e21.zip |
Sometimes it's OK if multiplication overflows
-rw-r--r-- | src/ats/plugin_ats_ril.c | 2 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.c | 8 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 8 | ||||
-rw-r--r-- | src/fragmentation/defragmentation.c | 4 | ||||
-rw-r--r-- | src/fragmentation/fragmentation.c | 12 | ||||
-rw-r--r-- | src/fs/fs_api.c | 4 | ||||
-rw-r--r-- | src/fs/fs_search.c | 4 | ||||
-rw-r--r-- | src/fs/gnunet-auto-share.c | 12 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_time_lib.h | 12 | ||||
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 2 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps.c | 4 | ||||
-rw-r--r-- | src/util/bandwidth.c | 4 | ||||
-rw-r--r-- | src/util/time.c | 26 | ||||
-rw-r--r-- | src/vpn/vpn_api.c | 2 |
15 files changed, 72 insertions, 34 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index a3bdf200c..ea7920779 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -1835,7 +1835,7 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1835 | GNUNET_assert(y <= (double) solver->parameters.step_time_max.rel_value_us); | 1835 | GNUNET_assert(y <= (double) solver->parameters.step_time_max.rel_value_us); |
1836 | GNUNET_assert(y >= (double) solver->parameters.step_time_min.rel_value_us); | 1836 | GNUNET_assert(y >= (double) solver->parameters.step_time_min.rel_value_us); |
1837 | 1837 | ||
1838 | time_next = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y); | 1838 | time_next = GNUNET_TIME_relative_saturating_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y); |
1839 | 1839 | ||
1840 | // LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", | 1840 | // LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", |
1841 | // used_ratio, | 1841 | // used_ratio, |
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 0e9b7a3af..22349aa80 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -819,8 +819,8 @@ ch_message_sent (void *cls, | |||
819 | if (0 != rel->expected_delay.rel_value_us) | 819 | if (0 != rel->expected_delay.rel_value_us) |
820 | { | 820 | { |
821 | rel->retry_timer = | 821 | rel->retry_timer = |
822 | GNUNET_TIME_relative_multiply (rel->expected_delay, | 822 | GNUNET_TIME_relative_saturating_multiply (rel->expected_delay, |
823 | CADET_RETRANSMIT_MARGIN); | 823 | CADET_RETRANSMIT_MARGIN); |
824 | } | 824 | } |
825 | else | 825 | else |
826 | { | 826 | { |
@@ -2110,8 +2110,8 @@ GCCH_handle_data_ack (struct CadetChannel *ch, | |||
2110 | struct GNUNET_TIME_Absolute new_target; | 2110 | struct GNUNET_TIME_Absolute new_target; |
2111 | struct GNUNET_TIME_Relative delay; | 2111 | struct GNUNET_TIME_Relative delay; |
2112 | 2112 | ||
2113 | delay = GNUNET_TIME_relative_multiply (rel->retry_timer, | 2113 | delay = GNUNET_TIME_relative_saturating_multiply (rel->retry_timer, |
2114 | CADET_RETRANSMIT_MARGIN); | 2114 | CADET_RETRANSMIT_MARGIN); |
2115 | new_target = GNUNET_TIME_absolute_add (rel->head_sent->timestamp, | 2115 | new_target = GNUNET_TIME_absolute_add (rel->head_sent->timestamp, |
2116 | delay); | 2116 | delay); |
2117 | delay = GNUNET_TIME_absolute_get_remaining (new_target); | 2117 | delay = GNUNET_TIME_absolute_get_remaining (new_target); |
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index face765e4..1c500f716 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -1318,8 +1318,8 @@ schedule_next_keepalive (struct CadetConnection *c, int fwd) | |||
1318 | { | 1318 | { |
1319 | if (1 > c->create_retry) | 1319 | if (1 > c->create_retry) |
1320 | c->create_retry = 1; | 1320 | c->create_retry = 1; |
1321 | delay = GNUNET_TIME_relative_multiply (create_connection_time, | 1321 | delay = GNUNET_TIME_relative_saturating_multiply (create_connection_time, |
1322 | c->create_retry); | 1322 | c->create_retry); |
1323 | if (c->create_retry < 64) // TODO make configurable | 1323 | if (c->create_retry < 64) // TODO make configurable |
1324 | c->create_retry *= 2; | 1324 | c->create_retry *= 2; |
1325 | } | 1325 | } |
@@ -1548,7 +1548,7 @@ connection_reset_timeout (struct CadetConnection *c, int fwd) | |||
1548 | 1548 | ||
1549 | if (NULL != *ti) | 1549 | if (NULL != *ti) |
1550 | GNUNET_SCHEDULER_cancel (*ti); | 1550 | GNUNET_SCHEDULER_cancel (*ti); |
1551 | delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 4); | 1551 | delay = GNUNET_TIME_relative_saturating_multiply (refresh_connection_time, 4); |
1552 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1552 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1553 | " timing out in %s\n", | 1553 | " timing out in %s\n", |
1554 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO)); | 1554 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO)); |
@@ -1681,7 +1681,7 @@ schedule_check_duplicates (struct CadetConnection *c) | |||
1681 | 1681 | ||
1682 | if (NULL != c->check_duplicates_task) | 1682 | if (NULL != c->check_duplicates_task) |
1683 | return; | 1683 | return; |
1684 | delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5); | 1684 | delay = GNUNET_TIME_relative_saturating_multiply (refresh_connection_time, 5); |
1685 | c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay, | 1685 | c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay, |
1686 | &check_duplicates, | 1686 | &check_duplicates, |
1687 | c); | 1687 | c); |
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c index bc401435e..cc0f5a8c5 100644 --- a/src/fragmentation/defragmentation.c +++ b/src/fragmentation/defragmentation.c | |||
@@ -564,8 +564,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
564 | { | 564 | { |
565 | dc->latency = estimate_latency (mc); | 565 | dc->latency = estimate_latency (mc); |
566 | } | 566 | } |
567 | delay = GNUNET_TIME_relative_multiply (dc->latency, | 567 | delay = GNUNET_TIME_relative_saturating_multiply (dc->latency, |
568 | bc + 1); | 568 | bc + 1); |
569 | if ( (last + fid == num_fragments) || | 569 | if ( (last + fid == num_fragments) || |
570 | (0 == mc->bits) || | 570 | (0 == mc->bits) || |
571 | (GNUNET_YES == duplicate) ) | 571 | (GNUNET_YES == duplicate) ) |
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c index eb0bad675..02444cf14 100644 --- a/src/fragmentation/fragmentation.c +++ b/src/fragmentation/fragmentation.c | |||
@@ -260,7 +260,7 @@ transmit_next (void *cls) | |||
260 | delay = GNUNET_TIME_UNIT_ZERO; | 260 | delay = GNUNET_TIME_UNIT_ZERO; |
261 | if (fc->num_rounds < 64) | 261 | if (fc->num_rounds < 64) |
262 | delay = GNUNET_TIME_relative_max (delay, | 262 | delay = GNUNET_TIME_relative_max (delay, |
263 | GNUNET_TIME_relative_multiply | 263 | GNUNET_TIME_relative_saturating_multiply |
264 | (fc->msg_delay, | 264 | (fc->msg_delay, |
265 | (1ULL << fc->num_rounds))); | 265 | (1ULL << fc->num_rounds))); |
266 | else | 266 | else |
@@ -269,7 +269,7 @@ transmit_next (void *cls) | |||
269 | { | 269 | { |
270 | /* full round transmitted wait 2x delay for ACK before going again */ | 270 | /* full round transmitted wait 2x delay for ACK before going again */ |
271 | fc->num_rounds++; | 271 | fc->num_rounds++; |
272 | delay = GNUNET_TIME_relative_multiply (fc->ack_delay, 2); | 272 | delay = GNUNET_TIME_relative_saturating_multiply (fc->ack_delay, 2); |
273 | /* never use zero, need some time for ACK always */ | 273 | /* never use zero, need some time for ACK always */ |
274 | delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay); | 274 | delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay); |
275 | fc->wack = GNUNET_YES; | 275 | fc->wack = GNUNET_YES; |
@@ -432,8 +432,8 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, | |||
432 | if (0 == ack_cnt) | 432 | if (0 == ack_cnt) |
433 | { | 433 | { |
434 | /* complete loss */ | 434 | /* complete loss */ |
435 | fc->msg_delay = GNUNET_TIME_relative_multiply (fc->msg_delay, | 435 | fc->msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay, |
436 | snd_cnt); | 436 | snd_cnt); |
437 | } | 437 | } |
438 | else if (snd_cnt > ack_cnt) | 438 | else if (snd_cnt > ack_cnt) |
439 | { | 439 | { |
@@ -515,8 +515,8 @@ GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc, | |||
515 | if (NULL != ack_delay) | 515 | if (NULL != ack_delay) |
516 | *ack_delay = fc->ack_delay; | 516 | *ack_delay = fc->ack_delay; |
517 | if (NULL != msg_delay) | 517 | if (NULL != msg_delay) |
518 | *msg_delay = GNUNET_TIME_relative_multiply (fc->msg_delay, | 518 | *msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay, |
519 | fc->num_rounds); | 519 | fc->num_rounds); |
520 | GNUNET_free (fc); | 520 | GNUNET_free (fc); |
521 | } | 521 | } |
522 | 522 | ||
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index 1e8af23c5..7e769483b 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -178,8 +178,8 @@ process_job_queue (void *cls) | |||
178 | break; | 178 | break; |
179 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 179 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
180 | run_time = | 180 | run_time = |
181 | GNUNET_TIME_relative_multiply (h->avg_block_latency, | 181 | GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency, |
182 | qe->blocks * qe->start_times); | 182 | qe->blocks * qe->start_times); |
183 | end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); | 183 | end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); |
184 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 184 | rst = GNUNET_TIME_absolute_get_remaining (end_time); |
185 | if (0 == rst.rel_value_us) | 185 | if (0 == rst.rel_value_us) |
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 7874bb6e0..198577b08 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -458,8 +458,8 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
458 | (unsigned long long) off, | 458 | (unsigned long long) off, |
459 | sr); | 459 | sr); |
460 | sr->remaining_probe_time = | 460 | sr->remaining_probe_time = |
461 | GNUNET_TIME_relative_multiply (sr->h->avg_block_latency, | 461 | GNUNET_TIME_relative_saturating_multiply (sr->h->avg_block_latency, |
462 | 2 * (1 + sr->availability_trials)); | 462 | 2 * (1 + sr->availability_trials)); |
463 | sr->probe_ctx = | 463 | sr->probe_ctx = |
464 | GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off, | 464 | GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off, |
465 | len, sr->anonymity, | 465 | len, sr->anonymity, |
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 96f86bf5d..cc0111111 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -29,9 +29,9 @@ | |||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | 31 | ||
32 | #define MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | 32 | #define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) |
33 | 33 | ||
34 | #define MAX_FREQUENCY GNUNET_TIME_UNIT_MINUTES | 34 | #define MIN_DELAY GNUNET_TIME_UNIT_MINUTES |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
@@ -672,11 +672,11 @@ schedule_next_task () | |||
672 | /* delay by at most 4h, at least 1s, and otherwise in between depending | 672 | /* delay by at most 4h, at least 1s, and otherwise in between depending |
673 | on how long it took to scan */ | 673 | on how long it took to scan */ |
674 | delay = GNUNET_TIME_absolute_get_duration (start_time); | 674 | delay = GNUNET_TIME_absolute_get_duration (start_time); |
675 | delay = GNUNET_TIME_relative_min (MIN_FREQUENCY, | 675 | delay = GNUNET_TIME_relative_saturating_multiply (delay, 100); |
676 | GNUNET_TIME_relative_multiply (delay, | 676 | delay = GNUNET_TIME_relative_min (delay, |
677 | 100)); | 677 | MAX_DELAY); |
678 | delay = GNUNET_TIME_relative_max (delay, | 678 | delay = GNUNET_TIME_relative_max (delay, |
679 | MAX_FREQUENCY); | 679 | MIN_DELAY); |
680 | run_task = GNUNET_SCHEDULER_add_delayed (delay, | 680 | run_task = GNUNET_SCHEDULER_add_delayed (delay, |
681 | &scan, | 681 | &scan, |
682 | NULL); | 682 | NULL); |
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index f8a7b61f0..63462f7dc 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -1036,7 +1036,7 @@ put_migration_continuation (void *cls, int success, | |||
1036 | ppd->migration_delay); | 1036 | ppd->migration_delay); |
1037 | mig_pause.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1037 | mig_pause.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1038 | ppd->migration_delay.rel_value_us); | 1038 | ppd->migration_delay.rel_value_us); |
1039 | ppd->migration_delay = GNUNET_TIME_relative_multiply (ppd->migration_delay, 2); | 1039 | ppd->migration_delay = GNUNET_TIME_relative_saturating_multiply (ppd->migration_delay, 2); |
1040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1041 | "Replicated content already exists locally, asking to stop migration for %s\n", | 1041 | "Replicated content already exists locally, asking to stop migration for %s\n", |
1042 | GNUNET_STRINGS_relative_time_to_string (mig_pause, | 1042 | GNUNET_STRINGS_relative_time_to_string (mig_pause, |
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 64c5769c6..224edc03e 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h | |||
@@ -421,6 +421,18 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
421 | 421 | ||
422 | 422 | ||
423 | /** | 423 | /** |
424 | * Saturating multiply relative time by a given factor. | ||
425 | * | ||
426 | * @param rel some duration | ||
427 | * @param factor integer to multiply with | ||
428 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor | ||
429 | */ | ||
430 | struct GNUNET_TIME_Relative | ||
431 | GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, | ||
432 | unsigned long long factor); | ||
433 | |||
434 | |||
435 | /** | ||
424 | * Divide relative time by a given factor. | 436 | * Divide relative time by a given factor. |
425 | * | 437 | * |
426 | * @param rel some duration | 438 | * @param rel some duration |
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index c5ecf3b4d..dfbcd388a 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -950,7 +950,7 @@ daemon_started (void *cls, | |||
950 | } | 950 | } |
951 | peers[search_peer].search_str = search_strings[peer->id]; | 951 | peers[search_peer].search_str = search_strings[peer->id]; |
952 | peers[search_peer].search_str_matched = GNUNET_NO; | 952 | peers[search_peer].search_str_matched = GNUNET_NO; |
953 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | 953 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_saturating_multiply( |
954 | reannounce_period_max, | 954 | reannounce_period_max, |
955 | 2), | 955 | 2), |
956 | &find_string, | 956 | &find_string, |
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 90aab93fd..9de1f8d3a 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -1508,7 +1508,7 @@ compute_rand_delay (struct GNUNET_TIME_Relative mean, | |||
1508 | * via multiplying round_interval with a 'fraction' (0 to value)/value | 1508 | * via multiplying round_interval with a 'fraction' (0 to value)/value |
1509 | */ | 1509 | */ |
1510 | rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); | 1510 | rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); |
1511 | ret = GNUNET_TIME_relative_multiply (mean, rand_delay); | 1511 | ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay); |
1512 | ret = GNUNET_TIME_relative_divide (ret, max_rand_delay); | 1512 | ret = GNUNET_TIME_relative_divide (ret, max_rand_delay); |
1513 | ret = GNUNET_TIME_relative_add (ret, half_interval); | 1513 | ret = GNUNET_TIME_relative_add (ret, half_interval); |
1514 | 1514 | ||
@@ -2394,7 +2394,7 @@ run (void *cls, | |||
2394 | struct GNUNET_TIME_Relative half_round_interval; | 2394 | struct GNUNET_TIME_Relative half_round_interval; |
2395 | struct GNUNET_TIME_Relative max_round_interval; | 2395 | struct GNUNET_TIME_Relative max_round_interval; |
2396 | 2396 | ||
2397 | half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5); | 2397 | half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2); |
2398 | max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval); | 2398 | max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval); |
2399 | 2399 | ||
2400 | prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); | 2400 | prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); |
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 |
diff --git a/src/vpn/vpn_api.c b/src/vpn/vpn_api.c index b22b805cd..4add41ce4 100644 --- a/src/vpn/vpn_api.c +++ b/src/vpn/vpn_api.c | |||
@@ -352,7 +352,7 @@ reconnect (struct GNUNET_VPN_Handle *vh) | |||
352 | for (rr = vh->rr_head; NULL != rr; rr = rr->next) | 352 | for (rr = vh->rr_head; NULL != rr; rr = rr->next) |
353 | rr->request_id = 0; | 353 | rr->request_id = 0; |
354 | vh->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, | 354 | vh->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, |
355 | GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (vh->backoff, 2), | 355 | GNUNET_TIME_relative_min (GNUNET_TIME_relative_saturating_multiply (vh->backoff, 2), |
356 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30))); | 356 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30))); |
357 | vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff, | 357 | vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff, |
358 | &connect_task, | 358 | &connect_task, |