/* Get start time of next TP and of current SRV protocol run, and check if we
* are between them. */
valid_after = consensus->valid_after;
- srv_start_time =
- sr_state_get_start_time_of_current_protocol_run(valid_after);
+ srv_start_time = sr_state_get_start_time_of_current_protocol_run();
tp_start_time = hs_get_start_time_of_next_time_period(srv_start_time);
if (valid_after >= srv_start_time && valid_after < tp_start_time) {
/* Set the next rotation time of the descriptors for the given service for the
* time now. */
static void
-set_rotation_time(hs_service_t *service, time_t now)
+set_rotation_time(hs_service_t *service)
{
- time_t valid_after;
- const networkstatus_t *ns = networkstatus_get_live_consensus(now);
- if (ns) {
- valid_after = ns->valid_after;
- } else {
- valid_after = now;
- }
-
tor_assert(service);
+
service->state.next_rotation_time =
- sr_state_get_start_time_of_current_protocol_run(valid_after) +
+ sr_state_get_start_time_of_current_protocol_run() +
sr_state_get_protocol_run_duration();
{
* will be freed, the next one put in as the current and finally the next
* descriptor pointer is NULLified. */
static void
-rotate_service_descriptors(hs_service_t *service, time_t now)
+rotate_service_descriptors(hs_service_t *service)
{
if (service->desc_current) {
/* Close all IP circuits for the descriptor. */
service->desc_next = NULL;
/* We've just rotated, set the next time for the rotation. */
- set_rotation_time(service, now);
+ set_rotation_time(service);
}
/* Rotate descriptors for each service if needed. A non existing current
service->desc_current, service->desc_next,
safe_str_client(service->onion_address));
- rotate_service_descriptors(service, now);
+ rotate_service_descriptors(service);
} FOR_EACH_SERVICE_END;
}
/* Set the next rotation time of the descriptors. If it's Oct 25th
* 23:47:00, the next rotation time is when the next SRV is computed
* which is at Oct 26th 00:00:00 that is in 13 minutes. */
- set_rotation_time(service, now);
+ set_rotation_time(service);
}
/* Cleanup invalid intro points from the service descriptor. */
* time of the current protocol run.
*/
if (is_current) {
- srv_start = sr_state_get_start_time_of_previous_protocol_run(now);
+ srv_start = sr_state_get_start_time_of_previous_protocol_run();
} else {
- srv_start = sr_state_get_start_time_of_current_protocol_run(now);
+ srv_start = sr_state_get_start_time_of_current_protocol_run();
}
log_info(LD_REND, "Setting rev counter for TP #%u: "
return srv;
}
-/** Return the start time of the current SR protocol run. For example, if the
- * time is 23/06/2017 23:47:08 and a full SR protocol run is 24 hours, this
- * function should return 23/06/2017 00:00:00. */
+/** Return the start time of the current SR protocol run using the times from
+ * the current consensus. For example, if the latest consensus valid-after is
+ * 23/06/2017 23:00:00 and a full SR protocol run is 24 hours, this function
+ * returns 23/06/2017 00:00:00. */
time_t
-sr_state_get_start_time_of_current_protocol_run(time_t now)
+sr_state_get_start_time_of_current_protocol_run(void)
{
int total_rounds = SHARED_RANDOM_N_ROUNDS * SHARED_RANDOM_N_PHASES;
int voting_interval = get_voting_interval();
/* Find the time the current round started. */
- time_t beginning_of_current_round = get_start_time_of_current_round();
+ time_t beginning_of_curr_round = get_start_time_of_current_round();
/* Get current SR protocol round */
- int current_round = (now / voting_interval) % total_rounds;
+ int curr_round_slot;
+ curr_round_slot = (beginning_of_curr_round / voting_interval) % total_rounds;
/* Get start time by subtracting the time elapsed from the beginning of the
protocol run */
- time_t time_elapsed_since_start_of_run = current_round * voting_interval;
- return beginning_of_current_round - time_elapsed_since_start_of_run;
+ time_t time_elapsed_since_start_of_run = curr_round_slot * voting_interval;
+
+ log_debug(LD_GENERAL, "Current SRV proto run: Start of current round: %u. "
+ "Time elapsed: %u (%d)", (unsigned) beginning_of_curr_round,
+ (unsigned) time_elapsed_since_start_of_run, voting_interval);
+
+ return beginning_of_curr_round - time_elapsed_since_start_of_run;
}
/** Return the start time of the previous SR protocol run. See
* sr_state_get_start_time_of_current_protocol_run() for more details. */
time_t
-sr_state_get_start_time_of_previous_protocol_run(time_t now)
+sr_state_get_start_time_of_previous_protocol_run(void)
{
time_t start_time_of_current_run =
- sr_state_get_start_time_of_current_protocol_run(now);
+ sr_state_get_start_time_of_current_protocol_run();
/* We get the start time of previous protocol run, by getting the start time
* of current run and the subtracting a full protocol run from that. */
/* Number of phase we have in a protocol. */
#define SHARED_RANDOM_N_PHASES 2
-time_t sr_state_get_start_time_of_current_protocol_run(time_t now);
-time_t sr_state_get_start_time_of_previous_protocol_run(time_t now);
+time_t sr_state_get_start_time_of_current_protocol_run(void);
+time_t sr_state_get_start_time_of_previous_protocol_run(void);
unsigned int sr_state_get_phase_duration(void);
unsigned int sr_state_get_protocol_run_duration(void);
time_t get_start_time_of_current_round(void);
&mock_service_ns->fresh_until);
voting_schedule_recalculate_timing(get_options(),
mock_service_ns->valid_after);
+ /* Check that service is in the right time period point */
+ tt_int_op(hs_in_period_between_tp_and_srv(mock_service_ns, 0), OP_EQ,
+ cfg->service_in_new_tp);
+
/* Set client consensus time. */
set_consensus_times(cfg->client_valid_after,
&mock_client_ns->valid_after);
&mock_client_ns->fresh_until);
voting_schedule_recalculate_timing(get_options(),
mock_client_ns->valid_after);
-
- /* New time period checks for this scenario. */
- tt_int_op(hs_in_period_between_tp_and_srv(mock_service_ns, 0), OP_EQ,
- cfg->service_in_new_tp);
+ /* Check that client is in the right time period point */
tt_int_op(hs_in_period_between_tp_and_srv(mock_client_ns, 0), OP_EQ,
cfg->client_in_new_tp);
¤t_time);
tt_int_op(retval, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), current_time);
- run_start_time =
- sr_state_get_start_time_of_current_protocol_run(current_time);
+ run_start_time = sr_state_get_start_time_of_current_protocol_run();
/* Compare it with the correct result */
format_iso_time(tbuf, run_start_time);
¤t_time);
tt_int_op(retval, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), current_time);
- run_start_time =
- sr_state_get_start_time_of_current_protocol_run(current_time);
+ run_start_time = sr_state_get_start_time_of_current_protocol_run();
/* Compare it with the correct result */
format_iso_time(tbuf, run_start_time);
¤t_time);
tt_int_op(retval, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), current_time);
- run_start_time =
- sr_state_get_start_time_of_current_protocol_run(current_time);
+ run_start_time = sr_state_get_start_time_of_current_protocol_run();
/* Compare it with the correct result */
format_iso_time(tbuf, run_start_time);
¤t_time);
tt_int_op(retval, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), current_time);
- run_start_time =
- sr_state_get_start_time_of_current_protocol_run(current_time);
+ run_start_time = sr_state_get_start_time_of_current_protocol_run();
/* Compare it with the correct result */
format_iso_time(tbuf, run_start_time);
voting_schedule_recalculate_timing(get_options(), now);
time_t start_time_of_protocol_run =
- sr_state_get_start_time_of_current_protocol_run(now);
+ sr_state_get_start_time_of_current_protocol_run();
tt_assert(start_time_of_protocol_run);
/* Check that the round start time of the beginning of the run, is itself */