-
Notifications
You must be signed in to change notification settings - Fork 446
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
Conversation
fe6c3a0
to
56675b9
Compare
circle.yml
Outdated
- sudo apt-get update | ||
- sudo apt-get install -f || true | ||
- sudo dpkg -i libnss3*.deb |
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.
@mkg20001 is this the fix for all the Chrome errors we started seeing in Circle?? Awesome!!!
//cc @victorbjelkholm
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.
@diasdavid Yes.
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! |
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 |
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 |
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? |
@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", |
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.
Haven't seen that we are doing RC versions anywhere else, can we release stable versions of these?
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
56675b9
to
0e2793f
Compare
Rebased all changes against current master and released stable versions of the libp2p-websocket-star* modules. |
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.
LGTM
.aegir.js
Outdated
} | ||
server2 = _server | ||
ready() | ||
}) |
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.
@mkg20001 mind putting the two tasks, sigServer.start
and wsRendezvous.start
in a async.parallel
flow?
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.
They are already parallel...
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.
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) |
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) 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", |
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 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 }) |
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.
Does it still require that the PeerInfo gets passed on the constructor? Why?
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.
in the README of ws-star it says: const ws = new WSStar({ id: id }) // the id is required for the crypto challenge
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 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
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.
How else can the transport get the id?
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.
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.
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.
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.
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.
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)
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.
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.
@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
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.
@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) |
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.
All of the checks happening are synchronous, there is no reason to use async.parallel
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.
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 )
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.
Wanna improve both?
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.
Sure
expect(Object.keys(peers)).to.have.length(1) | ||
expect(Object.keys(nodeWS.swarm.muxedConns)).to.have.length(0) | ||
cb() | ||
} |
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.
Same from?
expect(Object.keys(nodeAll.swarm.muxedConns)).to.have.length(1) | ||
cb() | ||
} | ||
], done) |
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.
Same here
expect(Object.keys(nodeWStar.swarm.muxedConns)).to.have.length(0) | ||
cb() | ||
} | ||
], done) |
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.
Same here
Can you provide a configuration you've tested this with in In my tests to implement this I found some odd issues with the multi addresses. config: {
Addresses: {
Swarm: [
'/dns4/ws-star-signal-2.servep2p.com/wss/p2p-websocket-star/'
]
}
} My logs output:
And it does not successfully connect with any peers over websocket star. When I add this to 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. |
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) |
The only annoying thing is that now it is not possible to configure the
because in that scenario the I'd really like to have the WebSocketStar available in Ipfs though, because the WebRTC keeps crashing my application. |
You can use it without peer id and use this signalling server instead: |
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') |
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.
Please use standard require('async/parallel')
.aegir.js
Outdated
let server | ||
let server2 |
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.
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) => { |
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.
Unnecessary style change.
.aegir.js
Outdated
} | ||
server2 = _server | ||
ready() | ||
}) |
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.
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) |
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.
good catch!
} | ||
], done) | ||
} | ||
setTimeout(check, 500, nodeTCP, done, 1, 1) |
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.
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 */ |
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.
Instead of creating a copy of tcp+websockets+webrtc-star
please do try to augment the other test suite
@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! |
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. |
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
## [1.1.6](libp2p/js-libp2p-webrtc@v1.1.5...v1.1.6) (2023-04-21) ### Bug Fixes * readme: Remove confusing section ([libp2p#122](libp2p/js-libp2p-webrtc#122)) ([dc78154](libp2p/js-libp2p-webrtc@dc78154))
Adds tests for libp2p-websocket-star
Ref libp2p/js-libp2p-websocket-star#3