summaryrefslogtreecommitdiff
path: root/src/or/rendservice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/rendservice.c')
-rw-r--r--src/or/rendservice.c109
1 files changed, 52 insertions, 57 deletions
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 0cda1d95c0..45454985ed 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -11,8 +11,8 @@ const char rendservice_c_id[] =
#include "or.h"
-static origin_circuit_t *find_intro_circuit(routerinfo_t *router,
- const char *pk_digest);
+static circuit_t *find_intro_circuit(routerinfo_t *router,
+ const char *pk_digest);
/** Represents the mapping from a virtual port of a rendezvous service to
* a real port on some IP.
@@ -179,7 +179,7 @@ parse_port_config(const char *string)
} else {
addrport = smartlist_get(sl,1);
if (strchr(addrport, ':') || strchr(addrport, '.')) {
- if (parse_addr_port(LOG_WARN, addrport, NULL, &addr, &p)<0) {
+ if (parse_addr_port(addrport, NULL, &addr, &p)<0) {
log_warn(LD_CONFIG,"Unparseable address in hidden service port "
"configuration.");
goto err;
@@ -285,7 +285,7 @@ static void
rend_service_update_descriptor(rend_service_t *service)
{
rend_service_descriptor_t *d;
- origin_circuit_t *circ;
+ circuit_t *circ;
int i,n;
routerinfo_t *router;
@@ -310,7 +310,7 @@ rend_service_update_descriptor(rend_service_t *service)
continue;
}
circ = find_intro_circuit(router, service->pk_digest);
- if (circ && circ->_base.purpose == CIRCUIT_PURPOSE_S_INTRO) {
+ if (circ && circ->purpose == CIRCUIT_PURPOSE_S_INTRO) {
/* We have an entirely established intro circuit. */
d->intro_points[d->n_intro_points] = tor_strdup(router->nickname);
d->intro_point_extend_info[d->n_intro_points] =
@@ -410,7 +410,7 @@ rend_service_requires_uptime(rend_service_t *service)
* rendezvous point.
*/
int
-rend_service_introduce(origin_circuit_t *circuit, const char *request,
+rend_service_introduce(circuit_t *circuit, const char *request,
size_t request_len)
{
char *ptr, *r_cookie;
@@ -421,7 +421,7 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
int r, i;
size_t len, keylen;
crypto_dh_env_t *dh = NULL;
- origin_circuit_t *launched = NULL;
+ circuit_t *launched = NULL;
crypt_path_t *cpath = NULL;
char serviceid[REND_SERVICE_ID_LEN+1];
char hexcookie[9];
@@ -430,12 +430,12 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
circuit->rend_pk_digest,10);
log_info(LD_REND, "Received INTRODUCE2 cell for service %s on circ %d.",
- escaped(serviceid), circuit->_base.n_circ_id);
+ escaped(serviceid), circuit->n_circ_id);
- if (circuit->_base.purpose != CIRCUIT_PURPOSE_S_INTRO) {
+ if (circuit->purpose != CIRCUIT_PURPOSE_S_INTRO) {
log_warn(LD_PROTOCOL,
"Got an INTRODUCE2 over a non-introduction circuit %d.",
- circuit->_base.n_circ_id);
+ circuit->n_circ_id);
return -1;
}
@@ -443,7 +443,7 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
if (request_len < DIGEST_LEN+REND_COOKIE_LEN+(MAX_NICKNAME_LEN+1)+
DH_KEY_LEN+42) {
log_warn(LD_PROTOCOL, "Got a truncated INTRODUCE2 cell on circ %d.",
- circuit->_base.n_circ_id);
+ circuit->n_circ_id);
return -1;
}
@@ -518,7 +518,7 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
ptr=memchr(rp_nickname,0,nickname_field_len);
if (!ptr || ptr == rp_nickname) {
log_warn(LD_PROTOCOL,
- "Couldn't find a nul-padded nickname in INTRODUCE2 cell.");
+ "Couldn't find a null-padded nickname in INTRODUCE2 cell.");
return -1;
}
if ((version == 0 && !is_legal_nickname(rp_nickname)) ||
@@ -609,8 +609,7 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
return 0;
err:
if (dh) crypto_dh_free(dh);
- if (launched)
- circuit_mark_for_close(TO_CIRCUIT(launched), END_CIRC_AT_ORIGIN);
+ if (launched) circuit_mark_for_close(launched, END_CIRC_AT_ORIGIN);
if (extend_info) extend_info_free(extend_info);
return -1;
}
@@ -619,12 +618,12 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
* than the last hop: launches a new circuit to the same rendezvous point.
*/
void
-rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc)
+rend_service_relaunch_rendezvous(circuit_t *oldcirc)
{
- origin_circuit_t *newcirc;
+ circuit_t *newcirc;
cpath_build_state_t *newstate, *oldstate;
- tor_assert(oldcirc->_base.purpose == CIRCUIT_PURPOSE_S_CONNECT_REND);
+ tor_assert(oldcirc->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND);
if (!oldcirc->build_state ||
oldcirc->build_state->failure_count > MAX_REND_FAILURES ||
@@ -664,10 +663,8 @@ rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc)
oldstate->pending_final_cpath = NULL;
memcpy(newcirc->rend_query, oldcirc->rend_query, REND_SERVICE_ID_LEN+1);
- memcpy(newcirc->rend_pk_digest, oldcirc->rend_pk_digest,
- DIGEST_LEN);
- memcpy(newcirc->rend_cookie, oldcirc->rend_cookie,
- REND_COOKIE_LEN);
+ memcpy(newcirc->rend_pk_digest, oldcirc->rend_pk_digest, DIGEST_LEN);
+ memcpy(newcirc->rend_cookie, oldcirc->rend_cookie, REND_COOKIE_LEN);
}
/** Launch a circuit to serve as an introduction point for the service
@@ -677,7 +674,7 @@ static int
rend_service_launch_establish_intro(rend_service_t *service,
const char *nickname)
{
- origin_circuit_t *launched;
+ circuit_t *launched;
log_info(LD_REND,
"Launching circuit to introduction point %s for service %s",
@@ -698,7 +695,7 @@ rend_service_launch_establish_intro(rend_service_t *service,
sizeof(launched->rend_query));
memcpy(launched->rend_pk_digest, service->pk_digest, DIGEST_LEN);
- if (launched->_base.state == CIRCUIT_STATE_OPEN)
+ if (launched->state == CIRCUIT_STATE_OPEN)
rend_service_intro_has_opened(launched);
return 0;
}
@@ -707,7 +704,7 @@ rend_service_launch_establish_intro(rend_service_t *service,
* sends a RELAY_ESTABLISH_INTRO cell.
*/
void
-rend_service_intro_has_opened(origin_circuit_t *circuit)
+rend_service_intro_has_opened(circuit_t *circuit)
{
rend_service_t *service;
size_t len;
@@ -716,7 +713,8 @@ rend_service_intro_has_opened(origin_circuit_t *circuit)
char auth[DIGEST_LEN + 9];
char serviceid[REND_SERVICE_ID_LEN+1];
- tor_assert(circuit->_base.purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO);
+ tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO);
+ tor_assert(CIRCUIT_IS_ORIGIN(circuit));
tor_assert(circuit->cpath);
base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
@@ -725,13 +723,13 @@ rend_service_intro_has_opened(origin_circuit_t *circuit)
service = rend_service_get_by_pk_digest(circuit->rend_pk_digest);
if (!service) {
log_warn(LD_REND, "Unrecognized service ID %s on introduction circuit %d.",
- serviceid, circuit->_base.n_circ_id);
+ serviceid, circuit->n_circ_id);
goto err;
}
log_info(LD_REND,
"Established circuit %d as introduction point for service %s",
- circuit->_base.n_circ_id, serviceid);
+ circuit->n_circ_id, serviceid);
/* Build the payload for a RELAY_ESTABLISH_INTRO cell. */
len = crypto_pk_asn1_encode(service->private_key, buf+2,
@@ -750,32 +748,29 @@ rend_service_intro_has_opened(origin_circuit_t *circuit)
}
len += r;
- if (connection_edge_send_command(NULL, TO_CIRCUIT(circuit),
- RELAY_COMMAND_ESTABLISH_INTRO,
+ if (connection_edge_send_command(NULL, circuit,RELAY_COMMAND_ESTABLISH_INTRO,
buf, len, circuit->cpath->prev)<0) {
log_info(LD_GENERAL,
"Couldn't send introduction request for service %s on circuit %d",
- serviceid, circuit->_base.n_circ_id);
+ serviceid, circuit->n_circ_id);
goto err;
}
return;
err:
- circuit_mark_for_close(TO_CIRCUIT(circuit), END_CIRC_AT_ORIGIN);
+ circuit_mark_for_close(circuit, END_CIRC_AT_ORIGIN);
}
/** Called when we get an INTRO_ESTABLISHED cell; mark the circuit as a
* live introduction point, and note that the service descriptor is
* now out-of-date.*/
int
-rend_service_intro_established(origin_circuit_t *circuit, const char *request,
+rend_service_intro_established(circuit_t *circuit, const char *request,
size_t request_len)
{
rend_service_t *service;
- (void) request;
- (void) request_len;
- if (circuit->_base.purpose != CIRCUIT_PURPOSE_S_ESTABLISH_INTRO) {
+ if (circuit->purpose != CIRCUIT_PURPOSE_S_ESTABLISH_INTRO) {
log_warn(LD_PROTOCOL,
"received INTRO_ESTABLISHED cell on non-intro circuit.");
goto err;
@@ -783,15 +778,15 @@ rend_service_intro_established(origin_circuit_t *circuit, const char *request,
service = rend_service_get_by_pk_digest(circuit->rend_pk_digest);
if (!service) {
log_warn(LD_REND, "Unknown service on introduction circuit %d.",
- circuit->_base.n_circ_id);
+ circuit->n_circ_id);
goto err;
}
service->desc_is_dirty = time(NULL);
- circuit->_base.purpose = CIRCUIT_PURPOSE_S_INTRO;
+ circuit->purpose = CIRCUIT_PURPOSE_S_INTRO;
return 0;
err:
- circuit_mark_for_close(TO_CIRCUIT(circuit), END_CIRC_AT_ORIGIN);
+ circuit_mark_for_close(circuit, END_CIRC_AT_ORIGIN);
return -1;
}
@@ -799,7 +794,7 @@ rend_service_intro_established(origin_circuit_t *circuit, const char *request,
* RELAY_COMMAND_RENDEZVOUS1 cell.
*/
void
-rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
+rend_service_rendezvous_has_opened(circuit_t *circuit)
{
rend_service_t *service;
char buf[RELAY_PAYLOAD_SIZE];
@@ -807,7 +802,7 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
char serviceid[REND_SERVICE_ID_LEN+1];
char hexcookie[9];
- tor_assert(circuit->_base.purpose == CIRCUIT_PURPOSE_S_CONNECT_REND);
+ tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND);
tor_assert(circuit->cpath);
tor_assert(circuit->build_state);
hop = circuit->build_state->pending_final_cpath;
@@ -820,7 +815,7 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
log_info(LD_REND,
"Done building circuit %d to rendezvous with "
"cookie %s for service %s",
- circuit->_base.n_circ_id, hexcookie, serviceid);
+ circuit->n_circ_id, hexcookie, serviceid);
service = rend_service_get_by_pk_digest(circuit->rend_pk_digest);
if (!service) {
@@ -840,8 +835,7 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
DIGEST_LEN);
/* Send the cell */
- if (connection_edge_send_command(NULL, TO_CIRCUIT(circuit),
- RELAY_COMMAND_RENDEZVOUS1,
+ if (connection_edge_send_command(NULL, circuit, RELAY_COMMAND_RENDEZVOUS1,
buf, REND_COOKIE_LEN+DH_KEY_LEN+DIGEST_LEN,
circuit->cpath->prev)<0) {
log_warn(LD_GENERAL, "Couldn't send RENDEZVOUS1 cell.");
@@ -863,11 +857,11 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
circuit->build_state->pending_final_cpath = NULL; /* prevent double-free */
/* Change the circuit purpose. */
- circuit->_base.purpose = CIRCUIT_PURPOSE_S_REND_JOINED;
+ circuit->purpose = CIRCUIT_PURPOSE_S_REND_JOINED;
return;
err:
- circuit_mark_for_close(TO_CIRCUIT(circuit), END_CIRC_AT_ORIGIN);
+ circuit_mark_for_close(circuit, END_CIRC_AT_ORIGIN);
}
/*
@@ -878,14 +872,15 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
* <b>router</b> for the service whose public key is <b>pk_digest</b>. Return
* NULL if no such service is found.
*/
-static origin_circuit_t *
+static circuit_t *
find_intro_circuit(routerinfo_t *router, const char *pk_digest)
{
- origin_circuit_t *circ = NULL;
+ circuit_t *circ = NULL;
tor_assert(router);
while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest,
CIRCUIT_PURPOSE_S_INTRO))) {
+ tor_assert(circ->cpath);
if (!strcasecmp(circ->build_state->chosen_exit->nickname,
router->nickname)) {
return circ;
@@ -895,6 +890,7 @@ find_intro_circuit(routerinfo_t *router, const char *pk_digest)
circ = NULL;
while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest,
CIRCUIT_PURPOSE_S_ESTABLISH_INTRO))) {
+ tor_assert(circ->cpath);
if (!strcasecmp(circ->build_state->chosen_exit->nickname,
router->nickname)) {
return circ;
@@ -1090,7 +1086,7 @@ rend_service_dump_stats(int severity)
routerinfo_t *router;
rend_service_t *service;
char *nickname;
- origin_circuit_t *circ;
+ circuit_t *circ;
for (i=0; i < smartlist_len(rend_service_list); ++i) {
service = smartlist_get(rend_service_list, i);
@@ -1110,7 +1106,7 @@ rend_service_dump_stats(int severity)
continue;
}
log(severity, LD_GENERAL, " Intro point at %s: circuit is %s",nickname,
- circuit_state_to_string(circ->_base.state));
+ circuit_state_to_string(circ->state));
}
}
}
@@ -1121,15 +1117,14 @@ rend_service_dump_stats(int severity)
* or 0 for success.
*/
int
-rend_service_set_connection_addr_port(edge_connection_t *conn,
- origin_circuit_t *circ)
+rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ)
{
rend_service_t *service;
int i;
rend_service_port_config_t *p;
char serviceid[REND_SERVICE_ID_LEN+1];
- tor_assert(circ->_base.purpose == CIRCUIT_PURPOSE_S_REND_JOINED);
+ tor_assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED);
log_debug(LD_REND,"beginning to hunt for addr/port");
base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
circ->rend_pk_digest,10);
@@ -1137,19 +1132,19 @@ rend_service_set_connection_addr_port(edge_connection_t *conn,
if (!service) {
log_warn(LD_REND, "Couldn't find any service associated with pk %s on "
"rendezvous circuit %d; closing.",
- serviceid, circ->_base.n_circ_id);
+ serviceid, circ->n_circ_id);
return -1;
}
for (i = 0; i < smartlist_len(service->ports); ++i) {
p = smartlist_get(service->ports, i);
- if (conn->_base.port == p->virtual_port) {
- conn->_base.addr = p->real_addr;
- conn->_base.port = p->real_port;
+ if (conn->port == p->virtual_port) {
+ conn->addr = p->real_addr;
+ conn->port = p->real_port;
return 0;
}
}
log_info(LD_REND, "No virtual port mapping exists for port %d on service %s",
- conn->_base.port,serviceid);
+ conn->port,serviceid);
return -1;
}