Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring libp2p-websocket-star to the Transports family! 🌟 #122

Merged
merged 8 commits into from
Nov 27, 2017

Conversation

mkg20001
Copy link
Member

@mkg20001 mkg20001 commented Sep 6, 2017

Adds tests for libp2p-websocket-star
Ref libp2p/js-libp2p-websocket-star#3

circle.yml Outdated
- sudo apt-get update
- sudo apt-get install -f || true
- sudo dpkg -i libnss3*.deb
Copy link
Member

Choose a reason for hiding this comment

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

@mkg20001 is this the fix for all the Chrome errors we started seeing in Circle?? Awesome!!!

//cc @victorbjelkholm

Copy link
Member Author

Choose a reason for hiding this comment

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

@diasdavid Yes.

@daviddias
Copy link
Member

Ok, I've gone through and give a big CR (with refactoring in place) to websocket-star. Overall there is a ton of work there and I'm really happy to see it coming together, thank you @mkg20001 👏🏽👏🏽👏🏽👏🏽!

The CR+Refactor can be found in:

To release and integrate websocket-star with confidence, recommending our users to try it out, I still want to see some issues solved and/or improved. I've opened issues in both repos so that it is clear what is missing, lists can be found in:

@mkg20001 is this something you would like to finish? I can continue helping by providing CR and coding time, just not sure how much time I can allocate that soon :)

Thanks!

@daviddias daviddias changed the title test: add libp2p-websocket-star tests Bring libp2p-websocket-star to the Transports family! 🌟 Sep 11, 2017
@mkg20001
Copy link
Member Author

@mkg20001 is this something you would like to finish? I can continue helping by providing CR and coding time, just not sure how much time I can allocate that soon :)

Yes but I'm also working on https://github.com/ZeroNetJS/zeronet-js/ and my last year in school just began so I won't be working on this project that much

@daviddias
Copy link
Member

daviddias commented Sep 11, 2017

I didn't know about zeronet-js with libp2p! That's rad! :D

Actually, this is more than rad! it is super-duper rad! Wanna show it working today at the IPFS All Hands? ipfs/team-mgmt#499

@mkg20001
Copy link
Member Author

Actually, this is more than rad! it is super-duper rad! Wanna show it working today at the IPFS All Hands?

After thinking about that for a while and talking with my parents I decided it would be a good idea. I'm usually a bit shy and this would be the first every meeting/conference/etc where I would participate. But I would like to participate. How can I join? How does that work?

@daviddias
Copy link
Member

@dryajov @victorbjelkholm can I get your review here as well?

package.json Outdated
@@ -60,6 +60,8 @@
"libp2p-tcp": "~0.11.0",
"libp2p-webrtc-star": "~0.13.0",
"libp2p-websockets": "~0.10.1",
"libp2p-websocket-star": "0.3.0-rc4",
"libp2p-websocket-star-signal": "0.3.0-rc4",
Copy link
Member

Choose a reason for hiding this comment

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

Haven't seen that we are doing RC versions anywhere else, can we release stable versions of these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@ghost ghost assigned mkg20001 Oct 28, 2017
@ghost ghost added status/in-progress In progress and removed status/ready Ready to be worked labels Oct 28, 2017
@mkg20001
Copy link
Member Author

Rebased all changes against current master and released stable versions of the libp2p-websocket-star* modules.
Merge?

Copy link
Member

@dryajov dryajov left a comment

Choose a reason for hiding this comment

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

LGTM

.aegir.js Outdated
}
server2 = _server
ready()
})
Copy link
Member

Choose a reason for hiding this comment

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

@mkg20001 mind putting the two tasks, sigServer.start and wsRendezvous.start in a async.parallel flow?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are already parallel...

Copy link
Member

Choose a reason for hiding this comment

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

I mean, to make it more structured with Parallel. I also see Ready being called 3 times and only checked for 2

.aegir.js Outdated
}
server.stop(done)
}), 2000)
setTimeout(() => require('async/each')([node, server, server2], (s, n) => s.stop(n), done), 2000)
Copy link
Member

Choose a reason for hiding this comment

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

a) Please do not require modules throughout the codebase, always require it at the top.
b) Preserve the {} when nesting multiple calls.
c) Use async/parallel for this

package.json Outdated
@@ -62,6 +62,8 @@
"libp2p-tcp": "~0.11.1",
"libp2p-webrtc-star": "~0.13.2",
"libp2p-websockets": "~0.10.4",
"libp2p-websocket-star": "~0.5.0",
"libp2p-websocket-star-rendezvous": "~0.2.0",
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for keeping the ~ for <1.0.0 :)

@@ -36,11 +37,13 @@ class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}
const webRTCStar = new WebRTCStar()
const wsStar = new WebSocketStar({ id: peerInfo.id })
Copy link
Member

Choose a reason for hiding this comment

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

Does it still require that the PeerInfo gets passed on the constructor? Why?

Choose a reason for hiding this comment

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

in the README of ws-star it says: const ws = new WSStar({ id: id }) // the id is required for the crypto challenge

Choose a reason for hiding this comment

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

this requierment to have the { id: peerInfo.id } makes it impossible to configure the WebSocketStar through the IPFS node constructor like:

libp2p: { // add custom modules to the libp2p stack of your node
    modules: {}
  }

because the peer id is not available at that point

Copy link
Member Author

Choose a reason for hiding this comment

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

How else can the transport get the id?

Copy link
Member

Choose a reason for hiding this comment

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

The first question should be "why does this Id exist in the first place", if:

  • a) is to auth with the rendezvous point, the reality is that the rendezvous point doesn't have any list of pre-shared ids, so using the PeerId or something else at random is the same
  • b) is to auth with the other peers, then that is a double crypto challenge because secio already does that.

Copy link
Member

Choose a reason for hiding this comment

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

There are two things here:

  • a) Authentication between peers (end to end) - assured by SECIO ✔️
  • b) Authentication with the rendezvous point - what you are trying to achieve with the PeerId

b) is a bit more complicated because you want to peers to prove who they are with the rendezvous point.

I'm torn that one the best solution is through PeerId because that really breaks the transport interface expectation. We also want to move away from centralized rendezvous points and just make any node be able to do that, which kind of means that a transport will need access to libp2p itself. Once we end up doing this, it might lead to changing how modules are loaded to a DI scheme.

Copy link
Member Author

@mkg20001 mkg20001 Nov 6, 2017

Choose a reason for hiding this comment

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

There are now 5 possible solutions:

  • Use wsstar.lazySetId() somewhere later in the code
  • Don't add the peerId and run the server with --disableCryptoChallenge (insecure!)
  • libp2p-websocket-star #117 (comment) (or similar)
  • DI scheme as mentioned above (isn't implemented so this isn't a good short-term solution)
  • Something else that works short-term at least

Which one would be the best? (I prefer the first one)

Copy link
Member

Choose a reason for hiding this comment

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

@mkg20001 what about deploying a first version without the cryptoChallenge so that js-ipfs users can try it out today and we work on the DI scheme (which @pgte and me will start using more of his time towards that) as a separate endeavor so that then we can add the crypto challenge?

Copy link
Member Author

Choose a reason for hiding this comment

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

@diasdavid The peerId IS accesible at the time of transport creation. No need to use the insecure version. https://github.com/ipfs/js-ipfs/compare/master...mkg20001:master.diff

Copy link
Member Author

Choose a reason for hiding this comment

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

@diasdavid Insecure server running at /dns/ws-star-signal-4.servep2p.com/wss/p2p-websocket-star/

expect(Object.keys(nodeWS.swarm.muxedConns)).to.have.length(1)
cb()
}
], done)
Copy link
Member

Choose a reason for hiding this comment

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

All of the checks happening are synchronous, there is no reason to use async.parallel

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied this from test/nodejs-bundle/tcp+websockets+webrtc-star.js ( https://github.com/libp2p/js-libp2p/blob/master/test/nodejs-bundle/tcp%2Bwebsockets%2Bwebrtc-star.js#L107-L118 )

Copy link
Member

Choose a reason for hiding this comment

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

Wanna improve both?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeWS.swarm.muxedConns)).to.have.length(0)
cb()
}
Copy link
Member

Choose a reason for hiding this comment

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

Same from?

expect(Object.keys(nodeAll.swarm.muxedConns)).to.have.length(1)
cb()
}
], done)
Copy link
Member

Choose a reason for hiding this comment

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

Same here

expect(Object.keys(nodeWStar.swarm.muxedConns)).to.have.length(0)
cb()
}
], done)
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@Beanow
Copy link

Beanow commented Nov 16, 2017

Can you provide a configuration you've tested this with in js-ipfs?

In my tests to implement this I found some odd issues with the multi addresses.
Using a test server,

config: {
  Addresses: {
    Swarm: [
      '/dns4/ws-star-signal-2.servep2p.com/wss/p2p-websocket-star/'
    ]
  }
}

My logs output:

Swarm listening on /dns4/ws-star-signal-2.servep2p.com/wss/p2p-websocket-star/ipfs/QmcdoJPn4CStGjJd58XQE3GfLZQHSshMovhoGMNFoHd9px/ipfs/QmcdoJPn4CStGjJd58XQE3GfLZQHSshMovhoGMNFoHd9px

And it does not successfully connect with any peers over websocket star.

When I add this to src/core/runtime/libp2p-browser.js

peerInfo.multiaddrs.clear()
peerInfo.multiaddrs.add(multiaddr('/dns4/ws-star-signal-1.servep2p.com/wss/p2p-websocket-star/'))
const wsstar = new WSStar({id: peerInfo.id})

It will do peer discovery, bitswap and pubsub correctly.

@mkg20001
Copy link
Member Author

mkg20001 commented Nov 19, 2017

Try it with https://github.com/mkg20001/js-ipfs/tree/feat-websocketstar or apply this patch and see if it works (edit: works for me)

@patrickdet
Copy link

patrickdet commented Nov 26, 2017

The only annoying thing is that now it is not possible to configure the libp2p transport with the WebSocketStar from the configuration like:

  const ipfs = new Ipfs({
    libp2p: {
      modules: {
        transport: [new WebSocketStar({id: peerInfo.id})],
        discovery: [new WebSocketStar({id: peerInfo.id})]
      }
    }
  })

because in that scenario the peerInfo is not available yet. Not sure if it is critical to have that though.

I'd really like to have the WebSocketStar available in Ipfs though, because the WebRTC keeps crashing my application.

@mkg20001
Copy link
Member Author

You can use it without peer id and use this signalling server instead: /dns/ws-star-signal-4.servep2p.com/wss/p2p-websocket-star/. note that it's not as secure as the other servers (no crypto challenge)

@daviddias
Copy link
Member

Let's focus on figuring out #130 to get that PeerId on the transport. Until then let's move with the not as secure, also not yet audited version.

.aegir.js Outdated
@@ -4,9 +4,12 @@ const Node = require('./test/nodejs-bundle/nodejs-bundle.js')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const pull = require('pull-stream')
const {parallel} = require('async')
Copy link
Member

Choose a reason for hiding this comment

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

Please use standard require('async/parallel')

.aegir.js Outdated
let server
let server2
Copy link
Member

Choose a reason for hiding this comment

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

Since we now have two "servers", let's use qualifying names:

  • wrtcRendezvous
  • wsRendezvous

.aegir.js Outdated
sigServer.start({ port: 15555 }, (err, _server) => {
sigServer.start({
port: 15555
}, (err, _server) => {
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary style change.

.aegir.js Outdated
}
server2 = _server
ready()
})
Copy link
Member

Choose a reason for hiding this comment

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

I mean, to make it more structured with Parallel. I also see Ready being called 3 times and only checked for 2

@@ -91,57 +91,32 @@ describe('TCP + WebSockets + WebRTCStar', () => {
(cb) => nodeTCP.stop(cb),
(cb) => nodeWS.stop(cb),
(cb) => nodeWStar.stop(cb),
(cb) => ss.stop(done)
(cb) => ss.stop(cb)
Copy link
Member

Choose a reason for hiding this comment

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

good catch!

}
], done)
}
setTimeout(check, 500, nodeTCP, done, 1, 1)
Copy link
Member

Choose a reason for hiding this comment

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

Please use instead:

setTimeout(() => check(nodeTCP, 1, 1, done), 500

And update the function arguments respectively (rule: callback always comes last)

@@ -0,0 +1,154 @@
/* eslint-env mocha */
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating a copy of tcp+websockets+webrtc-star please do try to augment the other test suite

@daviddias
Copy link
Member

daviddias commented Nov 26, 2017

@mkg20001 thanks for pushing this :) I've made some comments. I am happy to finish this one tomorrow early morning if you don't have time until then. Thank you!

@ghost ghost assigned daviddias Nov 27, 2017
@daviddias daviddias merged commit 95f029e into master Nov 27, 2017
@daviddias daviddias deleted the libp2p-websocket-star branch November 27, 2017 09:10
@ghost ghost removed the status/in-progress In progress label Nov 27, 2017
@mitra42
Copy link

mitra42 commented Nov 28, 2017

I see a number of configurations posted as not working above, is there a conclusion of a configuration that works ? Could it be posted here.

maschad added a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants