zebra_network::peer_set::initialize

Function crawl_and_dial

source
async fn crawl_and_dial<C, S>(
    config: Config,
    demand_tx: Sender<MorePeers>,
    demand_rx: Receiver<MorePeers>,
    candidates: CandidateSet<S>,
    outbound_connector: C,
    peerset_tx: Sender<(PeerSocketAddr, Client)>,
    active_outbound_connections: ActiveConnectionCounter,
    address_book_updater: Sender<MetaAddrChange>,
) -> Result<(), BoxError>
where C: Service<OutboundConnectorRequest, Response = (PeerSocketAddr, Client), Error = BoxError> + Clone + Send + 'static, C::Future: Send + 'static, S: Service<Request, Response = Response, Error = BoxError> + Send + Sync + 'static, S::Future: Send + 'static,
Expand description

Given a channel demand_rx that signals a need for new peers, try to find and connect to new peers, and send the resulting peer::Clients through the peerset_tx channel.

Crawl for new peers every config.crawl_new_peer_interval. Also crawl whenever there is demand, but no new peers in candidates. After crawling, try to connect to one new peer using outbound_connector.

If a handshake fails, restore the unused demand signal by sending it to demand_tx.

The crawler terminates when candidates.update() or peerset_tx returns a permanent internal error. Transient errors and individual peer errors should be handled within the crawler.

Uses active_outbound_connections to limit the number of active outbound connections across both the initial peers and crawler. The limit is based on config.