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

Function try_connect_one_addr

connectd/connectd.c:763–931  ·  view source on GitHub ↗

~ This is the routine which tries to connect. */

Source from the content-addressed store, hash-verified

761
762/*~ This is the routine which tries to connect. */
763static void try_connect_one_addr(struct connecting *connect)
764{
765 int fd, af;
766 bool use_proxy = connect->daemon->always_use_proxy;
767 const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum];
768 struct io_conn *conn;
769 bool use_dns = connect->daemon->use_dns;
770 struct addrinfo hints, *ais, *aii;
771 struct wireaddr_internal addrhint;
772 int gai_err;
773 struct sockaddr_in *sa4;
774 struct sockaddr_in6 *sa6;
775
776 assert(!connect->conn);
777
778 /* Out of addresses? */
779 if (connect->addrnum == tal_count(connect->addrs)) {
780 connect_failed(connect->daemon, &connect->id,
781 connect->addrhint, CONNECT_ALL_ADDRESSES_FAILED,
782 "All addresses failed: %s",
783 connect->errors);
784 tal_free(connect);
785 return;
786 }
787
788 /* Might not even be able to create eg. IPv6 sockets */
789 af = -1;
790
791 switch (addr->itype) {
792 case ADDR_INTERNAL_SOCKNAME:
793 af = AF_LOCAL;
794 /* Local sockets don't use tor proxy */
795 use_proxy = false;
796 break;
797 case ADDR_INTERNAL_ALLPROTO:
798 status_failed(STATUS_FAIL_INTERNAL_ERROR,
799 "Can't connect ALLPROTO");
800 case ADDR_INTERNAL_AUTOTOR:
801 status_failed(STATUS_FAIL_INTERNAL_ERROR,
802 "Can't connect AUTOTOR");
803 case ADDR_INTERNAL_STATICTOR:
804 status_failed(STATUS_FAIL_INTERNAL_ERROR,
805 "Can't connect STATICTOR");
806 case ADDR_INTERNAL_FORPROXY:
807 use_proxy = true;
808 break;
809 case ADDR_INTERNAL_WIREADDR:
810 switch (addr->u.wireaddr.type) {
811 case ADDR_TYPE_TOR_V2_REMOVED:
812 af = -1;
813 break;
814 case ADDR_TYPE_TOR_V3:
815 use_proxy = true;
816 break;
817 case ADDR_TYPE_IPV4:
818 af = AF_INET;
819 break;
820 case ADDR_TYPE_IPV6:

Callers 2

destroy_io_connFunction · 0.85
try_connect_peerFunction · 0.85

Calls 7

tal_freeFunction · 0.85
tal_append_fmtFunction · 0.85
wireaddr_from_ipv4Function · 0.85
wireaddr_from_ipv6Function · 0.85
connect_failedFunction · 0.70
status_failedFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected