| 1159 | } |
| 1160 | |
| 1161 | static void peer_connected_hook_final(struct peer_connected_hook_payload *payload STEALS) |
| 1162 | { |
| 1163 | struct lightningd *ld = payload->ld; |
| 1164 | struct channel *channel; |
| 1165 | struct wireaddr_internal addr = payload->addr; |
| 1166 | struct peer *peer = payload->peer; |
| 1167 | u8 *error; |
| 1168 | |
| 1169 | /* Whatever happens, we free payload (it's currently a child |
| 1170 | * of the peer, which may be freed if we fail to start |
| 1171 | * subd). */ |
| 1172 | tal_steal(tmpctx, payload); |
| 1173 | |
| 1174 | /* If we disconnected in the meantime, forget about it. |
| 1175 | * (disconnect will have failed any connect commands). */ |
| 1176 | if (peer->connected == PEER_DISCONNECTED) |
| 1177 | return; |
| 1178 | |
| 1179 | /* Check for specific errors of a hook */ |
| 1180 | if (payload->error) { |
| 1181 | error = payload->error; |
| 1182 | goto send_error; |
| 1183 | } |
| 1184 | |
| 1185 | /* Now we finally consider ourselves connected! */ |
| 1186 | assert(peer->connected == PEER_CONNECTING); |
| 1187 | peer->connected = PEER_CONNECTED; |
| 1188 | |
| 1189 | /* Succeed any connect() commands */ |
| 1190 | connect_succeeded(ld, peer, payload->incoming, &payload->addr); |
| 1191 | |
| 1192 | /* Notify anyone who cares */ |
| 1193 | notify_connect(ld, &peer->id, payload->incoming, &addr); |
| 1194 | |
| 1195 | #if DEVELOPER |
| 1196 | /* Developer hack to fail all channels on permfail line. */ |
| 1197 | if (dev_disconnect_permanent(ld)) { |
| 1198 | list_for_each(&peer->channels, channel, list) { |
| 1199 | channel_fail_permanent(channel, REASON_LOCAL, |
| 1200 | "dev_disconnect permfail"); |
| 1201 | subd_send_msg(ld->connectd, |
| 1202 | take(towire_connectd_peer_final_msg(NULL, &peer->id, |
| 1203 | peer->connectd_counter, |
| 1204 | channel->error))); |
| 1205 | } |
| 1206 | return; |
| 1207 | } |
| 1208 | #endif |
| 1209 | |
| 1210 | /* connect appropriate subds for all (active) channels! */ |
| 1211 | list_for_each(&peer->channels, channel, list) { |
| 1212 | if (channel_active(channel)) { |
| 1213 | log_debug(channel->log, "Peer has reconnected, state %s: connecting subd", |
| 1214 | channel_state_name(channel)); |
| 1215 | |
| 1216 | connect_activate_subd(ld, channel); |
| 1217 | } |
| 1218 | } |
no test coverage detected