1 #ifndef LIGHTNING_GOSSIPD_QUERIES_H
2 #define LIGHTNING_GOSSIPD_QUERIES_H
3 #include "config.h"
4 #include <ccan/short_types/short_types.h>
5 
6 struct channel_update_timestamps;
7 struct daemon;
8 struct io_conn;
9 struct peer;
10 struct short_channel_id;
11 
12 /* Various handlers when peer fwds a gossip query msg: return is NULL or
13  * error packet. */
14 const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg);
15 const u8 *handle_reply_short_channel_ids_end(struct peer *peer, const u8 *msg);
16 const u8 *handle_query_channel_range(struct peer *peer, const u8 *msg);
17 const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg);
18 
19 /* This called when the peer is idle. */
20 void maybe_send_query_responses(struct peer *peer);
21 
22 /* BOLT #7:
23  *
24  * `query_option_flags` is a bitfield represented as a minimally-encoded bigsize.
25  * Bits have the following meaning:
26  *
27  * | Bit Position  | Meaning                 |
28  * | ------------- | ----------------------- |
29  * | 0             | Sender wants timestamps |
30  * | 1             | Sender wants checksums  |
31  */
32 enum query_option_flags {
33 	QUERY_ADD_TIMESTAMPS = 0x1,
34 	QUERY_ADD_CHECKSUMS = 0x2,
35 };
36 
37 /* Ask this peer for a range of scids.  Must support it, and not already
38  * have a query pending. */
39 bool query_channel_range(struct daemon *daemon,
40 			 struct peer *peer,
41 			 u32 first_blocknum, u32 number_of_blocks,
42 			 enum query_option_flags qflags,
43 			 void (*cb)(struct peer *peer,
44 				    u32 first_blocknum, u32 number_of_blocks,
45 				    const struct range_query_reply *replies));
46 
47 /* Ask this peer for info about an array of scids, with optional query_flags */
48 bool query_short_channel_ids(struct daemon *daemon,
49 			     struct peer *peer,
50 			     const struct short_channel_id *scids,
51 			     const u8 *query_flags,
52 			     void (*cb)(struct peer *peer, bool complete));
53 
54 #if DEVELOPER
55 struct io_plan *query_scids_req(struct io_conn *conn,
56 				struct daemon *daemon,
57 				const u8 *msg);
58 
59 struct io_plan *dev_query_channel_range(struct io_conn *conn,
60 					struct daemon *daemon,
61 					const u8 *msg);
62 
63 /* This is a testing hack to allow us to artificially lower the maximum bytes
64  * of short_channel_ids we'll encode, using dev_set_max_scids_encode_size. */
65 struct io_plan *dev_set_max_scids_encode_size(struct io_conn *conn,
66 					      struct daemon *daemon,
67 					      const u8 *msg);
68 #endif /* DEVELOPER */
69 
70 #endif /* LIGHTNING_GOSSIPD_QUERIES_H */
71