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