-
Notifications
You must be signed in to change notification settings - Fork 94
fix: handle reconnection to signaling server #112
Conversation
In my related PR [109] I wanted the peers to reconnect to each other if a peer disconnects from the signalling server by re-sending the 'intro' messages any time the wss connection to the signalling server is reestablished. This seems like a far more general solution that covers both peer disconnections and signalling-server disconnections (and doesn't seem to trigger Coveralls:) Have you noticed any noticeable performance issues with larger swarms? |
src/index.js
Outdated
listener.io.emit('ss-join', ma.toString()) | ||
listener.io.on('ws-handshake', incommingDial) | ||
listener.io.on('ws-peer', this._peerDiscovered) | ||
listener.emit('listening') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be an issue for libp2p-swarm because it shouldn't emit listening
a second time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@pgte can you also add tests for this? |
listener.io.on('ws-handshake', incommingDial) | ||
listener.io.on('ws-peer', this._peerDiscovered) | ||
|
||
listener.io.on('connect', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the reconnect
event? Like @5310 did on https://github.com/libp2p/js-libp2p-webrtc-star/pull/109/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A reconnect is still a connect, IMO needs to go through the same handshake as a connect. Why treat it differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense now with the latest change, thanks!
@diasdavid any clue on how to test this? I would like to start and stop the server, but it's buried inside a gulp file. Any idea? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the testing, just create a Node.js test with the file extension of .node.js
and aegir
will only run it in Node.js, this way you can rely in your own SigServer
listener.io.on('ws-handshake', incommingDial) | ||
listener.io.on('ws-peer', this._peerDiscovered) | ||
|
||
listener.io.on('connect', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense now with the latest change, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @pgte :)
If a connection to the signalling server dies and then recovers, Socket.io emits the
connect
event again.It happens that the peer was ignoring it. This fixes it.