Browse Source

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.
George Kadianakis 13 years ago
parent
commit
abe03f4943
4 changed files with 59 additions and 6 deletions
  1. 54 1
      src/or/connection.c
  2. 1 0
      src/or/connection.h
  3. 2 5
      src/or/main.c
  4. 2 0
      src/or/or.h

+ 54 - 1
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); 
+  }
+}

+ 1 - 0
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);

+ 2 - 5
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) &&

+ 2 - 0
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. */