@@ -1274,10 +1274,17 @@ static void update_remote_addr(struct lightningd *ld,
12741274 const struct wireaddr * remote_addr ,
12751275 const struct node_id peer_id )
12761276{
1277+ u16 public_port ;
1278+
12771279 /* failsafe to prevent privacy leakage. */
12781280 if (ld -> always_use_proxy || ld -> config .disable_ip_discovery )
12791281 return ;
12801282
1283+ /* Peers will have likey reported our dynamic outbound TCP port.
1284+ * Best guess is that we use default port for the selected network,
1285+ * until we add a commandline switch to override this. */
1286+ public_port = chainparams_get_ln_port (chainparams );
1287+
12811288 switch (remote_addr -> type ) {
12821289 case ADDR_TYPE_IPV4 :
12831290 /* init pointers first time */
@@ -1292,10 +1299,14 @@ static void update_remote_addr(struct lightningd *ld,
12921299 break ;
12931300 }
12941301 /* tell gossip we have a valid update */
1295- if (wireaddr_eq_without_port (ld -> remote_addr_v4 , remote_addr ))
1302+ if (wireaddr_eq_without_port (ld -> remote_addr_v4 , remote_addr )) {
1303+ ld -> discovered_ip_v4 = tal_dup (ld , struct wireaddr ,
1304+ ld -> remote_addr_v4 );
1305+ ld -> discovered_ip_v4 -> port = public_port ;
12961306 subd_send_msg (ld -> gossip , towire_gossipd_remote_addr (
12971307 tmpctx ,
1298- ld -> remote_addr_v4 ));
1308+ ld -> discovered_ip_v4 ));
1309+ }
12991310 /* store latest values */
13001311 * ld -> remote_addr_v4 = * remote_addr ;
13011312 ld -> remote_addr_v4_peer = peer_id ;
@@ -1311,10 +1322,14 @@ static void update_remote_addr(struct lightningd *ld,
13111322 * ld -> remote_addr_v6 = * remote_addr ;
13121323 break ;
13131324 }
1314- if (wireaddr_eq_without_port (ld -> remote_addr_v6 , remote_addr ))
1325+ if (wireaddr_eq_without_port (ld -> remote_addr_v6 , remote_addr )) {
1326+ ld -> discovered_ip_v6 = tal_dup (ld , struct wireaddr ,
1327+ ld -> remote_addr_v6 );
1328+ ld -> discovered_ip_v6 -> port = public_port ;
13151329 subd_send_msg (ld -> gossip , towire_gossipd_remote_addr (
13161330 tmpctx ,
1317- ld -> remote_addr_v6 ));
1331+ ld -> discovered_ip_v6 ));
1332+ }
13181333 * ld -> remote_addr_v6 = * remote_addr ;
13191334 ld -> remote_addr_v6_peer = peer_id ;
13201335 break ;
@@ -2247,22 +2262,22 @@ static struct command_result *json_getinfo(struct command *cmd,
22472262 for (size_t i = 0 ; i < count_announceable ; i ++ )
22482263 json_add_address (response , NULL , cmd -> ld -> announceable + i );
22492264
2250- /* Currently, IP discovery will only be announced by gossipd, if we
2251- * don't already have usable addresses.
2265+ /* Currently, IP discovery will only be announced by gossipd,
2266+ * if we don't already have usable addresses.
22522267 * See `create_node_announcement` in `gossip_generation.c`. */
22532268 if (count_announceable == 0 ) {
2254- if (cmd -> ld -> remote_addr_v4 != NULL &&
2269+ if (cmd -> ld -> discovered_ip_v4 != NULL &&
22552270 !wireaddr_arr_contains (
22562271 cmd -> ld -> announceable ,
2257- cmd -> ld -> remote_addr_v4 ))
2272+ cmd -> ld -> discovered_ip_v4 ))
22582273 json_add_address (response , NULL ,
2259- cmd -> ld -> remote_addr_v4 );
2260- if (cmd -> ld -> remote_addr_v6 != NULL &&
2274+ cmd -> ld -> discovered_ip_v4 );
2275+ if (cmd -> ld -> discovered_ip_v6 != NULL &&
22612276 !wireaddr_arr_contains (
22622277 cmd -> ld -> announceable ,
2263- cmd -> ld -> remote_addr_v6 ))
2278+ cmd -> ld -> discovered_ip_v6 ))
22642279 json_add_address (response , NULL ,
2265- cmd -> ld -> remote_addr_v6 );
2280+ cmd -> ld -> discovered_ip_v6 );
22662281 }
22672282 json_array_end (response );
22682283
0 commit comments