-
Notifications
You must be signed in to change notification settings - Fork 471
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
Cannot use kad-dht for contentRouting query #2661
Comments
Few issues in your sample code, but the below works
import { createLibp2p } from "libp2p";
import { webSockets } from "@libp2p/websockets";
import { tcp } from "@libp2p/tcp";
import * as filters from "@libp2p/websockets/filters";
import { bootstrap } from "@libp2p/bootstrap";
import { kadDHT } from "@libp2p/kad-dht";
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
import { identify, identifyPush } from "@libp2p/identify";
import { yamux } from "@chainsafe/libp2p-yamux";
import { noise } from "@chainsafe/libp2p-noise";
import { CID } from "multiformats/cid";
import { sha256 } from "multiformats/hashes/sha2";
import * as raw from "multiformats/codecs/raw";
const createNode = async () => {
return await createLibp2p({
addresses: {
listen: [
"/p2p-circuit"
],
},
transports: [
webSockets({ filter: filters.all }),
circuitRelayTransport(),
tcp(),
],
streamMuxers: [yamux()],
connectionEncrypters: [noise()],
peerDiscovery: [
bootstrap({
list: [
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
],
}),],
services: {
identify: identify(),
identifyPush: identifyPush(),
dht: kadDHT({
clientMode: true,
querySelfInterval: 10
}),
},
})
}
let node1 = await createNode();
let node2 = await createNode();
await node1.start();
await node2.start();
console.log("node1 id",node1.peerId);
console.log("node2 id",node2.peerId);
// wait to get p2p-circuit connections
await new Promise(resolve => setTimeout(resolve, 5000))
const addr = "js-libp2p-dht-test";
const cid = CID.create(1, raw.code, await sha256.digest(new TextEncoder().encode(addr)));
console.log("providing to network, will take minute or so...")
await node2.contentRouting.provide(cid, { useNetwork: true, useCache: true })
console.log("provide done by node2")
console.log("node1 looking for provider...")
try {
for await (const provider of node1.contentRouting.findProviders(cid, {
useNetwork: true,
useCache: true,
})) {
console.log(provider)
}
} catch (error) {
console.error("Error occurred while finding provider:", error);
} |
Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days. |
I'm pretty sure you can provide without being a server. Being a DHT server is more about whether you're publicly reachable. |
Thanks @2color - I was always under the assumption that you need to be running as a DHT server to be able provide CID's to the network. Edited the above. |
Severity: High
Description:
Steps to reproduce the error:
Output:
The text was updated successfully, but these errors were encountered: