mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-30 16:31:57 +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
|
||||
|
@@ -93,6 +93,7 @@ fn ping_protocol() {
|
||||
let addr = rx.next().await.unwrap();
|
||||
swarm2.add_address(&peer1_id, addr.clone());
|
||||
let mut req_id = swarm2.send_request(&peer1_id, ping.clone());
|
||||
assert!(swarm2.is_pending_outbound(&peer1_id, &req_id));
|
||||
|
||||
loop {
|
||||
match swarm2.next().await {
|
||||
|
Reference in New Issue
Block a user