| 1560 | } |
| 1561 | |
| 1562 | static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn, |
| 1563 | struct peer *peer) |
| 1564 | { |
| 1565 | struct timemono now = time_mono(); |
| 1566 | assert(peer->to_peer == peer_conn); |
| 1567 | |
| 1568 | /* If it's been over a second, make a fresh start. */ |
| 1569 | if (time_to_sec(timemono_between(now, peer->bytes_rcvd_start_time)) > 0) { |
| 1570 | peer->bytes_rcvd_start_time = now; |
| 1571 | peer->bytes_rcvd_this_second = 0; |
| 1572 | } |
| 1573 | |
| 1574 | /* You sent too much this second? */ |
| 1575 | if (peer->bytes_rcvd_this_second > peer->daemon->incoming_stream_limit) { |
| 1576 | status_unusual_once(&peer->throttle_warned, |
| 1577 | CI_UNEXPECTED |
| 1578 | "Throttling incoming peer %s:" |
| 1579 | " too much traffic", |
| 1580 | fmt_node_id(tmpctx, &peer->id)); |
| 1581 | |
| 1582 | /* Set timer for next second (if not already) */ |
| 1583 | if (!peer->recv_timer) { |
| 1584 | peer->recv_timer = new_abstimer(&peer->daemon->timers, |
| 1585 | peer, |
| 1586 | timemono_add(peer->bytes_rcvd_start_time, |
| 1587 | time_from_sec(1)), |
| 1588 | recv_throttle_timeout, |
| 1589 | peer); |
| 1590 | } |
| 1591 | return io_wait(peer_conn, &peer->peer_in, |
| 1592 | read_hdr_from_peer, peer); |
| 1593 | } |
| 1594 | |
| 1595 | /* BOLT #8: |
| 1596 | * |
| 1597 | * ### Receiving and Decrypting Messages |
| 1598 | * |
| 1599 | * In order to decrypt the _next_ message in the network |
| 1600 | * stream, the following steps are completed: |
| 1601 | * |
| 1602 | * 1. Read _exactly_ 18 bytes from the network buffer. |
| 1603 | */ |
| 1604 | peer->peer_in = tal_arr(peer, u8, CRYPTOMSG_HDR_SIZE); |
| 1605 | return io_read(peer_conn, peer->peer_in, CRYPTOMSG_HDR_SIZE, |
| 1606 | read_body_from_peer, peer); |
| 1607 | } |
| 1608 | |
| 1609 | static struct io_plan *subd_conn_init(struct io_conn *subd_conn, |
| 1610 | struct subd *subd) |
no test coverage detected