diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-08-19 15:41:28 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-08-19 15:41:28 +0000 |
commit | 24f1d29be17eef10c308049f484af1fc85a10696 (patch) | |
tree | c22c3879e8f5e730fbfa53c48549d2723f9b2c46 /src/or/rendservice.c | |
parent | 0711408c2280b9b5c284061a81c9e34836429e7f (diff) | |
download | tor-24f1d29be17eef10c308049f484af1fc85a10696.tar.gz tor-24f1d29be17eef10c308049f484af1fc85a10696.zip |
Apply proposal 121 patch 3, with minor tweaks and a few comments.
svn:r16598
Diffstat (limited to 'src/or/rendservice.c')
-rw-r--r-- | src/or/rendservice.c | 103 |
1 files changed, 68 insertions, 35 deletions
diff --git a/src/or/rendservice.c b/src/or/rendservice.c index b6b929f6f7..5f0430bef0 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -487,9 +487,8 @@ rend_service_update_descriptor(rend_service_t *service) d->timestamp = time(NULL); d->version = service->descriptor_version; d->intro_nodes = smartlist_create(); - /* Whoever understands descriptor version 2 also understands intro - * protocol 2. So we only support 2. */ - d->protocols = 1 << 2; + /* Support intro protocols 2 and 3. */ + d->protocols = (1 << 2) + (1 << 3); for (i = 0; i < smartlist_len(service->intro_nodes); ++i) { rend_intro_point_t *intro_svc = smartlist_get(service->intro_nodes, i); @@ -1446,52 +1445,86 @@ upload_service_descriptor(rend_service_t *service) get_options()->PublishHidServDescriptors) { networkstatus_t *c = networkstatus_get_latest_consensus(); if (c && smartlist_len(c->routerstatus_list) > 0) { - int seconds_valid; + int seconds_valid, i, j, num_descs; smartlist_t *descs = smartlist_create(); - int i; - /* Encode the current descriptor. */ - seconds_valid = rend_encode_v2_descriptors(descs, service->desc, now, - NULL, 0); - if (seconds_valid < 0) { - log_warn(LD_BUG, "Internal error: couldn't encode service descriptor; " - "not uploading."); - smartlist_free(descs); - return; - } - /* Post the current descriptors to the hidden service directories. */ - rend_get_service_id(service->desc->pk, serviceid); - log_info(LD_REND, "Sending publish request for hidden service %s", - serviceid); - directory_post_to_hs_dir(descs, 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) { + smartlist_t *client_cookies = smartlist_create(); + /* 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_env_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, NULL, 1); + 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, "Sending publish request for hidden service %s", + serviceid); directory_post_to_hs_dir(descs, 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(descs, 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!"); } |