[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Revert cpuworker to use addr/port



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv3034/src/or

Modified Files:
	cpuworker.c 
Log Message:
Revert cpuworker to use addr/port

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- cpuworker.c	13 Jul 2004 18:23:40 -0000	1.46
+++ cpuworker.c	16 Jul 2004 21:47:18 -0000	1.47
@@ -19,7 +19,7 @@
 #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 @@
 
 /** 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 @@
 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 @@
     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 @@
  *          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 @@
       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++;