| 159 | } |
| 160 | |
| 161 | void peer_channels_cleanup(struct peer *peer) |
| 162 | { |
| 163 | struct channel *c, **channels; |
| 164 | |
| 165 | /* Freeing channels can free peer, so gather first. */ |
| 166 | channels = tal_arr(tmpctx, struct channel *, 0); |
| 167 | list_for_each(&peer->channels, c, list) |
| 168 | tal_arr_expand(&channels, c); |
| 169 | |
| 170 | if (peer->uncommitted_channel) { |
| 171 | /* Frees peer if no channels */ |
| 172 | kill_uncommitted_channel(peer->uncommitted_channel, |
| 173 | "Disconnected"); |
| 174 | } else if (tal_count(channels) == 0) |
| 175 | /* Was completely idle. */ |
| 176 | tal_free(peer); |
| 177 | |
| 178 | for (size_t i = 0; i < tal_count(channels); i++) { |
| 179 | c = channels[i]; |
| 180 | if (channel_state_wants_peercomms(c->state)) { |
| 181 | channel_cleanup_commands(c, "Disconnected"); |
| 182 | channel_fail_transient(c, true, "Disconnected"); |
| 183 | } else if (channel_state_uncommitted(c->state)) { |
| 184 | channel_unsaved_close_conn(c, "Disconnected"); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid) |
| 190 | { |
no test coverage detected