Merge remote-tracking branch 'asn-mytor/bug4725_take2'

This commit is contained in:
Nick Mathewson 2011-12-20 14:28:31 -05:00
commit 26053bd7c9
3 changed files with 24 additions and 11 deletions

View File

@ -6828,21 +6828,29 @@ get_transport_bindaddr(const char *line, const char *transport)
return NULL;
}
/** Return a static string containing the address:port a proxy
* transport should bind on. */
const char *
/** Return a string containing the address:port that a proxy transport
* should bind on. The string is stored on the heap and must be freed
* by the caller of this function. */
char *
get_bindaddr_for_transport(const char *transport)
{
static const char default_addrport[] = "127.0.0.1:0";
const char *bindaddr = NULL;
char *default_addrport = NULL;
const char *stored_bindaddr = NULL;
config_line_t *line = get_transport_in_state_by_name(transport);
if (!line)
return default_addrport;
if (!line) /* Found no references in state for this transport. */
goto no_bindaddr_found;
bindaddr = get_transport_bindaddr(line->value, transport);
stored_bindaddr = get_transport_bindaddr(line->value, transport);
if (stored_bindaddr) /* found stored bindaddr in state file. */
return tor_strdup(stored_bindaddr);
return bindaddr ? bindaddr : default_addrport;
no_bindaddr_found:
/** If we didn't find references for this pluggable transport in the
state file, we should instruct the pluggable transport proxy to
listen on INADDR_ANY on a random ephemeral port. */
tor_asprintf(&default_addrport, "%s:%s", fmt_addr32(INADDR_ANY), "0");
return default_addrport;
}
/** Save <b>transport</b> listening on <b>addr</b>:<b>port</b> to

View File

@ -77,7 +77,7 @@ int options_need_geoip_info(const or_options_t *options,
void save_transport_to_state(const char *transport_name,
const tor_addr_t *addr, uint16_t port);
const char *get_bindaddr_for_transport(const char *transport);
char *get_bindaddr_for_transport(const char *transport);
int getinfo_helper_config(control_connection_t *conn,
const char *question, char **answer,

View File

@ -919,13 +919,18 @@ static char *
get_bindaddr_for_proxy(const managed_proxy_t *mp)
{
char *bindaddr = NULL;
char *bindaddr_tmp = NULL;
smartlist_t *string_tmp = smartlist_create();
tor_assert(mp->is_server);
SMARTLIST_FOREACH_BEGIN(mp->transports_to_launch, char *, t) {
tor_asprintf(&bindaddr, "%s-%s", t, get_bindaddr_for_transport(t));
bindaddr_tmp = get_bindaddr_for_transport(t);
tor_asprintf(&bindaddr, "%s-%s", t, bindaddr_tmp);
smartlist_add(string_tmp, bindaddr);
tor_free(bindaddr_tmp);
} SMARTLIST_FOREACH_END(t);
bindaddr = smartlist_join_strings(string_tmp, ",", 0, NULL);