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

Function add_gossip_addrs

connectd/connectd.c:1685–1710  ·  view source on GitHub ↗

~ Orders the addresses which lightningd gave us. * * Ignores deprecated protocols and the `addrhint` that is assumed to be * already added first. Adds all IPv6 addresses, followed by IPv4 and then TOR. * This ensures we are modern and use IPv6 when possible, falling back to * direct (faster) IPv4 and finally (less stable) TOR connections. */

Source from the content-addressed store, hash-verified

1683 * This ensures we are modern and use IPv6 when possible, falling back to
1684 * direct (faster) IPv4 and finally (less stable) TOR connections. */
1685static void add_gossip_addrs(struct wireaddr_internal **addrs,
1686 const struct wireaddr *normal_addrs,
1687 const struct wireaddr_internal *addrhint)
1688{
1689 /* Wrap each one in a wireaddr_internal and add to addrs. */
1690 for (size_t i = 0; i < tal_count(normal_addrs); i++) {
1691 /* This is not supported, ignore. */
1692 if (normal_addrs[i].type == ADDR_TYPE_TOR_V2_REMOVED)
1693 continue;
1694 /* The hint was already added earlier */
1695 if (wireaddr_int_equals_wireaddr(addrhint, &normal_addrs[i]))
1696 continue;
1697 /* We add IPv4 and TOR in separate loops to prefer IPv6 */
1698 if (normal_addrs[i].type == ADDR_TYPE_IPV4)
1699 continue;
1700 if (normal_addrs[i].type == ADDR_TYPE_TOR_V3)
1701 continue;
1702 struct wireaddr_internal addr;
1703 addr.itype = ADDR_INTERNAL_WIREADDR;
1704 addr.u.wireaddr = normal_addrs[i];
1705 tal_arr_expand(addrs, addr);
1706 }
1707 /* Do the loop for skipped protocols in preferred order. */
1708 add_gossip_addrs_bytype(addrs, normal_addrs, addrhint, ADDR_TYPE_IPV4);
1709 add_gossip_addrs_bytype(addrs, normal_addrs, addrhint, ADDR_TYPE_TOR_V3);
1710}
1711
1712/*~ Consumes addrhint if not NULL.
1713 *

Callers 1

try_connect_peerFunction · 0.85

Calls 2

add_gossip_addrs_bytypeFunction · 0.85

Tested by

no test coverage detected