[or-cvs] cleanup

Roger Dingledine arma at seul.org
Sat Sep 28 00:53:01 UTC 2002


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

Modified Files:
	config.c connection.c connection_ap.c connection_op.c 
	connection_or.c directory.c main.c onion.c or.h routers.c 
Log Message:
cleanup

prkey is only fetched when it's needed
tor nodes who aren't dirservers now fetch directories and autoconnect
  to new nodes listed in the directory
default role is a non-dirserver node


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- config.c	26 Sep 2002 12:09:09 -0000	1.17
+++ config.c	28 Sep 2002 00:52:59 -0000	1.18
@@ -123,8 +123,7 @@
    options->DirRebuildPeriod = 600;
    options->DirFetchPeriod = 6000;
 //   options->ReconnectPeriod = 6001;
-   options->Role = ROLE_OR_LISTEN | ROLE_OR_CONNECT_ALL | ROLE_OP_LISTEN | ROLE_AP_LISTEN |
-                   ROLE_DIR_LISTEN | ROLE_DIR_SERVER;
+   options->Role = ROLE_OR_LISTEN | ROLE_OR_CONNECT_ALL | ROLE_OP_LISTEN | ROLE_AP_LISTEN;
 
    code = poptGetNextOpt(optCon);         /* first we handle command-line args */
    if ( code == -1 )

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- connection.c	26 Sep 2002 12:09:10 -0000	1.25
+++ connection.c	28 Sep 2002 00:52:59 -0000	1.26
@@ -135,8 +135,6 @@
 
   if (conn->pkey)
     crypto_free_pk_env(conn->pkey);
-  if (conn->prkey)
-    crypto_free_pk_env(conn->prkey);
 
   if(conn->s > 0) {
     log(LOG_INFO,"connection_free(): closing fd %d.",conn->s);
@@ -145,7 +143,7 @@
   free(conn);
 }
 
-int connection_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local, int type) {
+int connection_create_listener(struct sockaddr_in *local, int type) {
   connection_t *conn;
   int s;
   int one=1;
@@ -188,8 +186,6 @@
 
   /* remember things so you can tell the baby sockets */
   memcpy(&conn->local,local,sizeof(struct sockaddr_in));
-  if(prkey)
-    conn->prkey = crypto_pk_dup_key(prkey);
 
   log(LOG_DEBUG,"connection_create_listener(): Listening on local port %u.",ntohs(local->sin_port));
 
@@ -228,8 +224,6 @@
 
   /* learn things from parent, so we can perform auth */
   memcpy(&newconn->local,&conn->local,sizeof(struct sockaddr_in));
-  if(conn->prkey)
-    newconn->prkey = crypto_pk_dup_key(conn->prkey);
   newconn->address = strdup(inet_ntoa(remote.sin_addr)); /* remember the remote address */
 
   if(connection_add(newconn) < 0) { /* no space, forget it */
@@ -244,8 +238,8 @@
   return 0;
 }
 
-/* private function, to create the 'local' variable used below */
-static int learn_local(struct sockaddr_in *local) {
+/* create the 'local' variable used below */
+int learn_local(struct sockaddr_in *local) {
   /* local host information */
   char localhostname[512];
   struct hostent *localhost;
@@ -269,7 +263,7 @@
   return 0;
 }
 
-int retry_all_connections(int role, crypto_pk_env_t *prkey, uint16_t or_listenport,
+int retry_all_connections(int role, uint16_t or_listenport,
   uint16_t op_listenport, uint16_t ap_listenport, uint16_t dir_listenport) {
 
   /* start all connections that should be up but aren't */
@@ -282,33 +276,33 @@
   local.sin_port = htons(or_listenport);
 
   if(role & ROLE_OR_CONNECT_ALL) {
-    router_retry_connections(prkey, &local);
+    router_retry_connections(&local);
   }
 
   if(role & ROLE_OR_LISTEN) {
     if(!connection_get_by_type(CONN_TYPE_OR_LISTENER)) {
-      connection_or_create_listener(prkey, &local);
+      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)) {
-      connection_op_create_listener(prkey, &local);
+      connection_op_create_listener(&local);
     }
   }
 
   if(role & ROLE_AP_LISTEN) {
     local.sin_port = htons(ap_listenport);
     if(!connection_get_by_type(CONN_TYPE_AP_LISTENER)) {
-      connection_ap_create_listener(NULL, &local); /* no need to tell it the private key. */
+      connection_ap_create_listener(&local);
     }
   }
 
   if(role & ROLE_DIR_LISTEN) {
     local.sin_port = htons(dir_listenport);
     if(!connection_get_by_type(CONN_TYPE_DIR_LISTENER)) {
-      connection_dir_create_listener(NULL, &local); /* no need to tell it the private key. */
+      connection_dir_create_listener(&local);
     }
   }
  

Index: connection_ap.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_ap.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- connection_ap.c	27 Sep 2002 23:34:51 -0000	1.18
+++ connection_ap.c	28 Sep 2002 00:52:59 -0000	1.19
@@ -393,9 +393,9 @@
 
 }
 
-int connection_ap_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+int connection_ap_create_listener(struct sockaddr_in *local) {
   log(LOG_DEBUG,"connection_create_ap_listener starting");
-  return connection_create_listener(prkey, local, CONN_TYPE_AP_LISTENER);
+  return connection_create_listener(local, CONN_TYPE_AP_LISTENER);
 }
 
 int connection_ap_handle_listener_read(connection_t *conn) {

Index: connection_op.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_op.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- connection_op.c	20 Sep 2002 19:33:13 -0000	1.10
+++ connection_op.c	28 Sep 2002 00:52:59 -0000	1.11
@@ -51,7 +51,7 @@
   log(LOG_DEBUG,"op_handshake_process_keys() : Received auth.");
 
   /* decrypt response */
-  retval = crypto_pk_private_decrypt(conn->prkey, auth_cipher, 128, auth_plain,RSA_PKCS1_PADDING);
+  retval = crypto_pk_private_decrypt(getprivatekey(), auth_cipher, 128, auth_plain,RSA_PKCS1_PADDING);
   if (retval == -1)
   { 
     log(LOG_ERR,"Decrypting keys from new OP failed.");
@@ -110,9 +110,9 @@
 
 }
 
-int connection_op_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+int connection_op_create_listener(struct sockaddr_in *local) {
   log(LOG_DEBUG,"connection_create_op_listener starting");
-  return connection_create_listener(prkey, local, CONN_TYPE_OP_LISTENER);
+  return connection_create_listener(local, CONN_TYPE_OP_LISTENER);
 }
 
 int connection_op_handle_listener_read(connection_t *conn) {

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- connection_or.c	26 Sep 2002 12:09:10 -0000	1.15
+++ connection_or.c	28 Sep 2002 00:52:59 -0000	1.16
@@ -142,7 +142,7 @@
  * *result to 1 if connect() returned before completing, or to 2
  * if it completed, and returns the new conn.
  */
-connection_t *connection_or_connect(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local, 
+connection_t *connection_or_connect(routerinfo_t *router, struct sockaddr_in *local, 
                                     uint16_t port, int *result) {
   connection_t *conn;
   struct sockaddr_in router_addr;
@@ -154,8 +154,6 @@
 
   /* set up conn so it's got all the data we need to remember */
   conn->addr = router->addr, conn->port = router->or_port; /* NOTE we store or_port here always */
-  if(prkey)
-    conn->prkey = crypto_pk_dup_key(prkey);
   conn->bandwidth = router->bandwidth;
   conn->pkey = crypto_pk_dup_key(router->pkey);
   conn->address = strdup(router->address);
@@ -237,7 +235,7 @@
   if(conn)
     return conn;
 
-  conn = connection_or_connect(router, NULL, local, router->op_port, &result);
+  conn = connection_or_connect(router, local, router->op_port, &result);
   if(!conn)
     return NULL;
 
@@ -342,11 +340,11 @@
  *
  */
 
-connection_t *connection_or_connect_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+connection_t *connection_or_connect_as_or(routerinfo_t *router, struct sockaddr_in *local) {
   connection_t *conn;
   int result=0; /* so connection_or_connect() can tell us what happened */
 
-  assert(router && prkey && local);
+  assert(router && local);
 
   if(router->addr == local->sin_addr.s_addr && router->or_port == ntohs(local->sin_port)) {
     /* this is me! don't connect to me. */
@@ -354,7 +352,7 @@
     return NULL;
   }
 
-  conn = connection_or_connect(router, prkey, local, router->or_port, &result);
+  conn = connection_or_connect(router, local, router->or_port, &result);
   if(!conn)
     return NULL;
 
@@ -454,7 +452,7 @@
   log(LOG_DEBUG,"or_handshake_client_process_auth() : Received auth.");
 
   /* decrypt response */
-  retval = crypto_pk_private_decrypt(conn->prkey, cipher, 128, buf, RSA_PKCS1_PADDING);
+  retval = crypto_pk_private_decrypt(getprivatekey(), cipher, 128, buf, RSA_PKCS1_PADDING);
   if (retval == -1)
   { 
     log(LOG_ERR,"Public-key decryption failed during authentication to %s:%u.",
@@ -562,7 +560,7 @@
   log(LOG_DEBUG,"or_handshake_server_process_auth() : Received auth.");
 
   /* decrypt response */
-  retval = crypto_pk_private_decrypt(conn->prkey, cipher, 128, buf, RSA_PKCS1_PADDING);
+  retval = crypto_pk_private_decrypt(getprivatekey(), cipher, 128, buf, RSA_PKCS1_PADDING);
   if (retval == -1)
   { 
     log(LOG_ERR,"Public-key decryption failed processing auth message from new client.");
@@ -678,7 +676,7 @@
   log(LOG_DEBUG,"or_handshake_server_process_nonce() : Received auth.");
 
   /* decrypt response */
-  retval = crypto_pk_private_decrypt(conn->prkey, cipher, 128, buf,RSA_PKCS1_PADDING);
+  retval = crypto_pk_private_decrypt(getprivatekey(), cipher, 128, buf,RSA_PKCS1_PADDING);
   if (retval == -1)
   {
     log(LOG_ERR,"Public-key decryption failed during authentication to %s:%u.",
@@ -719,9 +717,9 @@
 /* ********************************** */
 
 
-int connection_or_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+int connection_or_create_listener(struct sockaddr_in *local) {
   log(LOG_DEBUG,"connection_create_or_listener starting");
-  return connection_create_listener(prkey, local, CONN_TYPE_OR_LISTENER);
+  return connection_create_listener(local, CONN_TYPE_OR_LISTENER);
 }
 
 int connection_or_handle_listener_read(connection_t *conn) {

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- directory.c	26 Sep 2002 13:17:14 -0000	1.2
+++ directory.c	28 Sep 2002 00:52:59 -0000	1.3
@@ -122,8 +122,8 @@
       return -1;
     }
     /* eof reached, kill it, but first process the_directory and learn about new routers. */
-    log(LOG_DEBUG,"connection_dir_process_inbuf(): conn reached eof. Processing directory.");
-    log(LOG_DEBUG,"connection_dir_process_inbuf(): Received directory (size %d) '%s'", directorylen, the_directory);
+//    log(LOG_DEBUG,"connection_dir_process_inbuf(): conn reached eof. Processing directory.");
+    log(LOG_DEBUG,"connection_dir_process_inbuf(): Received directory (size %d)\n%s", directorylen, the_directory);
     if(directorylen == 0) {
       log(LOG_DEBUG,"connection_dir_process_inbuf(): Empty directory. Ignoring.");
       return -1;
@@ -131,6 +131,13 @@
     if(router_get_list_from_string(the_directory, options.ORPort) < 0) {
       log(LOG_DEBUG,"connection_dir_process_inbuf(): ...but parsing failed. Ignoring.");
     }
+    if(options.Role & ROLE_OR_CONNECT_ALL) { /* connect to them all */
+      struct sockaddr_in local; /* local address */
+      if(learn_local(&local) < 0)
+        return -1;
+      local.sin_port = htons(options.ORPort);
+      router_retry_connections(&local);
+    }
     return -1;
   }
 
@@ -240,9 +247,9 @@
   return 0;
 }
 
-int connection_dir_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+int connection_dir_create_listener(struct sockaddr_in *local) {
   log(LOG_DEBUG,"connection_create_dir_listener starting");
-  return connection_create_listener(prkey, local, CONN_TYPE_DIR_LISTENER);
+  return connection_create_listener(local, CONN_TYPE_DIR_LISTENER);
 }
 
 int connection_dir_handle_listener_read(connection_t *conn) {

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- main.c	26 Sep 2002 13:17:14 -0000	1.26
+++ main.c	28 Sep 2002 00:52:59 -0000	1.27
@@ -19,12 +19,21 @@
 static int please_dumpstats=0; /* whether we should dump stats during the loop */
 
 /* private key */
-static crypto_pk_env_t *prkey;
+static crypto_pk_env_t *privatekey;
 
 routerinfo_t *my_routerinfo=NULL;
 
 /********* END VARIABLES ************/
 
+void setprivatekey(crypto_pk_env_t *k) {
+  privatekey = k;
+}
+
+crypto_pk_env_t *getprivatekey(void) {
+  assert(privatekey);
+  return privatekey;
+}
+
 /****************************************************************************
 *
 * This section contains accessors and other methods on the connection_array
@@ -398,6 +407,7 @@
   int i;
   int timeout;
   int poll_result;
+  crypto_pk_env_t *prkey;
 
   /* load the routers file */
   if(router_get_list_from_file(options.RouterFile, options.ORPort) < 0) {
@@ -417,11 +427,12 @@
       log(LOG_ERR,"Error loading private key.");
       return -1;
     }
+    setprivatekey(prkey);
   }
 
   /* start-up the necessary connections based on global_role. This is where we
    * try to connect to all the other ORs, and start the listeners */
-  retry_all_connections(options.Role, prkey, options.ORPort,
+  retry_all_connections(options.Role, options.ORPort,
                         options.OPPort, options.APPort, options.DirPort);
 
   for(;;) {

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- onion.c	24 Sep 2002 10:43:56 -0000	1.16
+++ onion.c	28 Sep 2002 00:52:59 -0000	1.17
@@ -30,7 +30,7 @@
 int process_onion(circuit_t *circ, connection_t *conn) {
   aci_t aci_type;
 
-  if(!decrypt_onion((onion_layer_t *)circ->onion,circ->onionlen,conn->prkey)) {
+  if(!decrypt_onion((onion_layer_t *)circ->onion,circ->onionlen,getprivatekey())) {
     log(LOG_DEBUG,"command_process_create_cell(): decrypt_onion() failed, closing circuit.");
     return -1;
   }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- or.h	26 Sep 2002 13:17:14 -0000	1.28
+++ or.h	28 Sep 2002 00:52:59 -0000	1.29
@@ -230,7 +230,6 @@
   
 /* used by OR, to keep state while connect()ing: Kludge. */
 
-  crypto_pk_env_t *prkey;
   struct sockaddr_in local;
 
 #if 0 /* obsolete, we now use conn->bandwidth */
@@ -449,12 +448,13 @@
 
 void connection_free(connection_t *conn);
 
-int connection_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local, int type);
+int connection_create_listener(struct sockaddr_in *local, int type);
 
 int connection_handle_listener_read(connection_t *conn, int new_type, int new_state);
 
 /* start all connections that should be up but aren't */
-int retry_all_connections(int role, crypto_pk_env_t *prkey, uint16_t or_listenport, 
+int learn_local(struct sockaddr_in *local);
+int retry_all_connections(int role, uint16_t or_listenport, 
   uint16_t op_listenport, uint16_t ap_listenport, uint16_t dir_listenport);
 connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port);
 
@@ -512,7 +512,7 @@
 
 int connection_ap_finished_flushing(connection_t *conn);
 
-int connection_ap_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
+int connection_ap_create_listener(struct sockaddr_in *local);
 
 int connection_ap_handle_listener_read(connection_t *conn);
 
@@ -534,7 +534,7 @@
 
 int connection_op_finished_flushing(connection_t *conn);
 
-int connection_op_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
+int connection_op_create_listener(struct sockaddr_in *local);
 
 int connection_op_handle_listener_read(connection_t *conn);
 
@@ -554,11 +554,11 @@
 int or_handshake_server_process_auth(connection_t *conn);
 int or_handshake_server_process_nonce(connection_t *conn);
 
-connection_t *connect_to_router_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
-connection_t *connection_or_connect_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
+connection_t *connect_to_router_as_or(routerinfo_t *router, struct sockaddr_in *local);
+connection_t *connection_or_connect_as_or(routerinfo_t *router, struct sockaddr_in *local);
 connection_t *connection_or_connect_as_op(routerinfo_t *router, struct sockaddr_in *local);
 
-int connection_or_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
+int connection_or_create_listener(struct sockaddr_in *local);
 int connection_or_handle_listener_read(connection_t *conn);
 
 /********************************* directory.c ***************************/
@@ -570,11 +570,13 @@
 int directory_handle_command(connection_t *conn);
 int directory_handle_reading(connection_t *conn);
 int connection_dir_finished_flushing(connection_t *conn);
-int connection_dir_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
+int connection_dir_create_listener(struct sockaddr_in *local);
 int connection_dir_handle_listener_read(connection_t *conn);
 
 /********************************* main.c ***************************/
 
+void setprivatekey(crypto_pk_env_t *k);
+crypto_pk_env_t *getprivatekey(void);
 int connection_add(connection_t *conn);
 int connection_remove(connection_t *conn);
 void connection_set_poll_socket(connection_t *conn);
@@ -647,7 +649,7 @@
 
 /********************************* routers.c ***************************/
 
-void router_retry_connections(crypto_pk_env_t *prkey, struct sockaddr_in *local);
+void router_retry_connections(struct sockaddr_in *local);
 routerinfo_t *router_pick_directory_server(void);
 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
 unsigned int *router_new_route(int *routelen);

Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- routers.c	26 Sep 2002 13:19:13 -0000	1.14
+++ routers.c	28 Sep 2002 00:52:59 -0000	1.15
@@ -35,7 +35,7 @@
 
 /****************************************************************************/
 
-void router_retry_connections(crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+void router_retry_connections(struct sockaddr_in *local) {
   int i;
   routerinfo_t *router;
 
@@ -43,7 +43,7 @@
     router = router_array[i];
     if(!connection_exact_get_by_addr_port(router->addr,router->or_port)) { /* not in the list */
       log(LOG_DEBUG,"retry_all_connections(): connecting to OR %s:%u.",router->address,router->or_port);
-      connection_or_connect_as_or(router, prkey, local);
+      connection_or_connect_as_or(router, local);
     }
   }
 }



More information about the tor-commits mailing list