MCPcopy Create free account
hub / github.com/ElementsProject/lightning / append_gossmap_addresses

Function append_gossmap_addresses

connectd/connectd.c:186–264  ·  view source on GitHub ↗

~ Nodes (can) advertize one or more addresses in their node_announcement: * these are lower priority than ones explicitly supplied to the `connect` * command, though. */

Source from the content-addressed store, hash-verified

184 * these are lower priority than ones explicitly supplied to the `connect`
185 * command, though. */
186static void append_gossmap_addresses(struct wireaddr_internal **wireaddrs,
187 struct daemon *daemon,
188 const struct node_id *node_id)
189{
190 struct gossmap_node *node;
191 u8 *nannounce;
192 struct node_id id;
193 secp256k1_ecdsa_signature signature;
194 u32 timestamp;
195 u8 *addresses, *features;
196 u8 rgb_color[3], alias[32];
197 struct tlv_node_ann_tlvs *na_tlvs;
198 struct wireaddr *alladdrs, *addrs[3];
199 struct gossmap *gossmap = get_gossmap(daemon);
200
201 node = gossmap_find_node(gossmap, node_id);
202 if (!node)
203 return;
204
205 nannounce = gossmap_node_get_announce(tmpctx, gossmap,
206 node);
207 if (!nannounce)
208 return;
209
210 if (!fromwire_node_announcement(tmpctx, nannounce,
211 &signature, &features,
212 &timestamp,
213 &id, rgb_color, alias,
214 &addresses,
215 &na_tlvs)) {
216 status_broken("Bad node_announcement for %s in gossip_store: %s",
217 fmt_node_id(tmpctx, node_id),
218 tal_hex(tmpctx, nannounce));
219 return;
220 }
221
222 alladdrs = fromwire_wireaddr_array(tmpctx, addresses);
223 if (!alladdrs) {
224 status_broken("Bad wireaddrs in node_announcement in gossip_store: %s",
225 tal_hex(tmpctx, nannounce));
226 return;
227 }
228
229 /* Orders the gossip addresses.
230 *
231 * Ignore deprecated protocols. Adds all IPv6 addresses, followed by
232 * IPv4 and then TOR. This ensures we are modern and use IPv6 when
233 * possible, falling back to direct (faster) IPv4 and finally (less
234 * stable) TOR connections. */
235 for (size_t i = 0; i < ARRAY_SIZE(addrs); i++)
236 addrs[i] = tal_arr(tmpctx, struct wireaddr, 0);
237
238 for (size_t i = 0; i < tal_count(alladdrs); i++) {
239 /* A switch, so compiler tells you to update it if we
240 * add a new type! */
241 switch (alladdrs[i].type) {
242 case ADDR_TYPE_IPV6:
243 case ADDR_TYPE_DNS:

Callers 2

reconnectFunction · 0.85
connect_to_peerFunction · 0.85

Calls 7

gossmap_find_nodeFunction · 0.85
fmt_node_idFunction · 0.85
tal_hexFunction · 0.85
fromwire_wireaddr_arrayFunction · 0.85
append_addrFunction · 0.85
get_gossmapFunction · 0.70

Tested by

no test coverage detected