From 89c76a5a78d9930a757e8a11757e70b9d187d87f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 May 2018 08:48:24 +0930 Subject: [PATCH] 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 --- common/wireaddr.c | 26 ++++++++++++++++++++++++++ common/wireaddr.h | 3 +++ gossipd/gossip.c | 9 --------- gossipd/tor.c | 10 ---------- gossipd/tor.h | 2 -- lightningd/connect_control.c | 3 ++- lightningd/gossip_control.c | 2 +- lightningd/lightningd.c | 1 + lightningd/lightningd.h | 1 + lightningd/options.c | 9 +++++++++ 10 files changed, 43 insertions(+), 23 deletions(-) diff --git a/common/wireaddr.c b/common/wireaddr.c index 92b8d618f..97b19e81b 100644 --- a/common/wireaddr.c +++ b/common/wireaddr.c @@ -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; +} diff --git a/common/wireaddr.h b/common/wireaddr.h index 3c4c64ea5..8e62e5c50 100644 --- a/common/wireaddr.h +++ b/common/wireaddr.h @@ -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 */ diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 4fa5eb7db..f1769603f 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -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, diff --git a/gossipd/tor.c b/gossipd/tor.c index b01e5cc8d..3ce8fb916 100644 --- a/gossipd/tor.c +++ b/gossipd/tor.c @@ -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; -} diff --git a/gossipd/tor.h b/gossipd/tor.h index 7848ffb57..4d8f76bb5 100644 --- a/gossipd/tor.h +++ b/gossipd/tor.h @@ -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, diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 9d2f99a7a..4de222e1a 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -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"); diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index ffd030669..6cccffba0 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -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); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 642b20c3a..557f042a6 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -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; } diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 755f7a4db..90da02582 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -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); diff --git a/lightningd/options.c b/lightningd/options.c index c8a3361d2..39f94aee5 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -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); }