From ca9e3e4cc1df92e1f55f9c5b614e5383c033ac94 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 21 Dec 2022 11:41:04 +0100 Subject: [PATCH] opts: adds --announce-addr-discovered-port config option This will give the user an option to set a custom port when using discovered IPs for node_announcents. Without this, only the selected networks default port can used. Changelog-Added: Adds --announce-addr-discovered-port config option to set custom port for IP discovery. --- lightningd/lightningd.h | 3 +++ lightningd/options.c | 12 ++++++++++++ lightningd/peer_control.c | 11 ++--------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index eec2f8508..6fa1cc413 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -62,6 +62,9 @@ struct config { /* Excplicitly turns 'on' or 'off' IP discovery feature. */ enum opt_autobool ip_discovery; + /* Public TCP port assumed for IP discovery. Defaults to chainparams. */ + u32 ip_discovery_port; + /* Minimal amount of effective funding_satoshis for accepting channels */ u64 min_capacity_sat; diff --git a/lightningd/options.c b/lightningd/options.c index 89403c15c..f4267ecd8 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -846,6 +846,9 @@ static const struct config testnet_config = { /* Excplicitly turns 'on' or 'off' IP discovery feature. */ .ip_discovery = OPT_AUTOBOOL_AUTO, + /* Public TCP port assumed for IP discovery. Defaults to chainparams. */ + .ip_discovery_port = 0, + /* Sets min_effective_htlc_capacity - at 1000$/BTC this is 10ct */ .min_capacity_sat = 10000, @@ -912,6 +915,9 @@ static const struct config mainnet_config = { /* Excplicitly turns 'on' or 'off' IP discovery feature. */ .ip_discovery = OPT_AUTOBOOL_AUTO, + /* Public TCP port assumed for IP discovery. Defaults to chainparams. */ + .ip_discovery_port = 0, + /* Sets min_effective_htlc_capacity - at 1000$/BTC this is 10ct */ .min_capacity_sat = 10000, @@ -1223,6 +1229,9 @@ static void register_opts(struct lightningd *ld) 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_arg("--announce-addr-discovered-port", opt_set_uintval, + opt_show_uintval, &ld->config.ip_discovery_port, + "Sets the public TCP port to use for announcing discovered IPs."); opt_register_noarg("--offline", opt_set_offline, ld, "Start in offline-mode (do not automatically reconnect and do not accept incoming connections)"); @@ -1427,6 +1436,9 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[]) else ld->config = mainnet_config; + /* Set the ln_port given from chainparams */ + ld->config.ip_discovery_port = chainparams->ln_port; + /* Now we can initialize wallet_dsn */ ld->wallet_dsn = tal_fmt(ld, "sqlite3://%s/lightningd.sqlite3", ld->config_netdir); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index b84e76a7b..dfb75e795 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1305,18 +1305,11 @@ static void update_remote_addr(struct lightningd *ld, const struct wireaddr *remote_addr, const struct node_id peer_id) { - u16 public_port; - /* failsafe to prevent privacy leakage. */ if (ld->always_use_proxy || ld->config.ip_discovery == OPT_AUTOBOOL_FALSE) return; - /* Peers will have likey reported our dynamic outbound TCP port. - * Best guess is that we use default port for the selected network, - * until we add a commandline switch to override this. */ - public_port = chainparams_get_ln_port(chainparams); - switch (remote_addr->type) { case ADDR_TYPE_IPV4: /* init pointers first time */ @@ -1334,7 +1327,7 @@ static void update_remote_addr(struct lightningd *ld, if (wireaddr_eq_without_port(ld->remote_addr_v4, remote_addr)) { ld->discovered_ip_v4 = tal_dup(ld, struct wireaddr, ld->remote_addr_v4); - ld->discovered_ip_v4->port = public_port; + ld->discovered_ip_v4->port = ld->config.ip_discovery_port; subd_send_msg(ld->gossip, towire_gossipd_discovered_ip( tmpctx, ld->discovered_ip_v4)); @@ -1357,7 +1350,7 @@ static void update_remote_addr(struct lightningd *ld, if (wireaddr_eq_without_port(ld->remote_addr_v6, remote_addr)) { ld->discovered_ip_v6 = tal_dup(ld, struct wireaddr, ld->remote_addr_v6); - ld->discovered_ip_v6->port = public_port; + ld->discovered_ip_v6->port = ld->config.ip_discovery_port; subd_send_msg(ld->gossip, towire_gossipd_discovered_ip( tmpctx, ld->discovered_ip_v6));