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

Function try_connect_peer

connectd/connectd.c:1716–1799  ·  view source on GitHub ↗

~ Consumes addrhint if not NULL. * * That's a pretty ugly interface: we should use TAKEN, but we only have one * caller so it's marginal. */

Source from the content-addressed store, hash-verified

1714 * That's a pretty ugly interface: we should use TAKEN, but we only have one
1715 * caller so it's marginal. */
1716static void try_connect_peer(struct daemon *daemon,
1717 const struct node_id *id,
1718 struct wireaddr *gossip_addrs,
1719 struct wireaddr_internal *addrhint STEALS)
1720{
1721 struct wireaddr_internal *addrs;
1722 bool use_proxy = daemon->always_use_proxy;
1723 struct connecting *connect;
1724
1725 /* Already existing? Must have crossed over, it'll know soon. */
1726 if (peer_htable_get(&daemon->peers, id))
1727 return;
1728
1729 /* If we're trying to connect it right now, that's OK. */
1730 if ((connect = find_connecting(daemon, id))) {
1731 /* If we've been passed in new connection details
1732 * for this connection, update our addrhint + add
1733 * to addresses to check */
1734 if (addrhint) {
1735 connect->addrhint = tal_steal(connect, addrhint);
1736 tal_arr_expand(&connect->addrs, *addrhint);
1737 }
1738
1739 return;
1740 }
1741
1742 /* Start an array of addresses to try. */
1743 addrs = tal_arr(tmpctx, struct wireaddr_internal, 0);
1744
1745 /* They can supply an optional address for the connect RPC */
1746 /* We add this first so its tried first by connectd */
1747 if (addrhint)
1748 tal_arr_expand(&addrs, *addrhint);
1749
1750 add_gossip_addrs(&addrs, gossip_addrs, addrhint);
1751
1752 if (tal_count(addrs) == 0) {
1753 /* Don't resolve via DNS seed if we're supposed to use proxy. */
1754 if (use_proxy) {
1755 /* You're allowed to use names with proxies; in fact it's
1756 * a good idea. */
1757 struct wireaddr_internal unresolved;
1758 const char **hostnames = seednames(tmpctx, id);
1759 for (size_t i = 0; i < tal_count(hostnames); i++) {
1760 wireaddr_from_unresolved(&unresolved,
1761 hostnames[i],
1762 chainparams_get_ln_port(chainparams));
1763 tal_arr_expand(&addrs, unresolved);
1764 }
1765 } else if (daemon->use_dns) {
1766 add_seed_addrs(&addrs, id,
1767 daemon->broken_resolver_response);
1768 }
1769 }
1770
1771 /* Still no address? Fail immediately. Lightningd can still choose
1772 * to retry; an address may get gossiped or appear on the DNS seed. */
1773 if (tal_count(addrs) == 0) {

Callers 1

connect_to_peerFunction · 0.85

Calls 8

find_connectingFunction · 0.85
add_gossip_addrsFunction · 0.85
seednamesFunction · 0.85
wireaddr_from_unresolvedFunction · 0.85
add_seed_addrsFunction · 0.85
try_connect_one_addrFunction · 0.85
connect_failedFunction · 0.70
chainparams_get_ln_portFunction · 0.50

Tested by

no test coverage detected