async fn limit_initial_peers(
    config: &Config,
    address_book_updater: tokio::sync::mpsc::Sender<MetaAddrChange>,
) -> HashSet<SocketAddr> {
    let all_peers = config.initial_peers().await;
    let peers_count = all_peers.len();

    if peers_count <= config.peerset_initial_target_size {
        return all_peers;
    }

    // Limit the number of initial peers to `config.peerset_initial_target_size`
    info!(
        "Limiting the initial peers list from {} to {}",
        peers_count, config.peerset_initial_target_size
    );

    // Split all the peers into the `initial_peers` that will be returned and
    // `unused_peers` that will be sent to the address book.
    let mut all_peers: Vec<SocketAddr> = all_peers.into_iter().collect();
    let (initial_peers, unused_peers) =
        all_peers.partial_shuffle(&mut rand::thread_rng(), config.peerset_initial_target_size);

    // Send the unused peers to the address book.
    for peer in unused_peers {
        let peer_addr = MetaAddr::new_initial_peer(*peer);
        // `send` only waits when the channel is full.
        // The address book updater is a separate task, so we will only wait for a short time.
        let _ = address_book_updater.send(peer_addr).await;
    }

    initial_peers.iter().copied().collect()
}
/// Limit the number of `initial_peers` addresses entries to the configured
/// `peerset_initial_target_size`.
///
/// Returns randomly chosen entries from the provided set of addresses.
///
/// Sends any unused entries to the `address_book_updater`.
Limit the number of `initial_peers` addresses entries to the configured
`peerset_initial_target_size`.

Returns randomly chosen entries from the provided set of addresses.

Sends any unused entries to the `address_book_updater`.
Limit the number of ` initial_peers ` addresses entries to the configured ` peerset_initial_target_size ` . Returns randomly chosen entries from the provided set of addresses . Sends any unused entries to the ` address_book_updater ` .
async fn limit_initial_peers(
    config: &Config,
    address_book_updater: tokio::sync::mpsc::Sender<MetaAddrChange>,
) -> HashSet<SocketAddr> {
    let all_peers = config.initial_peers().await;
    let peers_count = all_peers.len();
    if peers_count <= config.peerset_initial_target_size {
        return all_peers;
    }
    // Limit the number of initial peers to `config.peerset_initial_target_size`
    info!(
        "Limiting the initial peers list from {} to {}",
        peers_count, config.peerset_initial_target_size
    );
    // Split all the peers into the `initial_peers` that will be returned and
    // `unused_peers` that will be sent to the address book.
    let mut all_peers: Vec<SocketAddr> = all_peers.into_iter().collect();
    let (initial_peers, unused_peers) =
        all_peers.partial_shuffle(&mut rand::thread_rng(), config.peerset_initial_target_size);
    // Send the unused peers to the address book.
    for peer in unused_peers {
        let peer_addr = MetaAddr::new_initial_peer(*peer);
        // `send` only waits when the channel is full.
        // The address book updater is a separate task, so we will only wait for a short time.
        let _ = address_book_updater.send(peer_addr).await;
    }
    initial_peers.iter().copied().collect()
}
async fn limit_initial_peers ( config : & Config , address_book_updater : tokio :: sync :: mpsc :: Sender < MetaAddrChange > , ) -> HashSet < SocketAddr > { let all_peers = config . initial_peers ( ) . await ; let peers_count = all_peers . len ( ) ; if peers_count <= config . peerset_initial_target_size { return all_peers ; } // Limit the number of initial peers to `config.peerset_initial_target_size` info ! ( " " peers_count config peerset_initial_target_size ) ; // Split all the peers into the `initial_peers` that will be returned and // `unused_peers` that will be sent to the address book. let mut all_peers : Vec < SocketAddr > = all_peers . into_iter ( ) . collect ( ) ; let ( initial_peers , unused_peers ) = all_peers . partial_shuffle ( & mut rand :: thread_rng ( ) , config . peerset_initial_target_size ) ; // Send the unused peers to the address book. for peer in unused_peers { let peer_addr = MetaAddr :: new_initial_peer ( * peer ) ; // `send` only waits when the channel is full. // The address book updater is a separate task, so we will only wait for a short time. let _ = address_book_updater . send ( peer_addr ) . await ; } initial_peers . iter ( ) . copied ( ) . collect ( ) }
Limit the number of `initial_peers` addresses entries to the configured
`peerset_initial_target_size`.
Limit the number of ` initial_peers ` addresses entries to the configured ` peerset_initial_target_size ` .
config
&Config
address_book_updater
tokio::sync::mpsc::Sender<MetaAddrChange>