mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-04 20:21:33 +00:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user