MCPcopy Create free account
hub / github.com/ElementsProject/lightning / update_remote_addr

Function update_remote_addr

lightningd/peer_control.c:1278–1349  ·  view source on GitHub ↗

Compare and store `remote_addr` and the `peer_id` that reported it. * If new address was reported by at least one other, do node_announcement */

Source from the content-addressed store, hash-verified

1276/* Compare and store `remote_addr` and the `peer_id` that reported it.
1277 * If new address was reported by at least one other, do node_announcement */
1278static void update_remote_addr(struct lightningd *ld,
1279 const struct wireaddr *remote_addr,
1280 const struct node_id peer_id)
1281{
1282 u16 public_port;
1283
1284 /* failsafe to prevent privacy leakage. */
1285 if (ld->always_use_proxy || ld->config.disable_ip_discovery)
1286 return;
1287
1288 /* Peers will have likey reported our dynamic outbound TCP port.
1289 * Best guess is that we use default port for the selected network,
1290 * until we add a commandline switch to override this. */
1291 public_port = chainparams_get_ln_port(chainparams);
1292
1293 switch (remote_addr->type) {
1294 case ADDR_TYPE_IPV4:
1295 /* init pointers first time */
1296 if (ld->remote_addr_v4 == NULL) {
1297 ld->remote_addr_v4 = tal_dup(ld, struct wireaddr,
1298 remote_addr);
1299 ld->remote_addr_v4_peer = peer_id;
1300 }
1301 /* if updated by the same peer just remember the latest addr */
1302 if (node_id_eq(&ld->remote_addr_v4_peer, &peer_id)) {
1303 *ld->remote_addr_v4 = *remote_addr;
1304 break;
1305 }
1306 /* tell gossip we have a valid update */
1307 if (wireaddr_eq_without_port(ld->remote_addr_v4, remote_addr)) {
1308 ld->discovered_ip_v4 = tal_dup(ld, struct wireaddr,
1309 ld->remote_addr_v4);
1310 ld->discovered_ip_v4->port = public_port;
1311 subd_send_msg(ld->gossip, towire_gossipd_discovered_ip(
1312 tmpctx,
1313 ld->discovered_ip_v4));
1314 }
1315 /* store latest values */
1316 *ld->remote_addr_v4 = *remote_addr;
1317 ld->remote_addr_v4_peer = peer_id;
1318 break;
1319 case ADDR_TYPE_IPV6:
1320 /* same code :s/4/6/ without the comments ;) */
1321 if (ld->remote_addr_v6 == NULL) {
1322 ld->remote_addr_v6 = tal_dup(ld, struct wireaddr,
1323 remote_addr);
1324 ld->remote_addr_v6_peer = peer_id;
1325 }
1326 if (node_id_eq(&ld->remote_addr_v6_peer, &peer_id)) {
1327 *ld->remote_addr_v6 = *remote_addr;
1328 break;
1329 }
1330 if (wireaddr_eq_without_port(ld->remote_addr_v6, remote_addr)) {
1331 ld->discovered_ip_v6 = tal_dup(ld, struct wireaddr,
1332 ld->remote_addr_v6);
1333 ld->discovered_ip_v6->port = public_port;
1334 subd_send_msg(ld->gossip, towire_gossipd_discovered_ip(
1335 tmpctx,

Callers 1

peer_connectedFunction · 0.85

Calls 5

node_id_eqFunction · 0.85
wireaddr_eq_without_portFunction · 0.85
subd_send_msgFunction · 0.70
chainparams_get_ln_portFunction · 0.50

Tested by

no test coverage detected