@@ -654,40 +654,40 @@ impl Kademlia {
654
654
self . pending_substreams . insert ( substream_id, peer) ;
655
655
self . peers . entry ( peer) . or_default ( ) . pending_actions . insert ( substream_id, action) ;
656
656
657
- return Ok ( ( ) ) ;
657
+ Ok ( ( ) )
658
658
}
659
659
Err ( err) => {
660
660
tracing:: trace!( target: LOG_TARGET , ?query, ?peer, ?err, "Failed to open substream. Dialing peer" ) ;
661
661
662
662
match self . service . dial ( & peer) {
663
663
Ok ( ( ) ) => {
664
664
self . pending_dials . entry ( peer) . or_default ( ) . push ( action) ;
665
- return Ok ( ( ) ) ;
665
+ Ok ( ( ) )
666
666
}
667
667
668
668
// Already connected is a recoverable error.
669
- Err ( Error :: AlreadyConnected ) => ( ) ,
669
+ Err ( Error :: AlreadyConnected ) => {
670
+ // Dial returned `Error::AlreadyConnected`, retry opening the substream.
671
+ match self . service . open_substream ( peer) {
672
+ Ok ( substream_id) => {
673
+ self . pending_substreams . insert ( substream_id, peer) ;
674
+ self . peers
675
+ . entry ( peer)
676
+ . or_default ( )
677
+ . pending_actions
678
+ . insert ( substream_id, action) ;
679
+ Ok ( ( ) )
680
+ }
681
+ Err ( err) => {
682
+ tracing:: trace!( target: LOG_TARGET , ?query, ?peer, ?err, "Failed to open substream a second time" ) ;
683
+ Err ( err)
684
+ }
685
+ }
686
+ }
670
687
671
688
Err ( error) => {
672
689
tracing:: trace!( target: LOG_TARGET , ?query, ?peer, ?error, "Failed to dial peer" ) ;
673
- return Err ( error) ;
674
- }
675
- } ;
676
-
677
- // Dial returned `Error::AlreadyConnected`, retry opening the substream.
678
- match self . service . open_substream ( peer) {
679
- Ok ( substream_id) => {
680
- self . pending_substreams . insert ( substream_id, peer) ;
681
- self . peers
682
- . entry ( peer)
683
- . or_default ( )
684
- . pending_actions
685
- . insert ( substream_id, action) ;
686
- return Ok ( ( ) ) ;
687
- }
688
- Err ( err) => {
689
- tracing:: trace!( target: LOG_TARGET , ?query, ?peer, ?err, "Failed to open substream a second time" ) ;
690
- return Err ( err) ;
690
+ Err ( error)
691
691
}
692
692
}
693
693
}
0 commit comments