Skip to content

Commit

Permalink
Move always-use-proxy auto-override to master daemon.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed May 10, 2018
1 parent 1106c40 commit 89c76a5
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 23 deletions.
26 changes: 26 additions & 0 deletions common/wireaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions common/wireaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
9 changes: 0 additions & 9 deletions gossipd/gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions gossipd/tor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions gossipd/tor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 89c76a5

Please sign in to comment.