| 1680 | } |
| 1681 | |
| 1682 | static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn, |
| 1683 | struct peer *peer) |
| 1684 | { |
| 1685 | u64 cpu_budget, wait_usec; |
| 1686 | assert(peer->to_peer == peer_conn); |
| 1687 | |
| 1688 | maybe_reset_usage_window(peer); |
| 1689 | |
| 1690 | cpu_budget = peer_cpu_budget(peer); |
| 1691 | |
| 1692 | wait_usec = maybe_throttle_usec(peer, &peer->throttle_warned, "incoming", |
| 1693 | peer->gs.bytes_rcvd_this_second, peer->daemon->incoming_stream_limit, |
| 1694 | peer->gs.cpu_usec_this_second, cpu_budget); |
| 1695 | if (wait_usec) { |
| 1696 | /* Set timer for when we'll be back under quota (if not already) */ |
| 1697 | if (!peer->recv_timer) { |
| 1698 | peer->recv_timer = new_abstimer(&peer->daemon->timers, |
| 1699 | peer, |
| 1700 | timemono_add(time_mono(), time_from_usec(wait_usec)), |
| 1701 | recv_throttle_timeout, |
| 1702 | peer); |
| 1703 | } |
| 1704 | return io_wait(peer_conn, &peer->peer_in, |
| 1705 | read_hdr_from_peer, peer); |
| 1706 | } |
| 1707 | |
| 1708 | /* BOLT #8: |
| 1709 | * |
| 1710 | * ### Receiving and Decrypting Messages |
| 1711 | * |
| 1712 | * In order to decrypt the _next_ message in the network |
| 1713 | * stream, the following steps are completed: |
| 1714 | * |
| 1715 | * 1. Read _exactly_ 18 bytes from the network buffer. |
| 1716 | */ |
| 1717 | peer->peer_in = tal_arr(peer, u8, CRYPTOMSG_HDR_SIZE); |
| 1718 | return io_read(peer_conn, peer->peer_in, CRYPTOMSG_HDR_SIZE, |
| 1719 | read_body_from_peer, peer); |
| 1720 | } |
| 1721 | |
| 1722 | static struct io_plan *subd_conn_init(struct io_conn *subd_conn, |
| 1723 | struct subd *subd) |
no test coverage detected