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

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

  • 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

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

Closing as the resolution has been suggested.

@TheDiscordian
Copy link
Member

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

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
@tarunbatra
Copy link
Contributor

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

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
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

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

9 participants