Query this peer for these short-channel-ids. */
| 68 | |
| 69 | /* Query this peer for these short-channel-ids. */ |
| 70 | bool query_short_channel_ids(struct daemon *daemon, |
| 71 | struct peer *peer, |
| 72 | const struct short_channel_id *scids, |
| 73 | const u8 *query_flags, |
| 74 | void (*cb)(struct peer *peer, bool complete)) |
| 75 | { |
| 76 | u8 *encoded, *msg; |
| 77 | struct tlv_query_short_channel_ids_tlvs *tlvs; |
| 78 | /* BOLT #7: |
| 79 | * |
| 80 | * 1. type: 261 (`query_short_channel_ids`) (`gossip_queries`) |
| 81 | * 2. data: |
| 82 | * * [`chain_hash`:`chain_hash`] |
| 83 | * * [`u16`:`len`] |
| 84 | * * [`len*byte`:`encoded_short_ids`] |
| 85 | */ |
| 86 | const size_t reply_overhead = 32 + 2; |
| 87 | size_t max_encoded_bytes = 65535 - 2 - reply_overhead; |
| 88 | |
| 89 | /* Can't query if they don't have gossip_queries_feature */ |
| 90 | if (!peer->gossip_queries_feature) |
| 91 | return false; |
| 92 | |
| 93 | /* BOLT #7: |
| 94 | * - MAY include an optional `query_flags`. If so: |
| 95 | * - MUST set `encoding_type`, as for `encoded_short_ids`. |
| 96 | * - Each query flag is a minimally-encoded bigsize. |
| 97 | * - MUST encode one query flag per `short_channel_id`. |
| 98 | */ |
| 99 | if (query_flags) |
| 100 | assert(tal_count(query_flags) == tal_count(scids)); |
| 101 | |
| 102 | /* BOLT #7: |
| 103 | * |
| 104 | * The sender: |
| 105 | * - MUST NOT send `query_short_channel_ids` if it has sent a previous |
| 106 | * `query_short_channel_ids` to this peer and not received |
| 107 | * `reply_short_channel_ids_end`. |
| 108 | */ |
| 109 | if (peer->scid_query_outstanding) |
| 110 | return false; |
| 111 | |
| 112 | encoded = encoding_start(tmpctx, true); |
| 113 | for (size_t i = 0; i < tal_count(scids); i++) { |
| 114 | /* BOLT #7: |
| 115 | * |
| 116 | * Encoding types: |
| 117 | * * `0`: uncompressed array of `short_channel_id` types, in |
| 118 | * ascending order. |
| 119 | */ |
| 120 | assert(i == 0 || scids[i].u64 > scids[i-1].u64); |
| 121 | encoding_add_short_channel_id(&encoded, &scids[i]); |
| 122 | } |
| 123 | |
| 124 | if (!encoding_end(encoded, max_encoded_bytes)) { |
| 125 | status_broken("query_short_channel_ids: %zu is too many", |
| 126 | tal_count(scids)); |
| 127 | return false; |
no test coverage detected