protocols/req-resp: Make is_pending_outbound return true on pending connection (#1928)

`is_pending_outbound` should return true if the connection
to the mentioned peer hasn't been established, yet.

Closes issue: #1885

Signed-off-by: Tejas Sanap <sanap.tejas@gmail.com>
This commit is contained in:
Tejas Sanap
2021-01-21 19:04:58 +05:30
committed by GitHub
parent bbd3df64ed
commit 5d22e30cc9
2 changed files with 10 additions and 2 deletions

View File

@ -431,9 +431,16 @@ where
/// [`PeerId`] initiated by [`RequestResponse::send_request`] is still
/// pending, i.e. waiting for a response.
pub fn is_pending_outbound(&self, peer: &PeerId, request_id: &RequestId) -> bool {
self.connected.get(peer)
// Check if request is already sent on established connection.
let est_conn = self.connected.get(peer)
.map(|cs| cs.iter().any(|c| c.pending_inbound_responses.contains(request_id)))
.unwrap_or(false)
.unwrap_or(false);
// Check if request is still pending to be sent.
let pen_conn = self.pending_outbound_requests.get(peer)
.map(|rps| rps.iter().any(|rp| {rp.request_id == *request_id}))
.unwrap_or(false);
est_conn || pen_conn
}
/// Checks whether an inbound request from the peer with the provided