| 662 | } |
| 663 | |
| 664 | void force_peer_disconnect(struct lightningd *ld, |
| 665 | const struct peer *peer, |
| 666 | const char *why) |
| 667 | { |
| 668 | struct channel *c, *next; |
| 669 | |
| 670 | /* Don't bother on shutting down */ |
| 671 | if (!ld->connectd) |
| 672 | return; |
| 673 | |
| 674 | /* Disconnect subds */ |
| 675 | if (peer->uncommitted_channel) |
| 676 | kill_uncommitted_channel(peer->uncommitted_channel, why); |
| 677 | |
| 678 | list_for_each_safe(&peer->channels, c, next, list) { |
| 679 | if (!c->owner) |
| 680 | continue; |
| 681 | |
| 682 | if (!channel_state_wants_peercomms(c->state)) |
| 683 | continue; |
| 684 | |
| 685 | log_debug(c->log, "Forcing disconnect due to %s", why); |
| 686 | /* This frees c! */ |
| 687 | if (channel_state_uncommitted(c->state)) |
| 688 | channel_unsaved_close_conn(c, why); |
| 689 | else |
| 690 | channel_set_owner(c, NULL); |
| 691 | } |
| 692 | |
| 693 | subd_send_msg(peer->ld->connectd, |
| 694 | take(towire_connectd_disconnect_peer(NULL, &peer->id, |
| 695 | peer->connectd_counter))); |
| 696 | } |
| 697 | |
| 698 | static void connect_init_done(struct subd *connectd, |
| 699 | const u8 *reply, |
no test coverage detected