Move always-use-proxy auto-override to master daemon.

This means it will effect connect commands too (though it's too
late to stop DNS lookups caused by commandline options).

We also warn that this is one case where we allow forcing through Tor
without a proxy set: it just means all connections will fail.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-05-10 08:48:24 +09:30
parent 1106c40217
commit 89c76a5a78
10 changed files with 43 additions and 23 deletions

View File

@ -490,3 +490,29 @@ struct addrinfo *wireaddr_to_addrinfo(const tal_t *ctx,
}
abort();
}
bool all_tor_addresses(const struct wireaddr_internal *wireaddr)
{
for (int i = 0; i < tal_count(wireaddr); i++) {
switch (wireaddr[i].itype) {
case ADDR_INTERNAL_SOCKNAME:
return false;
case ADDR_INTERNAL_ALLPROTO:
return false;
case ADDR_INTERNAL_AUTOTOR:
continue;
case ADDR_INTERNAL_WIREADDR:
switch (wireaddr[i].u.wireaddr.type) {
case ADDR_TYPE_IPV4:
case ADDR_TYPE_IPV6:
return false;
case ADDR_TYPE_TOR_V2:
case ADDR_TYPE_TOR_V3:
case ADDR_TYPE_PADDING:
continue;
}
}
abort();
}
return true;
}

View File

@ -136,4 +136,7 @@ struct addrinfo *wireaddr_to_addrinfo(const tal_t *ctx,
const struct wireaddr *wireaddr);
struct addrinfo *wireaddr_internal_to_addrinfo(const tal_t *ctx,
const struct wireaddr_internal *wireaddr);
bool all_tor_addresses(const struct wireaddr_internal *wireaddr);
#endif /* LIGHTNING_COMMON_WIREADDR_H */

View File

@ -1810,15 +1810,6 @@ static struct io_plan *gossip_activate(struct daemon_conn *master,
else
binding = NULL;
/* If we only advertize Tor addresses, force everything through proxy
* to avoid other leakage */
if (!daemon->use_proxy_always
&& tal_count(daemon->announcable) != 0
&& all_tor_addresses(daemon->announcable)) {
status_trace("Only announcing Tor addresses: forcing proxy use");
daemon->use_proxy_always = true;
}
/* OK, we're ready! */
daemon_conn_send(&daemon->master,
take(towire_gossipctl_activate_reply(NULL,

View File

@ -163,13 +163,3 @@ struct io_plan *io_tor_connect(struct io_conn *conn,
return io_connect(conn, tor_proxyaddr,
&io_tor_connect_do_req, reach_tor);
}
bool all_tor_addresses(const struct wireaddr *wireaddr)
{
for (int i = 0; i < tal_count(wireaddr); i++) {
if (wireaddr[i].type != ADDR_TYPE_TOR_V2
&& wireaddr[i].type != ADDR_TYPE_TOR_V3)
return false;
}
return true;
}

View File

@ -8,8 +8,6 @@ struct wireaddr;
struct io_conn;
struct reaching;
bool all_tor_addresses(const struct wireaddr *wireaddr);
struct io_plan *io_tor_connect(struct io_conn *conn,
const struct addrinfo *tor_proxyaddr,
const struct wireaddr *addr,

View File

@ -152,7 +152,8 @@ static void json_connect(struct command *cmd,
port = DEFAULT_PORT;
}
if (!parse_wireaddr_internal(name, &addr, port, false,
!cmd->ld->use_proxy_always,
!cmd->ld->use_proxy_always
&& !cmd->ld->pure_tor_setup,
&err_msg)) {
command_fail(cmd, "Host %s:%u not valid: %s",
name, port, err_msg ? err_msg : "port is 0");

View File

@ -225,7 +225,7 @@ void gossip_init(struct lightningd *ld)
get_offered_local_features(tmpctx), wireaddrs,
listen_announce, ld->rgb,
ld->alias, ld->config.channel_update_interval, ld->reconnect,
ld->proxyaddr, ld->use_proxy_always,
ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup,
allow_localhost,
ld->tor_service_password ? ld->tor_service_password : "");
subd_send_msg(ld->gossip, msg);

View File

@ -85,6 +85,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->ini_autocleaninvoice_expiredby = 86400;
ld->proxyaddr = NULL;
ld->use_proxy_always = false;
ld->pure_tor_setup = false;
ld->tor_service_password = NULL;
return ld;
}

View File

@ -196,6 +196,7 @@ struct lightningd {
struct wireaddr *proxyaddr;
bool use_proxy_always;
char *tor_service_password;
bool pure_tor_setup;
};
const struct chainparams *get_chainparams(const struct lightningd *ld);

View File

@ -839,6 +839,15 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[])
if (argc != 1)
errx(1, "no arguments accepted");
/* We keep a separate variable rather than overriding use_proxy_always,
* so listconfigs shows the correct thing. */
if (tal_count(ld->proposed_wireaddr) != 0
&& all_tor_addresses(ld->proposed_wireaddr)) {
ld->pure_tor_setup = true;
if (!ld->proxyaddr)
log_info(ld->log, "Pure Tor setup with no --proxy:"
" you won't be able to make connections out");
}
check_config(ld);
}