aboutsummaryrefslogtreecommitdiff
path: root/src/or/connection_or.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-07-03 00:13:41 -0400
committerNick Mathewson <nickm@torproject.org>2011-07-03 00:13:41 -0400
commit6053e11ee6540750a68a7c59a1b91727f7e10952 (patch)
treeec4893214c3552adb9f6203deb80be9a41e6f0d1 /src/or/connection_or.c
parent72125389979af60b659dc469159ea9be397a2ffa (diff)
downloadtor-6053e11ee6540750a68a7c59a1b91727f7e10952.tar.gz
tor-6053e11ee6540750a68a7c59a1b91727f7e10952.zip
Refactor the interfaces of transport/proxy lookup fns
Returning a tristate is needless here; we can just use the yielded transport/proxy_type field to tell whether there's a proxy, and have the return indicate success/failure. Also, store the proxy_type in the or_connection_t rather than letting it get out of sync if a configuration reload happens between launching the or_connection and deciding what to say with it.
Diffstat (limited to 'src/or/connection_or.c')
-rw-r--r--src/or/connection_or.c39
1 files changed, 11 insertions, 28 deletions
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 2de25f6807..a02ec1e268 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -317,7 +317,7 @@ connection_or_finished_flushing(or_connection_t *conn)
int
connection_or_finished_connecting(or_connection_t *or_conn)
{
- int proxy_type;
+ const int proxy_type = or_conn->proxy_type;
connection_t *conn;
tor_assert(or_conn);
conn = TO_CONN(or_conn);
@@ -327,27 +327,6 @@ connection_or_finished_connecting(or_connection_t *or_conn)
conn->address,conn->port);
control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE, 0);
- proxy_type = PROXY_NONE;
-
- if (get_options()->HTTPSProxy)
- proxy_type = PROXY_CONNECT;
- else if (get_options()->Socks4Proxy)
- proxy_type = PROXY_SOCKS4;
- else if (get_options()->Socks5Proxy)
- proxy_type = PROXY_SOCKS5;
- else if (get_options()->ClientTransportPlugin) {
- const transport_t *transport=NULL;
- int r;
- r = find_transport_by_bridge_addrport(&conn->addr,conn->port,&transport);
- if (r == 0) {
- tor_assert(transport);
- log_debug(LD_GENERAL, "Found transport. Setting proxy type!\n");
- proxy_type = transport->socks_version;
- } else if (r == -1) {
- return -1;
- }
- }
-
if (proxy_type != PROXY_NONE) {
/* start proxy handshake */
if (connection_proxy_connect(conn, proxy_type) < 0) {
@@ -846,6 +825,7 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
int r;
tor_addr_t proxy_addr;
uint16_t proxy_port;
+ int proxy_type;
tor_assert(_addr);
tor_assert(id_digest);
@@ -864,12 +844,15 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED, 0);
/* If we are using a proxy server, find it and use it. */
- r = get_proxy_addrport(&proxy_addr, &proxy_port, TO_CONN(conn));
- if (r == 0) { /* proxy found. */
- tor_addr_copy(&addr, &proxy_addr);
- port = proxy_port;
- conn->_base.proxy_state = PROXY_INFANT;
- } else if (r == -1) { /* proxy could not be found. */
+ r = get_proxy_addrport(&proxy_addr, &proxy_port, &proxy_type, TO_CONN(conn));
+ if (r == 0) {
+ conn->proxy_type = proxy_type;
+ if (proxy_type != PROXY_NONE) {
+ tor_addr_copy(&addr, &proxy_addr);
+ port = proxy_port;
+ conn->_base.proxy_state = PROXY_INFANT;
+ }
+ } else {
log_warn(LD_GENERAL, "Tried to connect through proxy, but proxy address "
"could not be found.");
connection_free(TO_CONN(conn));