Closed olivier-nerot closed 1 year ago
- the peer:connectis received by the emitting node, several times. i.e the node seems to connect to itself
Incoming dials may log multiple connections. The reason for this is that a node will trial to dial multiple addresses to a peer. Once a connection is established it will abort the "slower" connections, so you should only end up with 1. This is more pronounced in nodes on the local machine because you the latency between the various addresses is negligible.
- the state.node.contentRouting.get(peerId._id) promise in peer:discover event throws an error, telling there is no peer available. It sounds surprising, as if a peer is discovered, it should mean there are peers available.
You're using content routing to find attempt to find a peer you've just discovered, what's the reason for this? 1. Use peerRouting
for peers, and 2. you might just want to check the peerStore
, but i'm not sure what you're actually trying to do here.
3, the state.node.contentRouting.get(connection.remotePeer._id) promise in peer:connect often sends an timeout error,
This DHT in JS is currently quite slow so timeouts can be pretty common. We're working on adding recent improvements we've made to the DHT in Go, but it's not there yet. Again, you shouldn't be using contentRouting to find Peers.
4, if I do a node.stop() on node 1, node 2 receives well the peer:disconnect event, but also a peer:connectright right after, with the same timeout as in 3 :
You're connected to the webrtc-star server, this could be another node connecting to you. You're not logging the disconnect peer id properly, so you can't easily see the difference between the peers.
5, if I do a disconnect() + connect() on node 1,
I'm not following what you're trying to do here. Why are you disconnecting and reconnecting?
Thanks for your answer. I will try to sum up my goal to make it clearer.
The purpose of this code is to share and co-edit documents, so I need to know who is on the network and their profiles. To do so, I store the connected user profile into contentrouting (dht) when he connects. Then, when peer is connected, I get its user profile with contentRouting.get(connection.remotePeer._id)
. To goal is to have the connected user's profile as soon as it is online, i.e connected, as there is an autodial:true.
If I understand, you mean a peerstore
would be better than the dht/contentrouting
? I was planing to use dht/contentrouting
to store users+documents data, to share them between peers, and to use pubsub
to send co-edition events and chat messages.
So, should I remove dht, and use peerstore.metadatBook
instead ? Or a datastore
, as said here to have data persistence ? It looks like datastore
is linked to ipfs... so maybe I should 'upgrade' to a whole ipfs layer ?
Dealing with 4. and 5. I was testing what's happening if a peer looses network, to eventually node.start() it again. I can confirm (with a better log), that a node.stop()
on peer1 sends the disconnect event to peer2, but also a connect event right afterwards :
neo:p2p-store peer disconnected QmNN4tm2Z2T2LVzVLs3i2tKvj5nJRGCAP3Jkqfz9J2STCh +12ms
neo:p2p-store peer connected QmNN4tm2Z2T2LVzVLs3i2tKvj5nJRGCAP3Jkqfz9J2STCh +870ms
I have finally removed dht, which was still too slow : two computers on the same local network could have to wait several seconds to access shared values. I am still surprised by the connect/disconnect events : il I Libp2p.stop() on a computer (A), another one (B) will receive a Libp2p.connectionManager.on('peer:disconnect') event, fine. But a few seconds after, (B) receives also a Libp2p.connectionManager.on('peer:connect') event, whereas node is stopped on (A). This seems to happen only when WebRTCStar is enabled, as in the code above.
Closing due to staleness
Hello,
With the code below, with last libp2p version (0.28.10), I have a few surprising behaviors, by running it on two nodes into the same local network :
the
peer:connect
is received by the emitting node, several times. i.e the node seems to connect to itselfthe
state.node.contentRouting.get(peerId._id)
promise inpeer:discover
event throws an error, telling there is no peer available. It sounds surprising, as if a peer is discovered, it should mean there are peers available.the
state.node.contentRouting.get(connection.remotePeer._id)
promise inpeer:connect
often sends an timeout error,if I do a
node.stop()
on node 1, node 2 receives well thepeer:disconnect
event, but also apeer:connect
right right after, with the same timeout as in 3 :if I do a
disconnect()
+connect()
on node 1, the only event received afterwards by node 1 ispeer:discover
withoutpeer:connect
, and even if apubsub.suscribe()
is called inconnect()
, the messages sent by node 2 are not received anymore by node 1. Messages sent from node 1 are nevertheless well received by node 2.It globally works, as pubsub messages can be sent and received, but there seems to be dysfunctions (or things I misunderstood) between peer events, node stop and start, and contentrouting get and put.
The code is coming from several libp2p examples.
Thanks for any clue to understand it better.