async fn crawl_and_dial<C, S>(
config: Config,
demand_tx: Sender<MorePeers>,
demand_rx: Receiver<MorePeers>,
next_peer_service: RateLimitOnYield<Buffer<BoxService<AddressBookRequest, AddressBookResponse, BoxError>, AddressBookRequest>, AddressBookResponse>,
crawl_service: RateLimitBySkipping<CrawlFanout<S>>,
address_book_service: Buffer<BoxService<AddressBookRequest, AddressBookResponse, BoxError>, AddressBookRequest>,
outbound_connector: C,
peerset_tx: Sender<(PeerSocketAddr, Client)>,
active_outbound_connections: ActiveConnectionCounter,
address_book_updater: AddressBookChangeSender,
) -> Result<(), BoxError>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 candidate peers.
After crawling, try to connect to one new peer using outbound_connector.
On every crawl timer tick, also queue a dial attempt for each spare outbound
connection slot that has a candidate ready to dial, so the peer set keeps
growing until it reaches config.peerset_outbound_connection_limit() or
runs out of ready candidates.
If a handshake fails, restore the unused demand signal by sending it to
demand_tx.
The crawler terminates when a crawl 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.