Browse Source

if they ask for exactly one entrynode, don't pick it as an exitnode.

also, fix part of the zero-identity-router-in-stats bug


svn:r2252
Roger Dingledine 21 years ago
parent
commit
2d8a1f208a
2 changed files with 13 additions and 4 deletions
  1. 12 3
      src/or/circuitbuild.c
  2. 1 1
      src/or/connection.c

+ 12 - 3
src/or/circuitbuild.c

@@ -798,9 +798,12 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
   int n_connections;
   int best_support = -1;
   int n_best_support=0;
-  smartlist_t *sl, *preferredexits, *excludedexits;
+  smartlist_t *sl, *preferredexits, *preferredentries, *excludedexits;
   routerinfo_t *router;
 
+  preferredentries = smartlist_create();
+  add_nickname_list_to_smartlist(preferredentries,options.EntryNodes);
+
   get_connection_array(&carray, &n_connections);
 
   /* Count how many connections are waiting for a circuit to be built.
@@ -850,6 +853,12 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
              router->nickname, i);
       continue; /* skip routers that reject all */
     }
+    if(smartlist_len(preferredentries)==1 &&
+       router == (routerinfo_t*)smartlist_get(preferredentries, 0)) {
+      n_supported[i] = -1;
+      log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- it's our only preferred entry node.", router->nickname, i);
+      continue;
+    }
     n_supported[i] = 0;
     for (j = 0; j < n_connections; ++j) { /* iterate over connections */
       if (carray[j]->type != CONN_TYPE_AP ||
@@ -917,6 +926,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
   }
 
   smartlist_free(preferredexits);
+  smartlist_free(preferredentries);
   smartlist_free(excludedexits);
   smartlist_free(sl);
   tor_free(n_supported);
@@ -926,7 +936,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
   }
   if (options.StrictExitNodes)
     log_fn(LOG_WARN, "No exit routers seem to be running; can't choose an exit.");
-  
+
   return NULL;
 }
 
@@ -943,7 +953,6 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
 static routerinfo_t *choose_good_exit_server(uint8_t purpose, routerlist_t *dir)
 {
   routerinfo_t *r;
-  /* XXX one day, consider picking chosen_exit knowing what's in EntryNodes */
   switch(purpose) {
     case CIRCUIT_PURPOSE_C_GENERAL:
       return choose_good_exit_server_general(dir);

+ 1 - 1
src/or/connection.c

@@ -199,7 +199,7 @@ void connection_about_to_close_connection(connection_t *conn)
           rep_hist_note_connect_failed(conn->identity_digest, time(NULL));
       } else if (0) { // XXX reason == CLOSE_REASON_UNUSED_OR_CONN) {
         rep_hist_note_disconnect(conn->identity_digest, time(NULL));
-      } else {
+      } else if(conn->identity_digest) {
         rep_hist_note_connection_died(conn->identity_digest, time(NULL));
       }
       break;