MCPcopy Create free account
hub / github.com/ElementsProject/lightning / send_manual_ping

Function send_manual_ping

connectd/multiplex.c:1818–1879  ·  view source on GitHub ↗

Lightningd says to send a ping */

Source from the content-addressed store, hash-verified

1816
1817/* Lightningd says to send a ping */
1818void send_manual_ping(struct daemon *daemon, const u8 *msg)
1819{
1820 u8 *ping;
1821 struct node_id id;
1822 u64 reqid;
1823 u16 len, num_pong_bytes;
1824 struct peer *peer;
1825
1826 if (!fromwire_connectd_ping(msg, &reqid, &id, &num_pong_bytes, &len))
1827 master_badmsg(WIRE_CONNECTD_PING, msg);
1828
1829 peer = peer_htable_get(daemon->peers, &id);
1830 if (!peer) {
1831 daemon_conn_send(daemon->master,
1832 take(towire_connectd_ping_done(NULL, reqid,
1833 false, 0)));
1834 return;
1835 }
1836
1837 /* We're not supposed to send another ping until previous replied */
1838 if (peer->expecting_pong != PONG_UNEXPECTED) {
1839 daemon_conn_send(daemon->master,
1840 take(towire_connectd_ping_done(NULL, reqid,
1841 false, 0)));
1842 return;
1843 }
1844
1845 /* It should never ask for an oversize ping. */
1846 ping = make_ping(NULL, num_pong_bytes, len);
1847 if (tal_count(ping) > 65535)
1848 status_failed(STATUS_FAIL_MASTER_IO, "Oversize ping");
1849
1850 peer->ping_start = time_mono();
1851 inject_peer_msg(peer, take(ping));
1852
1853 status_debug("sending ping expecting %sresponse",
1854 num_pong_bytes >= 65532 ? "no " : "");
1855
1856 /* BOLT #1:
1857 *
1858 * A node receiving a `ping` message:
1859 * - if `num_pong_bytes` is less than 65532:
1860 * - MUST respond by sending a `pong` message, with `byteslen` equal
1861 * to `num_pong_bytes`.
1862 * - otherwise (`num_pong_bytes` is **not** less than 65532):
1863 * - MUST ignore the `ping`.
1864 */
1865 if (num_pong_bytes >= 65532) {
1866 daemon_conn_send(daemon->master,
1867 take(towire_connectd_ping_done(NULL, reqid,
1868 true, 0)));
1869 return;
1870 }
1871
1872 /* We'll respond to lightningd once the pong comes in */
1873 peer->expecting_pong = PONG_EXPECTED_COMMAND;
1874 peer->ping_reqid = reqid;
1875

Callers 1

recv_reqFunction · 0.85

Calls 8

daemon_conn_sendFunction · 0.85
make_pingFunction · 0.85
time_monoFunction · 0.85
tal_freeFunction · 0.85
set_ping_timerFunction · 0.85
inject_peer_msgFunction · 0.70
master_badmsgFunction · 0.50
status_failedFunction · 0.50

Tested by

no test coverage detected