[or-cvs] onion proxies now work (i think)

Roger Dingledine arma at seul.org
Wed Sep 4 06:29:32 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_or.c main.c onion.c or.h 
	routers.c 
Log Message:
onion proxies now work (i think)


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- config.c	3 Sep 2002 19:03:16 -0000	1.15
+++ config.c	4 Sep 2002 06:29:27 -0000	1.16
@@ -188,37 +188,44 @@
       }
    }
 
+   if ( options->Role < 0 || options->Role > 15 )
+   {
+      log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive).");
+      code = -1;
+   }
+
    if ( options->RouterFile == NULL )
    {
       log(LOG_ERR,"RouterFile option required, but not found.");
       code = -1;
    }
 
-   if ( options->PrivateKeyFile == NULL )
+   if ( ROLE_IS_OR(options->Role) && options->PrivateKeyFile == NULL )
    {
-      log(LOG_ERR,"PrivateKeyFile option required, but not found.");
+      log(LOG_ERR,"PrivateKeyFile option required for OR, but not found.");
       code = -1;
    }
 
-   if ( options->ORPort < 1 )
+   if ( (options->Role & ROLE_OR_LISTEN) && options->ORPort < 1 )
    {
       log(LOG_ERR,"ORPort option required and must be a positive integer value.");
       code = -1;
    }
 
-   if ( options->OPPort < 1 )
+   if ( (options->Role & ROLE_OP_LISTEN) && options->OPPort < 1 )
    {
       log(LOG_ERR,"OPPort option required and must be a positive integer value.");
       code = -1;
    }
 
-   if ( options->APPort < 1 )
+   if ( (options->Role & ROLE_AP_LISTEN) && options->APPort < 1 )
    {
       log(LOG_ERR,"APPort option required and must be a positive integer value.");
       code = -1;
    }
 
-   if ( options->CoinWeight < 0.0 || options->CoinWeight >= 1.0 )
+   if ( (options->Role & ROLE_AP_LISTEN) &&
+        (options->CoinWeight < 0.0 || options->CoinWeight >= 1.0) )
    {
       log(LOG_ERR,"CoinWeight option must be a value from 0.0 upto 1.0, but not including 1.0.");
       code = -1;
@@ -245,12 +252,6 @@
    if ( options->LinkPadding != 0 && options->LinkPadding != 1 )
    {
       log(LOG_ERR,"LinkPadding option must be either 0 or 1.");
-      code = -1;
-   }
-
-   if ( options->Role < 0 || options->Role > 15 )
-   {
-      log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive).");
       code = -1;
    }
 

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- connection.c	3 Sep 2002 19:03:16 -0000	1.18
+++ connection.c	4 Sep 2002 06:29:27 -0000	1.19
@@ -297,13 +297,13 @@
   return 0;
 }
 
-connection_t *connection_connect_to_router_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, uint16_t local_or_port) {
+connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port) {
   struct sockaddr_in local; /* local address */
 
   if(learn_local(&local) < 0)
     return NULL;
   local.sin_port = htons(local_or_port);
-  return connection_or_connect_as_op(router, prkey, &local);
+  return connection_or_connect_as_op(router, &local);
 }
 
 int connection_read_to_buf(connection_t *conn) {
@@ -356,7 +356,7 @@
   if(!len)
     return 0;
 
-  if( (conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_OR) ||
+  if( (!connection_speaks_cells(conn)) ||
       (!connection_state_is_open(conn)) ||
       (options.LinkPadding == 0) ) {
     /* connection types other than or and op, or or/op not in 'open' state, should flush immediately */
@@ -528,8 +528,9 @@
   }
 #if 0
   printf("Sending: Cell header crypttext: ");
+  px = (char *)&newcell;
   for(x=0;x<8;x++) {
-    printf("%u ",newheader[x]);
+    printf("%u ",px[x]);
   }
   printf("\n");
 #endif

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- connection_or.c	3 Sep 2002 19:03:16 -0000	1.11
+++ connection_or.c	4 Sep 2002 06:29:28 -0000	1.12
@@ -218,21 +218,25 @@
  *
  */
 
-connection_t *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local) {
+connection_t *connection_or_connect_as_op(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. */
+    log(LOG_WARNING,"connection_or_connect_as_op(): You just asked me to connect to myself.");
     return NULL;
   }
 
   /* this function should never be called if we're already connected to router, but */
-  /* FIXME we should check here if we're already connected, and return the conn */
+  /* check first to be sure */
+  conn = connection_exact_get_by_addr_port(router->addr,router->or_port);
+  if(conn)
+    return conn;
 
-  conn = connection_or_connect(router, prkey, local, router->op_port, &result);
+  conn = connection_or_connect(router, NULL, local, router->op_port, &result);
   if(!conn)
     return NULL;
 
@@ -276,6 +280,7 @@
   *(uint32_t *)message = htonl(bandwidth);
   memcpy((void *)(message + 4), (void *)conn->f_crypto->key, 8);
   memcpy((void *)(message + 12), (void *)conn->b_crypto->key, 8);
+
 #if 0
   printf("f_session_key: ");
   for(x=0;x<8;x++) {

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- main.c	3 Sep 2002 18:44:23 -0000	1.20
+++ main.c	4 Sep 2002 06:29:28 -0000	1.21
@@ -198,8 +198,9 @@
 
 
 
+/* FIXME can we cut this function out? */
 connection_t *connect_to_router_as_op(routerinfo_t *router) {
-  return connection_connect_to_router_as_op(router, prkey, options.ORPort);
+  return connection_connect_to_router_as_op(router, options.ORPort);
 }
 
 void connection_watch_events(connection_t *conn, short events) {
@@ -418,16 +419,18 @@
     return -1;
   }
 
-  /* load the private key */
-  prkey = crypto_new_pk_env(CRYPTO_PK_RSA);
-  if (!prkey) {
-    log(LOG_ERR,"Error creating a crypto environment.");
-    return -1;
-  }
-  if (crypto_pk_read_private_key_filename(prkey, options.PrivateKeyFile))
-  {
-    log(LOG_ERR,"Error loading private key.");
-    return -1;
+  /* load the private key, if we're supposed to have one */
+  if(ROLE_IS_OR(global_role)) {
+    prkey = crypto_new_pk_env(CRYPTO_PK_RSA);
+    if (!prkey) {
+      log(LOG_ERR,"Error creating a crypto environment.");
+      return -1;
+    }
+    if (crypto_pk_read_private_key_filename(prkey, options.PrivateKeyFile))
+    {
+      log(LOG_ERR,"Error loading private key.");
+      return -1;
+    }
   }
 
   /* start-up the necessary connections based on global_role. This is where we

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- onion.c	3 Sep 2002 19:10:23 -0000	1.13
+++ onion.c	4 Sep 2002 06:29:28 -0000	1.14
@@ -4,6 +4,8 @@
 
 #include "or.h"
 
+extern int global_role; /* from main.c */
+
 /********* START VARIABLES **********/
 
 tracked_onion_t *tracked_onions = NULL; /* linked list of tracked onions */
@@ -109,8 +111,9 @@
   log(LOG_DEBUG,"new_route(): Chosen route length %d.",*routelen);
 
   for(i=0;i<rarray_len;i++) {
-    log(LOG_DEBUG,"Contemplating whether router %d is any good...",i);
-    if(!connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) {
+    log(LOG_DEBUG,"Contemplating whether router %d is a new option...",i);
+    if( (global_role & ROLE_OR_CONNECT_ALL) &&
+      !connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) {
       log(LOG_DEBUG,"Nope, %d is not connected.",i);
       goto next_i_loop;
     }
@@ -156,7 +159,7 @@
     log(LOG_DEBUG,"new_route(): Contemplating router %u.",choice);
     if(choice == oldchoice ||
       (oldchoice < rarray_len && !pkey_cmp(rarray[choice]->pkey, rarray[oldchoice]->pkey)) ||
-      !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port)) {
+      ((global_role & ROLE_OR_CONNECT_ALL) && !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port))) {
       /* Same router as last choice, or router twin,
        *   or no routers with that key are connected to us.
        * Try again. */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- or.h	3 Sep 2002 18:44:24 -0000	1.17
+++ or.h	4 Sep 2002 06:29:28 -0000	1.18
@@ -56,6 +56,8 @@
 #define ROLE_OP_LISTEN 4
 #define ROLE_AP_LISTEN 8
 
+#define ROLE_IS_OR(role) ((role & ROLE_OR_LISTEN) || (role & ROLE_OR_CONNECT_ALL) || (role & ROLE_OP_LISTEN))
+
 #define CONN_TYPE_OP_LISTENER 1
 #define CONN_TYPE_OP 2
 #define CONN_TYPE_OR_LISTENER 3
@@ -413,7 +415,7 @@
 /* start all connections that should be up but aren't */
 int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len,
 		  crypto_pk_env_t *prkey, uint16_t or_port, uint16_t op_port, uint16_t ap_port);
-connection_t *connection_connect_to_router_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, uint16_t local_or_port);
+connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port);
 
 int connection_read_to_buf(connection_t *conn);
 
@@ -509,7 +511,7 @@
 
 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 *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, 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_handle_listener_read(connection_t *conn);

Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- routers.c	27 Aug 2002 19:28:35 -0000	1.9
+++ routers.c	4 Sep 2002 06:29:28 -0000	1.10
@@ -14,6 +14,8 @@
 
 #include "or.h"
 
+extern int global_role; /* from main.c */
+
 /* private function, to determine whether the current entry in the router list is actually us */
 static int router_is_me(uint32_t or_address, uint16_t or_listenport, uint16_t my_or_listenport)
 {
@@ -25,6 +27,11 @@
   
   char *addr = NULL;
   int i = 0;
+
+  if(!ROLE_IS_OR(global_role)) {
+    /* we're not an OR. This obviously isn't us. */
+    return 0;
+  }
   
   /* obtain local host information */
   if (gethostname(localhostname,512) < 0) {



More information about the tor-commits mailing list