[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r9484: Add a REMAP state to stream events so that controllers can l (in tor/trunk: . doc/spec src/or)



Author: nickm
Date: 2007-02-05 14:15:13 -0500 (Mon, 05 Feb 2007)
New Revision: 9484

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/doc/spec/control-spec.txt
   tor/trunk/src/or/connection_edge.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/relay.c
Log:
 r11641@catbus:  nickm | 2007-02-05 13:59:26 -0500
 Add a REMAP state to stream events so that controllers can learn exactly when the target address for a stream has changed.  May help Vidalia resolve confusions related to bug 375.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r11641] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-02-05 18:33:52 UTC (rev 9483)
+++ tor/trunk/ChangeLog	2007-02-05 19:15:13 UTC (rev 9484)
@@ -97,8 +97,9 @@
     - Add a SOCKS_BAD_HOSTNAME client status event so controllers
       can learn when clients are sending malformed hostnames to Tor.
     - Clean up documentation for controller status events.
+    - Add a REMAP status to stream events to note that a stream's address has
+      changed because of a cached address or a MapAddress directive.
 
-
 Changes in version 0.1.2.6-alpha - 2007-01-09
   o Major bugfixes:
     - Fix an assert error introduced in 0.1.2.5-alpha: if a single TLS

Modified: tor/trunk/doc/spec/control-spec.txt
===================================================================
--- tor/trunk/doc/spec/control-spec.txt	2007-02-05 18:33:52 UTC (rev 9483)
+++ tor/trunk/doc/spec/control-spec.txt	2007-02-05 19:15:13 UTC (rev 9484)
@@ -832,6 +832,7 @@
       StreamStatus =
                "NEW"          / ; New request to connect
                "NEWRESOLVE"   / ; New request to resolve an address
+               "REMAP"        / ; Address re-mapped to another
                "SENTCONNECT"  / ; Sent a connect cell along a circuit
                "SENTRESOLVE"  / ; Sent a resolve cell along a circuit
                "SUCCEEDED"    / ; Received a reply; stream established

Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c	2007-02-05 18:33:52 UTC (rev 9483)
+++ tor/trunk/src/or/connection_edge.c	2007-02-05 19:15:13 UTC (rev 9484)
@@ -682,9 +682,10 @@
 
 /** Look at address, and rewrite it until it doesn't want any
  * more rewrites; but don't get into an infinite loop.
- * Don't write more than maxlen chars into address.
+ * Don't write more than maxlen chars into address.  Return true if the
+ * address changed; false otherwise.
  */
-void
+int
 addressmap_rewrite(char *address, size_t maxlen)
 {
   addressmap_entry_t *ent;
@@ -695,7 +696,7 @@
     ent = strmap_get(addressmap, address);
 
     if (!ent || !ent->new_address)
-      return; /* done, no rewrite needed */
+      return (rewrites > 0); /* done, no rewrite needed */
 
     cp = tor_strdup(escaped_safe_str(ent->new_address));
     log_info(LD_APP, "Addressmap: rewriting %s to %s",
@@ -707,6 +708,7 @@
            "Loop detected: we've rewritten %s 16 times! Using it as-is.",
            escaped_safe_str(address));
   /* it's fine to rewrite a rewrite, but don't loop forever */
+  return 1;
 }
 
 /** If we have a cached reverse DNS entry for the address stored in the
@@ -1216,7 +1218,9 @@
     }
   } else {
     /* For address map controls, remap the address */
-    addressmap_rewrite(socks->address, sizeof(socks->address));
+    if (addressmap_rewrite(socks->address, sizeof(socks->address))) {
+      control_event_stream_status(conn, STREAM_EVENT_REMAP, 0);
+    }
   }
 
   if (address_is_in_virtual_range(socks->address)) {

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-02-05 18:33:52 UTC (rev 9483)
+++ tor/trunk/src/or/control.c	2007-02-05 19:15:13 UTC (rev 9484)
@@ -3206,6 +3206,7 @@
       case STREAM_EVENT_NEW: status = "NEW"; break;
       case STREAM_EVENT_NEW_RESOLVE: status = "NEWRESOLVE"; break;
       case STREAM_EVENT_FAILED_RETRIABLE: status = "DETACHED"; break;
+      case STREAM_EVENT_REMAP: status = "REMAP"; break;
       default:
         log_warn(LD_BUG, "Unrecognized status code %d", (int)tp);
         return 0;

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-02-05 18:33:52 UTC (rev 9483)
+++ tor/trunk/src/or/or.h	2007-02-05 19:15:13 UTC (rev 9484)
@@ -2208,7 +2208,7 @@
 void addressmap_clear_configured(void);
 void addressmap_clear_transient(void);
 void addressmap_free_all(void);
-void addressmap_rewrite(char *address, size_t maxlen);
+int addressmap_rewrite(char *address, size_t maxlen);
 int addressmap_have_mapping(const char *address);
 void addressmap_register(const char *address, char *new_address,
                          time_t expires);
@@ -2272,7 +2272,8 @@
   STREAM_EVENT_CLOSED       = 4,
   STREAM_EVENT_NEW          = 5,
   STREAM_EVENT_NEW_RESOLVE  = 6,
-  STREAM_EVENT_FAILED_RETRIABLE = 7
+  STREAM_EVENT_FAILED_RETRIABLE = 7,
+  STREAM_EVENT_REMAP        = 8
 } stream_status_event_t;
 
 typedef enum or_conn_status_event_t {

Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c	2007-02-05 18:33:52 UTC (rev 9483)
+++ tor/trunk/src/or/relay.c	2007-02-05 19:15:13 UTC (rev 9484)
@@ -750,8 +750,10 @@
             router_parse_addr_policy_from_string("reject *:*", -1);
         }
         /* rewrite it to an IP if we learned one. */
-        addressmap_rewrite(conn->socks_request->address,
-                           sizeof(conn->socks_request->address));
+        if (addressmap_rewrite(conn->socks_request->address,
+                               sizeof(conn->socks_request->address))) {
+          control_event_stream_status(conn, STREAM_EVENT_REMAP, 0);
+        }
         if (conn->_base.chosen_exit_optional) {
           /* stop wanting a specific exit */
           conn->_base.chosen_exit_optional = 0;