| 607 | } |
| 608 | |
| 609 | void force_peer_disconnect(struct lightningd *ld, |
| 610 | const struct peer *peer, |
| 611 | const char *why) |
| 612 | { |
| 613 | struct channel *c, *next; |
| 614 | |
| 615 | /* Don't bother on shutting down */ |
| 616 | if (!ld->connectd) |
| 617 | return; |
| 618 | |
| 619 | /* Disconnect subds */ |
| 620 | if (peer->uncommitted_channel) |
| 621 | kill_uncommitted_channel(peer->uncommitted_channel, why); |
| 622 | |
| 623 | list_for_each_safe(&peer->channels, c, next, list) { |
| 624 | if (!c->owner) |
| 625 | continue; |
| 626 | |
| 627 | if (!channel_state_wants_peercomms(c->state)) |
| 628 | continue; |
| 629 | |
| 630 | log_debug(c->log, "Forcing disconnect due to %s", why); |
| 631 | /* This frees c! */ |
| 632 | if (channel_state_uncommitted(c->state)) |
| 633 | channel_unsaved_close_conn(c, why); |
| 634 | else |
| 635 | channel_set_owner(c, NULL); |
| 636 | } |
| 637 | |
| 638 | subd_send_msg(peer->ld->connectd, |
| 639 | take(towire_connectd_disconnect_peer(NULL, &peer->id, |
| 640 | peer->connectd_counter))); |
| 641 | } |
| 642 | |
| 643 | static void connect_init_done(struct subd *connectd, |
| 644 | const u8 *reply, |
no test coverage detected