GNUNET_assert(y <= (double) solver->parameters.step_time_max.rel_value_us);
GNUNET_assert(y >= (double) solver->parameters.step_time_min.rel_value_us);
- time_next = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y);
+ time_next = GNUNET_TIME_relative_saturating_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y);
// LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n",
// used_ratio,
if (0 != rel->expected_delay.rel_value_us)
{
rel->retry_timer =
- GNUNET_TIME_relative_multiply (rel->expected_delay,
- CADET_RETRANSMIT_MARGIN);
+ GNUNET_TIME_relative_saturating_multiply (rel->expected_delay,
+ CADET_RETRANSMIT_MARGIN);
}
else
{
struct GNUNET_TIME_Absolute new_target;
struct GNUNET_TIME_Relative delay;
- delay = GNUNET_TIME_relative_multiply (rel->retry_timer,
- CADET_RETRANSMIT_MARGIN);
+ delay = GNUNET_TIME_relative_saturating_multiply (rel->retry_timer,
+ CADET_RETRANSMIT_MARGIN);
new_target = GNUNET_TIME_absolute_add (rel->head_sent->timestamp,
delay);
delay = GNUNET_TIME_absolute_get_remaining (new_target);
{
if (1 > c->create_retry)
c->create_retry = 1;
- delay = GNUNET_TIME_relative_multiply (create_connection_time,
- c->create_retry);
+ delay = GNUNET_TIME_relative_saturating_multiply (create_connection_time,
+ c->create_retry);
if (c->create_retry < 64) // TODO make configurable
c->create_retry *= 2;
}
if (NULL != *ti)
GNUNET_SCHEDULER_cancel (*ti);
- delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 4);
+ delay = GNUNET_TIME_relative_saturating_multiply (refresh_connection_time, 4);
LOG (GNUNET_ERROR_TYPE_DEBUG,
" timing out in %s\n",
GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO));
if (NULL != c->check_duplicates_task)
return;
- delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
+ delay = GNUNET_TIME_relative_saturating_multiply (refresh_connection_time, 5);
c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
&check_duplicates,
c);
{
dc->latency = estimate_latency (mc);
}
- delay = GNUNET_TIME_relative_multiply (dc->latency,
- bc + 1);
+ delay = GNUNET_TIME_relative_saturating_multiply (dc->latency,
+ bc + 1);
if ( (last + fid == num_fragments) ||
(0 == mc->bits) ||
(GNUNET_YES == duplicate) )
delay = GNUNET_TIME_UNIT_ZERO;
if (fc->num_rounds < 64)
delay = GNUNET_TIME_relative_max (delay,
- GNUNET_TIME_relative_multiply
+ GNUNET_TIME_relative_saturating_multiply
(fc->msg_delay,
(1ULL << fc->num_rounds)));
else
{
/* full round transmitted wait 2x delay for ACK before going again */
fc->num_rounds++;
- delay = GNUNET_TIME_relative_multiply (fc->ack_delay, 2);
+ delay = GNUNET_TIME_relative_saturating_multiply (fc->ack_delay, 2);
/* never use zero, need some time for ACK always */
delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay);
fc->wack = GNUNET_YES;
if (0 == ack_cnt)
{
/* complete loss */
- fc->msg_delay = GNUNET_TIME_relative_multiply (fc->msg_delay,
- snd_cnt);
+ fc->msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay,
+ snd_cnt);
}
else if (snd_cnt > ack_cnt)
{
if (NULL != ack_delay)
*ack_delay = fc->ack_delay;
if (NULL != msg_delay)
- *msg_delay = GNUNET_TIME_relative_multiply (fc->msg_delay,
- fc->num_rounds);
+ *msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay,
+ fc->num_rounds);
GNUNET_free (fc);
}
break;
case GNUNET_FS_QUEUE_PRIORITY_NORMAL:
run_time =
- GNUNET_TIME_relative_multiply (h->avg_block_latency,
- qe->blocks * qe->start_times);
+ GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency,
+ qe->blocks * qe->start_times);
end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
rst = GNUNET_TIME_absolute_get_remaining (end_time);
if (0 == rst.rel_value_us)
(unsigned long long) off,
sr);
sr->remaining_probe_time =
- GNUNET_TIME_relative_multiply (sr->h->avg_block_latency,
- 2 * (1 + sr->availability_trials));
+ GNUNET_TIME_relative_saturating_multiply (sr->h->avg_block_latency,
+ 2 * (1 + sr->availability_trials));
sr->probe_ctx =
GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off,
len, sr->anonymity,
#include "platform.h"
#include "gnunet_util_lib.h"
-#define MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
+#define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
-#define MAX_FREQUENCY GNUNET_TIME_UNIT_MINUTES
+#define MIN_DELAY GNUNET_TIME_UNIT_MINUTES
/**
/* delay by at most 4h, at least 1s, and otherwise in between depending
on how long it took to scan */
delay = GNUNET_TIME_absolute_get_duration (start_time);
- delay = GNUNET_TIME_relative_min (MIN_FREQUENCY,
- GNUNET_TIME_relative_multiply (delay,
- 100));
+ delay = GNUNET_TIME_relative_saturating_multiply (delay, 100);
+ delay = GNUNET_TIME_relative_min (delay,
+ MAX_DELAY);
delay = GNUNET_TIME_relative_max (delay,
- MAX_FREQUENCY);
+ MIN_DELAY);
run_task = GNUNET_SCHEDULER_add_delayed (delay,
&scan,
NULL);
ppd->migration_delay);
mig_pause.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
ppd->migration_delay.rel_value_us);
- ppd->migration_delay = GNUNET_TIME_relative_multiply (ppd->migration_delay, 2);
+ ppd->migration_delay = GNUNET_TIME_relative_saturating_multiply (ppd->migration_delay, 2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Replicated content already exists locally, asking to stop migration for %s\n",
GNUNET_STRINGS_relative_time_to_string (mig_pause,
unsigned long long factor);
+/**
+ * Saturating multiply relative time by a given factor.
+ *
+ * @param rel some duration
+ * @param factor integer to multiply with
+ * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
+ */
+struct GNUNET_TIME_Relative
+GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel,
+ unsigned long long factor);
+
+
/**
* Divide relative time by a given factor.
*
}
peers[search_peer].search_str = search_strings[peer->id];
peers[search_peer].search_str_matched = GNUNET_NO;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_saturating_multiply(
reannounce_period_max,
2),
&find_string,
* via multiplying round_interval with a 'fraction' (0 to value)/value
*/
rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay);
- ret = GNUNET_TIME_relative_multiply (mean, rand_delay);
+ ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay);
ret = GNUNET_TIME_relative_divide (ret, max_rand_delay);
ret = GNUNET_TIME_relative_add (ret, half_interval);
struct GNUNET_TIME_Relative half_round_interval;
struct GNUNET_TIME_Relative max_round_interval;
- half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5);
+ half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2);
max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval);
prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval);
else
{
double factor = 1.0 * left_bytes / (double) av->available_bytes_per_s__;
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- (unsigned long long) factor);
+ delay = GNUNET_TIME_relative_saturating_multiply (GNUNET_TIME_UNIT_SECONDS,
+ (unsigned long long) factor);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %llu bps it will take us %s for %lld bytes to reach excess threshold\n",
}
+/**
+ * Saturating multiply relative time by a given factor.
+ *
+ * @param rel some duration
+ * @param factor integer to multiply with
+ * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
+ */
+struct GNUNET_TIME_Relative
+GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel,
+ unsigned long long factor)
+{
+ struct GNUNET_TIME_Relative ret;
+
+ if (0 == factor)
+ return GNUNET_TIME_UNIT_ZERO;
+ if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ ret.rel_value_us = rel.rel_value_us * factor;
+ if (ret.rel_value_us / factor != rel.rel_value_us)
+ {
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
+ return ret;
+}
+
+
/**
* Divide relative time by a given factor.
*
for (rr = vh->rr_head; NULL != rr; rr = rr->next)
rr->request_id = 0;
vh->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
- GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (vh->backoff, 2),
+ GNUNET_TIME_relative_min (GNUNET_TIME_relative_saturating_multiply (vh->backoff, 2),
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)));
vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff,
&connect_task,