Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

A few BUGFIXES and new tests to cover those scenarios #54

Closed
wants to merge 22 commits into from

Conversation

michaelfakhri
Copy link
Contributor

@michaelfakhri michaelfakhri commented Dec 13, 2016

Here is a summary of all the changes:

  • Variable maSelf was redirecting all dials to come back through the last added listener. This definitely does not make any sense, since the last added listener will most likely be another signalling server which will have a completely different multi-address. This means that the peer will never get the answer for the offer creating an error state on the server side and on the peer's side.
  • Closing the listener did not close the socket connection to the signalling server. This safe to do at the moment since each listener creates a new socket connection to be used.
  • Moved the close and getObservedAddr functions to be added only when the listen function is called since they do not make any sense if the listener is not listening.There is no multi-address to return or a listener to close if its not listening.
  • Fixed ss-leave event which did not pass the multi-address to the server
  • Fixed an issue where the listener was added with a function as the key to the listeners map/array
  • Moved adding the listener to the listeners array to occur only once its connected to the signalling server, otherwise its just have a bad listener that cannot actually dial anywhere

Part of this PR addresses Websocket stays connected even after webrtc-star listener is closed #51

EDIT: This PR also adds support for handling multiple signalling servers
Let me know if you need me to make any changes.

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome PR @michaelfakhri, thank you for adding tests in. Made a couple of comments, would be great to have those addressed for the merge

listener.close = (callback) => {
if (!callback) {
callback = function noop () {}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's replace this by a more simpler: callback = callback || () => {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}, 100)
}
listener.getAddrs = (callback) => {
process.nextTick(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not available in the browser, should use setImmediate instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -71,3 +71,74 @@ describe('dial', () => {
// TODO IPv6 not supported yet
})
})
describe('complex dial scenarios', () => {
let ws1, ws2, listenerToClose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using standard for linting? This fails linting

Copy link
Contributor Author

@michaelfakhri michaelfakhri Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, everything was good using gulp lint on my machine and on travis. I used npm run lint the second time round and it was still fine, should I have used something else?

@@ -58,7 +57,7 @@ function WebRTCStar () {
channel.on('signal', function (signal) {
sioClient.emit('ss-handshake', {
intentId: intentId,
srcMultiaddr: maSelf.toString(),
srcMultiaddr: listeners[Object.keys(listeners)[0]].ma.toString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make it fail if more than one listener is added. Can you add a test for multiple listeners?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added two tests earlier that test multiple listeners connected to the same signalling server but are listening on different addresses. The code here simply follows the same criteria for picking the sioClient. Nothing weird going on but the code previously attached a random address to the signalling which is weird. In a multiple signalling server scenario, that maSelf code could fail on server and client side.

@@ -116,11 +115,11 @@ function WebRTCStar () {
if (!callback) {
callback = function noop () {}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's replace this by a more simpler: callback = callback || () => {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!callback) {
callback = function noop () {}
}
callback = callback || function () {}

const intentId = (~~(Math.random() * 1e9)).toString(36) + Date.now()
const sioClient = listeners[Object.keys(listeners)[0]].io
Copy link
Contributor Author

@michaelfakhri michaelfakhri Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid I think the criteria for picking the sioClient here is not quite right, since it should be picking the signalling that we know the other peer is connected to (from the ma). This method just picks the first signalling server available and sends the offer without taking into account that peer might not be connected to that specific server. (Keeping in mind this only a problem in multiple signalling server scenario)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right @michaelfakhri, the picking of the 'right signalling server' wasn't added because we always had only one, but we should support multiple nevertheless.

Would you like to add that + a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, perhaps I might also attempt to decouple the listeners from the signalling servers in the process.

@michaelfakhri michaelfakhri changed the title A few BUGFIXES and new tests to cover those scenarios WIP: A few BUGFIXES and new tests to cover those scenarios Dec 20, 2016
@michaelfakhri
Copy link
Contributor Author

note to self 1: simple-peer 6.1.3 breaks libp2p webrtc transport (something to do with onSuccess callback), 6.1.0 work just fine so I used npm shrinkwrap to get tests passing by forcing simple peer to 6.1.0
note to self 2: df2 fix callback error in tests

@daviddias
Copy link
Member

Interesting note, thanks for catching that @michaelfakhri, will check how to update properly :)

@daviddias
Copy link
Member

@michaelfakhri found the issue, the 'Fallback' option in simple-peer is expecting an interface that wrtc doesn't support - feross/simple-peer@e9ffcfa#commitcomment-20490182

@daviddias
Copy link
Member

@michaelfakhri could you rebase master onto your PR? I've fixed the simple-peer version while it gets resolved, no need for shrinkwrap right now :)

@michaelfakhri michaelfakhri changed the title WIP: A few BUGFIXES and new tests to cover those scenarios A few BUGFIXES and new tests to cover those scenarios Jan 17, 2017
@michaelfakhri
Copy link
Contributor Author

@diasdavid Thanks for looking into it and fixing it!

This is now ready for review / merge.

I attempted a rebase but did something wrong and ended up bringing in all the commits into the branch instead of rebasing but thats easily fixable using a squash merge at the end.

I have seen two issues (not related to this PR though) that might need attention / investigation:

  • TRAVIS CI firefox browser tests are not all running (for e.g: dial is not run and it seems to be just hanging)
  • TRAVIS CI karma test crashes with segmentation fault on node.js v4 on master and this PR too

@michaelfakhri
Copy link
Contributor Author

Continued here: #89

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Websocket stays connected even after webrtc-star listener is closed
3 participants