From 1b9cec8e911eb86d895715cb9f7bb1ad44699cab Mon Sep 17 00:00:00 2001 From: Saibato Date: Tue, 24 Sep 2019 06:40:17 +0000 Subject: [PATCH] Don't exit w/ INTERNAL_ERROR, if --addr or --bind-addr is used with an .onion address The Fairy Tail version of .onion option calls on cmdline reroute the call to --announce-addr or just drop it in case of bind. Signed-off-by: Saibato --- lightningd/options.c | 50 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/lightningd/options.c b/lightningd/options.c index 3c27c0b89..1208e9091 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -149,16 +149,6 @@ static char *opt_add_addr_withtype(const char *arg, } -static char *opt_add_addr(const char *arg, struct lightningd *ld) -{ - return opt_add_addr_withtype(arg, ld, ADDR_LISTEN_AND_ANNOUNCE, true); -} - -static char *opt_add_bind_addr(const char *arg, struct lightningd *ld) -{ - return opt_add_addr_withtype(arg, ld, ADDR_LISTEN, true); -} - static char *opt_add_announce_addr(const char *arg, struct lightningd *ld) { const struct wireaddr *wn; @@ -193,6 +183,46 @@ static char *opt_add_announce_addr(const char *arg, struct lightningd *ld) return NULL; } +static char *opt_add_addr(const char *arg, struct lightningd *ld) +{ + struct wireaddr_internal addr; + + /* handle in case you used the addr option with an .onion */ + if (parse_wireaddr_internal(arg, &addr, 0, true, false, true, NULL)) { + if (addr.itype == ADDR_INTERNAL_WIREADDR && ( + addr.u.wireaddr.type == ADDR_TYPE_TOR_V2 || + addr.u.wireaddr.type == ADDR_TYPE_TOR_V3)) { + log_unusual(ld->log, "You used `--addr=%s` option with an .onion address, please use" + " `--announce-addr` ! You are lucky in this node live some wizards and" + " fairies, we have done this for you and announce, Be as hidden as wished", + arg); + return opt_add_announce_addr(arg, ld); + } + } + /* the intended call */ + return opt_add_addr_withtype(arg, ld, ADDR_LISTEN_AND_ANNOUNCE, true); +} + +static char *opt_add_bind_addr(const char *arg, struct lightningd *ld) +{ + struct wireaddr_internal addr; + + /* handle in case you used the bind option with an .onion */ + if (parse_wireaddr_internal(arg, &addr, 0, true, false, true, NULL)) { + if (addr.itype == ADDR_INTERNAL_WIREADDR && ( + addr.u.wireaddr.type == ADDR_TYPE_TOR_V2 || + addr.u.wireaddr.type == ADDR_TYPE_TOR_V3)) { + log_unusual(ld->log, "You used `--bind-addr=%s` option with an .onion address," + " You are lucky in this node live some wizards and" + " fairies, we have done this for you and don't announce, Be as hidden as wished", + arg); + return NULL; + } + } + /* the intended call */ + return opt_add_addr_withtype(arg, ld, ADDR_LISTEN, true); +} + static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u) { snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u);