opts: announce-addr-discovered on/off/auto switch

This adds the option to explicitly enable ip-discovery, which maybe
helpful for example when a user wants TOR announced along with
discovered IPs to improve connectivity and have TOR just as a fallback.

Changelog-Added: Adds config switch 'announce-addr-discovered': on/off/auto
This commit is contained in:
Michael Schmoock
2022-12-20 17:49:03 +01:00
parent bd75f8ea6c
commit 3babbc5201
10 changed files with 39 additions and 8 deletions

View File

@@ -88,7 +88,8 @@ On success, an object is returned, containing:
- **autolisten** (boolean, optional): `autolisten` field from config or cmdline, or default
- **proxy** (string, optional): `proxy` field from config or cmdline, or default
- **disable-dns** (boolean, optional): `true` if `disable-dns` was set in config or cmdline
- **disable-ip-discovery** (boolean, optional): `true` if `disable-ip-discovery` was set in config or cmdline
- **disable-ip-discovery** (boolean, optional): `true` if `disable-ip-discovery` was set in config or cmdline (DEPRECATED)
- **ip-discovery** (string, optional): `true` if `ip-discovery` was set in config or cmdline
- **encrypted-hsm** (boolean, optional): `true` if `encrypted-hsm` was set in config or cmdline
- **rpc-file-mode** (string, optional): `rpc-file-mode` field from config or cmdline, or default
- **log-level** (string, optional): `log-level` field from config or cmdline, or default

View File

@@ -247,6 +247,11 @@
"type": "boolean",
"description": "`true` if `disable-ip-discovery` was set in config or cmdline"
},
"announce-addr-discovered": {
"type": "string",
"description": "`true`/`false`/`auto` depending on how `announce-addr-discovered` was set in config or cmdline",
"added": "v23.02"
},
"encrypted-hsm": {
"type": "boolean",
"description": "`true` if `encrypted-hsm` was set in config or cmdline"

View File

@@ -3,6 +3,7 @@
#include "config.h"
#include <ccan/asort/asort.h>
#include <ccan/cast/cast.h>
#include <ccan/ccan/opt/opt.h>
#include <ccan/mem/mem.h>
#include <common/daemon_conn.h>
#include <common/features.h>
@@ -44,8 +45,10 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
tal_arr_expand(&was, daemon->announceable[i]);
/* Add discovered IPs v4/v6 verified by peer `remote_addr` feature. */
/* Only do that if we don't have addresses announced. */
if (count_announceable == 0) {
/* Only do that if we don't have any addresses announced or
* `config.ip_discovery` is explicitly enabled. */
if ((daemon->ip_discovery == OPT_AUTOBOOL_AUTO && count_announceable == 0) ||
daemon->ip_discovery == OPT_AUTOBOOL_TRUE) {
if (daemon->discovered_ip_v4 != NULL &&
!wireaddr_arr_contains(was, daemon->discovered_ip_v4))
tal_arr_expand(&was, *daemon->discovered_ip_v4);

View File

@@ -346,6 +346,7 @@ static void handle_local_private_channel(struct daemon *daemon, const u8 *msg)
static void handle_discovered_ip(struct daemon *daemon, const u8 *msg)
{
struct wireaddr discovered_ip;
size_t count_announceable;
if (!fromwire_gossipd_discovered_ip(msg, &discovered_ip))
master_badmsg(WIRE_GOSSIPD_DISCOVERED_IP, msg);
@@ -380,8 +381,11 @@ static void handle_discovered_ip(struct daemon *daemon, const u8 *msg)
return;
update_node_annoucement:
status_debug("Update our node_announcement for discovered address: %s",
fmt_wireaddr(tmpctx, &discovered_ip));
count_announceable = tal_count(daemon->announceable);
if ((daemon->ip_discovery == OPT_AUTOBOOL_AUTO && count_announceable == 0) ||
daemon->ip_discovery == OPT_AUTOBOOL_TRUE)
status_debug("Update our node_announcement for discovered address: %s",
fmt_wireaddr(tmpctx, &discovered_ip));
maybe_send_own_node_announce(daemon, false);
}
@@ -727,7 +731,8 @@ static void gossip_init(struct daemon *daemon, const u8 *msg)
&daemon->announceable,
&dev_gossip_time,
&dev_fast_gossip,
&dev_fast_gossip_prune)) {
&dev_fast_gossip_prune,
&daemon->ip_discovery)) {
master_badmsg(WIRE_GOSSIPD_INIT, msg);
}
@@ -1096,6 +1101,7 @@ int main(int argc, char *argv[])
daemon->rates = NULL;
daemon->discovered_ip_v4 = NULL;
daemon->discovered_ip_v6 = NULL;
daemon->ip_discovery = OPT_AUTOBOOL_AUTO;
list_head_init(&daemon->deferred_updates);
/* Tell the ecdh() function how to talk to hsmd */

View File

@@ -1,6 +1,7 @@
#ifndef LIGHTNING_GOSSIPD_GOSSIPD_H
#define LIGHTNING_GOSSIPD_GOSSIPD_H
#include "config.h"
#include <ccan/ccan/opt/opt.h>
#include <ccan/timer/timer.h>
#include <common/node_id.h>
#include <lightningd/options.h>
@@ -52,6 +53,7 @@ struct daemon {
/* verified remote_addr as reported by recent peers */
struct wireaddr *discovered_ip_v4;
struct wireaddr *discovered_ip_v6;
enum opt_autobool ip_discovery;
/* Timer until we can send an updated node_announcement */
struct oneshot *node_announce_timer;

View File

@@ -16,6 +16,7 @@ msgdata,gossipd_init,announceable,wireaddr,num_announceable
msgdata,gossipd_init,dev_gossip_time,?u32,
msgdata,gossipd_init,dev_fast_gossip,bool,
msgdata,gossipd_init,dev_fast_gossip_prune,bool,
msgdata,gossipd_init,ip_discovery,u32,
msgtype,gossipd_init_reply,3100
1 #include <common/cryptomsg.h>
16 msgdata,gossipd_init,dev_fast_gossip,bool,
17 msgdata,gossipd_init,dev_fast_gossip_prune,bool,
18 msgtype,gossipd_init_reply,3100 msgdata,gossipd_init,ip_discovery,u32,
19 msgtype,gossipd_init_reply,3100
20 # In developer mode, we can mess with time.
21 msgtype,gossipd_dev_set_time,3001
22 msgdata,gossipd_dev_set_time,dev_gossip_time,u32,

View File

@@ -262,7 +262,8 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
ld->announceable,
IFDEV(ld->dev_gossip_time ? &ld->dev_gossip_time: NULL, NULL),
IFDEV(ld->dev_fast_gossip, false),
IFDEV(ld->dev_fast_gossip_prune, false));
IFDEV(ld->dev_fast_gossip_prune, false),
ld->config.ip_discovery);
subd_req(ld->gossip, ld->gossip, take(msg), -1, 0,
gossipd_init_done, NULL);

View File

@@ -1,6 +1,7 @@
#ifndef LIGHTNING_LIGHTNINGD_LIGHTNINGD_H
#define LIGHTNING_LIGHTNINGD_LIGHTNINGD_H
#include "config.h"
#include <ccan/ccan/opt/opt.h>
#include <lightningd/htlc_end.h>
#include <lightningd/htlc_set.h>
#include <lightningd/options.h>
@@ -58,6 +59,8 @@ struct config {
/* Are we allowed to use DNS lookup for peers. */
bool use_dns;
/* Excplicitly turns 'on' or 'off' IP discovery feature. */
enum opt_autobool ip_discovery;
/* Turn off IP address announcement discovered via peer `remote_addr` */
bool disable_ip_discovery;

View File

@@ -843,6 +843,8 @@ static const struct config testnet_config = {
.use_dns = true,
/* Excplicitly turns 'on' or 'off' IP discovery feature. */
.ip_discovery = OPT_AUTOBOOL_AUTO,
/* Turn off IP address announcement discovered via peer `remote_addr` */
.disable_ip_discovery = false,
@@ -909,6 +911,8 @@ static const struct config mainnet_config = {
.use_dns = true,
/* Excplicitly turns 'on' or 'off' IP discovery feature. */
.ip_discovery = OPT_AUTOBOOL_AUTO,
/* Turn off IP address announcement discovered via peer `remote_addr` */
.disable_ip_discovery = false,
@@ -1211,9 +1215,13 @@ static void register_opts(struct lightningd *ld)
opt_register_arg("--announce-addr", opt_add_announce_addr, NULL,
ld,
"Set an IP address (v4 or v6) or .onion v3 to announce, but not listen on");
opt_register_noarg("--disable-ip-discovery", opt_set_bool,
&ld->config.disable_ip_discovery,
"Turn off announcement of discovered public IPs");
opt_register_arg("--announce-addr-discovered", opt_set_autobool_arg, opt_show_autobool,
&ld->config.ip_discovery,
"Explicitly turns IP discovery 'on' or 'off'.");
opt_register_noarg("--offline", opt_set_offline, ld,
"Start in offline-mode (do not automatically reconnect and do not accept incoming connections)");

View File

@@ -73,7 +73,8 @@ def test_remote_addr(node_factory, bitcoind):
# don't announce anything per se
opts = {'may_reconnect': True,
'dev-allow-localhost': None,
'dev-no-reconnect': None}
'dev-no-reconnect': None,
'ip-discovery': True}
l1, l2, l3 = node_factory.get_nodes(3, opts)
# Disable announcing local autobind addresses with dev-allow-localhost.