From 2f247c7bfbe8eca92b5a2b0619ce5c01f9278679 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 10 Nov 2021 10:57:41 +1030 Subject: [PATCH] torv2: remove support for advertizing and connecting. October was the date Torv2 is no longer supported by the Tor Project; it will probably not work at all by next release, so we should remove it now even though it's not quite the 6 months we prefer for deprecation cycles. I still see 110 nodes advertizing Torv2 (vs 10,292 Torv3); we still parse and display it, we just don't advertize or connect to it. Signed-off-by: Rusty Russell --- common/json_helpers.c | 2 +- common/test/run-ip_port_parsing.c | 18 ++++++++---------- common/wireaddr.c | 18 ++++++++---------- common/wireaddr.h | 2 +- connectd/connectd.c | 16 ++++++++++------ connectd/netaddress.c | 4 ++-- devtools/gossipwith.c | 2 +- lightningd/options.c | 10 ++++------ tests/test_gossip.py | 5 +---- 9 files changed, 36 insertions(+), 41 deletions(-) diff --git a/common/json_helpers.c b/common/json_helpers.c index 65308d7ba..44efdffbd 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -273,7 +273,7 @@ void json_add_address(struct json_stream *response, const char *fieldname, json_add_string(response, "type", "ipv6"); json_add_string(response, "address", addrstr); json_add_num(response, "port", addr->port); - } else if (addr->type == ADDR_TYPE_TOR_V2) { + } else if (addr->type == ADDR_TYPE_TOR_V2_REMOVED) { json_add_string(response, "type", "torv2"); json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr)); json_add_num(response, "port", addr->port); diff --git a/common/test/run-ip_port_parsing.c b/common/test/run-ip_port_parsing.c index ad9f73d77..68b1bdc55 100644 --- a/common/test/run-ip_port_parsing.c +++ b/common/test/run-ip_port_parsing.c @@ -182,19 +182,17 @@ int main(int argc, char *argv[]) assert(parse_wireaddr("4ruvswpqec5i2gogopxl4vm5bruzknbvbylov2awbo4rxiq4cimdldad.onion", &addr, 1, false, NULL)); assert(addr.port == 1); - assert(parse_wireaddr("odpzvneidqdf5hdq.onion:49150", &addr, 1, false, NULL)); - assert(addr.port == 49150); + /* We don't accept torv2 any more */ + assert(!parse_wireaddr("odpzvneidqdf5hdq.onion:49150", &addr, 1, false, NULL)); + assert(!parse_wireaddr("odpzvneidqdf5hdq.onion", &addr, 1, false, NULL)); - assert(parse_wireaddr("odpzvneidqdf5hdq.onion", &addr, 1, false, NULL)); - assert(addr.port == 1); - - // Don't accept legacy hidden services with deprecated APIs on + /* Neither allow_deprecated = true nor false will parse it now */ assert(!parse_wireaddr_internal("odpzvneidqdf5hdq.onion", &addr_int, 1, - false, false, false, /* allow_deprecated = */ false, NULL)); - assert(parse_wireaddr_internal("odpzvneidqdf5hdq.onion", &addr_int, 1, - false, false, false, /* allow_deprecated = */ true, NULL)); + false, false, false, false, NULL)); + assert(!parse_wireaddr_internal("odpzvneidqdf5hdq.onion", &addr_int, 1, + false, false, false, true, NULL)); - assert(tal_count(wireaddr_from_hostname(tmpctx, "odpzvneidqdf5hdq.onion", 1, NULL, NULL, NULL)) > 0); + assert(wireaddr_from_hostname(tmpctx, "odpzvneidqdf5hdq.onion", 1, NULL, NULL, NULL) == NULL); assert(wireaddr_from_hostname(tmpctx, "aaa.onion", 1, NULL, NULL, NULL) == NULL); common_shutdown(); diff --git a/common/wireaddr.c b/common/wireaddr.c index 6851df8f8..08b0683fb 100644 --- a/common/wireaddr.c +++ b/common/wireaddr.c @@ -31,7 +31,7 @@ bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr) case ADDR_TYPE_IPV6: addr->addrlen = 16; break; - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: addr->addrlen = TOR_V2_ADDRLEN; break; case ADDR_TYPE_TOR_V3: @@ -209,7 +209,7 @@ bool wireaddr_is_wildcard(const struct wireaddr *addr) case ADDR_TYPE_IPV6: case ADDR_TYPE_IPV4: return memeqzero(addr->addr, addr->addrlen); - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: case ADDR_TYPE_WEBSOCKET: return false; @@ -255,7 +255,7 @@ char *fmt_wireaddr_without_port(const tal_t * ctx, const struct wireaddr *a) if (!inet_ntop(AF_INET6, a->addr, addrstr, INET6_ADDRSTRLEN)) return "Unprintable-ipv6-address"; return tal_fmt(ctx, "[%s]", addrstr); - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: return tal_fmt(ctx, "%s.onion", b32_encode(tmpctx, a->addr, a->addrlen)); @@ -345,9 +345,7 @@ wireaddr_from_hostname(const tal_t *ctx, u8 *dec = b32_decode(tmpctx, hostname, strlen(hostname) - strlen(".onion")); tal_resize(&addrs, 1); - if (tal_count(dec) == TOR_V2_ADDRLEN) { - addrs[0].type = ADDR_TYPE_TOR_V2; - } else if (tal_count(dec) == TOR_V3_ADDRLEN) { + if (tal_count(dec) == TOR_V3_ADDRLEN) { addrs[0].type = ADDR_TYPE_TOR_V3; } else { if (err_msg) @@ -591,9 +589,9 @@ bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr, addr->itype = ADDR_INTERNAL_WIREADDR; if (parse_wireaddr(arg, &addr->u.wireaddr, port, dns_ok ? NULL : &needed_dns, err_msg)) { - if (!allow_deprecated && addr->u.wireaddr.type == ADDR_TYPE_TOR_V2) { + if (addr->u.wireaddr.type == ADDR_TYPE_TOR_V2_REMOVED) { if (err_msg) - *err_msg = "v2 Tor onion services are deprecated"; + *err_msg = "v2 Tor onion services not supported"; return false; } @@ -695,7 +693,7 @@ struct addrinfo *wireaddr_to_addrinfo(const tal_t *ctx, ai->ai_addrlen = sizeof(*sin6); ai->ai_addr = (struct sockaddr *)sin6; return ai; - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: case ADDR_TYPE_WEBSOCKET: break; @@ -750,7 +748,7 @@ bool all_tor_addresses(const struct wireaddr_internal *wireaddr) case ADDR_TYPE_IPV4: case ADDR_TYPE_IPV6: return false; - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: case ADDR_TYPE_WEBSOCKET: continue; diff --git a/common/wireaddr.h b/common/wireaddr.h index d7d894d23..b484be47f 100644 --- a/common/wireaddr.h +++ b/common/wireaddr.h @@ -50,7 +50,7 @@ struct sockaddr_un; enum wire_addr_type { ADDR_TYPE_IPV4 = 1, ADDR_TYPE_IPV6 = 2, - ADDR_TYPE_TOR_V2 = 3, + ADDR_TYPE_TOR_V2_REMOVED = 3, ADDR_TYPE_TOR_V3 = 4, ADDR_TYPE_WEBSOCKET = 6, }; diff --git a/connectd/connectd.c b/connectd/connectd.c index 68c767813..4cd25fbc4 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -962,7 +962,9 @@ static void try_connect_one_addr(struct connecting *connect) break; case ADDR_INTERNAL_WIREADDR: switch (addr->u.wireaddr.type) { - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: + af = -1; + break; case ADDR_TYPE_TOR_V3: use_proxy = true; break; @@ -1154,7 +1156,7 @@ static bool handle_wireaddr_listen(struct daemon *daemon, return false; /* Handle specially by callers. */ case ADDR_TYPE_WEBSOCKET: - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: break; } @@ -1659,9 +1661,12 @@ static void add_gossip_addrs(struct wireaddr_internal **addrs, /* Wrap each one in a wireaddr_internal and add to addrs. */ for (size_t i = 0; i < tal_count(normal_addrs); i++) { + /* This is not supported, ignore. */ + if (normal_addrs[i].type == ADDR_TYPE_TOR_V2_REMOVED) + continue; + /* add TOR addresses in a second loop */ - if (normal_addrs[i].type == ADDR_TYPE_TOR_V2 || - normal_addrs[i].type == ADDR_TYPE_TOR_V3) + if (normal_addrs[i].type == ADDR_TYPE_TOR_V3) continue; if (wireaddr_int_equals_wireaddr(addrhint, &normal_addrs[i])) continue; @@ -1672,8 +1677,7 @@ static void add_gossip_addrs(struct wireaddr_internal **addrs, } /* so connectd prefers direct connections if possible. */ for (size_t i = 0; i < tal_count(normal_addrs); i++) { - if (normal_addrs[i].type != ADDR_TYPE_TOR_V2 && - normal_addrs[i].type != ADDR_TYPE_TOR_V3) + if (normal_addrs[i].type != ADDR_TYPE_TOR_V3) continue; if (wireaddr_int_equals_wireaddr(addrhint, &normal_addrs[i])) continue; diff --git a/connectd/netaddress.c b/connectd/netaddress.c index ce55cfa39..dff03e92d 100644 --- a/connectd/netaddress.c +++ b/connectd/netaddress.c @@ -135,7 +135,7 @@ static bool IsRFC4843(const struct wireaddr *addr) static bool IsTor(const struct wireaddr *addr) { - return addr->type == ADDR_TYPE_TOR_V2 || addr->type == ADDR_TYPE_TOR_V3; + return addr->type == ADDR_TYPE_TOR_V3; } static bool IsLocal(const struct wireaddr *addr) @@ -256,7 +256,7 @@ bool guess_address(struct wireaddr *addr) memcpy(addr->addr, &sin6.sin6_addr, addr->addrlen); return ret; } - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: case ADDR_TYPE_WEBSOCKET: status_broken("Cannot guess address type %u", addr->type); diff --git a/devtools/gossipwith.c b/devtools/gossipwith.c index 2bd0a4778..97287103d 100644 --- a/devtools/gossipwith.c +++ b/devtools/gossipwith.c @@ -317,7 +317,7 @@ int main(int argc, char *argv[]) case ADDR_INTERNAL_WIREADDR: switch (addr.u.wireaddr.type) { - case ADDR_TYPE_TOR_V2: + case ADDR_TYPE_TOR_V2_REMOVED: case ADDR_TYPE_TOR_V3: opt_usage_exit_fail("Don't support proxy use"); break; diff --git a/lightningd/options.c b/lightningd/options.c index d8431c13c..152575254 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -254,9 +254,8 @@ static char *opt_add_addr(const char *arg, struct lightningd *ld) /* handle in case you used the addr option with an .onion */ if (parse_wireaddr_internal(arg, &addr, 0, true, false, true, deprecated_apis, NULL)) { - if (addr.itype == ADDR_INTERNAL_WIREADDR && ( - addr.u.wireaddr.type == ADDR_TYPE_TOR_V2 || - addr.u.wireaddr.type == ADDR_TYPE_TOR_V3)) { + if (addr.itype == ADDR_INTERNAL_WIREADDR && + 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", @@ -302,9 +301,8 @@ static char *opt_add_bind_addr(const char *arg, struct lightningd *ld) /* handle in case you used the bind option with an .onion */ if (parse_wireaddr_internal(arg, &addr, 0, true, false, true, deprecated_apis, NULL)) { - if (addr.itype == ADDR_INTERNAL_WIREADDR && ( - addr.u.wireaddr.type == ADDR_TYPE_TOR_V2 || - addr.u.wireaddr.type == ADDR_TYPE_TOR_V3)) { + if (addr.itype == ADDR_INTERNAL_WIREADDR && + 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", diff --git a/tests/test_gossip.py b/tests/test_gossip.py index b69531f80..b45e43031 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -918,9 +918,7 @@ def test_gossip_addresses(node_factory, bitcoind): '[::]:3', '127.0.0.1:2', 'vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion', - '3fyb44wdhnd2ghhl.onion:1234' ], - 'allow-deprecated-apis': True, }) l2 = node_factory.get_node() l1.rpc.connect(l2.info['id'], 'localhost', l2.port) @@ -934,8 +932,7 @@ def test_gossip_addresses(node_factory, bitcoind): assert len(nodes) == 1 and nodes[0]['addresses'] == [ {'type': 'ipv4', 'address': '127.0.0.1', 'port': 2}, {'type': 'ipv6', 'address': '::', 'port': 3}, - {'type': 'torv2', 'address': '3fyb44wdhnd2ghhl.onion', 'port': 1234}, - {'type': 'torv3', 'address': 'vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion', 'port': 9735} + {'type': 'torv3', 'address': 'vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion', 'port': 9735}, ]