mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
This commit is an attempt to beautify the previous commit.
It creates some helper functions that return the proxy type, proxy addr/port, etc.
This commit is contained in:
parent
abe03f4943
commit
5b050a9b08
@ -4101,37 +4101,82 @@ assert_connection_ok(connection_t *conn, time_t now)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/**
|
||||||
log_failed_proxy_connection(connection_t *conn)
|
Fills <b>addr</b> and <b>port</b> with the details of the proxy
|
||||||
{
|
server of type 'proxy_type' we are using.
|
||||||
or_options_t *options = get_options();
|
'conn' contains a connection_t and is used for finding pluggable
|
||||||
int proxy_type;
|
transports proxies.
|
||||||
tor_addr_t proxy_addr;
|
|
||||||
int proxy_port;
|
|
||||||
|
|
||||||
if (options->HTTPSProxy) {
|
Returns 1 if we were successfull, 0 if we are not using a proxy
|
||||||
tor_addr_copy(&proxy_addr, &options->HTTPSProxyAddr);
|
server and -1 if something went wrong.
|
||||||
proxy_port = options->HTTPSProxyPort;
|
*/
|
||||||
proxy_type = PROXY_CONNECT;
|
int
|
||||||
} else if (options->Socks4Proxy) {
|
get_proxy_addrport(int proxy_type, tor_addr_t *addr, uint16_t *port,
|
||||||
tor_addr_copy(&proxy_addr, &options->Socks4ProxyAddr);
|
connection_t *conn)
|
||||||
proxy_port = options->Socks4ProxyPort;
|
{
|
||||||
proxy_type = PROXY_SOCKS4;
|
or_options_t *options;
|
||||||
} else if (options->Socks5Proxy) {
|
|
||||||
tor_addr_copy(&proxy_addr, &options->Socks5ProxyAddr);
|
if (proxy_type == PROXY_NONE)
|
||||||
proxy_port = options->Socks5ProxyPort;
|
return 0;
|
||||||
proxy_type = PROXY_SOCKS5;
|
|
||||||
} else if (options->ClientTransportPlugin) {
|
options = get_options();
|
||||||
|
|
||||||
|
if (proxy_type == PROXY_CONNECT) {
|
||||||
|
tor_addr_copy(addr, &options->HTTPSProxyAddr);
|
||||||
|
*port = options->HTTPSProxyPort;
|
||||||
|
} else if (proxy_type == PROXY_SOCKS4) {
|
||||||
|
tor_addr_copy(addr, &options->Socks4ProxyAddr);
|
||||||
|
*port = options->Socks4ProxyPort;
|
||||||
|
} else if (proxy_type == PROXY_SOCKS5) {
|
||||||
|
tor_addr_copy(addr, &options->Socks5ProxyAddr);
|
||||||
|
*port = options->Socks5ProxyPort;
|
||||||
|
} else if (proxy_type == PROXY_PLUGGABLE) {
|
||||||
transport_info_t *transport;
|
transport_info_t *transport;
|
||||||
transport = find_transport_by_bridge_addrport(&conn->addr, conn->port);
|
transport = find_transport_by_bridge_addrport(&conn->addr, conn->port);
|
||||||
if (transport) {
|
if (transport) {
|
||||||
tor_addr_copy(&proxy_addr, &transport->addr);
|
tor_addr_copy(addr, &transport->addr);
|
||||||
proxy_port = transport->port;
|
*port = transport->port;
|
||||||
proxy_type = PROXY_PLUGGABLE;
|
|
||||||
} else
|
} else
|
||||||
return;
|
return -1;
|
||||||
} else
|
} else
|
||||||
tor_assert(0);
|
return -1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the proxy type used by tor.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
get_proxy_type(void)
|
||||||
|
{
|
||||||
|
or_options_t *options = get_options();
|
||||||
|
|
||||||
|
if (options->HTTPSProxy)
|
||||||
|
return PROXY_CONNECT;
|
||||||
|
else if (options->Socks4Proxy)
|
||||||
|
return PROXY_SOCKS4;
|
||||||
|
else if (options->Socks5Proxy)
|
||||||
|
return PROXY_SOCKS5;
|
||||||
|
else if (options->ClientTransportPlugin)
|
||||||
|
return PROXY_PLUGGABLE;
|
||||||
|
else
|
||||||
|
return PROXY_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Log a failed connection to a proxy server.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
log_failed_proxy_connection(connection_t *conn)
|
||||||
|
{
|
||||||
|
int proxy_type;
|
||||||
|
tor_addr_t proxy_addr;
|
||||||
|
uint16_t proxy_port;
|
||||||
|
|
||||||
|
proxy_type = get_proxy_type();
|
||||||
|
if (get_proxy_addrport(proxy_type, &proxy_addr, &proxy_port, conn) <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
log_warn(LD_NET,
|
log_warn(LD_NET,
|
||||||
"The connection to the %s proxy server at %s:%u just failed. "
|
"The connection to the %s proxy server at %s:%u just failed. "
|
||||||
@ -4140,6 +4185,9 @@ log_failed_proxy_connection(connection_t *conn)
|
|||||||
proxy_port);
|
proxy_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Transforms 'proxy_type' to it's string representation/
|
||||||
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
proxy_type_to_string(int proxy_type)
|
proxy_type_to_string(int proxy_type)
|
||||||
{
|
{
|
||||||
|
@ -58,6 +58,9 @@ int connection_connect(connection_t *conn, const char *address,
|
|||||||
int connection_proxy_connect(connection_t *conn, int type);
|
int connection_proxy_connect(connection_t *conn, int type);
|
||||||
int connection_read_proxy_handshake(connection_t *conn);
|
int connection_read_proxy_handshake(connection_t *conn);
|
||||||
void log_failed_proxy_connection(connection_t *conn);
|
void log_failed_proxy_connection(connection_t *conn);
|
||||||
|
int get_proxy_addrport(int proxy_type, tor_addr_t *addr, uint16_t *port, connection_t *conn);
|
||||||
|
int get_proxy_type(void);
|
||||||
|
|
||||||
|
|
||||||
int retry_all_listeners(smartlist_t *replaced_conns,
|
int retry_all_listeners(smartlist_t *replaced_conns,
|
||||||
smartlist_t *new_conns);
|
smartlist_t *new_conns);
|
||||||
|
@ -839,6 +839,11 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
|
|||||||
int socket_error = 0;
|
int socket_error = 0;
|
||||||
tor_addr_t addr;
|
tor_addr_t addr;
|
||||||
|
|
||||||
|
int r;
|
||||||
|
int proxy_type;
|
||||||
|
tor_addr_t proxy_addr;
|
||||||
|
uint16_t proxy_port;
|
||||||
|
|
||||||
tor_assert(_addr);
|
tor_assert(_addr);
|
||||||
tor_assert(id_digest);
|
tor_assert(id_digest);
|
||||||
tor_addr_copy(&addr, _addr);
|
tor_addr_copy(&addr, _addr);
|
||||||
@ -855,29 +860,14 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
|
|||||||
conn->_base.state = OR_CONN_STATE_CONNECTING;
|
conn->_base.state = OR_CONN_STATE_CONNECTING;
|
||||||
control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED, 0);
|
control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED, 0);
|
||||||
|
|
||||||
/* use a proxy server if available */
|
proxy_type = get_proxy_type();
|
||||||
if (options->HTTPSProxy) {
|
r = get_proxy_addrport(proxy_type, &proxy_addr, &proxy_port, TO_CONN(conn));
|
||||||
|
if (r == 1) { /* proxy found. */
|
||||||
|
addr = proxy_addr;
|
||||||
|
port = proxy_port;
|
||||||
conn->_base.proxy_state = PROXY_INFANT;
|
conn->_base.proxy_state = PROXY_INFANT;
|
||||||
tor_addr_copy(&addr, &options->HTTPSProxyAddr);
|
} else if (r < 0)
|
||||||
port = options->HTTPSProxyPort;
|
return NULL;
|
||||||
} else if (options->Socks4Proxy) {
|
|
||||||
conn->_base.proxy_state = PROXY_INFANT;
|
|
||||||
tor_addr_copy(&addr, &options->Socks4ProxyAddr);
|
|
||||||
port = options->Socks4ProxyPort;
|
|
||||||
} else if (options->Socks5Proxy) {
|
|
||||||
conn->_base.proxy_state = PROXY_INFANT;
|
|
||||||
tor_addr_copy(&addr, &options->Socks5ProxyAddr);
|
|
||||||
port = options->Socks5ProxyPort;
|
|
||||||
} else if (options->ClientTransportPlugin) {
|
|
||||||
transport_info_t *transport;
|
|
||||||
transport = find_transport_by_bridge_addrport(&addr, port);
|
|
||||||
if (transport) {
|
|
||||||
log_debug(LD_GENERAL, "Found transport. Setting up proxying!");
|
|
||||||
conn->_base.proxy_state = PROXY_INFANT;
|
|
||||||
tor_addr_copy(&addr, &transport->addr);
|
|
||||||
port = transport->port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (connection_connect(TO_CONN(conn), conn->_base.address,
|
switch (connection_connect(TO_CONN(conn), conn->_base.address,
|
||||||
&addr, port, &socket_error)) {
|
&addr, port, &socket_error)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user