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

Function get_random_node

gossipd/seeker.c:825–853  ·  view source on GitHub ↗

Find a random node with an announcement. */

Source from the content-addressed store, hash-verified

823
824/* Find a random node with an announcement. */
825static struct node_id *get_random_node(const tal_t *ctx,
826 struct seeker *seeker)
827{
828 struct gossmap *gossmap = gossmap_manage_get_gossmap(seeker->daemon->gm);
829 struct gossmap_node *node = gossmap_random_node(gossmap);
830
831 if (!node)
832 return NULL;
833
834 for (int i = 0; i<20; i++) {
835 struct node_id id;
836
837 gossmap_node_get_id(gossmap, node, &id);
838
839 /* Make sure it *has* an announcement, and we're not
840 * already connected */
841 if (!node_id_eq(&id, &seeker->daemon->id)
842 && gossmap_node_get_announce(tmpctx, gossmap, node)
843 && !find_peer(seeker->daemon, &id)) {
844 return tal_dup(ctx, struct node_id, &id);
845 }
846
847 node = gossmap_next_node(gossmap, node);
848 if (!node)
849 node = gossmap_first_node(gossmap);
850 }
851
852 return NULL;
853}
854
855/* Ask lightningd for more peers if we're short on gossip streamers. */
856static void maybe_get_new_peer(struct seeker *seeker)

Callers 1

maybe_get_new_peerFunction · 0.85

Calls 8

gossmap_random_nodeFunction · 0.85
gossmap_node_get_idFunction · 0.85
node_id_eqFunction · 0.85
gossmap_next_nodeFunction · 0.85
gossmap_first_nodeFunction · 0.85
find_peerFunction · 0.70

Tested by

no test coverage detected