File tree 1 file changed +11
-11
lines changed
1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -9,23 +9,23 @@ module.exports = configure(api => {
9
9
return async function findPeer ( peerId , options = { } ) {
10
10
options . arg = `${ Buffer . isBuffer ( peerId ) ? new CID ( peerId ) : peerId } `
11
11
12
- const res = await api . post ( 'dht/findpeer' , {
12
+ const res = await api . ndjson ( 'dht/findpeer' , {
13
13
timeout : options . timeout ,
14
14
signal : options . signal ,
15
15
searchParams : options
16
16
} )
17
17
18
- const data = await res . json ( )
19
-
20
- if ( data . Type === 3 ) {
21
- throw new Error ( data . Extra )
22
- }
18
+ for await ( const data of res ) {
19
+ if ( data . Type === 3 ) {
20
+ throw new Error ( data . Extra )
21
+ }
23
22
24
- if ( data . Type === 2 && data . Responses ) {
25
- const { ID , Addrs } = data . Responses [ 0 ]
26
- return {
27
- id : ID ,
28
- addrs : ( Addrs || [ ] ) . map ( a => multiaddr ( a ) )
23
+ if ( data . Type === 2 && data . Responses ) {
24
+ const { ID , Addrs } = data . Responses [ 0 ]
25
+ return {
26
+ id : ID ,
27
+ addrs : ( Addrs || [ ] ) . map ( a => multiaddr ( a ) )
28
+ }
29
29
}
30
30
}
31
31
You can’t perform that action at this time.
0 commit comments