| 142 | } |
| 143 | |
| 144 | static void peer_channels_cleanup(struct lightningd *ld, |
| 145 | const struct node_id *id) |
| 146 | { |
| 147 | struct peer *peer; |
| 148 | struct channel *c, **channels; |
| 149 | |
| 150 | peer = peer_by_id(ld, id); |
| 151 | if (!peer) |
| 152 | return; |
| 153 | |
| 154 | /* Freeing channels can free peer, so gather first. */ |
| 155 | channels = tal_arr(tmpctx, struct channel *, 0); |
| 156 | list_for_each(&peer->channels, c, list) |
| 157 | tal_arr_expand(&channels, c); |
| 158 | |
| 159 | if (peer->uncommitted_channel) { |
| 160 | /* Frees peer if no channels */ |
| 161 | kill_uncommitted_channel(peer->uncommitted_channel, |
| 162 | "Disconnected"); |
| 163 | } else if (tal_count(channels) == 0) |
| 164 | /* Was completely idle. */ |
| 165 | tal_free(peer); |
| 166 | |
| 167 | for (size_t i = 0; i < tal_count(channels); i++) { |
| 168 | c = channels[i]; |
| 169 | if (channel_active(c)) { |
| 170 | channel_cleanup_commands(c, "Disconnected"); |
| 171 | channel_fail_transient(c, "Disconnected"); |
| 172 | } else if (channel_unsaved(c)) { |
| 173 | channel_unsaved_close_conn(c, "Disconnected"); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid) |
| 179 | { |
no test coverage detected