prop224: Move service version into config object

It makes more sense to have the version in the configuration object of the
service because it is afterall a torrc option (HiddenServiceVersion).

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2017-07-13 08:51:14 -04:00
parent 3eeebd1b0c
commit 5d64ceb12d
4 changed files with 18 additions and 15 deletions

View File

@ -55,7 +55,7 @@ stage_services(smartlist_t *service_list)
* only >= v3 service. And remember, v2 has a different object type which is
* shadow copied from an hs_service_t type. */
SMARTLIST_FOREACH_BEGIN(service_list, hs_service_t *, s) {
if (s->version == HS_VERSION_TWO) {
if (s->config.version == HS_VERSION_TWO) {
SMARTLIST_DEL_CURRENT(service_list, s);
hs_service_free(s);
}
@ -157,7 +157,7 @@ config_has_invalid_options(const config_line_t *line_,
const config_line_t *line;
tor_assert(service);
tor_assert(service->version <= HS_VERSION_MAX);
tor_assert(service->config.version <= HS_VERSION_MAX);
/* List of options that a v3 service doesn't support thus must exclude from
* its configuration. */
@ -178,7 +178,7 @@ config_has_invalid_options(const config_line_t *line_,
{ opts_exclude_v3 }, /* v3. */
};
optlist = exclude_lists[service->version].list;
optlist = exclude_lists[service->config.version].list;
if (optlist == NULL) {
/* No exclude options to look at for this version. */
goto end;
@ -193,7 +193,8 @@ config_has_invalid_options(const config_line_t *line_,
if (!strcasecmp(line->key, opt)) {
log_warn(LD_CONFIG, "Hidden service option %s is incompatible with "
"version %" PRIu32 " of service in %s",
opt, service->version, service->config.directory_path);
opt, service->config.version,
service->config.directory_path);
ret = 1;
/* Continue the loop so we can find all possible options. */
continue;
@ -342,7 +343,7 @@ config_generic_service(const config_line_t *line_,
}
/* Version of the service. */
if (!strcasecmp(line->key, "HiddenServiceVersion")) {
service->version =
service->config.version =
(uint32_t) helper_parse_uint64(line->key, line->value, HS_VERSION_MIN,
HS_VERSION_MAX, &ok);
if (!ok || have_version) {
@ -462,7 +463,7 @@ config_service(const config_line_t *line, const or_options_t *options,
if (config_generic_service(line, options, service) < 0) {
goto err;
}
tor_assert(service->version <= HS_VERSION_MAX);
tor_assert(service->config.version <= HS_VERSION_MAX);
/* Before we configure the service on a per-version basis, we'll make
* sure that this set of options for a service are valid that is for
* instance an option only for v2 is not used for v3. */
@ -482,7 +483,7 @@ config_service(const config_line_t *line, const or_options_t *options,
/* Different functions are in charge of specific options for a version. We
* start just after the service directory line so once we hit another
* directory line, the function knows that it has to stop parsing. */
switch (service->version) {
switch (service->config.version) {
case HS_VERSION_TWO:
ret = rend_config_service(line->next, options, &service->config);
break;

View File

@ -250,7 +250,7 @@ close_service_circuits(hs_service_t *service)
tor_assert(service);
/* Only support for version >= 3. */
if (BUG(service->version < HS_VERSION_THREE)) {
if (BUG(service->config.version < HS_VERSION_THREE)) {
return;
}
/* Close intro points. */
@ -492,8 +492,9 @@ load_service_keys(hs_service_t *service)
ed25519_keypair_free(kp);
/* Build onion address from the newly loaded keys. */
tor_assert(service->version <= UINT8_MAX);
hs_build_address(&service->keys.identity_pk, (uint8_t) service->version,
tor_assert(service->config.version <= UINT8_MAX);
hs_build_address(&service->keys.identity_pk,
(uint8_t) service->config.version,
service->onion_address);
/* Write onion address to hostname file. */
@ -572,7 +573,7 @@ hs_service_new(const or_options_t *options)
/* Set default configuration value. */
set_service_default_config(&service->config, options);
/* Set the default service version. */
service->version = HS_SERVICE_DEFAULT_VERSION;
service->config.version = HS_SERVICE_DEFAULT_VERSION;
return service;
}

View File

@ -112,6 +112,10 @@ typedef struct hs_service_keys_t {
* set by the configuration file or by the control port. Nothing else should
* change those values. */
typedef struct hs_service_config_t {
/* Protocol version of the service. Specified by HiddenServiceVersion
* option. */
uint32_t version;
/* List of rend_service_port_config_t */
smartlist_t *ports;
@ -170,9 +174,6 @@ typedef struct hs_service_state_t {
/* Representation of a service running on this tor instance. */
typedef struct hs_service_t {
/* Protocol version of the service. Specified by HiddenServiceVersion. */
uint32_t version;
/* Onion address base32 encoded and NUL terminated. We keep it for logging
* purposes so we don't have to build it everytime. */
char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1];

View File

@ -471,7 +471,7 @@ test_load_keys(void *arg)
tt_assert(!tor_mem_is_zero((char *) s->keys.identity_pk.pubkey,
ED25519_PUBKEY_LEN));
/* Check onion address from identity key. */
hs_build_address(&s->keys.identity_pk, s->version, addr);
hs_build_address(&s->keys.identity_pk, s->config.version, addr);
tt_int_op(hs_address_is_valid(addr), OP_EQ, 1);
tt_str_op(addr, OP_EQ, s->onion_address);