-
Notifications
You must be signed in to change notification settings - Fork 1.2k
In-browser incorrect ipfs.swarm.connect on refresh #3400
Comments
libp2p stores known connection details in it's peer store and will try to reconnect when the node starts up (on page load after refreshing the page in this case). The remote node is probably advertising WSS and TCP addresses. Since browser nodes cannot connect to TCP addresses it's not clear why libp2p would attempt to do so as it can only fail. @vasco-santos can these addresses be filtered out or otherwise not connected to? |
Something looks strange in this case. Could you please log the AddressBook content after the As far as I understand, the First start:
Next starts
Considering the above, it is expected that the tcp based addresses will simply throw as there will be no transport for it. If all the addresses fail, the Aggregate error is thrown, which seems to be the case. The problematic point here is why all the addresses fail, taking into account that the |
@vasco-santos thank you for looking into this and your in-depth explanation! I added the following code:
And If it helps I tested this on both Firefox and Brave. |
You are doing that exactly after the connect right? Perhaps the peerId is not well created. You can probably use // Connect code above
const addressesRecord = ipfsNode.libp2p.peerStore.addressBook.get(connection.remotePeer)
// You can also get all the peers and iterate them
const peers = ipfsNode.libp2p.peerStore.peers
// Listen for changes triggered from identify/...
ipfsNode.libp2p.peerStore.on('change:multiaddrs', ({ peerId, multiaddrs}) => {
if (peerId.equals(connection.remotePeer) {
console.log(multiaddrs)
}
}) Let me know the results in both first run and second run. It might be good to check the PeerStore before the dial, in order to make sure you are using a new ipfs repo. btw, if you need the docs are here: |
@vasco-santos yep exactly after the connection. Creating the Here is what I am doing:
And here is the output: Once I reloaded the page this is the errors that I got: Since |
Thanks for the logs. For what I can see, after a dial happens your browser node will know 6 multiaddrs for the other peer. const serverMultiAddr = '/dns4/' + serverDomain + '/tcp/4005/wss/p2p/' + serverIPFSPeerID;
console.log('serverMultiAddr', serverMultiAddr);
const PeerId = require('peer-id');
const serverPeerID = PeerId.createFromCID(serverIPFSPeerID);
const addressBookRecordBeforeDial = ipfsNode.libp2p.peerStore.addressBook.get(serverPeerID);
// This should be empty in the first load, and contain known multiaddrs in the next load
console.log('addressBookRecordBeforeDial', addressBookRecordBeforeDial.length)
for (let i = 0; i < addressBookRecordBeforeDial.length; i++) {
console.log('addressBookRecordBeforeDial[i].multiaddr', addressBookRecordBeforeDial[i].multiaddr.toString())
}
// This will log the multiaddrs discovered over time for the peer
ipfsNode.libp2p.peerStore.on('change:multiaddrs', ({ peerId, multiaddrs }) => {
if (peerId.equals(serverPeerID)) {
console.log('new multiaddrs discovered')
console.log(multiaddrs.map((m) => m.toString());
console.log(multiaddrs.length);
}
})
const connection = await ipfsNode.swarm.connect(serverMultiAddr).catch(console.error);
console.log('connection', connection);
const addressBookRecordAfterDial = ipfsNode.libp2p.peerStore.addressBook.get(serverPeerID);
// This should have all the peers that will appear in the second dial
console.log('addressBookRecordBeforeDial', addressBookRecordAfterDial.length)
for (let i = 0; i < addressBookRecordAfterDial.length; i++) {
console.log('addressBookRecordAfterDial[i].multiaddr', addressBookRecordAfterDial[i].multiaddr.toString())
} It would be good to run this and ack my assumptions in the comments. I guess they might be wrong causing the issue. So, I already have a suspicion for this. I believe that the address that you are using is being lost. My theory is: First load
Second load
What can be done to mitigate this?
From libp2p stand point, we should look at improving the dial flow for these cases. We should probably inspect the content of an on going dial to see if we have new addresses for the peer in the second dial. I will open an issue to track that once we confirm this is the issue |
@vasco-santos one of the 5 multiaddrs does have the correct IP address, but it is incorrectly over TCP and with the incorrect port: Thank you for sending over that code snippet. Here are the results on the 1st page load: After reloading the page for about an hour I still haven't been able to reproduce the error... Not sure why.
Yes.
Not quite sure that I follow. Is this for the
And I have an NginX server listening on port
|
I removed the
I also have added in your recommended
So far I have been able to successfully connect to my server's node through UPDATE: |
The TCP address makes sense, since you were also listening on TCP.
Those swarm addresses will map into So, my recommendation was to do: const ipfs = await IPFS.create({
libp2p: {
addresses: {
announce: ['/dns4/ipfs.io'] // Your DNS
}
}
}) WIth this, your server node will announce its dns address on the identify exchange and everything should simply work. However, it seems that you are using a IPFS daemon directly, without using the programatically API. I will see if we can add this to the configuration to ease this process.
If you do not have any use case where peers outside of the browser context will connect to your node, then I can recommend you to remove it as you don't need to be listening for TCP connections. By the way, if
Ok, even hackier approach for now to have things running. You can do the addressBook set just before the dial and it will need to simply work. Meanwhile, we need to get this done properly, let me know how it worked with the EDIT: Added PR with the ability to add the announce addresses #3409 |
This PR adds the ability to add announces addresses via the config file and create options. This is really useful for browser contexts, so that other peers can announce their public addresses, like dns addresses. Ref: #3400
This works. I'm using JS-IPFS on NodeJs for my server so this will work.
I tried this, but the server started to listen on
I now have this set-up (just to be safe I added the
And so far this is working. |
Also, maybe it is already being considered, but it would be nice for JS-IPFS to be able to listen on secure websocket connections directly without an NginX reverse proxy server. 🙂 |
Nice, so if you do the announce with your
We are talking about some ideas to improve that experience, also taking into account go-ipfs. We should get a nicer solution in the next year |
Ok, did you include the peer Id in the dns address? The announce address should basically be your server multiaddr including the peerId part and the tcp port |
Ah, didn't realize that. This seemed to fix that issue. Thank you for all your help. |
Glad that it is sorted out. |
Version:
0.50.2
Platform:
Linux ubuntu 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Severity:
Medium - A non-essential functionality does not work, performance issues, etc.
Description:
When I first open my webpage and attempt to connect to another IPFS Node that I own I can successfully connect:
However, when I refresh the same page I get this error:
You'll notice that both the successful and unsuccessful connections are attempting to connect to the same peerID (
QmeYrvjcWzJTGRv8aJVfManvQfsBaN5fPwhXmMCzaLL
) but with the incorrect multiAddr the second time (/ip4/127.0.0.1/tcp/4002/p2p/QmeYrvjcWzJTGRv8aJVfManvQfsBaN5fPwhXmMCzaLL
).I'm assuming this is because JS-IPFS is attempting to connect to the external node via its peerID through the JS-IPFS node within the browser. Which obviously won't work since the browser is not listening to
127.0.0.1
.How can I prevent JS-IPFS from attempting to connect to a local (
127.0.0.1
) when I already gave it a domain and multiAddr to connect to (/dns4/example.com/tcp/4005/wss/p2p/QmeYrvjcWzJTGRv8aJVfManvQfsBaN5fPwhXmMCzaLL
)?Steps to reproduce the error:
The text was updated successfully, but these errors were encountered: