我在浏览器中使用这段代码。它似乎是通过http?连接到ipfs.io的。我希望只连接到分布式哈希表webRTC同行。我猜我需要把一些选项传递给Ipfs.create?我在这里看到了一个自定义libp2p的例子,但是选项的数量太多了。https://github.com/ipfs/js-ipfs/blob/master/examples/custom-libp2p/index.js
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<script>
(async () => {
const node = await Ipfs.create()
const data = 'Hello'
const results = await node.add(data)
console.log(results)
})()
</script>发布于 2020-09-02 17:57:52
您可以在创建实例时传递IPFS配置选项,这使您能够指定要侦听的远程WebRTC地址,并删除/更改要初始连接的引导程序节点。您可以在https://github.com/ipfs/js-ipfs/blob/ipfs%400.49.1/examples/browser-exchange-files/public/app.js#L48的文件交换示例中看到这一点。因此,您的配置可能如下所示:
const node = await Ipfs.create({
config: {
Addresses: {
Swarm: [
// These are public webrtc-star servers
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
]
},
// This removes the default IPFS peers to dial to. You can specify any known addresses you wish, or leave blank.
Bootstrap: []
}
})正如您提到的分布式哈希表,我只想指出,在WebRTC上运行分布式哈希表在小型、隔离的网络之外是不可行的。由于WebRTC拨号可能需要一些时间,这对分布式哈希表查询时间有很大影响。
https://stackoverflow.com/questions/63696779
复制相似问题