From 301acc9556fcfe6bbeb2fd378731f7c6a18438bf Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Mon, 27 Jun 2022 16:10:41 +0200 Subject: [PATCH] gossipd: only use IP discovery if no addresses are announced This will only add the discovered `remote_addr` IPs if no other addresses would be announced. Meaning whenever a public address was found by autobind or an address was specified via commandline or config, IP discovery will be disabled. Addresses: #5305 Note from the author: We could/should also enable IP discovery when we only have a TOR address (but without --always-use-proxy ofc). This will give nodes an option to have a bootstrap way to be reached until IP discovery can do the job in a more stable way. Changelog-Changed: Only use IP discovery as fallback when no addresses would be announced --- gossipd/gossip_generation.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gossipd/gossip_generation.c b/gossipd/gossip_generation.c index dfb621beb..b309e4883 100644 --- a/gossipd/gossip_generation.c +++ b/gossipd/gossip_generation.c @@ -35,20 +35,24 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon, u8 *addresses = tal_arr(tmpctx, u8, 0); u8 *announcement; struct tlv_node_ann_tlvs *na_tlv; - size_t i; + size_t i, count_announceable; /* add all announceable addresses */ + count_announceable = tal_count(daemon->announceable); was = tal_arr(tmpctx, struct wireaddr, 0); - for (i = 0; i < tal_count(daemon->announceable); i++) + for (i = 0; i < count_announceable; i++) tal_arr_expand(&was, daemon->announceable[i]); - /* add reported `remote_addr` v4 and v6 of our self */ - if (daemon->remote_addr_v4 != NULL && - !wireaddr_arr_contains(was, daemon->remote_addr_v4)) - tal_arr_expand(&was, *daemon->remote_addr_v4); - if (daemon->remote_addr_v6 != NULL && - !wireaddr_arr_contains(was, daemon->remote_addr_v6)) - tal_arr_expand(&was, *daemon->remote_addr_v6); + /* Add IP discovery `remote_addr` v4 and v6 of our self. */ + /* Only do that if we don't have addresses announced. */ + if (count_announceable == 0) { + if (daemon->remote_addr_v4 != NULL && + !wireaddr_arr_contains(was, daemon->remote_addr_v4)) + tal_arr_expand(&was, *daemon->remote_addr_v4); + if (daemon->remote_addr_v6 != NULL && + !wireaddr_arr_contains(was, daemon->remote_addr_v6)) + tal_arr_expand(&was, *daemon->remote_addr_v6); + } /* Sort by address type again, as we added dynamic remote_addr v4/v6. */ /* BOLT #7: