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

Function try_connect_one_addr

connectd/connectd.c:1054–1231  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1052
1053/*~ This is the routine which tries to connect. */
1054static void try_connect_one_addr(struct connecting *connect)
1055{
1056 int fd, af;
1057 bool use_proxy = connect->daemon->always_use_proxy;
1058 const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum];
1059 struct io_conn *conn;
1060 bool use_dns = connect->daemon->use_dns;
1061 struct addrinfo hints, *ais, *aii;
1062 int gai_err;
1063 struct sockaddr_in *sa4;
1064 struct sockaddr_in6 *sa6;
1065
1066 assert(!connect->conn);
1067 assert(!connect->waiting);
1068
1069 /* Out of addresses? */
1070 if (connect->addrnum == tal_count(connect->addrs)) {
1071 /* Free connect before connect_fail, so it doesn't think
1072 * a connect is in-progress if it wants to reconnect */
1073 struct daemon *daemon = connect->daemon;
1074 struct node_id id = connect->id;
1075 const char *errors = tal_steal(tmpctx, connect->errors);
1076 const char *reason = tal_steal(tmpctx, connect->reason);
1077 struct timemono start = connect->start;
1078 bool attempted = connect->connect_attempted;
1079
1080 tal_free(connect);
1081 connect_failed(daemon, &id, attempted, reason, start,
1082 CONNECT_ALL_ADDRESSES_FAILED,
1083 "All addresses failed: %s",
1084 errors);
1085 return;
1086 }
1087
1088 /* Might not even be able to create eg. IPv6 sockets */
1089 af = -1;
1090
1091 switch (addr->itype) {
1092 case ADDR_INTERNAL_SOCKNAME:
1093 af = AF_LOCAL;
1094 /* Local sockets don't use tor proxy */
1095 use_proxy = false;
1096 break;
1097 case ADDR_INTERNAL_ALLPROTO:
1098 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1099 "Can't connect ALLPROTO");
1100 case ADDR_INTERNAL_AUTOTOR:
1101 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1102 "Can't connect AUTOTOR");
1103 case ADDR_INTERNAL_STATICTOR:
1104 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1105 "Can't connect STATICTOR");
1106 case ADDR_INTERNAL_FORPROXY:
1107 use_proxy = true;
1108 break;
1109 case ADDR_INTERNAL_WIREADDR:
1110 switch (addr->u.wireaddr.wireaddr.type) {
1111 case ADDR_TYPE_TOR_V2_REMOVED:

Callers 3

destroy_io_connFunction · 0.85
try_connect_peerFunction · 0.85

Calls 10

tal_freeFunction · 0.85
tal_append_fmtFunction · 0.85
fmt_wireaddr_internalFunction · 0.85
wireaddr_from_ipv4Function · 0.85
wireaddr_from_ipv6Function · 0.85
append_addrFunction · 0.85
close_random_connectionFunction · 0.85
set_tcp_no_delayFunction · 0.85
connect_failedFunction · 0.70
status_failedFunction · 0.50

Tested by

no test coverage detected