| 1635 | } |
| 1636 | |
| 1637 | static 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 | |
| 1679 | static struct io_plan *subd_conn_init(struct io_conn *subd_conn, |
| 1680 | struct subd *subd) |
no test coverage detected