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

Function send_manual_ping

connectd/multiplex.c:1861–1922  ·  view source on GitHub ↗

Lightningd says to send a ping */

Source from the content-addressed store, hash-verified

1859
1860/* Lightningd says to send a ping */
1861void send_manual_ping(struct daemon *daemon, const u8 *msg)
1862{
1863 u8 *ping;
1864 struct node_id id;
1865 u64 reqid;
1866 u16 len, num_pong_bytes;
1867 struct peer *peer;
1868
1869 if (!fromwire_connectd_ping(msg, &reqid, &id, &num_pong_bytes, &len))
1870 master_badmsg(WIRE_CONNECTD_PING, msg);
1871
1872 peer = peer_htable_get(daemon->peers, &id);
1873 if (!peer) {
1874 daemon_conn_send(daemon->master,
1875 take(towire_connectd_ping_done(NULL, reqid,
1876 false, 0)));
1877 return;
1878 }
1879
1880 /* We're not supposed to send another ping until previous replied */
1881 if (peer->expecting_pong != PONG_UNEXPECTED) {
1882 daemon_conn_send(daemon->master,
1883 take(towire_connectd_ping_done(NULL, reqid,
1884 false, 0)));
1885 return;
1886 }
1887
1888 /* It should never ask for an oversize ping. */
1889 ping = make_ping(NULL, num_pong_bytes, len);
1890 if (tal_count(ping) > 65535)
1891 status_failed(STATUS_FAIL_MASTER_IO, "Oversize ping");
1892
1893 peer->ping_start = time_mono();
1894 inject_peer_msg(peer, take(ping));
1895
1896 status_debug("sending ping expecting %sresponse",
1897 num_pong_bytes >= 65532 ? "no " : "");
1898
1899 /* BOLT #1:
1900 *
1901 * A node receiving a `ping` message:
1902 * - if `num_pong_bytes` is less than 65532:
1903 * - MUST respond by sending a `pong` message, with `byteslen` equal
1904 * to `num_pong_bytes`.
1905 * - otherwise (`num_pong_bytes` is **not** less than 65532):
1906 * - MUST ignore the `ping`.
1907 */
1908 if (num_pong_bytes >= 65532) {
1909 daemon_conn_send(daemon->master,
1910 take(towire_connectd_ping_done(NULL, reqid,
1911 true, 0)));
1912 return;
1913 }
1914
1915 /* We'll respond to lightningd once the pong comes in */
1916 peer->expecting_pong = PONG_EXPECTED_COMMAND;
1917 peer->ping_reqid = reqid;
1918

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