Fixes small bugs.

This commit is contained in:
George Kadianakis 2011-06-14 16:00:55 +02:00
parent 5b050a9b08
commit 93526cdf0b
5 changed files with 72 additions and 20 deletions

View File

@ -4594,21 +4594,39 @@ transport_free(transport_info_t *transport)
/** Remember a new pluggable transport proxy at <b>addr</b>:<b>port</b>.
<b>name</b> is set to the name of the protocol this proxy uses.
<b>socks_ver</b> is set to the SOCKS version of the proxy.
Returns 1 on success, -1 on fail.
*/
void
int
transport_add_from_config(const tor_addr_t *addr, uint16_t port,
const char *name, int socks_ver)
{
transport_info_t *t = tor_malloc_zero(sizeof(transport_info_t));
if (transport_list) { /*check out for duplicate transport names*/
SMARTLIST_FOREACH_BEGIN(transport_list, transport_info_t *, transport) {
if (!strcmp(transport->name, name)) {
log_notice(LD_CONFIG, "More than one transports have '%s' as "
"their name.", transport->name);
goto err;
}
} SMARTLIST_FOREACH_END(transport);
}
tor_addr_copy(&t->addr, addr);
t->port = port;
t->name = tor_strdup(name);
t->socks_version = socks_ver;
if (!transport_list)
transport_list = smartlist_create();
smartlist_add(transport_list, t);
return 1;
err:
tor_free(t);
return -1;
}
/**
@ -4645,9 +4663,8 @@ match_bridges_with_transports(void)
found_match=1;
n_matches++;
b->transport = t;
tor_free(b->transport_name_config);
log_warn(LD_CONFIG, "Matched transport '%s'", t->name);
continue;
break;
}
} SMARTLIST_FOREACH_END(t);
if (!found_match) {
@ -4667,6 +4684,10 @@ match_bridges_with_transports(void)
return -1;
}
/* clear the method names taken from the config, we no longer need them. */
SMARTLIST_FOREACH(bridge_list, bridge_info_t *, b,
tor_free(b->transport_name_config));
return 1;
}
@ -4751,8 +4772,10 @@ learned_router_identity(const tor_addr_t *addr, uint16_t port,
* 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.
*
* Returns 1 on success, -1 on fail.
*/
void
int
bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
const char *digest, const char *transport_name)
{
@ -4760,7 +4783,7 @@ bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
if ((b = get_configured_bridge_by_addr_port_digest(addr, port, digest))) {
b->marked_for_removal = 0;
return;
return 1;
}
b = tor_malloc_zero(sizeof(bridge_info_t));
@ -4768,13 +4791,28 @@ bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
b->port = port;
if (digest)
memcpy(b->identity, digest, DIGEST_LEN);
if (transport_name)
if (transport_name) {
if (bridge_list) { /*check out for duplicate transport names*/
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge) {
if (!strcmp(bridge->transport_name_config, transport_name)) {
log_notice(LD_CONFIG, "More than one bridges have '%s' as "
"their transport name.", transport_name);
goto err;
}
} SMARTLIST_FOREACH_END(bridge);
}
b->transport_name_config = strdup(transport_name);
}
b->fetch_status.schedule = DL_SCHED_BRIDGE;
if (!bridge_list)
bridge_list = smartlist_create();
smartlist_add(bridge_list, b);
return 1;
err:
tor_free(b);
return -1;
}
/** Return true iff <b>routerset</b> contains the bridge <b>bridge</b>. */

View File

@ -82,7 +82,7 @@ int routerinfo_is_a_configured_bridge(const routerinfo_t *ri);
int node_is_a_configured_bridge(const node_t *node);
void learned_router_identity(const tor_addr_t *addr, uint16_t port,
const char *digest);
void bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
int bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
const char *digest,
const char *transport_name);
void retry_bridge_descriptor_fetch_directly(const char *digest);
@ -142,7 +142,7 @@ 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,
int transport_add_from_config(const tor_addr_t *addr, uint16_t port,
const char *name, int socks_ver);
transport_info_t *
find_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port);

View File

@ -570,7 +570,8 @@ static int options_transition_affects_descriptor(or_options_t *old_options,
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_bridge_line(const char *line, int validate_only,
or_options_t *options);
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,
@ -1222,7 +1223,7 @@ options_act(or_options_t *old_options)
if (options->Bridges) {
mark_bridge_list();
for (cl = options->Bridges; cl; cl = cl->next) {
if (parse_bridge_line(cl->value, 0)<0) {
if (parse_bridge_line(cl->value, 0, options)<0) {
log_warn(LD_BUG,
"Previously validated Bridge line could not be added!");
return -1;
@ -3709,7 +3710,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->Bridges) {
for (cl = options->Bridges; cl; cl = cl->next) {
if (parse_bridge_line(cl->value, 1)<0)
if (parse_bridge_line(cl->value, 1, options)<0)
REJECT("Bridge line did not parse. See logs for details.");
}
}
@ -4592,7 +4593,8 @@ options_init_logs(or_options_t *options, int validate_only)
* <b>validate_only</b> is 0, and the line is well-formed, then add
* the bridge described in the line to our internal bridge list. */
static int
parse_bridge_line(const char *line, int validate_only)
parse_bridge_line(const char *line, int validate_only,
or_options_t *options)
{
smartlist_t *items = NULL;
int r;
@ -4616,6 +4618,12 @@ parse_bridge_line(const char *line, int validate_only)
smartlist_del_keeporder(items, 0);
if (!strstr(field1, ".")) { /* new-style bridge line */
if (!options->ClientTransportPlugin) {
log_warn(LD_CONFIG, "Pluggable transports protocol found "
"in bridge line, but no ClientTransportPlugin lines found.");
goto err;
}
transport_name = field1;
addrport = smartlist_get(items, 0);
smartlist_del_keeporder(items, 0);
@ -4649,8 +4657,10 @@ parse_bridge_line(const char *line, int validate_only)
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,
fingerprint ? digest : NULL, transport_name);
if (bridge_add_from_config(&addr, port,
fingerprint ? digest : NULL,transport_name) < 0)
goto err;
}
r = 0;
@ -4729,8 +4739,10 @@ parse_client_transport_line(const char *line, int validate_only)
if (!validate_only) {
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);
if (transport_add_from_config(&addr, port, name,
socks_ver) < 0)
goto err;
}
r = 0;

View File

@ -4104,8 +4104,7 @@ 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 a connection_t and is used for finding pluggable
transports proxies.
'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.
@ -4186,7 +4185,7 @@ log_failed_proxy_connection(connection_t *conn)
}
/**
Transforms 'proxy_type' to it's string representation/
Return string representation of <b>proxy_type</b>.
*/
static const char *
proxy_type_to_string(int proxy_type)

View File

@ -860,14 +860,17 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
conn->_base.state = OR_CONN_STATE_CONNECTING;
control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED, 0);
/* 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;
port = proxy_port;
conn->_base.proxy_state = PROXY_INFANT;
} else if (r < 0)
} else if (r < 0) {
log_info(LD_PROTOCOL, "Failed on getting proxy addrport.");
return NULL;
}
switch (connection_connect(TO_CONN(conn), conn->_base.address,
&addr, port, &socket_error)) {