ソースを参照

my_routerinfo, router_is_me, and learn_my_address are obsolete
ACIs are decided now by strcmp'ing nicknames, rather than comparing addr:port


svn:r529

Roger Dingledine 20 年 前
コミット
efa8e288ef
7 ファイル変更21 行追加97 行削除
  1. 1 6
      src/or/circuit.c
  2. 1 1
      src/or/config.c
  3. 2 3
      src/or/connection_or.c
  4. 0 1
      src/or/main.c
  5. 10 10
      src/or/onion.c
  6. 1 2
      src/or/or.h
  7. 6 74
      src/or/routers.c

+ 1 - 6
src/or/circuit.c

@@ -789,7 +789,6 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
 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 @@ int circuit_extend(cell_t *cell, circuit_t *circ) {
   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 @@ int circuit_extend(cell_t *cell, circuit_t *circ) {
   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);

+ 1 - 1
src/or/config.c

@@ -200,7 +200,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
   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;

+ 2 - 3
src/or/connection_or.c

@@ -94,9 +94,8 @@ connection_t *connection_or_connect(routerinfo_t *router) {
 
   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;
   }
 

+ 0 - 1
src/or/main.c

@@ -7,7 +7,6 @@
 /********* START PROTOTYPES **********/
 
 static void dumpstats(void); /* dump stats to stdout */
-static int init_descriptor(void);
 
 /********* START VARIABLES **********/
 

+ 10 - 10
src/or/onion.c

@@ -8,17 +8,17 @@ extern or_options_t options; /* command-line and config-file options */
 
 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;
+  result = strcmp(local_nick, remote_nick);
+  assert(result);
+  if(result < 0)
     return ACI_TYPE_LOWER;
-  if(local_port > remote_port)
-    return ACI_TYPE_HIGHER;
-   /* else */
-   return ACI_TYPE_LOWER; 
+  return ACI_TYPE_HIGHER;
 }
 
 struct onion_queue_t {

+ 1 - 2
src/or/or.h

@@ -636,8 +636,7 @@ int main(int argc, char *argv[]);
 
 /********************************* 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);

+ 6 - 74
src/or/routers.c

@@ -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 @@ static int router_resolve_directory(directory_t *dir);
 
 /****************************************************************************/
 
-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 @@ void router_get_directory(directory_t **pdirectory) {
   *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 @@ router_resolve_directory(directory_t *dir)
              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 @@ policy_read_failed:
 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 @@ int router_compare_to_exit_policy(connection_t *conn) {
   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())