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

Function read_body_from_peer_done

connectd/multiplex.c:1484–1614  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1482static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn,
1483 struct peer *peer);
1484static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
1485 struct peer *peer)
1486{
1487 u8 *decrypted;
1488 struct channel_id channel_id;
1489 struct subd *subd;
1490 enum peer_wire type;
1491 struct timemono handled_start;
1492 struct io_plan *(*next_read)(struct io_conn *peer_conn,
1493 struct peer *peer) = read_hdr_from_peer;
1494
1495 decrypted = cryptomsg_decrypt_body(tmpctx, &peer->cs,
1496 peer->peer_in);
1497 if (!decrypted) {
1498 status_peer_debug(&peer->id, "Bad encrypted packet len %zu",
1499 tal_bytelen(peer->peer_in));
1500 return io_close(peer_conn);
1501 }
1502
1503 peer->gs.bytes_rcvd_this_second += tal_bytelen(peer->peer_in);
1504 tal_free(peer->peer_in);
1505
1506 type = fromwire_peektype(decrypted);
1507
1508 /* dev_disconnect can disable read */
1509 if (!peer->dev_read_enabled)
1510 return read_hdr_from_peer(peer_conn, peer);
1511
1512 switch (dev_disconnect_in(&peer->id, type)) {
1513 case DEV_DISCONNECT_IN_NORMAL:
1514 break;
1515 case DEV_DISCONNECT_IN_AFTER_RECV:
1516 next_read = close_peer_dev_disconnect;
1517 break;
1518 }
1519
1520 /* We got something! */
1521 peer->last_recv_time = time_mono();
1522
1523 /* Don't process packets while we're closing */
1524 if (peer->draining_state != NOT_DRAINING)
1525 return next_read(peer_conn, peer);
1526
1527 /* If we swallow this, just try again. */
1528 handled_start = time_mono();
1529 /* Count the CPU time for local messages (esp. gossip queries) */
1530 if (handle_message_locally(peer, decrypted)) {
1531 peer->gs.cpu_usec_this_second
1532 += time_to_usec(timemono_between(time_mono(), handled_start));
1533 /* Make sure to update peer->peer_in_lastmsg so we blame correct msg! */
1534 goto out;
1535 }
1536
1537 /* After this we should be able to match to subd by channel_id */
1538 if (!extract_channel_id(decrypted, &channel_id)) {
1539 /* We won't log this anywhere else, so do it here. */
1540 status_peer_io(LOG_IO_IN, &peer->id, decrypted);
1541

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
time_to_usecFunction · 0.85
timemono_betweenFunction · 0.85
extract_channel_idFunction · 0.85
sanitize_errorFunction · 0.85

Tested by

no test coverage detected