mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Merge remote-tracking branch 'dgoulet/ticket21980_031_01'
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
* protocol.
|
||||
**/
|
||||
|
||||
#define HS_COMMON_PRIVATE
|
||||
|
||||
#include "or.h"
|
||||
|
||||
#include "config.h"
|
||||
@@ -50,6 +52,46 @@ hs_check_service_private_dir(const char *username, const char *path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Get the default HS time period length in minutes from the consensus. */
|
||||
STATIC uint64_t
|
||||
get_time_period_length(void)
|
||||
{
|
||||
int32_t time_period_length = networkstatus_get_param(NULL, "hsdir-interval",
|
||||
HS_TIME_PERIOD_LENGTH_DEFAULT,
|
||||
HS_TIME_PERIOD_LENGTH_MIN,
|
||||
HS_TIME_PERIOD_LENGTH_MAX);
|
||||
/* Make sure it's a positive value. */
|
||||
tor_assert(time_period_length >= 0);
|
||||
/* uint64_t will always be able to contain a int32_t */
|
||||
return (uint64_t) time_period_length;
|
||||
}
|
||||
|
||||
/** Get the HS time period number at time <b>now</b> */
|
||||
STATIC uint64_t
|
||||
get_time_period_num(time_t now)
|
||||
{
|
||||
uint64_t time_period_num;
|
||||
uint64_t time_period_length = get_time_period_length();
|
||||
uint64_t minutes_since_epoch = now / 60;
|
||||
|
||||
/* Now subtract half a day to fit the prop224 time period schedule (see
|
||||
* section [TIME-PERIODS]). */
|
||||
tor_assert(minutes_since_epoch > HS_TIME_PERIOD_ROTATION_OFFSET);
|
||||
minutes_since_epoch -= HS_TIME_PERIOD_ROTATION_OFFSET;
|
||||
|
||||
/* Calculate the time period */
|
||||
time_period_num = minutes_since_epoch / time_period_length;
|
||||
return time_period_num;
|
||||
}
|
||||
|
||||
/** Get the number of the _upcoming_ HS time period, given that the current
|
||||
* time is <b>now</b>. */
|
||||
uint64_t
|
||||
hs_get_next_time_period_num(time_t now)
|
||||
{
|
||||
return get_time_period_num(now) + 1;
|
||||
}
|
||||
|
||||
/* Create a new rend_data_t for a specific given <b>version</b>.
|
||||
* Return a pointer to the newly allocated data structure. */
|
||||
static rend_data_t *
|
||||
|
||||
@@ -40,6 +40,15 @@
|
||||
/* String prefix for the signature of ESTABLISH_INTRO */
|
||||
#define ESTABLISH_INTRO_SIG_PREFIX "Tor establish-intro cell v1"
|
||||
|
||||
/* The default HS time period length */
|
||||
#define HS_TIME_PERIOD_LENGTH_DEFAULT 1440 /* 1440 minutes == one day */
|
||||
/* The minimum time period length as seen in prop224 section [TIME-PERIODS] */
|
||||
#define HS_TIME_PERIOD_LENGTH_MIN 30 /* minutes */
|
||||
/* The minimum time period length as seen in prop224 section [TIME-PERIODS] */
|
||||
#define HS_TIME_PERIOD_LENGTH_MAX (60 * 24 * 10) /* 10 days or 14400 minutes */
|
||||
/* The time period rotation offset as seen in prop224 section [TIME-PERIODS] */
|
||||
#define HS_TIME_PERIOD_ROTATION_OFFSET (12 * 60) /* minutes */
|
||||
|
||||
int hs_check_service_private_dir(const char *username, const char *path,
|
||||
unsigned int dir_group_readable,
|
||||
unsigned int create);
|
||||
@@ -60,5 +69,18 @@ const char *rend_data_get_desc_id(const rend_data_t *rend_data,
|
||||
const uint8_t *rend_data_get_pk_digest(const rend_data_t *rend_data,
|
||||
size_t *len_out);
|
||||
|
||||
uint64_t hs_get_next_time_period_num(time_t now);
|
||||
|
||||
#ifdef HS_COMMON_PRIVATE
|
||||
|
||||
#ifdef TOR_UNIT_TESTS
|
||||
|
||||
STATIC uint64_t get_time_period_length(void);
|
||||
STATIC uint64_t get_time_period_num(time_t now);
|
||||
|
||||
#endif /* TOR_UNIT_TESTS */
|
||||
|
||||
#endif /* HS_COMMON_PRIVATE */
|
||||
|
||||
#endif /* TOR_HS_COMMON_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user