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

Function try_connect_one_addr

connectd/connectd.c:1057–1234  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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