Platform: js-ipfs on Chrome v. 72.0.3626.121 and go-ipfs on 64-bit Windows 10
Objective
Enable Pubsub feature between IPFS node running on browser and IPFS running on local machine.
Overview of the Problem
We are trying to connect 2 nodes and get the Pubsub functionality working between them.
Node A is created programatically and runs in the browser. This node will Publish the message.
Node B runs as daemon in local machine, started via CLI. This node will Subscribe to a topic.
But, despite having tried several different configurations, we did not get the Pubsub feature working in this scenario.
Why is this necessary?
This behavior is required since it is part of our current strategy to pin the submitted ideas to IPFS, and make them available to the public in a decentralized way. Put simply, if we manage to achieve Pubsub between Node A and Node B, that means we can move forward with the POC app that we've been developing.
NODE A (browser) Current Config
First you need to require wrtc. This is necessary to setup a p2p connection between the 2 nodes:
const wrtc = require("wrtc"); // or require('electron-webrtc')
const WStar = require("libp2p-webrtc-star");
const wstar = new WStar({ wrtc });
Once you install IFPS on your machine and run ipfs start from the terminal, a folder named .ipfs will be created in your $HOME directory. Inside that folder, you will find a config file. The current state of my file is:
I start the daemon on the terminal using: ipfs daemon --enable-pubsub-experiment and subscribe to the topic using ipfs pubsub sub testing123
I navigate to localhost:3000 and the console logs:
Swarm listening on /p2p-circuit/ip4/127.0.0.1/tcp/4001/ipfs/QmPMaDyK2ee95BpjnMyWYiVi46EcZFrY8AUmSzieNSLbEa/ipfs/QmcCnVBpYLvcRLbutwRMkzeJwHfjbFaq8y9JQ2sLcBAX1L
Cool. So looks like the p2p circuit is online! So next we upload a file IPFS and save the CID to the state. (this.state.added_file_hash)
Then on the browser, we try to communicate with the daemon using
publishFileHash() {
const topic = "testing123";
const msg = Buffer.from(this.state.added_file_hash);
console.log("msg is");
console.log(this.state.added_file_hash);
this.ipfsNode.pubsub.publish(topic, msg, err => {
if (err) {
return console.error(`failed to publish to ${topic}`, err);
}
console.log(`published to ${topic}`);
});
}
After this, browser console logs: published to testing123 but the daemon does not get the message. 😢
Why P2P Circuit? Did you try a direct connection
So maybe Pubsub does not work with P2P circuits. However, I could not find a way to get a direct connection between the browser node and the daemon node.
If you use:
publishFileHash() {
const addr =
"/ip4/127.0.0.1/tcp/4001/ipfs/QmPMaDyK2ee95BpjnMyWYiVi46EcZFrY8AUmSzieNSLbEa";
this.ipfsNode.swarm.connect(addr, function(err) {
if (err) {
throw err;
}
const topic = "testing123";
const msg = Buffer.from(this.state.added_file_hash);
console.log("msg is");
console.log(this.state.added_file_hash);
this.ipfsNode.pubsub.publish(topic, msg, err => {
if (err) {
return console.error(`failed to publish to ${topic}`, err);
}
console.log(`published to ${topic}`);
});
});
}
You get an browser console logs an error that says:
I want to contribute but I'm not sure where to start...
If you would like to know more about why solving this task is critical, feel free to reach out to me or @abinashk😃 Right now this is our priority. If you're up for the challenge, I can also help setting up Node A and Node B so you can aid us to reach a conclusion 🥇
The text was updated successfully, but these errors were encountered:
gil-air-may
changed the title
Pubsub won't work between browser node and machine node (daemon)
Pubsub Won't Work Between Browser Node and Machine node (Daemon)
Mar 21, 2019
gil-air-may commentedMar 21, 2019
•
edited
DEADLINE⏳
27/03/2019
Objective
Overview of the Problem
We are trying to connect 2 nodes and get the Pubsub functionality working between them.
But, despite having tried several different configurations, we did not get the Pubsub feature working in this scenario.
Why is this necessary?
This behavior is required since it is part of our current strategy to pin the submitted ideas to IPFS, and make them available to the public in a decentralized way. Put simply, if we manage to achieve Pubsub between Node A and Node B, that means we can move forward with the POC app that we've been developing.
NODE A (browser) Current Config
First you need to require
wrtc. This is necessary to setup a p2p connection between the 2 nodes:Then you can instantiate the node by:
NODE B (daemon) Current Config
Once you install IFPS on your machine and run
ipfs startfrom the terminal, a folder named .ipfs will be created in your $HOME directory. Inside that folder, you will find aconfigfile. The current state of my file is:The Problem
I start the daemon on the terminal using:
ipfs daemon --enable-pubsub-experimentand subscribe to the topic usingipfs pubsub sub testing123I navigate to localhost:3000 and the console logs:
Cool. So looks like the p2p circuit is online! So next we upload a file IPFS and save the CID to the state. (this.state.added_file_hash)
Then on the browser, we try to communicate with the daemon using
After this, browser console logs:😢
published to testing123but the daemon does not get the message.Why P2P Circuit? Did you try a direct connection
So maybe Pubsub does not work with P2P circuits. However, I could not find a way to get a direct connection between the browser node and the daemon node.
If you use:
You get an browser console logs an error that says:
I want to contribute but I'm not sure where to start...
If you would like to know more about why solving this task is critical, feel free to reach out to me or @abinashk😃 Right now this is our priority. If you're up for the challenge, I can also help setting up Node A and Node B so you can aid us to reach a conclusion 🥇
The text was updated successfully, but these errors were encountered: