[tor-commits] [tor/master] Our warning now is much more specific, mentioning proxy type/addr/port.

nickm at torproject.org nickm at torproject.org
Mon Jul 11 20:01:36 UTC 2011


commit abe03f494321c985f5909558b5b476269982a894
Author: George Kadianakis <desnacked at gmail.com>
Date:   Tue Jun 14 03:27:07 2011 +0200

    Our warning now is much more specific, mentioning proxy type/addr/port.
    
    Not included in the previous commit, because the implementation is
    ugly; I see no other way of doing this though.
---
 src/or/connection.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/or/connection.h |    1 +
 src/or/main.c       |    7 +----
 src/or/or.h         |    2 +
 4 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index ae69502..087ee29 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -66,6 +66,8 @@ static void set_constrained_socket_buffers(tor_socket_t sock, int size);
 static const char *connection_proxy_state_to_string(int state);
 static int connection_read_https_proxy_response(connection_t *conn);
 static void connection_send_socks5_connect(connection_t *conn);
+static const char *proxy_type_to_string(int proxy_type);
+
 
 /** The last IPv4 address that our network interface seemed to have been
  * binding to, in host order.  We use this to detect when our IP changes. */
@@ -3936,7 +3938,7 @@ connection_dump_buffer_mem_stats(int severity)
         U64_PRINTF_ARG(used_by_type[i]), U64_PRINTF_ARG(alloc_by_type[i]));
   }
 }
-
+    
 /** Verify that connection <b>conn</b> has all of its invariants
  * correct. Trigger an assert if anything is invalid.
  */
@@ -4099,3 +4101,54 @@ assert_connection_ok(connection_t *conn, time_t now)
   }
 }
 
+void
+log_failed_proxy_connection(connection_t *conn)
+{
+  or_options_t *options = get_options();
+  int proxy_type;
+  tor_addr_t proxy_addr;
+  int proxy_port;
+
+  if (options->HTTPSProxy) {
+    tor_addr_copy(&proxy_addr, &options->HTTPSProxyAddr);
+    proxy_port = options->HTTPSProxyPort;
+    proxy_type = PROXY_CONNECT;
+  } else if (options->Socks4Proxy) {
+    tor_addr_copy(&proxy_addr, &options->Socks4ProxyAddr);
+    proxy_port = options->Socks4ProxyPort;
+    proxy_type = PROXY_SOCKS4;
+  } else if (options->Socks5Proxy) {
+    tor_addr_copy(&proxy_addr, &options->Socks5ProxyAddr);
+    proxy_port = options->Socks5ProxyPort;
+    proxy_type = PROXY_SOCKS5;
+  } else if (options->ClientTransportPlugin) {
+    transport_info_t *transport;
+    transport = find_transport_by_bridge_addrport(&conn->addr, conn->port);
+    if (transport) {
+      tor_addr_copy(&proxy_addr, &transport->addr);
+      proxy_port = transport->port;
+      proxy_type = PROXY_PLUGGABLE;
+    } else
+      return;
+  } else
+    tor_assert(0);
+  
+  log_warn(LD_NET,
+           "The connection to the %s proxy server at %s:%u just failed. "
+           "Make sure that the proxy server is up and running.",
+           proxy_type_to_string(proxy_type), fmt_addr(&proxy_addr), 
+           proxy_port);  
+}
+
+static const char *
+proxy_type_to_string(int proxy_type)
+{
+  switch (proxy_type) {
+  case PROXY_CONNECT:   return "HTTP";
+  case PROXY_SOCKS4:    return "SOCKS4";
+  case PROXY_SOCKS5:    return "SOCKS5";
+  case PROXY_PLUGGABLE: return "pluggable transports SOCKS";
+  case PROXY_NONE:      return "NULL"; /* probably a bug */
+  default:              tor_assert(0); 
+  }
+}
diff --git a/src/or/connection.h b/src/or/connection.h
index 94ae645..ba6a258 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -57,6 +57,7 @@ int connection_connect(connection_t *conn, const char *address,
 
 int connection_proxy_connect(connection_t *conn, int type);
 int connection_read_proxy_handshake(connection_t *conn);
+void log_failed_proxy_connection(connection_t *conn);
 
 int retry_all_listeners(smartlist_t *replaced_conns,
                         smartlist_t *new_conns);
diff --git a/src/or/main.c b/src/or/main.c
index 09d35ed..f456b03 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -761,11 +761,8 @@ conn_close_if_marked(int i)
   /* If the connection we are about to close was trying to connect to
   a proxy server and failed, the client won't be able to use that
   proxy. We should warn him about this. */
-  if (conn->proxy_state == PROXY_INFANT) {
-    log_warn(LD_NET,
-             "The connection to a configured proxy server just failed. "
-             "Make sure that the proxy server is up and running.");  
-  }
+  if (conn->proxy_state == PROXY_INFANT)
+    log_failed_proxy_connection(conn);
 
   IF_HAS_BUFFEREVENT(conn, goto unlink);
   if ((SOCKET_OK(conn->s) || conn->linked_conn) &&
diff --git a/src/or/or.h b/src/or/or.h
index 6f056b2..f713db7 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -230,6 +230,8 @@ typedef enum {
 #define PROXY_CONNECT 1
 #define PROXY_SOCKS4 2
 #define PROXY_SOCKS5 3
+/* pluggable transports proxy type */
+#define PROXY_PLUGGABLE 4
 
 /* Proxy client handshake states */
 /* We use a proxy but we haven't even connected to it yet. */ 





More information about the tor-commits mailing list