[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[or-cvs] general cleanup



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

Modified Files:
	cell.c circuit.c connection_ap.c connection_exit.c 
	connection_op.c main.c 
Log Message:
general cleanup


Index: cell.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cell.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- cell.c	26 Jun 2002 22:45:50 -0000	1.1.1.1
+++ cell.c	5 Jul 2002 06:27:23 -0000	1.2
@@ -3,8 +3,7 @@
 
 int check_sane_cell(cell_t *cell) {
 
-  if(!cell)
-    return -1;
+  assert(cell);
 
   if(cell->aci == 0) {
     log(LOG_DEBUG,"check_sane_cell(): Cell has aci=0. Dropping.");

Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- circuit.c	2 Jul 2002 09:36:58 -0000	1.3
+++ circuit.c	5 Jul 2002 06:27:23 -0000	1.4
@@ -3,7 +3,7 @@
 
 /********* START VARIABLES **********/
 
-circuit_t *global_circuitlist=NULL;
+static circuit_t *global_circuitlist=NULL;
 
 /********* END VARIABLES ************/
 
@@ -22,8 +22,7 @@
 void circuit_remove(circuit_t *circ) {
   circuit_t *tmpcirc;
 
-  if(!circ || !global_circuitlist)
-    return;
+  assert(circ && global_circuitlist);
 
   if(global_circuitlist == circ) {
     global_circuitlist = global_circuitlist->next;
@@ -36,11 +35,9 @@
       return;
     }
   }
-
 }
 
 circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) {
-
   circuit_t *circ; 
 
   circ = (circuit_t *)malloc(sizeof(circuit_t));
@@ -55,7 +52,7 @@
 
   /* ACIs */
   circ->p_aci = p_aci;
-  circ->n_aci = 0; /* we need to have identified the next hop to choose a correct ACI */
+  /* circ->n_aci remains 0 because we haven't identified the next hop yet */
 
   circuit_add(circ);
 
@@ -363,7 +360,6 @@
   /* currently, we assume it's too late to flush conn's buf here.
    * down the road, maybe we'll consider that eof doesn't mean can't-write
    */
-
   circuit_t *circ;
 
   while((circ = circuit_get_by_conn(conn))) {

Index: connection_ap.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_ap.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- connection_ap.c	2 Jul 2002 09:36:58 -0000	1.1
+++ connection_ap.c	5 Jul 2002 06:27:23 -0000	1.2
@@ -212,7 +212,6 @@
     
     /* ok, launch the connection */
     n_conn = connect_to_router_as_op(firsthop);
-    /* FIXME react to this somehow */
     if(!n_conn) { /* connect failed, forget the whole thing */
       log(LOG_DEBUG,"ap_handshake_establish_circuit(): connect to firsthop failed. Closing.");
       circuit_close(circ);

Index: connection_exit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_exit.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- connection_exit.c	2 Jul 2002 09:36:58 -0000	1.2
+++ connection_exit.c	5 Jul 2002 06:27:23 -0000	1.3
@@ -63,7 +63,8 @@
 int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) {
   struct hostent *rent;
   struct sockaddr_in dest_addr;
-  int s;
+  int retval;
+  int s; /* for the new socket, if we're on connecting_wait */
 
   /* an outgoing data cell has arrived */
 
@@ -148,14 +149,15 @@
         connection_set_poll_socket(conn);
         conn->state = EXIT_CONN_STATE_OPEN;
         connection_watch_events(conn, POLLIN);
-      } else { /* i'm not sure what this would be */
-        log(LOG_DEBUG,"connection_exit_process_cell(): in connecting_wait, not sure why.");
+	return 0;
       }
-      return 0;
+      log(LOG_DEBUG,"connection_exit_process_cell(): in connecting_wait, but I've already received everything. Closing.");
+      return -1;
     case EXIT_CONN_STATE_CONNECTING:
       log(LOG_DEBUG,"connection_exit_process_cell(): Data receiving while connecting. Queueing.");
-      /* FIXME kludge. shouldn't call write_to_buf directly. */
-      return write_to_buf(cell->payload, cell->length, &conn->outbuf, &conn->outbuflen, &conn->outbuf_datalen);
+      retval = connection_write_to_buf(cell->payload, cell->length, conn);
+      connection_watch_events(conn, POLLIN); /* make it stop trying to write */
+      return retval; 
     case EXIT_CONN_STATE_OPEN:
       return connection_write_to_buf(cell->payload, cell->length, conn);
   }

Index: connection_op.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_op.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- connection_op.c	30 Jun 2002 07:37:49 -0000	1.2
+++ connection_op.c	5 Jul 2002 06:27:23 -0000	1.3
@@ -81,11 +81,6 @@
   EVP_EncryptInit(&conn->b_ctx, EVP_des_ofb(), conn->b_session_key, conn->b_session_iv);
   EVP_DecryptInit(&conn->f_ctx, EVP_des_ofb(), conn->f_session_key, conn->f_session_iv);
 
-#if 0
-  /* FIXME must choose conn->aci here? What does it mean for a connection to have an aci? */
-  log(LOG_DEBUG,"new_entry_connection : Chosen ACI %u.",conn->aci);
-#endif
-
   conn->state = OP_CONN_STATE_OPEN;
   connection_watch_events(conn, POLLIN);
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- main.c	3 Jul 2002 17:30:59 -0000	1.4
+++ main.c	5 Jul 2002 06:27:23 -0000	1.5
@@ -6,7 +6,7 @@
 /* valid command-line options */
 static char *args = "hf:e:n:l:";
 
-int loglevel = LOG_DEBUG;
+int loglevel = LOG_DEBUG; /* global variable */
 
 //int global_role = ROLE_AP_LISTEN;
 int global_role = ROLE_OR_LISTEN | ROLE_OR_CONNECT_ALL | ROLE_OP_LISTEN | ROLE_AP_LISTEN;
@@ -29,26 +29,31 @@
   RouterFile=0, PrivateKeyFile, APPort, OPPort, ORPort, CoinWeight, MaxConn, TrafficShaping
 };
 
-connection_t *connection_array[MAXCONNECTIONS] =
+static connection_t *connection_array[MAXCONNECTIONS] =
         { NULL };
 
-struct pollfd poll_array[MAXCONNECTIONS] =
+static struct pollfd poll_array[MAXCONNECTIONS] =
         { [0 ... MAXCONNECTIONS-1] = { -1, 0, 0 } };
 
-int nfds=0; /* number of connections currently active */
-
-/* default logging threshold */
-extern int loglevel;
+static int nfds=0; /* number of connections currently active */
 
 /* private key */
-RSA *prkey = NULL;
+static RSA *prkey = NULL;
 
 /* router array */
-routerinfo_t **router_array = NULL;
-int rarray_len = 0;
+static routerinfo_t **router_array = NULL;
+static int rarray_len = 0;
 
 /********* END VARIABLES ************/
 
+/****************************************************************************
+*
+* This section contains accessors and other methods on the connection_array
+* and poll_array variables (which are global within this file and unavailable
+* outside it).
+*
+****************************************************************************/
+
 int connection_add(connection_t *conn) {
 
   if(nfds >= MAXCONNECTIONS-2) { /* 2, for some breathing room. should count the fenceposts. */
@@ -133,22 +138,27 @@
   return NULL;
 }
 
+
+
+
+/* the next 4 functions should move to routers.c once we get it
+ * cleaned up more. The router_array and rarray_len variables should
+ * move there too.
+ */
+
 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) {
   int i;
   routerinfo_t *router;
 
-  if (!router_array)
-    return NULL;
+  assert(router_array);
 
-  for(i=0;i<rarray_len;i++)
-  {
+  for(i=0;i<rarray_len;i++) {
     router = router_array[i];
     if ((router->addr == addr) && (router->or_port == port))
       return router;
   }
 
   return NULL;
-
 }
 
 routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen) {
@@ -165,6 +175,10 @@
   return create_onion(router_array,rarray_len,route,routelen,lenp,cpathp);
 }
 
+
+
+
+
 connection_t *connect_to_router_as_op(routerinfo_t *router) {
   return connection_connect_to_router_as_op(router, prkey, options[ORPort].r.i);
 }
@@ -261,7 +275,7 @@
     connection_free(conn);
     if(i<nfds) { /* we just replaced the one at i with a new one.
                     process it too. */
-      check_conn_read(i);
+      check_conn_marked(i);
     }
   }
 }
@@ -373,23 +387,11 @@
     log(LOG_ERR,"MaxConn option required but not found.");
     exit(1);
   }
-#if 0
-  if (!options[TrafficShaping].err)
-  { 
-    options[TrafficShaping].r.i = DEFAULT_POLICY;
-  }
-  else if ((options[TrafficShaping].r.i < 0) || (options[TrafficShaping].r.i > 1))
-  {
-    log(LOG_ERR,"Invalid value for the TrafficShaping option.");
-    exit(1);
-  }
-#endif
 
   ERR_load_crypto_strings();
   retval = do_main_loop();
   ERR_free_strings();
 
   return retval;
-
 }