mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
Preparatory indentation changes
Deindent a block of code inside the PublishHidServDescriptors option check in upload_service_descriptor(). Stylistic commit to make the subsequent reworking of this code cleaner.
This commit is contained in:
parent
af3be650e3
commit
968cb95602
1 changed files with 68 additions and 68 deletions
|
@ -3217,37 +3217,70 @@ upload_service_descriptor(rend_service_t *service)
|
|||
|
||||
/* Upload descriptor? */
|
||||
if (get_options()->PublishHidServDescriptors) {
|
||||
networkstatus_t *c = networkstatus_get_latest_consensus();
|
||||
if (c && smartlist_len(c->routerstatus_list) > 0) {
|
||||
int seconds_valid, i, j, num_descs;
|
||||
smartlist_t *descs = smartlist_new();
|
||||
smartlist_t *client_cookies = smartlist_new();
|
||||
/* Either upload a single descriptor (including replicas) or one
|
||||
* descriptor for each authorized client in case of authorization
|
||||
* type 'stealth'. */
|
||||
num_descs = service->auth_type == REND_STEALTH_AUTH ?
|
||||
smartlist_len(service->clients) : 1;
|
||||
for (j = 0; j < num_descs; j++) {
|
||||
crypto_pk_t *client_key = NULL;
|
||||
rend_authorized_client_t *client = NULL;
|
||||
smartlist_clear(client_cookies);
|
||||
switch (service->auth_type) {
|
||||
case REND_NO_AUTH:
|
||||
/* Do nothing here. */
|
||||
break;
|
||||
case REND_BASIC_AUTH:
|
||||
SMARTLIST_FOREACH(service->clients, rend_authorized_client_t *,
|
||||
cl, smartlist_add(client_cookies, cl->descriptor_cookie));
|
||||
break;
|
||||
case REND_STEALTH_AUTH:
|
||||
client = smartlist_get(service->clients, j);
|
||||
client_key = client->client_key;
|
||||
smartlist_add(client_cookies, client->descriptor_cookie);
|
||||
break;
|
||||
}
|
||||
/* Encode the current descriptor. */
|
||||
networkstatus_t *c = networkstatus_get_latest_consensus();
|
||||
if (c && smartlist_len(c->routerstatus_list) > 0) {
|
||||
int seconds_valid, i, j, num_descs;
|
||||
smartlist_t *descs = smartlist_new();
|
||||
smartlist_t *client_cookies = smartlist_new();
|
||||
/* Either upload a single descriptor (including replicas) or one
|
||||
* descriptor for each authorized client in case of authorization
|
||||
* type 'stealth'. */
|
||||
num_descs = service->auth_type == REND_STEALTH_AUTH ?
|
||||
smartlist_len(service->clients) : 1;
|
||||
for (j = 0; j < num_descs; j++) {
|
||||
crypto_pk_t *client_key = NULL;
|
||||
rend_authorized_client_t *client = NULL;
|
||||
smartlist_clear(client_cookies);
|
||||
switch (service->auth_type) {
|
||||
case REND_NO_AUTH:
|
||||
/* Do nothing here. */
|
||||
break;
|
||||
case REND_BASIC_AUTH:
|
||||
SMARTLIST_FOREACH(service->clients, rend_authorized_client_t *,
|
||||
cl, smartlist_add(client_cookies, cl->descriptor_cookie));
|
||||
break;
|
||||
case REND_STEALTH_AUTH:
|
||||
client = smartlist_get(service->clients, j);
|
||||
client_key = client->client_key;
|
||||
smartlist_add(client_cookies, client->descriptor_cookie);
|
||||
break;
|
||||
}
|
||||
/* Encode the current descriptor. */
|
||||
seconds_valid = rend_encode_v2_descriptors(descs, service->desc,
|
||||
now, 0,
|
||||
service->auth_type,
|
||||
client_key,
|
||||
client_cookies);
|
||||
if (seconds_valid < 0) {
|
||||
log_warn(LD_BUG, "Internal error: couldn't encode service "
|
||||
"descriptor; not uploading.");
|
||||
smartlist_free(descs);
|
||||
smartlist_free(client_cookies);
|
||||
return;
|
||||
}
|
||||
/* Post the current descriptors to the hidden service directories. */
|
||||
rend_get_service_id(service->desc->pk, serviceid);
|
||||
log_info(LD_REND, "Launching upload for hidden service %s",
|
||||
serviceid);
|
||||
directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
|
||||
seconds_valid);
|
||||
/* Free memory for descriptors. */
|
||||
for (i = 0; i < smartlist_len(descs); i++)
|
||||
rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
|
||||
smartlist_clear(descs);
|
||||
/* Update next upload time. */
|
||||
if (seconds_valid - REND_TIME_PERIOD_OVERLAPPING_V2_DESCS
|
||||
> rendpostperiod)
|
||||
service->next_upload_time = now + rendpostperiod;
|
||||
else if (seconds_valid < REND_TIME_PERIOD_OVERLAPPING_V2_DESCS)
|
||||
service->next_upload_time = now + seconds_valid + 1;
|
||||
else
|
||||
service->next_upload_time = now + seconds_valid -
|
||||
REND_TIME_PERIOD_OVERLAPPING_V2_DESCS + 1;
|
||||
/* Post also the next descriptors, if necessary. */
|
||||
if (seconds_valid < REND_TIME_PERIOD_OVERLAPPING_V2_DESCS) {
|
||||
seconds_valid = rend_encode_v2_descriptors(descs, service->desc,
|
||||
now, 0,
|
||||
now, 1,
|
||||
service->auth_type,
|
||||
client_key,
|
||||
client_cookies);
|
||||
|
@ -3258,52 +3291,19 @@ upload_service_descriptor(rend_service_t *service)
|
|||
smartlist_free(client_cookies);
|
||||
return;
|
||||
}
|
||||
/* Post the current descriptors to the hidden service directories. */
|
||||
rend_get_service_id(service->desc->pk, serviceid);
|
||||
log_info(LD_REND, "Launching upload for hidden service %s",
|
||||
serviceid);
|
||||
directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
|
||||
seconds_valid);
|
||||
/* Free memory for descriptors. */
|
||||
for (i = 0; i < smartlist_len(descs); i++)
|
||||
rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
|
||||
smartlist_clear(descs);
|
||||
/* Update next upload time. */
|
||||
if (seconds_valid - REND_TIME_PERIOD_OVERLAPPING_V2_DESCS
|
||||
> rendpostperiod)
|
||||
service->next_upload_time = now + rendpostperiod;
|
||||
else if (seconds_valid < REND_TIME_PERIOD_OVERLAPPING_V2_DESCS)
|
||||
service->next_upload_time = now + seconds_valid + 1;
|
||||
else
|
||||
service->next_upload_time = now + seconds_valid -
|
||||
REND_TIME_PERIOD_OVERLAPPING_V2_DESCS + 1;
|
||||
/* Post also the next descriptors, if necessary. */
|
||||
if (seconds_valid < REND_TIME_PERIOD_OVERLAPPING_V2_DESCS) {
|
||||
seconds_valid = rend_encode_v2_descriptors(descs, service->desc,
|
||||
now, 1,
|
||||
service->auth_type,
|
||||
client_key,
|
||||
client_cookies);
|
||||
if (seconds_valid < 0) {
|
||||
log_warn(LD_BUG, "Internal error: couldn't encode service "
|
||||
"descriptor; not uploading.");
|
||||
smartlist_free(descs);
|
||||
smartlist_free(client_cookies);
|
||||
return;
|
||||
}
|
||||
directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
|
||||
seconds_valid);
|
||||
/* Free memory for descriptors. */
|
||||
for (i = 0; i < smartlist_len(descs); i++)
|
||||
rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
|
||||
smartlist_clear(descs);
|
||||
}
|
||||
}
|
||||
smartlist_free(descs);
|
||||
smartlist_free(client_cookies);
|
||||
uploaded = 1;
|
||||
log_info(LD_REND, "Successfully uploaded v2 rend descriptors!");
|
||||
}
|
||||
smartlist_free(descs);
|
||||
smartlist_free(client_cookies);
|
||||
uploaded = 1;
|
||||
log_info(LD_REND, "Successfully uploaded v2 rend descriptors!");
|
||||
}
|
||||
}
|
||||
|
||||
/* If not uploaded, try again in one minute. */
|
||||
|
|
Loading…
Add table
Reference in a new issue