chore: update delegates config docs to use http client (#853)

This commit is contained in:
Vasco Santos 2021-02-11 11:42:10 +01:00 committed by GitHub
parent 46cb46188a
commit 9941414a91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -391,6 +391,7 @@ const Libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const MPLEX = require('libp2p-mplex') const MPLEX = require('libp2p-mplex')
const { NOISE } = require('libp2p-noise') const { NOISE } = require('libp2p-noise')
const ipfsHttpClient = require('ipfs-http-client')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing')
const PeerId = require('peer-id') const PeerId = require('peer-id')
@ -398,17 +399,25 @@ const PeerId = require('peer-id')
// create a peerId // create a peerId
const peerId = await PeerId.create() const peerId = await PeerId.create()
const delegatedPeerRouting = new DelegatedPeerRouter(ipfsHttpClient({
host: 'node0.delegate.ipfs.io' // In production you should setup your own delegates
protocol: 'https',
port: 443
}))
const delegatedContentRouting = new DelegatedContentRouter(peerId, ipfsHttpClient({
host: 'node0.delegate.ipfs.io' // In production you should setup your own delegates
protocol: 'https',
port: 443
}))
const node = await Libp2p.create({ const node = await Libp2p.create({
modules: { modules: {
transport: [TCP], transport: [TCP],
streamMuxer: [MPLEX], streamMuxer: [MPLEX],
connEncryption: [NOISE], connEncryption: [NOISE],
contentRouting: [ contentRouting: [delegatedContentRouting],
new DelegatedContentRouter(peerId) peerRouting: [delegatedPeerRouting],
],
peerRouting: [
new DelegatedPeerRouter()
],
}, },
peerId, peerId,
peerRouting: { // Peer routing configuration peerRouting: { // Peer routing configuration

View File

@ -107,9 +107,7 @@ describe('content-routing', () => {
host: '0.0.0.0', host: '0.0.0.0',
protocol: 'http', protocol: 'http',
port: 60197 port: 60197
}), [ }))
multiaddr('/ip4/0.0.0.0/tcp/60197')
])
;[node] = await peerUtils.createPeer({ ;[node] = await peerUtils.createPeer({
config: mergeOptions(baseOptions, { config: mergeOptions(baseOptions, {
@ -253,9 +251,7 @@ describe('content-routing', () => {
host: '0.0.0.0', host: '0.0.0.0',
protocol: 'http', protocol: 'http',
port: 60197 port: 60197
}), [ }))
multiaddr('/ip4/0.0.0.0/tcp/60197')
])
;[node] = await peerUtils.createPeer({ ;[node] = await peerUtils.createPeer({
config: mergeOptions(routingOptions, { config: mergeOptions(routingOptions, {