aboutsummaryrefslogtreecommitdiff
path: root/src/or/cpuworker.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-07-16 21:47:18 +0000
committerNick Mathewson <nickm@torproject.org>2004-07-16 21:47:18 +0000
commit656a6643347d5500dec3eab3fac8882b71d633f5 (patch)
tree53cb3a4eb8e0ccc7a57fdd8c8ef3970221387edb /src/or/cpuworker.c
parent0b3357d57382d93aee1abfc5d6f57de918794953 (diff)
downloadtor-656a6643347d5500dec3eab3fac8882b71d633f5.tar
tor-656a6643347d5500dec3eab3fac8882b71d633f5.tar.gz
Revert cpuworker to use addr/port
svn:r2049
Diffstat (limited to 'src/or/cpuworker.c')
-rw-r--r--src/or/cpuworker.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 04b54fc00..6b73d9510 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 <b>tag</b> 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++;