[or-cvs] my_routerinfo, router_is_me, and learn_my_address are obsol...

Roger Dingledine arma at seul.org
Wed Oct 1 01:49:55 UTC 2003


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

Modified Files:
	circuit.c config.c connection_or.c main.c onion.c or.h 
	routers.c 
Log Message:
my_routerinfo, router_is_me, and learn_my_address are obsolete
ACIs are decided now by strcmp'ing nicknames, rather than comparing addr:port


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- circuit.c	27 Sep 2003 21:09:55 -0000	1.70
+++ circuit.c	1 Oct 2003 01:49:53 -0000	1.71
@@ -789,7 +789,6 @@
 int circuit_extend(cell_t *cell, circuit_t *circ) {
   connection_t *n_conn;
   aci_t aci_type;
-  struct sockaddr_in me; /* my router identity */
   cell_t newcell;
 
   if(circ->n_conn) {
@@ -800,9 +799,6 @@
   circ->n_addr = ntohl(*(uint32_t*)(cell->payload+RELAY_HEADER_SIZE));
   circ->n_port = ntohs(*(uint16_t*)(cell->payload+RELAY_HEADER_SIZE+4));
 
-  if(learn_my_address(&me) < 0)
-    return -1;
-
   n_conn = connection_twin_get_by_addr_port(circ->n_addr,circ->n_port);
   if(!n_conn || n_conn->type != CONN_TYPE_OR) {
     /* i've disabled making connections through OPs, but it's definitely
@@ -824,8 +820,7 @@
   circ->n_conn = n_conn;
   log_fn(LOG_DEBUG,"n_conn is %s:%u",n_conn->address,n_conn->port);
 
-  aci_type = decide_aci_type(ntohl(me.sin_addr.s_addr), ntohs(me.sin_port),
-                             circ->n_addr, circ->n_port);
+  aci_type = decide_aci_type(options.Nickname, n_conn->nickname);
 
   log_fn(LOG_DEBUG,"aci_type = %u.",aci_type);
   circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, aci_type);

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- config.c	30 Sep 2003 23:06:23 -0000	1.49
+++ config.c	1 Oct 2003 01:49:53 -0000	1.50
@@ -200,7 +200,7 @@
   options->LogLevel = "debug";
   options->loglevel = LOG_DEBUG;
   options->DataDirectory = NULL;
-  options->CoinWeight = 0.8;
+  options->CoinWeight = 0.1;
   options->MaxConn = 900;
   options->DirFetchPostPeriod = 600;
   options->KeepalivePeriod = 300;

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- connection_or.c	30 Sep 2003 20:36:20 -0000	1.60
+++ connection_or.c	1 Oct 2003 01:49:53 -0000	1.61
@@ -94,9 +94,8 @@
 
   assert(router);
 
-  if(router_is_me(router->addr, router->or_port)) {
-    /* this is me! don't connect to me. XXX use nickname/key */
-    log(LOG_DEBUG,"connection_or_connect(): This is me. Skipping.");
+  if(options.Nickname && !strcmp(router->nickname,options.Nickname)) {
+    log_fn(LOG_WARNING,"You asked me to connect to myself! Failing.");
     return NULL;
   }
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- main.c	1 Oct 2003 01:08:20 -0000	1.120
+++ main.c	1 Oct 2003 01:49:53 -0000	1.121
@@ -7,7 +7,6 @@
 /********* START PROTOTYPES **********/
 
 static void dumpstats(void); /* dump stats to stdout */
-static int init_descriptor(void);
 
 /********* START VARIABLES **********/
 

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- onion.c	30 Sep 2003 08:18:09 -0000	1.68
+++ onion.c	1 Oct 2003 01:49:53 -0000	1.69
@@ -8,17 +8,17 @@
 
 static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len);
 
-int decide_aci_type(uint32_t local_addr, uint16_t local_port,
-                    uint32_t remote_addr, uint16_t remote_port) {
-
-  if(local_addr > remote_addr)
-    return ACI_TYPE_HIGHER;
-  if(local_addr < remote_addr)
+int decide_aci_type(char *local_nick, char *remote_nick) {
+  int result;
+ 
+  assert(remote_nick);
+  if(!local_nick)
     return ACI_TYPE_LOWER;
-  if(local_port > remote_port)
-    return ACI_TYPE_HIGHER;
-   /* else */
-   return ACI_TYPE_LOWER; 
+  result = strcmp(local_nick, remote_nick);
+  assert(result);
+  if(result < 0)
+    return ACI_TYPE_LOWER;
+  return ACI_TYPE_HIGHER;
 }
 
 struct onion_queue_t {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- or.h	1 Oct 2003 01:08:20 -0000	1.152
+++ or.h	1 Oct 2003 01:49:53 -0000	1.153
@@ -636,8 +636,7 @@
 
 /********************************* onion.c ***************************/
 
-int decide_aci_type(uint32_t local_addr, uint16_t local_port,
-                    uint32_t remote_addr, uint16_t remote_port);
+int decide_aci_type(char *local_nick, char *remote_nick);
 
 int onion_pending_add(circuit_t *circ);
 circuit_t *onion_next_task(void);

Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- routers.c	1 Oct 2003 01:08:20 -0000	1.66
+++ routers.c	1 Oct 2003 01:49:53 -0000	1.67
@@ -19,11 +19,11 @@
 
 /****************************************************************************/
 
-/* router array */
-static directory_t *directory = NULL;
+static directory_t *directory = NULL; /* router array */
+static routerinfo_t *desc_routerinfo = NULL; /* my descriptor */
+static char descriptor[8192]; /* string representation of my descriptor */
 
 extern or_options_t options; /* command-line and config-file options */
-static routerinfo_t *my_routerinfo;
 
 /****************************************************************************/
 
@@ -42,42 +42,6 @@
 
 /****************************************************************************/
 
-int learn_my_address(struct sockaddr_in *me) {
-  /* local host information */
-  char localhostname[256];
-  struct hostent *localhost;
-  static struct sockaddr_in answer;
-  static int already_learned=0;
-
-  if(!already_learned) {
-    /* obtain local host information */
-    if(gethostname(localhostname,sizeof(localhostname)) < 0) {
-      log_fn(LOG_WARNING,"Error obtaining local hostname");
-      return -1;
-    }
-    log_fn(LOG_DEBUG,"localhostname is '%s'.",localhostname);
-    localhost = gethostbyname(localhostname);
-    if (!localhost) {
-      log_fn(LOG_WARNING,"Error obtaining local host info.");
-      /* XXX maybe this is worse than warning? bad things happen when we don't know ourselves */
-      return -1;
-    }
-    memset(&answer,0,sizeof(struct sockaddr_in));
-    answer.sin_family = AF_INET;
-    memcpy((void *)&answer.sin_addr,(void *)localhost->h_addr,sizeof(struct in_addr));
-    answer.sin_port = htons((uint16_t) options.ORPort);
-    log_fn(LOG_DEBUG,"chose address as '%s'.",inet_ntoa(answer.sin_addr));
-    if (!strncmp("127.",inet_ntoa(answer.sin_addr), 4) &&
-        strcasecmp(localhostname, "localhost")) {
-      /* We're a loopback IP but we're not called localhost.  Uh oh! */
-      log_fn(LOG_WARNING, "Got a loopback address: /etc/hosts may be wrong");
-    }
-    already_learned = 1;
-  }
-  memcpy(me,&answer,sizeof(struct sockaddr_in));
-  return 0;
-}
-
 void router_retry_connections(void) {
   int i;
   routerinfo_t *router;
@@ -175,30 +139,6 @@
   *pdirectory = directory;
 }
 
-/* return 1 if addr and port corresponds to my addr and my or_listenport. else 0,
- * or -1 for failure.
- */
-int router_is_me(uint32_t addr, uint16_t port)
-{
-  /* XXXX Should this check the key too? */
-  struct sockaddr_in me; /* my router identity */
-
-  if(!options.OnionRouter) {
-    /* we're not an OR. This obviously isn't us. */
-    return 0;
-  }
- 
-  if(learn_my_address(&me) < 0)
-    return -1;
-    /* XXX people call this function like a boolean. that's bad news: -1 is true. */
-
-  if(ntohl(me.sin_addr.s_addr) == addr && ntohs(me.sin_port) == port)
-    return 1;
-
-  return 0;
-
-}
-
 /* delete a list of routers from memory */
 void routerinfo_free(routerinfo_t *router)
 {
@@ -806,8 +746,7 @@
              dir->routers[i]->address);
       remove = 1;
       routerinfo_free(dir->routers[i]);
-    } else if (router_is_me(dir->routers[i]->addr, dir->routers[i]->or_port)) {
-      my_routerinfo = dir->routers[i];
+    } else if (options.Nickname && !strcmp(dir->routers[i]->nickname, options.Nickname)) {
       remove = 1;
     }
     if (remove) {
@@ -1068,12 +1007,9 @@
 int router_compare_to_exit_policy(connection_t *conn) {
   struct exit_policy_t *tmpe;
 
-  if(!my_routerinfo) {
-    log_fn(LOG_WARNING, "my_routerinfo undefined! Rejected.");
-    return -1;
-  }
+  assert(desc_routerinfo);
 
-  for(tmpe=my_routerinfo->exit_policy; tmpe; tmpe=tmpe->next) {
+  for(tmpe=desc_routerinfo->exit_policy; tmpe; tmpe=tmpe->next) {
     assert(tmpe->address);
     assert(tmpe->port);
 
@@ -1093,10 +1029,6 @@
   return 0; /* accept all by default. */
 }
 
-
-static char descriptor[8192];
-/* XXX should this replace my_routerinfo? */
-static routerinfo_t *desc_routerinfo = NULL; 
 const char *router_get_my_descriptor(void) {
   if (!desc_routerinfo) {
     if (router_rebuild_descriptor())



More information about the tor-commits mailing list