File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use libp2p::swarm::{
21
21
} ;
22
22
use libp2p:: { request_response, PeerId , StreamProtocol } ;
23
23
use pollable_map:: futures:: FutureMap ;
24
+ use std:: collections:: hash_map:: Entry ;
24
25
use std:: collections:: HashMap ;
25
26
use std:: io:: { Error as IoError , ErrorKind as IoErrorKind } ;
26
27
use std:: task:: { Context , Poll } ;
@@ -185,23 +186,34 @@ impl Behaviour {
185
186
peer_id : PeerId ,
186
187
error : OutboundFailure ,
187
188
) {
188
- if let Some ( list) = self . pending_response . get_mut ( & peer_id) {
189
+ if let Entry :: Occupied ( mut entry) = self . pending_response . entry ( peer_id) {
190
+ let list = entry. get_mut ( ) ;
191
+
189
192
if let Some ( tx) = list. remove ( & id) {
190
193
_ = tx. send ( Err ( std:: io:: Error :: new (
191
194
std:: io:: ErrorKind :: BrokenPipe ,
192
195
error,
193
196
) ) ) ;
194
197
}
198
+
199
+ if list. is_empty ( ) {
200
+ entry. remove ( ) ;
201
+ }
195
202
}
196
203
}
204
+
197
205
fn process_inbound_failure (
198
206
& mut self ,
199
207
id : InboundRequestId ,
200
208
peer_id : PeerId ,
201
209
_: InboundFailure ,
202
210
) {
203
- if let Some ( list) = self . pending_request . get_mut ( & peer_id) {
211
+ if let Entry :: Occupied ( mut entry) = self . pending_request . entry ( peer_id) {
212
+ let list = entry. get_mut ( ) ;
204
213
list. remove ( & id) ;
214
+ if list. is_empty ( ) {
215
+ entry. remove ( ) ;
216
+ }
205
217
}
206
218
}
207
219
}
You can’t perform that action at this time.
0 commit comments