How many entries can I fit in a reply? */
| 373 | |
| 374 | /* How many entries can I fit in a reply? */ |
| 375 | static size_t max_entries(enum query_option_flags query_option_flags) |
| 376 | { |
| 377 | /* BOLT #7: |
| 378 | * |
| 379 | * 1. type: 264 (`reply_channel_range`) (`gossip_queries`) |
| 380 | * 2. data: |
| 381 | * * [`chain_hash`:`chain_hash`] |
| 382 | * * [`u32`:`first_blocknum`] |
| 383 | * * [`u32`:`number_of_blocks`] |
| 384 | * * [`byte`:`sync_complete`] |
| 385 | * * [`u16`:`len`] |
| 386 | * * [`len*byte`:`encoded_short_ids`] |
| 387 | */ |
| 388 | const size_t reply_overhead = 32 + 4 + 4 + 1 + 2; |
| 389 | size_t max_encoded_bytes = 65535 - 2 - reply_overhead; |
| 390 | size_t per_entry_size, max_num; |
| 391 | |
| 392 | per_entry_size = sizeof(struct short_channel_id); |
| 393 | |
| 394 | /* Upper bound to start. */ |
| 395 | max_num = max_encoded_bytes / per_entry_size; |
| 396 | |
| 397 | /* If we add timestamps, we need to encode tlv */ |
| 398 | if (query_option_flags & QUERY_ADD_TIMESTAMPS) { |
| 399 | max_encoded_bytes -= tlv_overhead(max_num, |
| 400 | sizeof(struct channel_update_timestamps)); |
| 401 | per_entry_size += sizeof(struct channel_update_timestamps); |
| 402 | } |
| 403 | |
| 404 | if (query_option_flags & QUERY_ADD_CHECKSUMS) { |
| 405 | max_encoded_bytes -= tlv_overhead(max_num, |
| 406 | sizeof(struct channel_update_checksums)); |
| 407 | per_entry_size += sizeof(struct channel_update_checksums); |
| 408 | } |
| 409 | |
| 410 | #if DEVELOPER |
| 411 | if (max_encoded_bytes > dev_max_encoding_bytes) |
| 412 | max_encoded_bytes = dev_max_encoding_bytes; |
| 413 | /* Always let one through! */ |
| 414 | if (max_encoded_bytes < per_entry_size) |
| 415 | max_encoded_bytes = per_entry_size; |
| 416 | #endif |
| 417 | |
| 418 | return max_encoded_bytes / per_entry_size; |
| 419 | } |
| 420 | |
| 421 | /* This gets all the scids they asked for, and optionally the timestamps and checksums */ |
| 422 | static struct short_channel_id *gather_range(const tal_t *ctx, |
no test coverage detected