-
Notifications
You must be signed in to change notification settings - Fork 445
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
new config #166
new config #166
Conversation
README.md
Outdated
} | ||
|
||
super(modules, peerInfo, peerBook, options) | ||
// overload any defaults of your bundle | ||
Object.assign(options, _options) |
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.
Double checking you want an assign
? You've gone to a lot of trouble to establish defaults which are easily removed. For example, if I pass an options object like { config: { addrs: { listen: ['/ip4/0.0.0.0/tcp/5555'] } } }
I blow away all the other defaults that have been set for peerDiscovery
, protocolMuxing
etc.
Do you need a merge or a smart assign instead?
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.
You are right, it need to be a deepMerge.
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.
look into lodash defaults/deepDefaults instead, they do what you need.
README.md
Outdated
// DHT is passed as its own enabling PeerRouting, ContentRouting and DHT itself components | ||
dht: DHT | ||
config: { // The config object is the part of the config that can go into a file, config.json. | ||
addrs: { // Multiaddrs |
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 peerInfo
already contains multiaddrs. What happens with 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.
They get added/merged. This is to enable the config to be a single JSON file that has the addrs without any complex setup.
README.md
Outdated
peerInfo: _peerInfo // The Identity of your Peer | ||
peerBook: _peerBook // Where peers get tracked, if undefined libp2p will create one instance | ||
modules: { | ||
transport: [ |
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 think some kind of first and second class transport system is needed.
For example: the new ws-star needs the libp2p swarm to dial the server via WS but WS is independent from the swarm.
(Edit: That means that WS would be a first class transport and ws-star a second class)
So any listen/dial stuff for first class transports would be setup before the second class transports are setup (so dialing does not fail)
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.
we had a proposal for transport priorities at some point, but it was rejected.
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.
@dryajov link it please
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.
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.
my bad, this is the correct one - libp2p/js-libp2p-tcp#78
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.
@dryajov that was a proposal for a pseudo priority based on what the module says. It needs to be a user defined.
README.md
Outdated
transport: { | ||
secio: { | ||
spdy: { | ||
'*': '*' |
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.
What does this exactly mean? Is the thing on the left the multiprotocol for secio and the thing on the right the protocol that is actually being dialed?
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 questions.
-
The nested'ness here is to represent order/options. This says "After the transport, always do SECIO, after SECIO you can do SPDY or MPLEX, then do whatever"
-
re:
'*': '*'
- My intention is to mean "Now protocol mux whatever protocol you want".
README.md
Outdated
ann: [] // To announce/share with the network (i.e DNS addr) | ||
notAnn: [] // To keep private | ||
}, | ||
peerDiscovery: { |
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 will the options be passed to the module here?
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 will, will present these details after this first pass on the looks of the config.
README.md
Outdated
interval: 1000 // ms | ||
enabled: true | ||
}, | ||
webrtc-star: { // webrtc-star options |
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.
Not consistent, should be webrtcStar
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 👍
README.md
Outdated
config: { // The config object is the part of the config that can go into a file, config.json. | ||
addrs: { // Multiaddrs | ||
listen: [] // To listen | ||
ann: [] // To announce/share with the network (i.e DNS addr) |
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.
Not a fan of these abbraviations, makes it difficult to understand what it really is unless you have context.
Also, taking inspiration from go-ipfs, it would turn out something like this:
{
addresses: {
swarm: [] // to listen
announce: [] // for sure to announce
noAnnounce: [] // stop these from announcing at all cost
api: ''
gateway: ''
}
}
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.
Ack.
I've continue my work on this PR. Made some progress and overall I like where this is headed (which is eventually enabling simpler configuration and #130). I tried passing the responsibility completely to libp2p to instantiate all of its modules (which was not the case for Transports and Discovery services) but I hit the 🐓&🥚 of transports such as WebRTC that might require special binding modules such as I do want to make sure that everything that goes on If this just sounded like alien 👽 mumbo jumbo to you, do not worry, I'll carry on with the coding and once it is fully ready, it will provide more clarity. If you are interested in understanding, let me know :) |
This sounds like you're recreating IoC (inversion of control) containers all over :) There are some out there that do that already. |
README.md
Outdated
EXPERIMENTAL: { // Experimental features ("behind a flag") | ||
pubsub: true, | ||
dht: true | ||
} |
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.
Make EXPERIMENTAL
part of the config.
README.md
Outdated
mplex: '*' | ||
} | ||
} | ||
} |
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 feature will have to be implemented at the Switch Level
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.
Before merging, I'll remove these options from the README and continue working on this feature design at #201
README.md
Outdated
@@ -101,47 +101,90 @@ libp2p becomes very simple and basically acts as a glue for every module that co | |||
```JavaScript | |||
// Creating a bundle that adds: | |||
// transport: websockets + tcp | |||
// stream-muxing: SPDY | |||
// stream-muxing: spdy & mplex | |||
// crypto-channel: secio | |||
// discovery: multicast-dns | |||
|
|||
const libp2p = require('libp2p') | |||
const TCP = require('libp2p-tcp') | |||
const WS = require('libp2p-websockets') | |||
const spdy = require('libp2p-spdy') |
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.
uppercase
README.md
Outdated
// crypto-channel: secio | ||
// discovery: multicast-dns | ||
|
||
const libp2p = require('libp2p') | ||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const spdy = require('libp2p-spdy') | ||
const mplex = require('libp2p-mplex') |
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.
uppercase + needs to be included in the modules
README.md
Outdated
// crypto-channel: secio | ||
// discovery: multicast-dns | ||
|
||
const libp2p = require('libp2p') | ||
const TCP = require('libp2p-tcp') | ||
const WS = require('libp2p-websockets') | ||
const spdy = require('libp2p-spdy') | ||
const mplex = require('libp2p-mplex') | ||
const secio = require('libp2p-secio') |
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.
uppercase
src/index.js
Outdated
setImmediate(() => discovery.stop(() => {})) | ||
if (this._modules.peerDiscovery) { | ||
this._discovery.forEach((d) => { | ||
setImmediate(() => d.stop(() => {})) |
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.
Something for another PR, but this smothers any error while stopping and means that when callback
is called for stop
all the discoveries might not have stopped yet.
src/index.js
Outdated
@@ -269,25 +296,26 @@ class Node extends EventEmitter { | |||
this._getPeerInfo(peer, (err, peerInfo) => { | |||
if (err) { return callback(err) } | |||
|
|||
this.switch.hangUp(peerInfo, callback) | |||
this._switch.hangUp(peerInfo, callback) | |||
}) | |||
} | |||
|
|||
ping (peer, callback) { | |||
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE) |
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.
Again for another PR - we need to call callback
with this error or the process will quit.
Can we merge and release this as is and finish the examples in separate PRs? |
@alanshaw I am working on this today. I think we need to resolve, #166 (comment) first, which I will work on. With the changes to the config, I feel it's important to make sure we have proper validation there so users aren't confused why their config is not working. I should have this resolved today or tomorrow. |
🚀 awesome @jacobheun! Apologies I hadn't clocked #166 (comment) |
docs: update echo example docs: update libp2p in browser example docs: update pubsub example docs: update peer and content routing examples docs: update discovery mechanisms example docs: update encrypted comms example docs: update protocol and stream muxing example
fixed examples and tests as a result of the config validation test: add config tests and fix bugs fix: linting
Okay, so I think I have everything checked off. I've rebased from master so everything is up to date (@diasdavid fyi on the rebase in case you pull). I've coupled the latest changes into two commits, hopefully this will help keep things clear.
I added tests for the new config validation. There is some custom logic there for peerDiscovery in modules and config, as well as experimental dht. Pubsub: pubsub should now only be initialized if it's enabled via EXPERIMENTAL. Calling any methods on pubsub when it's not enabled will result in an error. Provided there are no changes requested from those 2 latest commits, I think this should be good to go. |
@@ -1,2 +1,2 @@ | |||
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. | |||
javascript() | |||
javascript(['nodejs_versions': ['8.11.3']]) |
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.
@jacobheun @alanshaw switched to Node.js 8 for now until wrtc has builds for node 10
1. Run the listener in window 1, `node listener.js` | ||
2. Run the dialer in window 2, `node dialer.js` | ||
3. Type a message in either window and hit _enter_ | ||
4. Tell youself secrets to your hearts content! |
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 writing the tutorial. Helps for #186
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.
Awesome! Thank you for taking this one to the finish line with flying colors, @jacobheun ❤️
Only test that failed is Jenkins related (classic Mac OS failure) //cc @victorbjelkholm |
## [2.0.2](libp2p/js-libp2p-webrtc@v2.0.1...v2.0.2) (2023-05-15) ### Bug Fixes * use transport manager getListeners to get listen addresses ([libp2p#166](libp2p/js-libp2p-webrtc#166)) ([2e144f9](libp2p/js-libp2p-webrtc@2e144f9))
For #46. Takes into account:
Would love to get a ton of feedback from libp2p users.