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

feat: enable peer discovery modules by default #209

Merged
merged 8 commits into from
Jun 29, 2018

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Jun 28, 2018

This PR will enable any provided peer discovery modules by default if no configuration for the module is supplied/needed.

As before, modules can be explicitly disabled or enabled by passing config.

This enables pre-configured modules (instances) to be passed and enabled without them having to have a tag and an unused config section.

@ghost ghost assigned alanshaw Jun 28, 2018
@ghost ghost added the status/in-progress In progress label Jun 28, 2018
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.

I preferred being explicit but this is good as well. Mind adding tests?

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

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

@alanshaw if we're going to change the defaults I think we should change them in the ./src/config.js file.

With this change the config will throw an error if someone doesn't supply the config for the peerDiscovery, tests would be great here to catch that. We should set default values here:

js-libp2p/src/config.js

Lines 66 to 72 in 6905f1b

config.modules.peerDiscovery.forEach((discovery) => {
// If it's a function, validate we have configs for it
if (typeof discovery === 'function') {
Joi.reach(schema, 'config.peerDiscovery').keys({
[discovery.tag]: Joi.object().required()
})
}
. This also prevents us from needing to do null checks in the constructor.

@alanshaw
Copy link
Member Author

@jacobheun I don't think that peer discovery module validation code is working properly 😟 . I just found problems with the test for it and fixed them and it fails now:

f753d61

I'm not changing any defaults, just allowing modules that don't require any config or have already been configured to still be registered and started. IMHO it's unnecessary to require a developer to pass a preconfigured module instance and also have to set a config value with { enabled: true } somewhere else in the options. I think it is a reasonable expectation that if I pass a module and say nothing about whether it is enabled or disabled then I want it to be enabled.

I don't think we should validate config for each of the discovery modules - that's outside of the scope of this module. We can't know what all the config options are and keep that info up to date. All we could meaningfully do would be to validate a boolean enabled property, which I think should just be optional anyway - hence this PR.

@alanshaw
Copy link
Member Author

@jacobheun how about now? Is better 😛 ?

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

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

@alanshaw yesssss! This looks great, and thank you for cleaning up the config, so much easier to read. I agree that defaulting to enabled will be easier to users.

Failed ci looks to be CI having a bad day, not an issue with tests.

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.

LGTM. Mind rebasing master onto this branch and wait for CI before the merge?

This PR will enable any provided peer discovery modules by default if no configuration for the module is supplied/needed.

As before, modules can be explicitly disabled or enabled by passing config.

This also enables pre-configured modules (instances) to be passed and enabled without them having to have a `tag` and an unused config section.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
Configuration for the peer discovery modules is now optional so this does not need to be validated. This also cleans up the config module to reduce repetition.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
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.

3 participants