| 1066 | } |
| 1067 | |
| 1068 | bool query_channel_range(struct daemon *daemon, |
| 1069 | struct peer *peer, |
| 1070 | u32 first_blocknum, u32 number_of_blocks, |
| 1071 | enum query_option_flags qflags, |
| 1072 | void (*cb)(struct peer *, |
| 1073 | u32, u32, |
| 1074 | const struct range_query_reply *)) |
| 1075 | { |
| 1076 | u8 *msg; |
| 1077 | struct tlv_query_channel_range_tlvs *tlvs; |
| 1078 | |
| 1079 | assert((qflags & ~(QUERY_ADD_TIMESTAMPS|QUERY_ADD_CHECKSUMS)) == 0); |
| 1080 | assert(peer->gossip_queries_feature); |
| 1081 | assert(!peer->range_replies); |
| 1082 | assert(!peer->query_channel_range_cb); |
| 1083 | |
| 1084 | if (qflags) { |
| 1085 | tlvs = tlv_query_channel_range_tlvs_new(tmpctx); |
| 1086 | tlvs->query_option = tal(tlvs, bigsize_t); |
| 1087 | *tlvs->query_option = qflags; |
| 1088 | } else |
| 1089 | tlvs = NULL; |
| 1090 | status_peer_debug(&peer->id, |
| 1091 | "sending query_channel_range for blocks %u+%u", |
| 1092 | first_blocknum, number_of_blocks); |
| 1093 | |
| 1094 | msg = towire_query_channel_range(NULL, &chainparams->genesis_blockhash, |
| 1095 | first_blocknum, number_of_blocks, |
| 1096 | tlvs); |
| 1097 | queue_peer_msg(peer, take(msg)); |
| 1098 | peer->range_first_blocknum = first_blocknum; |
| 1099 | peer->range_end_blocknum = first_blocknum + number_of_blocks; |
| 1100 | peer->range_blocks_outstanding = number_of_blocks; |
| 1101 | peer->range_replies = tal_arr(peer, struct range_query_reply, 0); |
| 1102 | peer->query_channel_range_cb = cb; |
| 1103 | |
| 1104 | return true; |
| 1105 | } |
| 1106 | |
| 1107 | #if DEVELOPER |
| 1108 | /* This is a testing hack to allow us to artificially lower the maximum bytes |
no test coverage detected