@@ -7,7 +7,6 @@ const CID = require('cids')
77const multihash = require ( 'multihashes' )
88const each = require ( 'async/each' )
99const setImmediate = require ( 'async/setImmediate' )
10- // const bsplit = require('buffer-split')
1110const errCode = require ( 'err-code' )
1211
1312module . exports = ( self ) => {
@@ -35,7 +34,7 @@ module.exports = (self) => {
3534 }
3635 }
3736
38- self . libp2p . dht . get ( key , options . timeout , callback )
37+ self . libp2p . dht . get ( key , options , callback )
3938 } ) ,
4039
4140 /**
@@ -76,6 +75,7 @@ module.exports = (self) => {
7675 }
7776
7877 opts = opts || { }
78+ opts . maxNumProviders = opts [ 'num-providers' ]
7979
8080 if ( typeof key === 'string' ) {
8181 try {
@@ -85,14 +85,23 @@ module.exports = (self) => {
8585 }
8686 }
8787
88- if ( typeof opts === 'function' ) {
89- callback = opts
90- opts = { }
91- }
88+ self . libp2p . contentRouting . findProviders ( key , opts , ( err , res ) => {
89+ if ( err ) {
90+ return callback ( err )
91+ }
9292
93- opts = opts || { }
93+ // convert to go-ipfs return value, we need to revisit
94+ // this. For now will just conform.
95+ const goResult = {
96+ responses : res . map ( ( peerInfo ) => ( {
97+ id : peerInfo . id . toB58String ( ) ,
98+ addrs : peerInfo . multiaddrs . toArray ( ) . map ( ( a ) => a . toString ( ) )
99+ } ) ) ,
100+ type : 4
101+ }
94102
95- self . libp2p . contentRouting . findProviders ( key , opts . timeout || null , callback )
103+ callback ( null , goResult )
104+ } )
96105 } ) ,
97106
98107 /**
@@ -114,14 +123,13 @@ module.exports = (self) => {
114123
115124 // convert to go-ipfs return value, we need to revisit
116125 // this. For now will just conform.
117- const goResult = [
118- {
119- Responses : [ {
120- ID : info . id . toB58String ( ) ,
121- Addresses : info . multiaddrs . toArray ( ) . map ( ( a ) => a . toString ( ) )
122- } ]
123- }
124- ]
126+ const goResult = {
127+ responses : [ {
128+ id : info . id . toB58String ( ) ,
129+ addrs : info . multiaddrs . toArray ( ) . map ( ( a ) => a . toString ( ) )
130+ } ] ,
131+ type : 2
132+ }
125133
126134 callback ( null , goResult )
127135 } )
@@ -178,7 +186,11 @@ module.exports = (self) => {
178186 */
179187 query : promisify ( ( peerId , callback ) => {
180188 if ( typeof peerId === 'string' ) {
181- peerId = PeerId . createFromB58String ( peerId )
189+ try {
190+ peerId = PeerId . createFromB58String ( peerId )
191+ } catch ( err ) {
192+ callback ( err )
193+ }
182194 }
183195
184196 // TODO expose this method in peerRouting
0 commit comments