[or-cvs] Backport three bugfixes:

arma at seul.org arma at seul.org
Mon Jan 2 13:32:48 UTC 2006


Update of /home/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/tor-010x/tor/src/or

Modified Files:
      Tag: tor-0_1_0-patches
	connection_edge.c or.h relay.c 
Log Message:
Backport three bugfixes:
1) When a stream fails for reason exitpolicy, stop assuming that
   the router is lying about his exit policy.
2) When a stream fails for reason misc, allow it to retry just as
   if it was resolvefailed.
3) When a stream has failed three times, reset its failure count
   so we can try again and get all three tries.


Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.327.2.2
retrieving revision 1.327.2.3
diff -u -p -d -r1.327.2.2 -r1.327.2.3
--- connection_edge.c	1 Jul 2005 01:56:07 -0000	1.327.2.2
+++ connection_edge.c	2 Jan 2006 13:32:46 -0000	1.327.2.3
@@ -612,6 +612,19 @@ void addressmap_register(const char *add
          safe_str(address), safe_str(ent->new_address));
 }
 
+/** If <b>address</b> is in the client dns addressmap, reset
+ * the number of resolve failures we have on record for it.
+ * This is used when we fail a stream because it won't resolve:
+ * otherwise future attempts on that address will only try once.
+ */
+void
+client_dns_clear_failures(const char *address)
+{
+  addressmap_entry_t *ent = strmap_get(addressmap, address);
+  if (ent)
+    ent->num_resolve_failures = 0;
+}
+
 /** An attempt to resolve <b>address</b> failed at some OR.
  * Increment the number of resolve failures we have on record
  * for it, and then return that number.

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.610.2.5
retrieving revision 1.610.2.6
diff -u -p -d -r1.610.2.5 -r1.610.2.6
--- or.h	8 Dec 2005 21:33:56 -0000	1.610.2.5
+++ or.h	2 Jan 2006 13:32:46 -0000	1.610.2.6
@@ -1370,6 +1370,7 @@ void addressmap_free_all(void);
 void addressmap_rewrite(char *address, size_t maxlen);
 int addressmap_already_mapped(const char *address);
 void addressmap_register(const char *address, char *new_address, time_t expires);
+void client_dns_clear_failures(const char *address);
 int client_dns_incr_failures(const char *address);
 void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
 const char *addressmap_register_virtual_address(int type, char *new_address);

Index: relay.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/relay.c,v
retrieving revision 1.69
retrieving revision 1.69.2.1
diff -u -p -d -r1.69 -r1.69.2.1
--- relay.c	17 May 2005 20:00:24 -0000	1.69
+++ relay.c	2 Jan 2006 13:32:46 -0000	1.69.2.1
@@ -414,7 +414,7 @@ int connection_edge_send_command(connect
   }
 
   if (!circ) {
-    log_fn(LOG_WARN,"no circ. Closing conn.");
+    log_fn(LOG_INFO,"no circ. Closing conn.");
     tor_assert(fromconn);
     if (fromconn->type == CONN_TYPE_AP) {
       connection_mark_unattached_ap(fromconn, END_STREAM_REASON_INTERNAL);
@@ -578,7 +578,7 @@ errno_to_end_reason(int e)
 }
 
 /** How many times will I retry a stream that fails due to DNS
- * resolve failure?
+ * resolve failure or misc error?
  */
 #define MAX_RESOLVE_FAILURES 3
 
@@ -589,7 +589,8 @@ edge_reason_is_retriable(int reason) {
   return reason == END_STREAM_REASON_HIBERNATING ||
          reason == END_STREAM_REASON_RESOURCELIMIT ||
          reason == END_STREAM_REASON_EXITPOLICY ||
-         reason == END_STREAM_REASON_RESOLVEFAILED;
+         reason == END_STREAM_REASON_RESOLVEFAILED ||
+         reason == END_STREAM_REASON_MISC;
 }
 
 static int
@@ -629,19 +630,23 @@ connection_edge_process_end_not_open(
         }
         /* check if he *ought* to have allowed it */
         if (rh->length < 5 ||
-            (!tor_inet_aton(conn->socks_request->address, &in) &&
+            (tor_inet_aton(conn->socks_request->address, &in) &&
              !conn->chosen_exit_name)) {
           log_fn(LOG_NOTICE,"Exitrouter '%s' seems to be more restrictive than its exit policy. Not using this router as exit for now.", exitrouter->nickname);
           addr_policy_free(exitrouter->exit_policy);
           exitrouter->exit_policy =
             router_parse_addr_policy_from_string("reject *:*");
         }
+        /* rewrite it to an IP if we learned one. */
+        addressmap_rewrite(conn->socks_request->address,
+                           sizeof(conn->socks_request->address));
 
         if (connection_ap_detach_retriable(conn, circ) >= 0)
           return 0;
         /* else, conn will get closed below */
         break;
       case END_STREAM_REASON_RESOLVEFAILED:
+      case END_STREAM_REASON_MISC:
         if (client_dns_incr_failures(conn->socks_request->address)
             < MAX_RESOLVE_FAILURES) {
           /* We haven't retried too many times; reattach the connection. */
@@ -653,8 +658,10 @@ connection_edge_process_end_not_open(
             return 0;
           /* else, conn will get closed below */
         } else {
-          log_fn(LOG_NOTICE,"Have tried resolving address '%s' at %d different places. Giving up.",
+          log_fn(LOG_NOTICE,"Have tried resolving or connecting to address '%s' at %d different places. Giving up.",
                  safe_str(conn->socks_request->address), MAX_RESOLVE_FAILURES);
+          /* clear the failures, so it will have a full try next time */
+          client_dns_clear_failures(conn->socks_request->address);
         }
         break;
       case END_STREAM_REASON_HIBERNATING:



More information about the tor-commits mailing list