Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

ipfs.dht.findprovs is passing cb in timeout position to libp2p findProviders #1322

Closed
olizilla opened this issue Apr 23, 2018 · 10 comments
Closed
Labels
exp/novice Someone with a little familiarity can pick up kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up

Comments

@olizilla
Copy link
Member

  • Version: 0.28.2
  • Platform: all
  • Subsystem: dht

Type: Bug

Severity: High

Description:

ipfs.dht.findprovs is passing cb in timeout position to libp2p findProviders, and so the call fails to return anything.

In the dht component in js-ipfs

self._libp2pNode.contentRouting.findProviders(key, callback)

and the js-libp2p findProviders impl https://github.com/libp2p/js-libp2p/blob/03faf69212b0f3501291527f85b2bb85a8c5427e/src/content-routing.js#L5

Steps to reproduce the error:

In a browser with ipfs-companion installed and pointing at an embedded ipfs node:

ipfs.dht.findprovs('QmYPNmahJAvkMTU6tDx5zvhEkoLzEFeTDz6azDCSNqzKkW', console.log)
// Error: callback is not a function at Object.findProviders
jsipfs findprovs QmYPNmahJAvkMTU6tDx5zvhEkoLzEFeTDz6azDCSNqzKkW
// returns nothing, but exits cleanly
@daviddias
Copy link
Member

@olizilla wanna submit a PR to fix that? thanks for reporting :)

@olizilla
Copy link
Member Author

olizilla commented Apr 30, 2018 via email

@daviddias
Copy link
Member

The drill is to makes sure there is a PR and a test that standardizes the API call on https://github.com/ipfs/interface-ipfs-core and that it passes both js-ipfs and js-ipfs-api. Thanks @olizilla 👍

@alanshaw alanshaw added kind/bug A bug in existing code (including security flaws) exp/novice Someone with a little familiarity can pick up P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked labels May 18, 2018
@0x-r4bbit
Copy link
Contributor

@olizilla have you started implementing this already, or do you need any help with this?

@olizilla
Copy link
Member Author

@PascalPrecht I haven't started on this, please feel free to PR it if you're looking at it!

@0x-r4bbit
Copy link
Contributor

@olizilla I'll do that.

@diasdavid just to clarify the API. We wanna turn:

    findprovs: promisify((key, callback) => {

to

    findprovs: promisify((key, options, callback) => {

where options can have a timeout property, is that correct?

@0x-r4bbit
Copy link
Contributor

I guess on that note, we will have to introduce a decent default for timeout

@0x-r4bbit
Copy link
Contributor

0x-r4bbit commented Jul 20, 2018

@alanshaw do you know what the timeout default has to be here?

As https://github.com/libp2p/js-libp2p/blob/03faf69212b0f3501291527f85b2bb85a8c5427e/src/content-routing.js#L5 expects timeout in any case, we should have a default when callback is passed but no options.

I would also update interface-ipfs-core's spec accordingly (which doesn't provide that information either).

@alanshaw
Copy link
Member

Unless we want to explicitly set a default when not provided (IMHO I don't think we need to) I'd leave it to the implementation to set an appropriate value (you can pass null).

https://github.com/libp2p/js-libp2p-kad-dht/blob/012d2c3b30f3eb59a2ed68606090cd9757bfde52/src/index.js#L177-L197

@0x-r4bbit
Copy link
Contributor

Ah perfect, okay. Thanks!

0x-r4bbit added a commit to 0x-r4bbit/interface-ipfs-core that referenced this issue Jul 20, 2018
0x-r4bbit added a commit to 0x-r4bbit/js-ipfs that referenced this issue Jul 20, 2018
0x-r4bbit added a commit to 0x-r4bbit/interface-ipfs-core that referenced this issue Jul 25, 2018
0x-r4bbit added a commit to 0x-r4bbit/interface-ipfs-core that referenced this issue Aug 2, 2018
0x-r4bbit added a commit to 0x-r4bbit/js-ipfs that referenced this issue Aug 2, 2018
0x-r4bbit added a commit to 0x-r4bbit/interface-ipfs-core that referenced this issue Aug 2, 2018
@ghost ghost removed the status/ready Ready to be worked label Aug 2, 2018
alanshaw pushed a commit to ipfs-inactive/interface-js-ipfs-core that referenced this issue Aug 2, 2018
* feat(dht): add API to allow options in `findprovs()`

As discussed in: ipfs/js-ipfs#1322 (comment)

License: MIT
Signed-off-by: Pascal Precht <[email protected]>

* fix: typo in test name

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/novice Someone with a little familiarity can pick up kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

4 participants