Various trivial changes.

* Improved function documentation.
* Renamed find_bridge_transport_by_addrport() to
  find_transport_by_bridge_addrport().
* Sanitized log severities we use.
* Ran check-spaces.
This commit is contained in:
George Kadianakis 2011-06-12 16:41:32 +02:00
parent 29203b7f3f
commit 00ec4b2c00
5 changed files with 55 additions and 45 deletions

View File

@ -4603,8 +4603,7 @@ transport_add_from_config(const tor_addr_t *addr, uint16_t port,
tor_addr_copy(&t->addr, addr);
t->port = port;
/** check strdup return */
t->name = strdup(name);
t->name = tor_strdup(name);
t->socks_version = socks_ver;
if (!transport_list)
transport_list = smartlist_create();
@ -4654,15 +4653,16 @@ match_bridges_with_transports(void)
if (!found_match) {
log_warn(LD_CONFIG, "Couldn't find transport "
"match for %s!\n", b->transport_name_config);
/* tor_free(b->transport_name_config); */
return -1;
}
} SMARTLIST_FOREACH_END(b);
/* count number of transports to see if there were transports
that didn't get matched to a bridge. */
/* Count number of transports to make sure that all transports got
matched to bridges. */
SMARTLIST_FOREACH(transport_list, transport_info_t *, t, n_transports++);
if (n_transports != n_matches) {
log_warn(LD_CONFIG, "You have %d transports and we only "
log_warn(LD_CONFIG, "You have %d transports but we only "
"managed to match %d of them!\n", n_transports, n_matches);
return -1;
}
@ -4748,7 +4748,10 @@ learned_router_identity(const tor_addr_t *addr, uint16_t port,
/** Remember a new bridge at <b>addr</b>:<b>port</b>. If <b>digest</b>
* is set, it tells us the identity key too. If we already had the
* bridge in our list, unmark it, and don't actually add anything new. */
* bridge in our list, unmark it, and don't actually add anything new.
* If <b>transport_name</b> is non-NULL - the bridge is associated with a
* pluggable transport - we assign the transport to the bridge.
*/
void
bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
const char *digest, const char *transport_name)
@ -4805,11 +4808,12 @@ find_bridge_by_digest(const char *digest)
}
/** If <b>addr</b> and <b>port</b> match one of our known bridges,
* returns it's transport protocol if it has one, else returns NULL.
* returns its transport protocol if it has one, else returns NULL.
*/
transport_info_t *
find_bridge_transport_by_addrport(const tor_addr_t *addr, uint16_t port)
find_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port)
{
assert(bridge_list);
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge)
{
if (tor_addr_eq(&bridge->addr, addr) &&

View File

@ -17,13 +17,10 @@
typedef struct {
/* SOCKS version */
int socks_version;
/* Name of pluggable transport protocol */
char *name;
/* Address of proxy */
tor_addr_t addr;
/* Port of proxy */
uint16_t port;
} transport_info_t;
@ -143,13 +140,12 @@ void circuit_build_times_network_circ_success(circuit_build_times_t *cbt);
int circuit_build_times_get_bw_scale(networkstatus_t *ns);
void clear_transport_list(void);
int match_bridges_with_transports(void);
void transport_add_from_config(const tor_addr_t *addr, uint16_t port,
const char *name, int socks_ver);
transport_info_t *
find_bridge_transport_by_addrport(const tor_addr_t *addr, uint16_t port);
find_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port);
#endif

View File

@ -571,7 +571,7 @@ static int check_nickname_list(const char *lst, const char *name, char **msg);
static void config_register_addressmaps(or_options_t *options);
static int parse_bridge_line(const char *line, int validate_only);
static int parse_transport_line(const char *line, int validate_only);
static int parse_client_transport_line(const char *line, int validate_only);
static int parse_dir_server_line(const char *line,
dirinfo_type_t required_type,
int validate_only);
@ -1210,7 +1210,7 @@ options_act(or_options_t *old_options)
if (options->ClientTransportPlugin) {
clear_transport_list();
for (cl = options->ClientTransportPlugin; cl; cl = cl->next) {
if (parse_transport_line(cl->value, 0)<0) {
if (parse_client_transport_line(cl->value, 0)<0) {
log_warn(LD_BUG,
"Previously validated ClientTransportPlugin line "
"could not be added!");
@ -1234,6 +1234,7 @@ options_act(or_options_t *old_options)
/** Okay, we have Bridges and we have ClientTransportPlugins. Let's
match them together. */
if (options->Bridges && options->ClientTransportPlugin) {
assert(!server_mode(options));
if (match_bridges_with_transports() < 0)
return -1;
}
@ -3688,8 +3689,11 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->ClientTransportPlugin) {
if (!options->Bridges)
REJECT("ClientTransportPlugin found without any bridges.");
if (server_mode(options))
REJECT("ClientTransportPlugin found but we are a server.");
for (cl = options->ClientTransportPlugin; cl; cl = cl->next) {
if (parse_transport_line(cl->value, 1)<0)
if (parse_client_transport_line(cl->value, 1)<0)
REJECT("Transport line did not parse. See logs for details.");
}
}
@ -4633,7 +4637,7 @@ parse_bridge_line(const char *line, int validate_only)
}
if (!validate_only) {
log_warn(LD_DIR, "Bridge at %s:%d with transport %s (%s)",
log_debug(LD_DIR, "Bridge at %s:%d with transport %s (%s)",
fmt_addr(&addr), (int)port, transport_name,
fingerprint ? fingerprint : "no key listed");
bridge_add_from_config(&addr, port,
@ -4655,8 +4659,14 @@ parse_bridge_line(const char *line, int validate_only)
return r;
}
/** Read the contents of a ClientTransportPlugin line from
* <b>line</b>. Return 0 if the line is well-formed, and -1 if it
* isn't. If <b>validate_only</b> is 0, and the line is well-formed,
* then add the transport described in the line to our internal
* transport list.
*/
static int
parse_transport_line(const char *line, int validate_only)
parse_client_transport_line(const char *line, int validate_only)
{
smartlist_t *items = NULL;
int r;
@ -4672,7 +4682,7 @@ parse_transport_line(const char *line, int validate_only)
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
if (smartlist_len(items) < 3) {
log_warn(LD_CONFIG, "parse_transport_line(): "
log_warn(LD_CONFIG, "parse_client_transport_line(): "
"Too few arguments on ClientTransportPlugin line.");
goto err;
}
@ -4708,7 +4718,7 @@ parse_transport_line(const char *line, int validate_only)
}
if (!validate_only) {
log_warn(LD_DIR, "Transport %s at %s:%d", name,
log_debug(LD_DIR, "Transport %s found at %s:%d", name,
fmt_addr(&addr), (int)port);
transport_add_from_config(&addr, port, name,
socks_ver);

View File

@ -335,11 +335,11 @@ connection_or_finished_connecting(or_connection_t *or_conn)
proxy_type = PROXY_SOCKS4;
else if (get_options()->Socks5Proxy)
proxy_type = PROXY_SOCKS5;
else if (get_options()->UseBridges) {
else if (get_options()->ClientTransportPlugin) {
transport_info_t *transport;
transport = find_bridge_transport_by_addrport(&conn->addr,conn->port);
transport = find_transport_by_bridge_addrport(&conn->addr,conn->port);
if (transport) { /* this bridge supports transports. use proxy. */
log_warn(LD_GENERAL, "Setting up pluggable transport plugin proxy type!\n");
log_debug(LD_GENERAL, "Found transport. Setting proxy type!\n");
proxy_type = transport->socks_version;
}
}
@ -871,10 +871,9 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
port = options->Socks5ProxyPort;
} else if (options->ClientTransportPlugin) {
transport_info_t *transport;
transport = find_bridge_transport_by_addrport(&addr, port);
transport = find_transport_by_bridge_addrport(&addr, port);
if (transport) {
log_warn(LD_GENERAL, "Our bridge uses a pluggable transport plugin. "
"Setting up proxying!");
log_debug(LD_GENERAL, "Found transport. Setting up proxying!");
using_proxy = 1;
tor_addr_copy(&addr, &transport->addr);
port = transport->port;

View File

@ -2660,7 +2660,8 @@ typedef struct {
config_line_t *Bridges; /**< List of bootstrap bridge addresses. */
config_line_t *ClientTransportPlugin; /**< List of client transport plugins. */
config_line_t *ClientTransportPlugin; /**< List of client
transport plugins. */
int BridgeRelay; /**< Boolean: are we acting as a bridge relay? We make
* this explicit so we can change how we behave in the