Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dht.findProvs: TypeError: key.toBaseEncodedString is not a function #3502

Closed
tymmesyde opened this issue Jan 23, 2021 · 8 comments · Fixed by #3806
Closed

dht.findProvs: TypeError: key.toBaseEncodedString is not a function #3502

tymmesyde opened this issue Jan 23, 2021 · 8 comments · Fixed by #3806
Labels
kind/bug A bug in existing code (including security flaws) kind/support A question or request for support need/analysis Needs further analysis before proceeding

Comments

@tymmesyde
Copy link

tymmesyde commented Jan 23, 2021

  • Version: 0.53.2
  • Platform: Windows 10
  • Subsystem:

Severity: High

Description:

Unable to get providers from dht with a string cid.

Steps to reproduce the error:

Code:

const providers = await all(this.ipfs.dht.findProvs(`Qm...`));
console.log(providers);

Error:
TypeError: key.toBaseEncodedString is not a function

@tymmesyde tymmesyde added the need/triage Needs initial labeling and prioritization label Jan 23, 2021
tymmesyde added a commit to tymmesyde/js-ipfs that referenced this issue Jan 23, 2021
see the issue for details

Refs ipfs#3502
tymmesyde added a commit to tymmesyde/js-ipfs that referenced this issue Jan 24, 2021
see the issue for details

Refs ipfs#3502
@achingbrain
Copy link
Member

achingbrain commented Jan 25, 2021

The cid argument to ipfs.dht.findProvs should be of the CID type and not a string: https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/DHT.md#ipfsdhtfindprovscid-options

@achingbrain achingbrain added kind/support A question or request for support and removed need/triage Needs initial labeling and prioritization labels Jan 25, 2021
@jacobheun
Copy link
Contributor

jacobheun commented Feb 18, 2021

Closing as the resolution has been suggested.

@TheDiscordian
Copy link

TheDiscordian commented May 1, 2021

Requesting re-open, for 2 reasons.

  1. The linked doc uses a string in the example (ipfs.dht.findProvs('QmdPAhQRxrDKqkGPvQzBvjYe3kU8kiEEAd2J6ETEamKAD9'))
  2. Not using a string produces the exact same error.
const IPFS = require('ipfs-core');
const CID = require('cids');
 
async function run() {
	const node = await IPFS.create({
		repo: 'ok' + Math.random(),
		libp2p: {
			config: {
				dht: {
					enabled: true
				}
			}
		}
	});

	const { cid } = await node.add('Hello world');
	
	console.log(cid);
	// CID(QmNRCQWfgze6AbBCaT1rkrkV5tJ2aP4oTNPb5JZcXYywve)
	console.log(CID.isCID(cid));
	// true

	const providers = node.dht.findProvs(cid);
	
	for await (const provider of providers) {
		console.log(provider.id.toString());
	}
}
 
run();
[user@TheDesktop DHT]$ node index.js
generating 2048-bit (rsa only) RSA keypair...
to get started, enter:

        jsipfs cat /ipfs/QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr/readme

Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/QmVG4ZKiXgw1cU8VJ4fAj5P5aF45RAsE2tnskmghXNs2J7
Swarm listening on /ip4/<REDACTED>/tcp/4002/p2p/QmVG4ZKiXgw1cU8VJ4fAj5P5aF45RAsE2tnskmghXNs2J7
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/QmVG4ZKiXgw1cU8VJ4fAj5P5aF45RAsE2tnskmghXNs2J7
CID(QmNRCQWfgze6AbBCaT1rkrkV5tJ2aP4oTNPb5JZcXYywve)
true
/home/user/Programming/JS/Node/DHT/node_modules/libp2p-kad-dht/src/content-routing/index.js:79
      dht._log('findProviders %s', key.toBaseEncodedString())
                                       ^

TypeError: key.toBaseEncodedString is not a function
    at Object.findProviders (/home/user/Programming/JS/Node/DHT/node_modules/libp2p-kad-dht/src/content-routing/index.js:79:40)
    at findProviders.next (<anonymous>)
    at KadDHT.findProviders (/home/user/Programming/JS/Node/DHT/node_modules/libp2p-kad-dht/src/index.js:315:22)
    at findProviders.next (<anonymous>)
    at findProvs (/home/user/Programming/JS/Node/DHT/node_modules/ipfs-core/src/components/dht.js:67:24)
    at async run (/home/user/Programming/JS/Node/DHT/index.js:24:19)

@autonome
Copy link
Contributor

autonome commented May 4, 2021

@achingbrain ^ should reopen or file new issues?

@PyKestrel
Copy link

PyKestrel commented Jun 9, 2021

I have the same issue currently even after creating a CID object.

@lidel lidel reopened this Jul 9, 2021
@lidel lidel added kind/bug A bug in existing code (including security flaws) need/analysis Needs further analysis before proceeding labels Jul 9, 2021
@lidel lidel added this to Weekly Candidates in Maintenance Priorities - JS Jul 9, 2021
@tarunbatra
Copy link
Contributor

tarunbatra commented Jul 26, 2021

I am facing this issue as well with the dht.findProvs method. I am open to create a PR for this and it would help if someone can point me at places to look. @achingbrain @lidel

@tarunbatra
Copy link
Contributor

tarunbatra commented Aug 4, 2021

This issue was resolved for me when I installed the latest IPFS. I suspect it was resolved due to this change in ipfs/libp2p-kad-dht.

However this has led to other errors (Error: Unknown type, must be binary type) for me which I think are not suitable for this issue.

achingbrain added a commit that referenced this issue Aug 11, 2021
We convert CIDs to Uint8Arrays unnecessarily which breaks things.

Fixes #3502
Maintenance Priorities - JS automation moved this from Weekly Candidates to Done Aug 12, 2021
achingbrain added a commit that referenced this issue Aug 12, 2021
We convert CIDs to Uint8Arrays unnecessarily which breaks things.

Fixes #3502
@jarrillaga
Copy link

jarrillaga commented Apr 6, 2022

Hello guys, how are you?

I'm facing the exact same issue, this is my code:

const ipfs = await create();
const cid = new CID('QmdKcc3ETD4Xy2f8fJZSNvtfcBfk5sxyMqQthSGn6wEXe1')
const providers = ipfs.dht.findProvs(cid);

for await (const provider of providers) {
console.log(provider)
}

Error: throw Error('Unknown type, must be binary type')

As you can see, I'm sending the CID as an object instance and not the string.

I really need if someone help me with this?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) kind/support A question or request for support need/analysis Needs further analysis before proceeding
Development

Successfully merging a pull request may close this issue.

9 participants