From 0f9ba5358194c51557cc2a141a916ef3546c4276 Mon Sep 17 00:00:00 2001 From: Saibato Date: Wed, 25 Sep 2019 11:05:14 +0000 Subject: [PATCH] Add enable-autotor-v2 config variable With enable-autotor-v2 defined in cmdline the default behavior to create v3 onions with the tor service call, is set to v2 onions. Signed-off-by: Saibato --- connectd/connect_wire.csv | 1 + connectd/connectd.c | 12 +++++++++--- connectd/tor_autoservice.c | 6 ++---- connectd/tor_autoservice.h | 3 ++- lightningd/connect_control.c | 3 ++- lightningd/lightningd.h | 4 ++++ lightningd/options.c | 7 +++++++ wallet/test/test_utils.c | 1 + 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/connectd/connect_wire.csv b/connectd/connect_wire.csv index d2fc2f0df..89c7a6144 100644 --- a/connectd/connect_wire.csv +++ b/connectd/connect_wire.csv @@ -13,6 +13,7 @@ msgdata,connectctl_init,use_tor_proxy_always,bool, msgdata,connectctl_init,dev_allow_localhost,bool, msgdata,connectctl_init,use_dns,bool, msgdata,connectctl_init,tor_password,wirestring, +msgdata,connectctl_init,use_v3_autotor,bool, # Connectd->master, here are the addresses I bound, can announce. msgtype,connectctl_init_reply,2100 diff --git a/connectd/connectd.c b/connectd/connectd.c index 9e68e6478..a814c3419 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -148,6 +148,9 @@ struct daemon { /* File descriptors to listen on once we're activated. */ struct listen_fd *listen_fds; + + /* Allow to define the default behavior of tot services calls*/ + bool use_v3_autotor; }; /* Peers we're trying to reach: we iterate through addrs until we succeed @@ -1114,14 +1117,16 @@ static struct wireaddr_internal *setup_listeners(const tal_t *ctx, tor_autoservice(tmpctx, &proposed_wireaddr[i].u.torservice, tor_password, - binding); + binding, + daemon->use_v3_autotor); continue; }; add_announcable(announcable, tor_autoservice(tmpctx, &proposed_wireaddr[i].u.torservice, tor_password, - binding)); + binding, + daemon->use_v3_autotor)); } /* Sort and uniquify. */ @@ -1153,7 +1158,8 @@ static struct io_plan *connect_init(struct io_conn *conn, &proposed_listen_announce, &proxyaddr, &daemon->use_proxy_always, &daemon->dev_allow_localhost, &daemon->use_dns, - &tor_password)) { + &tor_password, + &daemon->use_v3_autotor)) { /* This is a helper which prints the type expected and the actual * message, then exits (it should never be called!). */ master_badmsg(WIRE_CONNECTCTL_INIT, msg); diff --git a/connectd/tor_autoservice.c b/connectd/tor_autoservice.c index 06d58a882..abc8cbdca 100644 --- a/connectd/tor_autoservice.c +++ b/connectd/tor_autoservice.c @@ -228,7 +228,8 @@ find_local_address(const struct wireaddr_internal *bindings) struct wireaddr *tor_autoservice(const tal_t *ctx, const struct wireaddr *tor_serviceaddr, const char *tor_password, - const struct wireaddr_internal *bindings) + const struct wireaddr_internal *bindings, + const bool use_v3_autotor) { int fd; const struct wireaddr *laddr; @@ -236,7 +237,6 @@ struct wireaddr *tor_autoservice(const tal_t *ctx, struct addrinfo *ai_tor; struct rbuf rbuf; char *buffer; - bool use_v3_autotor; laddr = find_local_address(bindings); ai_tor = wireaddr_to_addrinfo(tmpctx, tor_serviceaddr); @@ -251,8 +251,6 @@ struct wireaddr *tor_autoservice(const tal_t *ctx, buffer = tal_arr(tmpctx, char, rbuf_good_size(fd)); rbuf_init(&rbuf, fd, buffer, tal_count(buffer), buf_resize); - use_v3_autotor = true; - negotiate_auth(&rbuf, tor_password); onion = make_onion(ctx, &rbuf, laddr, use_v3_autotor); diff --git a/connectd/tor_autoservice.h b/connectd/tor_autoservice.h index 0fc85ca55..13b153c75 100644 --- a/connectd/tor_autoservice.h +++ b/connectd/tor_autoservice.h @@ -9,6 +9,7 @@ struct wireaddr *tor_autoservice(const tal_t *ctx, const struct wireaddr *tor_serviceaddr, const char *tor_password, - const struct wireaddr_internal *bindings); + const struct wireaddr_internal *bindings, + const bool use_v3_autotor); #endif /* LIGHTNING_CONNECTD_TOR_AUTOSERVICE_H */ diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 2b3b6e5bc..8f2bdaafe 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -366,7 +366,8 @@ int connectd_init(struct lightningd *ld) listen_announce, ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup, IFDEV(ld->dev_allow_localhost, false), ld->config.use_dns, - ld->tor_service_password ? ld->tor_service_password : ""); + ld->tor_service_password ? ld->tor_service_password : "", + ld->config.use_v3_autotor); subd_req(ld->connectd, ld->connectd, take(msg), -1, 0, connect_init_done, NULL); diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index b1c1c2bdf..5154a2807 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -67,6 +67,10 @@ struct config { /* Minimal amount of effective funding_satoshis for accepting channels */ u64 min_capacity_sat; + + /* Allow to define the default behavior of tot services calls*/ + bool use_v3_autotor; + }; struct lightningd { diff --git a/lightningd/options.c b/lightningd/options.c index 204ad1b56..3c27c0b89 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -485,6 +485,8 @@ static const struct config testnet_config = { /* Sets min_effective_htlc_capacity - at 1000$/BTC this is 10ct */ .min_capacity_sat = 10000, + + .use_v3_autotor = true, }; /* aka. "Dude, where's my coins?" */ @@ -544,6 +546,8 @@ static const struct config mainnet_config = { /* Sets min_effective_htlc_capacity - at 1000$/BTC this is 10ct */ .min_capacity_sat = 10000, + + .use_v3_autotor = true, }; static void check_config(struct lightningd *ld) @@ -976,6 +980,9 @@ static void register_opts(struct lightningd *ld) opt_register_noarg("--disable-dns", opt_set_invbool, &ld->config.use_dns, "Disable DNS lookups of peers"); + opt_register_noarg("--enable-autotor-v2-mode", opt_set_invbool, &ld->config.use_v3_autotor, + "Try to get a v2 onion address from the Tor service call, default is v3"); + opt_register_logging(ld); opt_register_version(); diff --git a/wallet/test/test_utils.c b/wallet/test/test_utils.c index 6f5c96fc7..4d49821b6 100644 --- a/wallet/test/test_utils.c +++ b/wallet/test/test_utils.c @@ -23,4 +23,5 @@ const struct config test_config = { .max_fee_multiplier = 10, .use_dns = true, .min_capacity_sat = 10000, + .use_v3_autotor = true, };