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

Function read_body_from_peer_done

connectd/multiplex.c:1414–1539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1412static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn,
1413 struct peer *peer);
1414static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
1415 struct peer *peer)
1416{
1417 u8 *decrypted;
1418 struct channel_id channel_id;
1419 struct subd *subd;
1420 enum peer_wire type;
1421 struct io_plan *(*next_read)(struct io_conn *peer_conn,
1422 struct peer *peer) = read_hdr_from_peer;
1423
1424 decrypted = cryptomsg_decrypt_body(tmpctx, &peer->cs,
1425 peer->peer_in);
1426 if (!decrypted) {
1427 status_peer_debug(&peer->id, "Bad encrypted packet len %zu",
1428 tal_bytelen(peer->peer_in));
1429 return io_close(peer_conn);
1430 }
1431
1432 peer->bytes_rcvd_this_second += tal_bytelen(peer->peer_in);
1433 tal_free(peer->peer_in);
1434
1435 type = fromwire_peektype(decrypted);
1436
1437 /* dev_disconnect can disable read */
1438 if (!peer->dev_read_enabled)
1439 return read_hdr_from_peer(peer_conn, peer);
1440
1441 switch (dev_disconnect_in(&peer->id, type)) {
1442 case DEV_DISCONNECT_IN_NORMAL:
1443 break;
1444 case DEV_DISCONNECT_IN_AFTER_RECV:
1445 next_read = close_peer_dev_disconnect;
1446 break;
1447 }
1448
1449 /* We got something! */
1450 peer->last_recv_time = time_mono();
1451
1452 /* Don't process packets while we're closing */
1453 if (peer->draining_state != NOT_DRAINING)
1454 return next_read(peer_conn, peer);
1455
1456 /* If we swallow this, just try again. */
1457 if (handle_message_locally(peer, decrypted)) {
1458 /* Make sure to update peer->peer_in_lastmsg so we blame correct msg! */
1459 goto out;
1460 }
1461
1462 /* After this we should be able to match to subd by channel_id */
1463 if (!extract_channel_id(decrypted, &channel_id)) {
1464 /* We won't log this anywhere else, so do it here. */
1465 status_peer_io(LOG_IO_IN, &peer->id, decrypted);
1466
1467 /* Could be a all-channel error or warning? Log it
1468 * more verbose: hang up on error. */
1469 if (type == WIRE_ERROR || type == WIRE_WARNING) {
1470 char *desc = sanitize_error(tmpctx, decrypted, NULL);
1471 /* FIXME: We should check old gossip, since we get many of

Callers

nothing calls this directly

Calls 15

cryptomsg_decrypt_bodyFunction · 0.85
tal_bytelenFunction · 0.85
io_closeFunction · 0.85
tal_freeFunction · 0.85
fromwire_peektypeFunction · 0.85
read_hdr_from_peerFunction · 0.85
time_monoFunction · 0.85
handle_message_locallyFunction · 0.85
extract_channel_idFunction · 0.85
sanitize_errorFunction · 0.85
send_warningFunction · 0.85
tal_hexFunction · 0.85

Tested by

no test coverage detected