We are fairly careful to avoid the peer DoSing us with channel queries: * this routine creates messages about a single short_channel_id, unless * it's finished all of them. */
| 124 | * this routine creates messages about a single short_channel_id, unless |
| 125 | * it's finished all of them. */ |
| 126 | const u8 **maybe_create_query_responses(const tal_t *ctx, |
| 127 | struct peer *peer, |
| 128 | struct gossmap *gossmap) |
| 129 | { |
| 130 | size_t i, num; |
| 131 | const u8 **msgs = tal_arr(ctx, const u8 *, 0); |
| 132 | |
| 133 | /* BOLT #7: |
| 134 | * |
| 135 | * - MUST respond to each known `short_channel_id`: |
| 136 | */ |
| 137 | /* Search for next short_channel_id we know about. */ |
| 138 | num = tal_count(peer->scid_queries); |
| 139 | for (i = peer->scid_query_idx; tal_count(msgs) == 0 && i < num; i++) { |
| 140 | struct gossmap_chan *chan; |
| 141 | struct gossmap_node *node; |
| 142 | struct node_id node_id; |
| 143 | |
| 144 | chan = gossmap_find_chan(gossmap, &peer->scid_queries[i]); |
| 145 | if (!chan) |
| 146 | continue; |
| 147 | |
| 148 | /* BOLT #7: |
| 149 | * - if bit 0 of `query_flag` is set: |
| 150 | * - MUST reply with a `channel_announcement` |
| 151 | */ |
| 152 | if (peer->scid_query_flags[i] & SCID_QF_ANNOUNCE) { |
| 153 | tal_arr_expand(&msgs, |
| 154 | gossmap_chan_get_announce(msgs, gossmap, chan)); |
| 155 | } |
| 156 | |
| 157 | /* BOLT #7: |
| 158 | * - if bit 1 of `query_flag` is set and it has received a |
| 159 | * `channel_update` from `node_id_1`: |
| 160 | * - MUST reply with the latest `channel_update` for |
| 161 | * `node_id_1` |
| 162 | * - if bit 2 of `query_flag` is set and it has received a |
| 163 | * `channel_update` from `node_id_2`: |
| 164 | * - MUST reply with the latest `channel_update` for |
| 165 | * `node_id_2` */ |
| 166 | if ((peer->scid_query_flags[i] & SCID_QF_UPDATE1) |
| 167 | && gossmap_chan_set(chan, 0)) { |
| 168 | tal_arr_expand(&msgs, |
| 169 | gossmap_chan_get_update(msgs, gossmap, chan, 0)); |
| 170 | } |
| 171 | if ((peer->scid_query_flags[i] & SCID_QF_UPDATE2) |
| 172 | && gossmap_chan_set(chan, 1)) { |
| 173 | tal_arr_expand(&msgs, |
| 174 | gossmap_chan_get_update(msgs, gossmap, chan, 1)); |
| 175 | } |
| 176 | |
| 177 | /* BOLT #7: |
| 178 | * - if bit 3 of `query_flag` is set and it has received |
| 179 | * a `node_announcement` from `node_id_1`: |
| 180 | * - MUST reply with the latest `node_announcement` for |
| 181 | * `node_id_1` |
| 182 | * - if bit 4 of `query_flag` is set and it has received a |
| 183 | * `node_announcement` from `node_id_2`: |
no test coverage detected