我目前正在使用ipfshttp客户端构建一个节点应用程序。
我需要订阅几个pubsub频道(~20个(。
当我连接到频道时,每次订阅都会收到200条响应,但只有6个第一次订阅的人会收到消息。
我在一个小片段中隔离了这个问题,只使用:
- 连接到节点(ipfs 0.4.23,我在0.8中尝试了另一个(
- 订阅20个频道(具有不同名称或具有不同处理程序的同一频道(
- 我总是重现这个问题(只连接到6个第一个订户(
我正在使用节点14.16.0 运行测试
当我查看ipfs-http-client
包时,我可以看到在第一个6之后,我实际上没有来自http请求的响应。不过,没有任何错误报告。
achingbrain回答了这个问题:https://github.com/ipfs/js-ipfs/issues/3741#issuecomment-898344849
在节点中,http客户端使用的默认代理将连接限制为6,以便与浏览器保持一致。您可以配置自己的代理来更改此项:
const { create } = require('ipfs-http-client');
const http = require('http')
async function echo(msg) {
console.log(`TopicID: ${msg.topicIDs[0]}, Msg: ${new TextDecoder().decode(msg.data)}`);
}
async function run() {
// connect to the default API address http://localhost:5001
const client = create({
agent: http.Agent({ keepAlive: true, maxSockets: Infinity })
});
console.log(await client.version());
for (let i = 0; i < 20; i++) {
await client.pubsub.subscribe(parseInt(i), echo);
}
}
run();