mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Tweaked connection{.c,.h,_or.c} based on nick's comments.
* Tweaked doxygen comments. * Changed returns of get_proxy_addrport(). * Ran make check-spaces. * Various small code tweaks.
This commit is contained in:
parent
392e947df5
commit
298f170036
@ -68,7 +68,6 @@ 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. */
|
||||
static uint32_t last_interface_ip = 0;
|
||||
@ -4101,14 +4100,11 @@ assert_connection_ok(connection_t *conn, time_t now)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Fills <b>addr</b> and <b>port</b> with the details of the proxy
|
||||
server of type 'proxy_type' we are using.
|
||||
'conn' contains the connection_t we are using the proxy for.
|
||||
|
||||
Returns 1 if we were successfull, 0 if we are not using a proxy
|
||||
server and -1 if something went wrong.
|
||||
*/
|
||||
/** Fills <b>addr</b> and <b>port</b> with the details of the proxy
|
||||
* server of type <b>proxy_type</b> we are using.
|
||||
* <b>conn</b> contains the connection_t we are using the proxy for.
|
||||
* Returns 0 if we were successfull or returns 1 if we are not using
|
||||
* a proxy. */
|
||||
int
|
||||
get_proxy_addrport(int proxy_type, tor_addr_t *addr, uint16_t *port,
|
||||
connection_t *conn)
|
||||
@ -4116,7 +4112,7 @@ get_proxy_addrport(int proxy_type, tor_addr_t *addr, uint16_t *port,
|
||||
or_options_t *options;
|
||||
|
||||
if (proxy_type == PROXY_NONE)
|
||||
return 0;
|
||||
return 1;
|
||||
|
||||
options = get_options();
|
||||
|
||||
@ -4130,22 +4126,20 @@ get_proxy_addrport(int proxy_type, tor_addr_t *addr, uint16_t *port,
|
||||
tor_addr_copy(addr, &options->Socks5ProxyAddr);
|
||||
*port = options->Socks5ProxyPort;
|
||||
} else if (proxy_type == PROXY_PLUGGABLE) {
|
||||
transport_info_t *transport;
|
||||
transport_t *transport;
|
||||
transport = find_transport_by_bridge_addrport(&conn->addr, conn->port);
|
||||
if (transport) {
|
||||
tor_addr_copy(addr, &transport->addr);
|
||||
*port = transport->port;
|
||||
} else
|
||||
return -1;
|
||||
} else
|
||||
return -1;
|
||||
|
||||
} else { /* no transport for this bridge. */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the proxy type used by tor.
|
||||
*/
|
||||
/** Returns the proxy type used by tor. */
|
||||
int
|
||||
get_proxy_type(void)
|
||||
{
|
||||
@ -4163,9 +4157,8 @@ get_proxy_type(void)
|
||||
return PROXY_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
Log a failed connection to a proxy server.
|
||||
*/
|
||||
/** Log a failed connection to a proxy server.
|
||||
* <b>conn</b> is the connection we use the proxy server for. */
|
||||
void
|
||||
log_failed_proxy_connection(connection_t *conn)
|
||||
{
|
||||
@ -4174,8 +4167,8 @@ log_failed_proxy_connection(connection_t *conn)
|
||||
uint16_t proxy_port;
|
||||
|
||||
proxy_type = get_proxy_type();
|
||||
if (get_proxy_addrport(proxy_type, &proxy_addr, &proxy_port, conn) <= 0)
|
||||
return;
|
||||
if (get_proxy_addrport(proxy_type, &proxy_addr, &proxy_port, conn) != 0)
|
||||
return; /* if we have no proxy set up leave this function. */
|
||||
|
||||
log_warn(LD_NET,
|
||||
"The connection to the %s proxy server at %s:%u just failed. "
|
||||
@ -4184,9 +4177,7 @@ log_failed_proxy_connection(connection_t *conn)
|
||||
proxy_port);
|
||||
}
|
||||
|
||||
/**
|
||||
Return string representation of <b>proxy_type</b>.
|
||||
*/
|
||||
/** Return string representation of <b>proxy_type</b>. */
|
||||
static const char *
|
||||
proxy_type_to_string(int proxy_type)
|
||||
{
|
||||
@ -4199,3 +4190,4 @@ proxy_type_to_string(int proxy_type)
|
||||
default: tor_assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,10 @@ 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 get_proxy_addrport(int proxy_type, tor_addr_t *addr, uint16_t *port, 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,
|
||||
smartlist_t *new_conns);
|
||||
|
||||
|
@ -336,7 +336,7 @@ connection_or_finished_connecting(or_connection_t *or_conn)
|
||||
else if (get_options()->Socks5Proxy)
|
||||
proxy_type = PROXY_SOCKS5;
|
||||
else if (get_options()->ClientTransportPlugin) {
|
||||
transport_info_t *transport;
|
||||
transport_t *transport;
|
||||
transport = find_transport_by_bridge_addrport(&conn->addr,conn->port);
|
||||
if (transport) { /* this bridge supports transports. use proxy. */
|
||||
log_debug(LD_GENERAL, "Found transport. Setting proxy type!\n");
|
||||
@ -863,13 +863,10 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
|
||||
/* If we are using a proxy server, find it and use it. */
|
||||
proxy_type = get_proxy_type();
|
||||
r = get_proxy_addrport(proxy_type, &proxy_addr, &proxy_port, TO_CONN(conn));
|
||||
if (r == 1) { /* proxy found. */
|
||||
addr = proxy_addr;
|
||||
if (r == 0) { /* proxy found. */
|
||||
tor_addr_copy(&addr, &proxy_addr);
|
||||
port = proxy_port;
|
||||
conn->_base.proxy_state = PROXY_INFANT;
|
||||
} else if (r < 0) {
|
||||
log_info(LD_PROTOCOL, "Failed on getting proxy addrport.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (connection_connect(TO_CONN(conn), conn->_base.address,
|
||||
|
Loading…
Reference in New Issue
Block a user