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

Function random_peers

plugins/chanbackup.c:578–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

576}
577
578static const struct node_id *random_peers(const tal_t *ctx,
579 const struct chanbackup *cb)
580{
581 struct peer_map_iter it;
582 const struct node_id *peer;
583 struct node_id *ids = tal_arr(ctx, struct node_id, 0);
584
585 /* Simple case: pick all of them */
586 if (peer_map_count(cb->peers) <= NUM_BACKUP_PEERS) {
587 for (peer = peer_map_first(cb->peers, &it);
588 peer;
589 peer = peer_map_next(cb->peers, &it)) {
590 tal_arr_expand(&ids, *peer);
591 }
592 } else {
593 while (peer_map_count(cb->peers) < NUM_BACKUP_PEERS) {
594 peer = peer_map_pick(cb->peers, pseudorand_u64(), &it);
595 if (already_have_node_id(ids, peer))
596 continue;
597 tal_arr_expand(&ids, *peer);
598 }
599 }
600 return ids;
601}
602
603static struct command_result *send_to_peers(struct command *cmd)
604{

Callers 1

send_to_peersFunction · 0.85

Calls 1

already_have_node_idFunction · 0.85

Tested by

no test coverage detected