Lightningd says to send a ping */
| 1746 | |
| 1747 | /* Lightningd says to send a ping */ |
| 1748 | void send_manual_ping(struct daemon *daemon, const u8 *msg) |
| 1749 | { |
| 1750 | u8 *ping; |
| 1751 | struct node_id id; |
| 1752 | u64 reqid; |
| 1753 | u16 len, num_pong_bytes; |
| 1754 | struct peer *peer; |
| 1755 | |
| 1756 | if (!fromwire_connectd_ping(msg, &reqid, &id, &num_pong_bytes, &len)) |
| 1757 | master_badmsg(WIRE_CONNECTD_PING, msg); |
| 1758 | |
| 1759 | peer = peer_htable_get(daemon->peers, &id); |
| 1760 | if (!peer) { |
| 1761 | daemon_conn_send(daemon->master, |
| 1762 | take(towire_connectd_ping_done(NULL, reqid, |
| 1763 | false, 0))); |
| 1764 | return; |
| 1765 | } |
| 1766 | |
| 1767 | /* We're not supposed to send another ping until previous replied */ |
| 1768 | if (peer->expecting_pong != PONG_UNEXPECTED) { |
| 1769 | daemon_conn_send(daemon->master, |
| 1770 | take(towire_connectd_ping_done(NULL, reqid, |
| 1771 | false, 0))); |
| 1772 | return; |
| 1773 | } |
| 1774 | |
| 1775 | /* It should never ask for an oversize ping. */ |
| 1776 | ping = make_ping(NULL, num_pong_bytes, len); |
| 1777 | if (tal_count(ping) > 65535) |
| 1778 | status_failed(STATUS_FAIL_MASTER_IO, "Oversize ping"); |
| 1779 | |
| 1780 | peer->ping_start = time_mono(); |
| 1781 | inject_peer_msg(peer, take(ping)); |
| 1782 | |
| 1783 | status_debug("sending ping expecting %sresponse", |
| 1784 | num_pong_bytes >= 65532 ? "no " : ""); |
| 1785 | |
| 1786 | /* BOLT #1: |
| 1787 | * |
| 1788 | * A node receiving a `ping` message: |
| 1789 | * - if `num_pong_bytes` is less than 65532: |
| 1790 | * - MUST respond by sending a `pong` message, with `byteslen` equal |
| 1791 | * to `num_pong_bytes`. |
| 1792 | * - otherwise (`num_pong_bytes` is **not** less than 65532): |
| 1793 | * - MUST ignore the `ping`. |
| 1794 | */ |
| 1795 | if (num_pong_bytes >= 65532) { |
| 1796 | daemon_conn_send(daemon->master, |
| 1797 | take(towire_connectd_ping_done(NULL, reqid, |
| 1798 | true, 0))); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | /* We'll respond to lightningd once the pong comes in */ |
| 1803 | peer->expecting_pong = PONG_EXPECTED_COMMAND; |
| 1804 | peer->ping_reqid = reqid; |
| 1805 |
no test coverage detected