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

Function json_ping

lightningd/ping.c:64–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64static struct command_result *json_ping(struct command *cmd,
65 const char *buffer,
66 const jsmntok_t *obj UNNEEDED,
67 const jsmntok_t *params)
68{
69 unsigned int *len, *pongbytes;
70 struct node_id *id;
71 u8 *msg;
72 static u64 reqid;
73 struct ping_command *ping_command;
74
75 if (!param_check(cmd, buffer, params,
76 p_req("id", param_node_id, &id),
77 p_opt_def("len", param_number, &len, 128),
78 p_opt_def("pongbytes", param_number, &pongbytes, 128),
79 NULL))
80 return command_param_failed();
81
82 /* BOLT #1:
83 *
84 * 1. `type`: a 2-byte big-endian field indicating the type of message
85 * 2. `payload`: ...
86 * The size of the message is required by the transport layer to fit
87 * into a 2-byte unsigned int; therefore, the maximum possible size is
88 * 65535 bytes.
89 *...
90 * 1. type: 18 (`ping`)
91 * 2. data:
92 * * [`u16`:`num_pong_bytes`]
93 * * [`u16`:`byteslen`]
94 * * [`byteslen*byte`:`ignored`]
95 */
96 if (*len > 65535 - 2 - 2 - 2) {
97 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
98 "%u would result in oversize ping", *len);
99 }
100
101 /* Note that > 65531 is valid: it means "no pong reply" */
102 if (*pongbytes > 65535) {
103 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
104 "pongbytes %u > 65535", *pongbytes);
105 }
106
107 if (!peer_by_id(cmd->ld, id))
108 return command_fail(cmd, LIGHTNINGD, "Peer not connected");
109
110 if (command_check_only(cmd))
111 return command_check_done(cmd);
112
113 ping_command = tal(cmd, struct ping_command);
114 ping_command->cmd = cmd;
115 ping_command->reqid = ++reqid;
116 list_add_tail(&cmd->ld->ping_commands, &ping_command->list);
117 tal_add_destructor2(ping_command, destroy_ping_command, cmd->ld);
118
119 msg = towire_connectd_ping(NULL, ping_command->reqid, id, *pongbytes, *len);
120 subd_send_msg(cmd->ld->connectd, take(msg));
121

Callers

nothing calls this directly

Calls 8

param_checkFunction · 0.85
peer_by_idFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
subd_send_msgFunction · 0.70
command_still_pendingFunction · 0.70

Tested by

no test coverage detected