Skip to content

Commit

Permalink
hs-v3: Implement HS_DESC UPLOAD event
Browse files Browse the repository at this point in the history
Signed-off-by: David Goulet <[email protected]>
  • Loading branch information
dgoulet-tor authored and nmathewson committed Dec 6, 2017
1 parent b71a9b6 commit c7050ea
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/or/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -7286,17 +7286,26 @@ control_event_hs_descriptor_created(const char *onion_address,
void
control_event_hs_descriptor_upload(const char *onion_address,
const char *id_digest,
const char *desc_id)
const char *desc_id,
const char *hsdir_index)
{
char *hsdir_index_field = NULL;

if (BUG(!onion_address || !id_digest || !desc_id)) {
return;
}

if (hsdir_index) {
tor_asprintf(&hsdir_index_field, " HSDIR_INDEX=%s", hsdir_index);
}

send_control_event(EVENT_HS_DESC,
"650 HS_DESC UPLOAD %s UNKNOWN %s %s\r\n",
"650 HS_DESC UPLOAD %s UNKNOWN %s %s%s\r\n",
onion_address,
node_describe_longname_by_id(id_digest),
desc_id);
desc_id,
hsdir_index_field ? hsdir_index_field : "");
tor_free(hsdir_index_field);
}

/** send HS_DESC event after got response from hs directory.
Expand Down
3 changes: 2 additions & 1 deletion src/or/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ void control_event_hs_descriptor_created(const char *onion_address,
int replica);
void control_event_hs_descriptor_upload(const char *onion_address,
const char *desc_id,
const char *hs_dir);
const char *hs_dir,
const char *hsdir_index);
void control_event_hs_descriptor_upload_end(const char *action,
const char *onion_address,
const char *hs_dir,
Expand Down
29 changes: 29 additions & 0 deletions src/or/hs_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,32 @@ hs_control_desc_event_created(const char *onion_address,
control_event_hs_descriptor_created(onion_address, base64_blinded_pk, -1);
}

/* Send on the control port the "HS_DESC UPLOAD [...]" event.
*
* Using the onion address of the descriptor's service, the HSDir identity
* digest, the blinded public key of the descriptor as a descriptor ID and the
* HSDir index for this particular request. None can be NULL. */
void
hs_control_desc_event_upload(const char *onion_address,
const char *hsdir_id_digest,
const ed25519_public_key_t *blinded_pk,
const uint8_t *hsdir_index)
{
char base64_blinded_pk[ED25519_BASE64_LEN + 1];

tor_assert(onion_address);
tor_assert(hsdir_id_digest);
tor_assert(blinded_pk);
tor_assert(hsdir_index);

/* Build base64 encoded blinded key. */
IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, blinded_pk) < 0) {
return;
}

control_event_hs_descriptor_upload(onion_address, hsdir_id_digest,
base64_blinded_pk,
hex_str((const char *) hsdir_index,
DIGEST256_LEN));
}

6 changes: 6 additions & 0 deletions src/or/hs_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident,
void hs_control_desc_event_created(const char *onion_address,
const ed25519_public_key_t *blinded_pk);

/* Event "HS_DESC UPLOAD [...]" */
void hs_control_desc_event_upload(const char *onion_address,
const char *hsdir_id_digest,
const ed25519_public_key_t *blinded_pk,
const uint8_t *hsdir_index);

#endif /* !defined(TOR_HS_CONTROL_H) */

5 changes: 4 additions & 1 deletion src/or/hs_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2267,9 +2267,12 @@ upload_descriptor_to_hsdir(const hs_service_t *service,
desc->desc->plaintext_data.revision_counter,
safe_str_client(node_describe(hsdir)),
safe_str_client(hex_str((const char *) index, 32)));

/* Fire a UPLOAD control port event. */
hs_control_desc_event_upload(service->onion_address, hsdir->identity,
&desc->blinded_kp.pubkey, index);
}

/* XXX: Inform control port of the upload event (#20699). */
end:
tor_free(encoded_desc);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/or/rendservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -3574,7 +3574,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
"directories to post descriptors to.");
control_event_hs_descriptor_upload(service_id,
"UNKNOWN",
"UNKNOWN");
"UNKNOWN", NULL);
goto done;
}
}
Expand Down Expand Up @@ -3629,7 +3629,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
hs_dir->or_port);
control_event_hs_descriptor_upload(service_id,
hs_dir->identity_digest,
desc_id_base32);
desc_id_base32, NULL);
tor_free(hs_dir_ip);
/* Remember successful upload to this router for next time. */
if (!smartlist_contains_digest(successful_uploads,
Expand Down

0 comments on commit c7050ea

Please sign in to comment.