Expand description
Candidate peer selection for outbound connections.
The crawler in crawl_and_dial manages
outbound peer connection attempts using the services in this module.
Successful connections become peers in the
PeerSet.
Candidate selection divides the set of all possible outbound peers into
disjoint subsets, using the PeerAddrState:
Respondedpeers, which we have had an outbound connection to.NeverAttemptedGossipedpeers, which we learned about from other peers but have never connected to. This includes gossiped peers, DNS seeder peers, cached peers, canonical addresses from theVersionmessages of inbound and outbound connections, and remote IP addresses of inbound connections.Failedpeers, which failed a connection attempt, or had an error during an outbound connection.AttemptPendingpeers, which we’ve recently queued for a connection.
Never attempted peers are always available for connection.
If a peer’s attempted, responded, or failure time is recent (within the liveness limit), we avoid reconnecting to it. Otherwise, we assume that it has disconnected or hung, and attempt reconnection.
┌──────────────────┐
│ Config / DNS │
┌───────────│ Seed │───────────┐
│ │ Addresses │ │
│ └──────────────────┘ │
│ │ untrusted_last_seen │
│ │ is unknown │
▼ │ ▼
┌──────────────────┐ │ ┌──────────────────┐
│ Handshake │ │ │ Peer Set │
│ Canonical │──────────┼──────────│ Gossiped │
│ Addresses │ │ │ Addresses │
└──────────────────┘ │ └──────────────────┘
untrusted_last_seen │ provides
set to now │ untrusted_last_seen
▼
Λ if attempted, responded, or failed:
╱ ╲ ignore gossiped info
▕ ▏ otherwise, if never attempted:
╲ ╱ skip updates to existing fields
V
┌───────────────────────────────┼───────────────────────────────┐
│ AddressBook │ │
│ disjoint `PeerAddrState`s ▼ │
│ ┌─────────────┐ ┌─────────────────────────┐ ┌─────────────┐ │
│ │ `Responded` │ │`NeverAttemptedGossiped` │ │ `Failed` │ │
┌┼▶│ Peers │ │ Peers │ │ Peers │◀┼┐
││ └─────────────┘ └─────────────────────────┘ └─────────────┘ ││
││ │ │ │ ││
││ #1 oldest_first #2 newest_first #3 oldest_first ││
││ ├──────────────────────┴──────────────────────┘ ││
││ ▼ ││
││ Λ ││
││ ╱ ╲ filter by ││
││ ▕ ▏ is_ready_for_connection_attempt ││
││ ╲ ╱ to remove recent `Responded`, ││
││ V `AttemptPending`, and `Failed` peers ││
││ │ ││
││ │ try outbound connection, ││
││ ▼ update last_attempt to now() ││
││┌────────────────┐ ││
│││`AttemptPending`│ ││
│││ Peers │ ││
││└────────────────┘ ││
│└────────┼──────────────────────────────────────────────────────┘│
│ ▼ │
│ Λ │
│ ╱ ╲ │
│ ▕ ▏─────────────────────────────────────────────────────┘
│ ╲ ╱ connection failed, update last_failure to now()
│ V
│ │
│ │ connection succeeded
│ ▼
│ ┌────────────┐
│ │ send │
│ │peer::Client│
│ │to Discover │
│ └────────────┘
│ │
│ ▼
│┌───────────────────────────────────────┐
││ when connection succeeds, and every │
││ time we receive a peer heartbeat: │
└│ * update state to `Responded` │
│ * update last_response to now() │
└───────────────────────────────────────┘Modules§
- crawl 🔒
- Crawling the network for more peer addresses.
- rate_
limit 🔒 - Rate-limiting middleware for candidate peer selection and crawling.
Functions§
- crawler_
services 🔒 - Builds the candidate selection services used by the crawler:
a
NextPeerServiceand aCrawlService. - next_
reconnect_ 🔒peer - Returns the next candidate for a connection attempt, if any are available.
- ready_
peer_ 🔒count - Returns the number of candidate peers that are currently ready for a
connection attempt, as selected by
next_reconnect_peer.
Type Aliases§
- Next
Peer 🔒Service - The service that chooses the next reconnection candidate.