Skip to content

feat: add topic validators to pubsub #75

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

Merged
merged 3 commits into from
May 27, 2020
Merged

Conversation

wemeetagain
Copy link
Member

Clean up validation in pubsub, add topic validator functions

  • validate method now has additional peer arg and triggers topic-specific validation functions
  • topicValidator is Map<string, (topic, peer, message) => unknown>
    • topic validators can be added / removed here
  • topic validation results can have additional processing overridden with _processTopicValidatorResult - default to truthy results passing validation

cc @jacobheun

@wemeetagain wemeetagain requested review from vasco-santos and a team May 23, 2020 20:37
@wemeetagain wemeetagain force-pushed the cayman/topic-validators branch from db5afb5 to 5712fd1 Compare May 23, 2020 20:57
@codecov-commenter
Copy link

codecov-commenter commented May 23, 2020

Codecov Report

Merging #75 into master will increase coverage by 0.17%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #75      +/-   ##
==========================================
+ Coverage   85.51%   85.68%   +0.17%     
==========================================
  Files          11       11              
  Lines         497      510      +13     
==========================================
+ Hits          425      437      +12     
- Misses         72       73       +1     
Impacted Files Coverage Δ
src/pubsub.js 85.71% <94.11%> (+0.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05fbf3c...9e35ed6. Read the comment docs.

Copy link
Collaborator

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

Is there any reason for not adding this to libp2p-pubsub? I think that this is the generic implementation and I would only expect the extended topic validators logic to be in this module

@wemeetagain
Copy link
Member Author

Is there any reason for not adding this to libp2p-pubsub?

I've been viewing these two open PRs (#75 and #74) as sort of clean up tasks so that this src/pubsub.js may be merged into libp2p-pubsub. (And so that this pubsub impl "has what we need" for the gossipsub v1.1 upgrade)
I think for this one, one of the bigger reasons I didnt' PR directly into libp2p-pubsub is bc this would be a breaking API change to the validate function. (from async (message: RPC.Message) => boolean to async (peer: Peer, message: RPC.Message) => boolean)

Somehow it seemed simpler to explore this with my pseudo libp2p-pubsub impl before having the broader discussion about merging breaking functionality back upstream.

Happy to make the PR to libp2p-pubsub if you think thats better tho.

@wemeetagain wemeetagain requested a review from jacobheun May 25, 2020 16:32
@vasco-santos
Copy link
Collaborator

@wemeetagain seems a good approach. We can start here and then iterate to js-libp2p-pubsub then! I will make sure to review this PR tomorrow

src/pubsub.js Outdated
const validatorFn = this.topicValidators.get(topic)
if (validatorFn) {
const result = validatorFn(topic, peer, message)
if (!this._processTopicValidatorResult(topic, peer, message, result)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return the function result instead of the condition?

Copy link
Member Author

@wemeetagain wemeetagain May 27, 2020

Choose a reason for hiding this comment

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

Process all the results instead of bailing after the first falsy processed result?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that this was changed according to what I was thinking :)

Copy link
Collaborator

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM

@wemeetagain wemeetagain merged commit 69323a0 into master May 27, 2020
@wemeetagain wemeetagain deleted the cayman/topic-validators branch May 27, 2020 19:36
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.

4 participants