~ This is the routine which tries to connect. */
| 1135 | |
| 1136 | /*~ This is the routine which tries to connect. */ |
| 1137 | static void try_connect_one_addr(struct connecting *connect) |
| 1138 | { |
| 1139 | int fd, af; |
| 1140 | bool use_proxy = connect->daemon->always_use_proxy; |
| 1141 | const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum]; |
| 1142 | struct io_conn *conn; |
| 1143 | bool use_dns = connect->daemon->use_dns; |
| 1144 | |
| 1145 | assert(!connect->conn); |
| 1146 | assert(!connect->waiting); |
| 1147 | |
| 1148 | /* Out of addresses? */ |
| 1149 | if (connect->addrnum == tal_count(connect->addrs)) { |
| 1150 | /* Free connect before connect_fail, so it doesn't think |
| 1151 | * a connect is in-progress if it wants to reconnect */ |
| 1152 | struct daemon *daemon = connect->daemon; |
| 1153 | struct node_id id = connect->id; |
| 1154 | const char *errors = tal_steal(tmpctx, connect->errors); |
| 1155 | const char *reason = tal_steal(tmpctx, connect->reason); |
| 1156 | struct timemono start = connect->start; |
| 1157 | bool attempted = connect->connect_attempted; |
| 1158 | |
| 1159 | tal_free(connect); |
| 1160 | connect_failed(daemon, &id, attempted, reason, start, |
| 1161 | CONNECT_ALL_ADDRESSES_FAILED, |
| 1162 | "All addresses failed: %s", |
| 1163 | errors); |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | /* Might not even be able to create eg. IPv6 sockets */ |
| 1168 | af = -1; |
| 1169 | |
| 1170 | switch (addr->itype) { |
| 1171 | case ADDR_INTERNAL_SOCKNAME: |
| 1172 | af = AF_LOCAL; |
| 1173 | /* Local sockets don't use tor proxy */ |
| 1174 | use_proxy = false; |
| 1175 | break; |
| 1176 | case ADDR_INTERNAL_ALLPROTO: |
| 1177 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1178 | "Can't connect ALLPROTO"); |
| 1179 | case ADDR_INTERNAL_AUTOTOR: |
| 1180 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1181 | "Can't connect AUTOTOR"); |
| 1182 | case ADDR_INTERNAL_STATICTOR: |
| 1183 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1184 | "Can't connect STATICTOR"); |
| 1185 | case ADDR_INTERNAL_FORPROXY: |
| 1186 | use_proxy = true; |
| 1187 | break; |
| 1188 | case ADDR_INTERNAL_WIREADDR: |
| 1189 | switch (addr->u.wireaddr.wireaddr.type) { |
| 1190 | case ADDR_TYPE_TOR_V2_REMOVED: |
| 1191 | af = -1; |
| 1192 | break; |
| 1193 | case ADDR_TYPE_TOR_V3: |
| 1194 | use_proxy = true; |
no test coverage detected