~ 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. */
| 505 | * compress afterwards. |
| 506 | */ |
| 507 | static void queue_channel_ranges(struct peer *peer, |
| 508 | u32 first_blocknum, u32 number_of_blocks, |
| 509 | enum query_option_flags query_option_flags) |
| 510 | { |
| 511 | struct routing_state *rstate = peer->daemon->rstate; |
| 512 | struct channel_update_timestamps *tstamps; |
| 513 | struct channel_update_checksums *csums; |
| 514 | struct short_channel_id *scids; |
| 515 | size_t off, limit; |
| 516 | |
| 517 | scids = gather_range(tmpctx, rstate, first_blocknum, number_of_blocks, |
| 518 | query_option_flags, &tstamps, &csums); |
| 519 | |
| 520 | limit = max_entries(query_option_flags); |
| 521 | off = 0; |
| 522 | |
| 523 | /* We need to send an empty msg if we have nothing! */ |
| 524 | do { |
| 525 | size_t n = tal_count(scids) - off; |
| 526 | u32 this_num_blocks; |
| 527 | |
| 528 | if (n > limit) { |
| 529 | status_debug("reply_channel_range: splitting %zu-%zu of %zu", |
| 530 | off, off + limit, tal_count(scids)); |
| 531 | n = limit; |
| 532 | |
| 533 | /* ... and reduce to a block boundary. */ |
| 534 | while (short_channel_id_blocknum(&scids[off + n - 1]) |
| 535 | == short_channel_id_blocknum(&scids[off + limit])) { |
| 536 | /* We assume one block doesn't have limit # |
| 537 | * channels. If it does, we have to violate |
| 538 | * spec and send over multiple blocks. */ |
| 539 | if (n == 0) { |
| 540 | status_broken("reply_channel_range: " |
| 541 | "could not fit %zu scids for %u!", |
| 542 | limit, |
| 543 | short_channel_id_blocknum(&scids[off + n - 1])); |
| 544 | n = limit; |
| 545 | break; |
| 546 | } |
| 547 | n--; |
| 548 | } |
| 549 | /* Get *next* channel, add num blocks */ |
| 550 | this_num_blocks |
| 551 | = short_channel_id_blocknum(&scids[off + n]) |
| 552 | - first_blocknum; |
| 553 | } else |
| 554 | /* Last one must end with correct total */ |
| 555 | this_num_blocks = number_of_blocks; |
| 556 | |
| 557 | send_reply_channel_range(peer, first_blocknum, this_num_blocks, |
| 558 | scids + off, |
| 559 | query_option_flags & QUERY_ADD_TIMESTAMPS |
| 560 | ? tstamps + off : NULL, |
| 561 | query_option_flags & QUERY_ADD_CHECKSUMS |
| 562 | ? csums + off : NULL, |
| 563 | n, |
| 564 | this_num_blocks == number_of_blocks); |
no test coverage detected