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

Function read_hdr_from_peer

connectd/multiplex.c:1637–1677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1635}
1636
1637static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn,
1638 struct peer *peer)
1639{
1640 u64 cpu_budget, wait_usec;
1641 assert(peer->to_peer == peer_conn);
1642
1643 maybe_reset_usage_window(peer);
1644
1645 /* Each peer gets its "fair share" of our local-message CPU */
1646 cpu_budget = peer->daemon->cpu_budget_usec_limit
1647 / peer_htable_count(peer->daemon->peers);
1648
1649 wait_usec = maybe_throttle_usec(peer, &peer->throttle_warned, "incoming",
1650 peer->gs.bytes_rcvd_this_second, peer->daemon->incoming_stream_limit,
1651 peer->gs.cpu_usec_this_second, cpu_budget);
1652 if (wait_usec) {
1653 /* Set timer for when we'll be back under quota (if not already) */
1654 if (!peer->recv_timer) {
1655 peer->recv_timer = new_abstimer(&peer->daemon->timers,
1656 peer,
1657 timemono_add(time_mono(), time_from_usec(wait_usec)),
1658 recv_throttle_timeout,
1659 peer);
1660 }
1661 return io_wait(peer_conn, &peer->peer_in,
1662 read_hdr_from_peer, peer);
1663 }
1664
1665 /* BOLT #8:
1666 *
1667 * ### Receiving and Decrypting Messages
1668 *
1669 * In order to decrypt the _next_ message in the network
1670 * stream, the following steps are completed:
1671 *
1672 * 1. Read _exactly_ 18 bytes from the network buffer.
1673 */
1674 peer->peer_in = tal_arr(peer, u8, CRYPTOMSG_HDR_SIZE);
1675 return io_read(peer_conn, peer->peer_in, CRYPTOMSG_HDR_SIZE,
1676 read_body_from_peer, peer);
1677}
1678
1679static struct io_plan *subd_conn_init(struct io_conn *subd_conn,
1680 struct subd *subd)

Callers 2

read_body_from_peer_doneFunction · 0.85
multiplex_peer_setupFunction · 0.85

Calls 5

maybe_reset_usage_windowFunction · 0.85
maybe_throttle_usecFunction · 0.85
timemono_addFunction · 0.85
time_monoFunction · 0.85
time_from_usecFunction · 0.85

Tested by

no test coverage detected