[or-cvs] fix endian issues for topics -- they might work on bsd now

Roger Dingledine arma at seul.org
Thu Feb 6 23:48:38 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home/arma/work/onion/cvs/src/or

Modified Files:
	circuit.c connection.c connection_ap.c connection_exit.c dns.c 
	or.h 
Log Message:
fix endian issues for topics -- they might work on bsd now
(they wouldn't have before)

alternate code which bypasses the dns farm, so we can compare speed



Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- circuit.c	6 Feb 2003 08:00:49 -0000	1.22
+++ circuit.c	6 Feb 2003 23:48:35 -0000	1.23
@@ -546,7 +546,7 @@
     memset(&cell, 0, sizeof(cell_t));
     cell.command = CELL_DATA;
     cell.length = TOPIC_HEADER_SIZE;
-    *(uint32_t *)cell.payload = conn->topic_id;
+    *(uint16_t *)(cell.payload+2) = htons(conn->topic_id);
     *cell.payload = TOPIC_COMMAND_END;
    
     if(conn == circ->p_conn) {

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- connection.c	6 Feb 2003 08:00:49 -0000	1.34
+++ connection.c	6 Feb 2003 23:48:35 -0000	1.35
@@ -617,7 +617,7 @@
 
   log(LOG_DEBUG,"connection_package_raw_inbuf(): Packaging %d bytes (%d waiting).",cell.length, amount_to_process);
 
-  *(uint32_t *)cell.payload = conn->topic_id;
+  *(uint16_t *)(cell.payload+2) = htons(conn->topic_id);
   *cell.payload = TOPIC_COMMAND_DATA;
   cell.length += TOPIC_HEADER_SIZE;
   cell.command = CELL_DATA;
@@ -673,7 +673,7 @@
     return 0;
   }
 
-  *(uint32_t *)cell.payload = conn->topic_id;
+  *(uint16_t *)(cell.payload+2) = htons(conn->topic_id);
   *cell.payload = TOPIC_COMMAND_SENDME;
   cell.length += TOPIC_HEADER_SIZE;
   cell.command = CELL_DATA;

Index: connection_ap.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_ap.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- connection_ap.c	6 Feb 2003 08:00:49 -0000	1.23
+++ connection_ap.c	6 Feb 2003 23:48:35 -0000	1.24
@@ -336,10 +336,9 @@
   /* deliver the dest_addr in a data cell */
   cell.command = CELL_DATA;
   cell.aci = circ->n_aci;
-  crypto_pseudo_rand(3, cell.payload+1); /* byte 0 is blank, bytes 1-3 are random */
+  crypto_pseudo_rand(2, cell.payload+2); /* bytes 0-1 is blank, bytes 2-3 are random */
   /* FIXME check for collisions */
-  cell.payload[0] = 0;
-  ap_conn->topic_id = *(uint32_t *)cell.payload;
+  ap_conn->topic_id = ntohs(*(uint16_t *)(cell.payload+2));
   cell.payload[0] = TOPIC_COMMAND_BEGIN;
   snprintf(cell.payload+4, CELL_PAYLOAD_SIZE-4, "%s,%d", ap_conn->dest_addr, ap_conn->dest_port);
   cell.length = strlen(cell.payload+TOPIC_HEADER_SIZE)+1+TOPIC_HEADER_SIZE;
@@ -381,8 +380,7 @@
   assert(cell && circ);
 
   topic_command = *cell->payload;
-  *cell->payload = 0;
-  topic_id = *(uint32_t *)cell->payload;
+  topic_id = ntohs(*(uint16_t *)(cell->payload+2));
   log(LOG_DEBUG,"connection_ap_process_data_cell(): command %d topic %d", topic_command, topic_id);
   num_seen++;
   log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen);

Index: connection_exit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_exit.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- connection_exit.c	6 Feb 2003 08:00:49 -0000	1.17
+++ connection_exit.c	6 Feb 2003 23:48:35 -0000	1.18
@@ -88,7 +88,7 @@
   memset(&cell, 0, sizeof(cell_t));
   cell.aci = circ->p_aci;
   cell.command = CELL_DATA;
-  *(uint32_t *)cell.payload = conn->topic_id;
+  *(uint16_t *)(cell.payload+2) = htons(conn->topic_id);
   *cell.payload = TOPIC_COMMAND_CONNECTED;
   cell.length = TOPIC_HEADER_SIZE;
   log(LOG_INFO,"connection_exit_send_connected(): passing back cell (aci %d).",circ->p_aci);
@@ -129,7 +129,7 @@
   }
 
   cell->payload[0] = 0;
-  n_conn->topic_id = *(uint32_t *)(cell->payload);
+  n_conn->topic_id = ntohs(*(uint16_t *)(cell->payload+2));
 
   n_conn->address = strdup(cell->payload + TOPIC_HEADER_SIZE);
   n_conn->port = atoi(comma+1);
@@ -150,7 +150,7 @@
   circ->n_conn = n_conn;
 
   /* send it off to the gethostbyname farm */
-  if(dns_tor_to_master(n_conn->address) < 0) {
+  if(dns_tor_to_master(n_conn) < 0) {
     log(LOG_DEBUG,"connection_exit_begin_conn(): Couldn't queue resolve request.");
     connection_remove(n_conn);
     connection_free(n_conn);
@@ -171,8 +171,7 @@
   assert(cell && circ);
 
   topic_command = *cell->payload;
-  *cell->payload = 0;
-  topic_id = *(uint32_t *)cell->payload;
+  topic_id = ntohs(*(uint16_t *)(cell->payload+2));
   log(LOG_DEBUG,"connection_exit_process_data_cell(): command %d topic %d", topic_command, topic_id);
   num_seen++;
   log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen);

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dns.c	6 Feb 2003 08:00:49 -0000	1.2
+++ dns.c	6 Feb 2003 23:48:35 -0000	1.3
@@ -339,10 +339,30 @@
   return 0;
 }
 
-int dns_tor_to_master(char *address) {
+int dns_tor_to_master(connection_t *exitconn) {
   connection_t *conn;
   unsigned char len;
 
+#ifdef DO_DNS_DIRECTLY
+  /* new version which does it all right here */
+  struct hostent *rent;
+  rent = gethostbyname(exitconn->address);
+  if (!rent) {
+    return -1;
+  }
+
+  memcpy((char *)&exitconn->addr, rent->h_addr, rent->h_length);
+  exitconn->addr = ntohl(exitconn->addr); /* get it back to host order */
+
+  if(connection_exit_connect(exitconn) < 0) {
+    exitconn->marked_for_close = 1;
+  }
+  return 0;
+#endif
+
+
+
+  /* old version which actually uses the dns farm */
   conn = connection_get_by_type(CONN_TYPE_DNSMASTER);
   if(!conn) {
     log(LOG_ERR,"dns_tor_to_master(): dns master nowhere to be found!");
@@ -350,13 +370,13 @@
     return -1;
   }
 
-  len = strlen(address);
+  len = strlen(exitconn->address);
   if(connection_write_to_buf(&len, 1, conn) < 0) {
     log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write length.");
     return -1;
   }
 
-  if(connection_write_to_buf(address, len, conn) < 0) {
+  if(connection_write_to_buf(exitconn->address, len, conn) < 0) {
     log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write address.");
     return -1;
   }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- or.h	6 Feb 2003 08:00:49 -0000	1.43
+++ or.h	6 Feb 2003 23:48:35 -0000	1.44
@@ -259,7 +259,7 @@
 
 /* used by exit and ap: */
 
-  uint32_t topic_id;
+  uint16_t topic_id;
   struct connection_t *next_topic;
   int n_receive_topicwindow;
   int p_receive_topicwindow;
@@ -650,7 +650,7 @@
 
 int connection_dns_finished_flushing(connection_t *conn);
 int connection_dns_process_inbuf(connection_t *conn);
-int dns_tor_to_master(char *address);
+int dns_tor_to_master(connection_t *exitconn);
 int dns_master_start(void);
 
 /********************************* main.c ***************************/



More information about the tor-commits mailing list