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

Function json_ping

lightningd/ping.c:39–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39static struct command_result *json_ping(struct command *cmd,
40 const char *buffer,
41 const jsmntok_t *obj UNNEEDED,
42 const jsmntok_t *params)
43{
44 unsigned int *len, *pongbytes;
45 struct node_id *id;
46 u8 *msg;
47
48 if (!param(cmd, buffer, params,
49 p_req("id", param_node_id, &id),
50 p_opt_def("len", param_number, &len, 128),
51 p_opt_def("pongbytes", param_number, &pongbytes, 128),
52 NULL))
53 return command_param_failed();
54
55 /* BOLT #1:
56 *
57 * 1. `type`: a 2-byte big-endian field indicating the type of message
58 * 2. `payload`: ...
59 * The size of the message is required by the transport layer to fit
60 * into a 2-byte unsigned int; therefore, the maximum possible size is
61 * 65535 bytes.
62 *...
63 * 1. type: 18 (`ping`)
64 * 2. data:
65 * * [`u16`:`num_pong_bytes`]
66 * * [`u16`:`byteslen`]
67 * * [`byteslen*byte`:`ignored`]
68 */
69 if (*len > 65535 - 2 - 2 - 2) {
70 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
71 "%u would result in oversize ping", *len);
72 }
73
74 /* Note that > 65531 is valid: it means "no pong reply" */
75 if (*pongbytes > 65535) {
76 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
77 "pongbytes %u > 65535", *pongbytes);
78 }
79
80 if (!peer_by_id(cmd->ld, id))
81 return command_fail(cmd, LIGHTNINGD, "Peer not connected");
82
83 msg = towire_connectd_ping(NULL, id, *pongbytes, *len);
84 subd_req(cmd, cmd->ld->connectd, take(msg), -1, 0, ping_reply, cmd);
85
86 return command_still_pending(cmd);
87}
88
89static const struct json_command ping_command = {
90 "ping",

Callers

nothing calls this directly

Calls 6

peer_by_idFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
subd_reqClass · 0.70
command_still_pendingFunction · 0.70
paramFunction · 0.50

Tested by

no test coverage detected