~ When we need to send an array of channels, it might go over our 64k packet * size. But because we use compression, we can't actually tell how much * we'll use. We pack them into the maximum amount for uncompressed, then * compress afterwards. */
| 639 | * compress afterwards. |
| 640 | */ |
| 641 | static void queue_channel_ranges(struct peer *peer, |
| 642 | u32 first_blocknum, u32 number_of_blocks, |
| 643 | enum query_option_flags query_option_flags) |
| 644 | { |
| 645 | struct daemon *daemon = peer->daemon; |
| 646 | struct channel_update_timestamps *tstamps; |
| 647 | struct channel_update_checksums *csums; |
| 648 | struct short_channel_id *scids; |
| 649 | size_t off, limit; |
| 650 | |
| 651 | scids = gather_range(tmpctx, daemon, first_blocknum, number_of_blocks, |
| 652 | query_option_flags, &tstamps, &csums); |
| 653 | |
| 654 | limit = max_entries(query_option_flags); |
| 655 | off = 0; |
| 656 | |
| 657 | /* We need to send an empty msg if we have nothing! */ |
| 658 | do { |
| 659 | size_t n = tal_count(scids) - off; |
| 660 | u32 this_num_blocks; |
| 661 | |
| 662 | if (n > limit) { |
| 663 | status_debug("reply_channel_range: splitting %zu-%zu of %zu", |
| 664 | off, off + limit, tal_count(scids)); |
| 665 | n = limit; |
| 666 | |
| 667 | /* ... and reduce to a block boundary. */ |
| 668 | while (short_channel_id_blocknum(scids[off + n - 1]) |
| 669 | == short_channel_id_blocknum(scids[off + limit])) { |
| 670 | /* We assume one block doesn't have limit # |
| 671 | * channels. If it does, we have to violate |
| 672 | * spec and send over multiple blocks. */ |
| 673 | if (n == 0) { |
| 674 | status_broken("reply_channel_range: " |
| 675 | "could not fit %zu scids for %u!", |
| 676 | limit, |
| 677 | short_channel_id_blocknum(scids[off + n - 1])); |
| 678 | n = limit; |
| 679 | break; |
| 680 | } |
| 681 | n--; |
| 682 | } |
| 683 | /* Get *next* channel, add num blocks */ |
| 684 | this_num_blocks |
| 685 | = short_channel_id_blocknum(scids[off + n]) |
| 686 | - first_blocknum; |
| 687 | } else |
| 688 | /* Last one must end with correct total */ |
| 689 | this_num_blocks = number_of_blocks; |
| 690 | |
| 691 | /* BOLT #7: |
| 692 | * If the incoming message includes `query_option`, the receiver |
| 693 | * MAY append additional information to its reply: |
| 694 | * - if bit 0 in `query_option_flags` is set, the receiver MAY |
| 695 | * append a `timestamps_tlv`... |
| 696 | * - if bit 1 in `query_option_flags` is set, the receiver MAY |
| 697 | * append a `checksums_tlv`... |
| 698 | */ |
no test coverage detected