File tree 3 files changed +20
-6
lines changed
3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -543,16 +543,16 @@ class Libp2p extends EventEmitter {
543
543
* @param {PeerId|Multiaddr|string } peer - the peer to close connections to
544
544
* @returns {Promise<void> }
545
545
*/
546
- hangUp ( peer ) {
547
- const peerInfo = getPeerInfo ( peer , this . peerStore )
546
+ async hangUp ( peer ) {
547
+ const { id } = getPeer ( peer )
548
548
549
- let connections = this . registrar . connections . get ( peerInfo . id . toB58String ( ) )
549
+ const connections = this . connectionManager . connections . get ( id . toB58String ( ) )
550
550
551
551
if ( ! connections ) {
552
- return Promise . resolve ( )
552
+ return
553
553
}
554
554
555
- return Promise . all (
555
+ await Promise . all (
556
556
connections . map ( connection => {
557
557
return connection . close ( )
558
558
} )
Original file line number Diff line number Diff line change @@ -111,7 +111,13 @@ class PeerRouting {
111
111
112
112
const output = await pipe (
113
113
merge (
114
- ...this . _routers . map ( router => [ router . findPeer ( id , options ) ] )
114
+ ...this . _routers . map ( router => ( async function * ( ) {
115
+ try {
116
+ yield [ await router . findPeer ( id , options ) ] ;
117
+ } catch ( err ) {
118
+ yield ;
119
+ }
120
+ } ) ( ) )
115
121
) ,
116
122
( source ) => filter ( source , Boolean ) ,
117
123
// @ts -ignore findPeer resolves a Promise
Original file line number Diff line number Diff line change @@ -106,6 +106,14 @@ describe('peer-routing', () => {
106
106
. to . eventually . be . rejected ( )
107
107
. and . to . have . property ( 'code' , 'ERR_FIND_SELF' )
108
108
} )
109
+
110
+ it ( 'should handle error' , async ( ) => {
111
+ const unknownPeers = await peerUtils . createPeerId ( { number : 1 , fixture : false } )
112
+
113
+ await expect ( nodes [ 0 ] . peerRouting . findPeer ( unknownPeers [ 0 ] ) )
114
+ . to . eventually . be . rejected ( )
115
+ . and . to . have . property ( 'code' , 'NOT_FOUND' )
116
+ } )
109
117
} )
110
118
111
119
describe ( 'via delegate router' , ( ) => {
You can’t perform that action at this time.
0 commit comments