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

Function send_manual_ping

connectd/multiplex.c:1270–1328  ·  view source on GitHub ↗

Lightningd says to send a ping */

Source from the content-addressed store, hash-verified

1268
1269/* Lightningd says to send a ping */
1270void send_manual_ping(struct daemon *daemon, const u8 *msg)
1271{
1272 u8 *ping;
1273 struct node_id id;
1274 u16 len, num_pong_bytes;
1275 struct peer *peer;
1276
1277 if (!fromwire_connectd_ping(msg, &id, &num_pong_bytes, &len))
1278 master_badmsg(WIRE_CONNECTD_PING, msg);
1279
1280 peer = peer_htable_get(&daemon->peers, &id);
1281 if (!peer) {
1282 daemon_conn_send(daemon->master,
1283 take(towire_connectd_ping_reply(NULL,
1284 false, 0)));
1285 return;
1286 }
1287
1288 /* We're not supposed to send another ping until previous replied */
1289 if (peer->expecting_pong != PONG_UNEXPECTED) {
1290 daemon_conn_send(daemon->master,
1291 take(towire_connectd_ping_reply(NULL,
1292 false, 0)));
1293 return;
1294 }
1295
1296 /* It should never ask for an oversize ping. */
1297 ping = make_ping(NULL, num_pong_bytes, len);
1298 if (tal_count(ping) > 65535)
1299 status_failed(STATUS_FAIL_MASTER_IO, "Oversize ping");
1300
1301 inject_peer_msg(peer, take(ping));
1302
1303 status_debug("sending ping expecting %sresponse",
1304 num_pong_bytes >= 65532 ? "no " : "");
1305
1306 /* BOLT #1:
1307 *
1308 * A node receiving a `ping` message:
1309 * - if `num_pong_bytes` is less than 65532:
1310 * - MUST respond by sending a `pong` message, with `byteslen` equal
1311 * to `num_pong_bytes`.
1312 * - otherwise (`num_pong_bytes` is **not** less than 65532):
1313 * - MUST ignore the `ping`.
1314 */
1315 if (num_pong_bytes >= 65532) {
1316 daemon_conn_send(daemon->master,
1317 take(towire_connectd_ping_reply(NULL,
1318 true, 0)));
1319 return;
1320 }
1321
1322 /* We'll respond to lightningd once the pong comes in */
1323 peer->expecting_pong = PONG_EXPECTED_COMMAND;
1324
1325 /* Since we're doing this manually, kill and restart timer. */
1326 tal_free(peer->ping_timer);
1327 set_ping_timer(peer);

Callers 1

recv_reqFunction · 0.85

Calls 7

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

Tested by

no test coverage detected