[or-cvs] cell now has a network appearance and an internal (struct) ...

Roger Dingledine arma at seul.org
Wed Oct 2 20:12:46 UTC 2002


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

Modified Files:
	connection.c or.h 
Log Message:
cell now has a network appearance and an internal (struct) appearance


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- connection.c	2 Oct 2002 01:03:00 -0000	1.29
+++ connection.c	2 Oct 2002 20:12:44 -0000	1.30
@@ -290,7 +290,7 @@
       connection_or_create_listener(&local);
     }
   }
-      
+
   if(role & ROLE_OP_LISTEN) {
     local.sin_port = htons(op_listenport);
     if(!connection_get_by_type(CONN_TYPE_OP_LISTENER)) {
@@ -561,16 +561,25 @@
 }
 
 int connection_write_cell_to_buf(cell_t *cellp, connection_t *conn) {
+  char networkcell[CELL_NETWORK_SIZE];
+  char *n = networkcell;
  
-  if(connection_encrypt_cell(cellp,conn)<0) {
+  memset(n,0,CELL_NETWORK_SIZE); /* zero it out to start */
+  *(aci_t *)n = htons(cellp->aci);
+  *(n+2) = cellp->command;
+  *(n+3) = cellp->length;
+  /* seq is reserved, leave zero */
+  memcpy(n+8,cellp->payload,CELL_PAYLOAD_SIZE);
+
+  if(connection_encrypt_cell(n,conn)<0) {
     return -1;
   }
 
-  return connection_write_to_buf((char *)cellp, sizeof(cell_t), conn);
+  return connection_write_to_buf(n, CELL_NETWORK_SIZE, conn);
 }
 
-int connection_encrypt_cell(cell_t *cellp, connection_t *conn) {
-  cell_t newcell;
+int connection_encrypt_cell(char *cellp, connection_t *conn) {
+  char cryptcell[CELL_NETWORK_SIZE];
 #if 0
   int x;
   char *px;
@@ -583,7 +592,7 @@
   printf("\n");
 #endif
 
-  if(crypto_cipher_encrypt(conn->f_crypto, (char *)cellp, sizeof(cell_t), (char *)&newcell)) {
+  if(crypto_cipher_encrypt(conn->f_crypto, cellp, CELL_NETWORK_SIZE, cryptcell)) {
     log(LOG_ERR,"Could not encrypt cell for connection %s:%u.",conn->address,conn->port);
     return -1;
   }
@@ -596,7 +605,7 @@
   printf("\n");
 #endif
 
-  memcpy(cellp,&newcell,sizeof(cell_t));
+  memcpy(cellp,cryptcell,CELL_NETWORK_SIZE);
   return 0;
 }
 
@@ -750,15 +759,15 @@
   /* check if there's a whole cell there.
    * if yes, pull it off, decrypt it, and process it.
    */
-  char crypted[128];
+  char crypted[CELL_NETWORK_SIZE];
   char outbuf[1024];
 //  int x;
-  cell_t *cellp;
+  cell_t cell;
 
-  if(conn->inbuf_datalen < 128) /* entire response available? */
+  if(conn->inbuf_datalen < CELL_NETWORK_SIZE) /* entire response available? */
     return 0; /* not yet */
 
-  if(connection_fetch_from_buf(crypted,128,conn) < 0) {
+  if(connection_fetch_from_buf(crypted,CELL_NETWORK_SIZE,conn) < 0) {
     return -1;
   }
 
@@ -770,7 +779,7 @@
   printf("\n");
 #endif
   /* decrypt */
-  if(crypto_cipher_decrypt(conn->b_crypto,crypted,sizeof(cell_t),(unsigned char *)outbuf)) {
+  if(crypto_cipher_decrypt(conn->b_crypto,crypted,CELL_NETWORK_SIZE,outbuf)) {
     log(LOG_ERR,"connection_process_cell_from_inbuf(): Decryption failed, dropping.");
     return connection_process_inbuf(conn); /* process the remainder of the buffer */
   }
@@ -783,11 +792,15 @@
   printf("\n");
 #endif
 
-  /* copy the rest of the cell */
-//  memcpy((char *)outbuf+8, (char *)crypted+8, sizeof(cell_t)-8);
-  cellp = (cell_t *)outbuf;
+  /* retrieve cell info from outbuf (create the struct from the string) */
+  memset(&cell,0,sizeof(cell_t)); /* zero it out to start */
+  cell.aci = ntohs(*(aci_t *)outbuf);
+  cell.command = *(outbuf+2);
+  cell.length = *(outbuf+3);
+  memcpy(cell.payload, outbuf+8, CELL_PAYLOAD_SIZE);
+
 //  log(LOG_DEBUG,"connection_process_cell_from_inbuf(): Decrypted cell is of type %u (ACI %u).",cellp->command,cellp->aci);
-  command_process_cell(cellp, conn);
+  command_process_cell(&cell, conn);
 
   return connection_process_inbuf(conn); /* process the remainder of the buffer */
 }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- or.h	1 Oct 2002 23:37:31 -0000	1.32
+++ or.h	2 Oct 2002 20:12:44 -0000	1.33
@@ -145,6 +145,7 @@
 #define CELL_CONNECTED 7
 
 #define CELL_PAYLOAD_SIZE 120
+#define CELL_NETWORK_SIZE 128
 
 typedef uint16_t aci_t;
 
@@ -334,13 +335,13 @@
   int forwf:4;
   uint16_t port;
   uint32_t addr;
-  time_t expire;
+  uint32_t expire;
   unsigned char keyseed[16];
 } onion_layer_t;
 
 typedef struct
 { 
-  time_t expire;
+  uint32_t expire;
   char digest[20]; /* SHA digest of the onion */
   void *prev;
   void *next;
@@ -495,7 +496,7 @@
 
 int connection_send_destroy(aci_t aci, connection_t *conn);
 int connection_send_connected(aci_t aci, connection_t *conn);
-int connection_encrypt_cell(cell_t *cellp, connection_t *conn);
+int connection_encrypt_cell(char *cellp, connection_t *conn);
 int connection_write_cell_to_buf(cell_t *cellp, connection_t *conn);
 
 int connection_process_inbuf(connection_t *conn);



More information about the tor-commits mailing list