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 */
| 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 */ |
| 1278 | static 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, |
no test coverage detected