node: Don't connect to all peer's addresses
Instead of connecting to the first address of a peer, we attempted to connect to all addresses, which caused problems.
This commit is contained in:
parent
b675185538
commit
2903b4f09a
|
|
@ -1617,14 +1617,17 @@ where
|
||||||
for (id, ka) in self
|
for (id, ka) in self
|
||||||
.available_peers()
|
.available_peers()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|(nid, kas)| kas.into_iter().map(move |ka| (nid, ka)))
|
.filter_map(|(nid, kas)| {
|
||||||
.filter(|(_, ka)| match (ka.last_success, ka.last_attempt) {
|
kas.into_iter()
|
||||||
// If we succeeded the last time we tried, this is a good address.
|
.find(|ka| match (ka.last_success, ka.last_attempt) {
|
||||||
(Some(success), attempt) => success >= attempt.unwrap_or_default(),
|
// If we succeeded the last time we tried, this is a good address.
|
||||||
// If we haven't succeeded yet, and we waited long enough, we can try this address.
|
(Some(success), attempt) => success >= attempt.unwrap_or_default(),
|
||||||
(None, Some(attempt)) => now - attempt >= CONNECTION_RETRY_DELTA,
|
// If we haven't succeeded yet, and we waited long enough, we can try this address.
|
||||||
// If we've never tried this address, it's worth a try.
|
(None, Some(attempt)) => now - attempt >= CONNECTION_RETRY_DELTA,
|
||||||
(None, None) => true,
|
// If we've never tried this address, it's worth a try.
|
||||||
|
(None, None) => true,
|
||||||
|
})
|
||||||
|
.map(|ka| (nid, ka))
|
||||||
})
|
})
|
||||||
.take(wanted)
|
.take(wanted)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue