From 0d23f4fb4a5cc404d487ce2767d5c23349f8391c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 May 2018 12:32:03 +0930 Subject: [PATCH] gossipd: hand io_tor_connect the host as a string. Previously it converted the wireaddr to a string internally: to support unresolved names we need that done externally. We actually tell the SOCKS5 proxy to do a domain lookup already, even though we give use IP/IPv6 address, so this change is sufficient to support connect-by-name. Note replacement of assert() with an explicit case statement, which has the benefit that the compiler complains when we add new ADDR_INTERNAL types. Signed-off-by: Rusty Russell --- gossipd/gossip.c | 23 ++++++++++++++++++++--- gossipd/tor.c | 6 +++--- gossipd/tor.h | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index ad7d9d214..9813844a1 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1925,10 +1925,27 @@ static struct io_plan *conn_init(struct io_conn *conn, struct reaching *reach) static struct io_plan *conn_proxy_init(struct io_conn *conn, struct reaching *reach) { - assert(reach->addr.itype == ADDR_INTERNAL_WIREADDR); + char *host = NULL; + u16 port; + + switch (reach->addr.itype) { + case ADDR_INTERNAL_WIREADDR: + host = fmt_wireaddr_without_port(tmpctx, + &reach->addr.u.wireaddr); + port = reach->addr.u.wireaddr.port; + break; + case ADDR_INTERNAL_SOCKNAME: + case ADDR_INTERNAL_ALLPROTO: + case ADDR_INTERNAL_AUTOTOR: + break; + } + + if (!host) + status_failed(STATUS_FAIL_INTERNAL_ERROR, + "Can't reach to %u address", reach->addr.itype); + io_set_finish(conn, connect_failed, reach); - return io_tor_connect(conn, reach->daemon->proxyaddr, - &reach->addr.u.wireaddr, reach); + return io_tor_connect(conn, reach->daemon->proxyaddr, host, port, reach); } static struct addrhint * diff --git a/gossipd/tor.c b/gossipd/tor.c index 3ce8fb916..59e5643dc 100644 --- a/gossipd/tor.c +++ b/gossipd/tor.c @@ -151,13 +151,13 @@ static struct io_plan *io_tor_connect_do_req(struct io_conn *conn, // called when we want to connect to TOR SOCKS5 struct io_plan *io_tor_connect(struct io_conn *conn, const struct addrinfo *tor_proxyaddr, - const struct wireaddr *addr, + const char *host, u16 port, struct reaching *reach) { struct reaching_socks *reach_tor = tal(reach, struct reaching_socks); - reach_tor->port = htons(addr->port); - reach_tor->host = fmt_wireaddr_without_port(reach_tor, addr); + reach_tor->port = htons(port); + reach_tor->host = tal_strdup(reach_tor, host); reach_tor->reach = reach; return io_connect(conn, tor_proxyaddr, diff --git a/gossipd/tor.h b/gossipd/tor.h index 4d8f76bb5..b265b753d 100644 --- a/gossipd/tor.h +++ b/gossipd/tor.h @@ -10,7 +10,7 @@ struct reaching; struct io_plan *io_tor_connect(struct io_conn *conn, const struct addrinfo *tor_proxyaddr, - const struct wireaddr *addr, + const char *host, u16 port, struct reaching *reach); #endif /* LIGHTNING_GOSSIPD_TOR_H */