diff --git a/doc/TODO b/doc/TODO index b84785e596..9a257cf804 100644 --- a/doc/TODO +++ b/doc/TODO @@ -53,7 +53,7 @@ NICK - Possible to get autoconf to easily install things into ~/.tor? key digest in place of nicknames. o Audit all uses of lookup-by-hostname and lookup-by-addr-port to search by digest when appropriate. -NICK - make sure to use addr/port in cpuworker tasks, because + o make sure to use addr/port in cpuworker tasks, because OPs don't have keys. NICK - and fix the function comments in rephist o Rep-hist functions need to store info by keyid diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 04b54fc00f..6b73d9510a 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -19,7 +19,7 @@ extern or_options_t options; /* command-line and config-file options */ #define MIN_CPUWORKERS 1 /** The tag specifies which circuit this onionskin was from. */ -#define TAG_LEN (DIGEST_LEN+2) +#define TAG_LEN 8 /** How many bytes are sent from tor to the cpuworker? */ #define LEN_ONION_QUESTION (1+TAG_LEN+ONIONSKIN_CHALLENGE_LEN) /** How many bytes are sent from the cpuworker back to tor? */ @@ -55,17 +55,23 @@ int connection_cpu_finished_flushing(connection_t *conn) { /** Pack addr,port,and circ_id; set *tag to the result. (See note on * cpuworker_main for wire format.) */ -static void tag_pack(char *tag, uint16_t circ_id, const char *identity_digest){ - *(uint16_t *)(tag) = circ_id; - memcpy(tag+2, identity_digest, DIGEST_LEN); +static void tag_pack(char *tag, uint32_t addr, uint16_t port, uint16_t circ_id) { + *(uint32_t *)tag = addr; + *(uint16_t *)(tag+4) = port; + *(uint16_t *)(tag+6) = circ_id; } /** Unpack tag into addr, port, and circ_id. */ -static void tag_unpack(const char *tag, uint16_t *circ_id, - char *identity_digest) { - *circ_id = *(const uint16_t *)(tag); - memcpy(identity_digest, tag+2, DIGEST_LEN); +static void tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t *circ_id) { + struct in_addr in; + + *addr = *(const uint32_t *)tag; + *port = *(const uint16_t *)(tag+4); + *circ_id = *(const uint16_t *)(tag+6); + + in.s_addr = htonl(*addr); + log_fn(LOG_DEBUG,"onion was from %s:%d, circ_id %d.", inet_ntoa(in), *port, *circ_id); } /** Called when the onion key has changed and we need to spawn new @@ -92,10 +98,11 @@ void cpuworkers_rotate(void) int connection_cpu_process_inbuf(connection_t *conn) { char success; unsigned char buf[LEN_ONION_RESPONSE]; + uint32_t addr; + uint16_t port; uint16_t circ_id; connection_t *p_conn; circuit_t *circ; - char identity_digest[DIGEST_LEN]; tor_assert(conn && conn->type == CONN_TYPE_CPUWORKER); @@ -123,11 +130,11 @@ int connection_cpu_process_inbuf(connection_t *conn) { connection_fetch_from_buf(buf,LEN_ONION_RESPONSE-1,conn); /* parse out the circ it was talking about */ - tag_unpack(buf, &circ_id, identity_digest); + tag_unpack(buf, &addr, &port, &circ_id); circ = NULL; /* XXXX This is actually right: we want a specific port here in * case there are multiple connections. */ - p_conn = connection_get_by_identity_digest(identity_digest,CONN_TYPE_OR); + p_conn = connection_exact_get_by_addr_port(addr,port); if(p_conn) circ = circuit_get_by_circ_id_conn(circ_id, p_conn); @@ -177,6 +184,10 @@ done_processing: * Opaque tag TAG_LEN * Onionskin challenge ONIONSKIN_REPLY_LEN * Negotiated keys KEY_LEN*2+DIGEST_LEN*2 + * + * (Note: this _should_ be by addr/port, since we're concerned with specific + * connections, not with routers (where we'd use identity). Also, using + * identity would break pre-0.0.8 OPs, which don't have identity keys.) */ static int cpuworker_main(void *data) { unsigned char question[ONIONSKIN_CHALLENGE_LEN]; @@ -351,7 +362,7 @@ int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type, log_fn(LOG_INFO,"circ->p_conn gone. Failing circ."); return -1; } - tag_pack(tag, circ->p_circ_id, circ->p_conn->identity_digest); + tag_pack(tag, circ->p_conn->addr, circ->p_conn->port, circ->p_circ_id); cpuworker->state = CPUWORKER_STATE_BUSY_ONION; num_cpuworkers_busy++;