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:
cloudhead 2023-11-10 13:42:06 +01:00
parent b675185538
commit 2903b4f09a
No known key found for this signature in database
1 changed files with 11 additions and 8 deletions

View File

@ -1617,8 +1617,9 @@ 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()
.find(|ka| match (ka.last_success, ka.last_attempt) {
// If we succeeded the last time we tried, this is a good address. // If we succeeded the last time we tried, this is a good address.
(Some(success), attempt) => success >= attempt.unwrap_or_default(), (Some(success), attempt) => success >= attempt.unwrap_or_default(),
// If we haven't succeeded yet, and we waited long enough, we can try this address. // If we haven't succeeded yet, and we waited long enough, we can try this address.
@ -1626,6 +1627,8 @@ where
// If we've never tried this address, it's worth a try. // If we've never tried this address, it's worth a try.
(None, None) => true, (None, None) => true,
}) })
.map(|ka| (nid, ka))
})
.take(wanted) .take(wanted)
{ {
self.connect(id, ka.addr.clone()); self.connect(id, ka.addr.clone());