Find a random node with an announcement. */
| 823 | |
| 824 | /* Find a random node with an announcement. */ |
| 825 | static 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. */ |
| 856 | static void maybe_get_new_peer(struct seeker *seeker) |
no test coverage detected