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

fix: invoke onProgress callback with DHT queries during routing #1652

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Mar 27, 2023

Allow passing an onProgress callback to the peer/content routers that can receive DHT query events.

Refs #1574

Allow passing an `onProgress` callback to the peer/content routers
that can receive DHT query events.

Experimental for now.
maschad
maschad previously approved these changes Mar 27, 2023
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

ProgessEvents! Woot!

for await (const event of this.dht.findProviders(cid, options)) {
options.onProgress?.(new CustomProgressEvent('content-routing:find-providers:dht:event', event))
Copy link
Member

@maschad maschad Mar 27, 2023

Choose a reason for hiding this comment

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

We could extract these event names to be consts and then reuse them.


const onProgress = sinon.stub()

await drain(nodes[0].contentRouting.findProviders(CID.parse('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB'), {
Copy link
Member

Choose a reason for hiding this comment

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

Where did this CID come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used elsewhere in the test suite 🤷

@achingbrain achingbrain marked this pull request as draft March 28, 2023 14:14
@achingbrain
Copy link
Member Author

Converted to draft because we need to be a bit cleverer about how we expose the ProgressEvent types.

If we don't expose them all we get errors:

await name.resolve(key, {
  onProgress(evt) {
    if (evt.type === 'content-routing:get:dht:event') {

    }
  }
})
This comparison appears to be unintentional because the types '"ipns:resolve:start" |
"ipns:resolve:success" | ..(more events here).. and '"content-routing:get:dht:event"'
have no overlap.

The problem is we want to avoid exposing all the ProgressEvent types for all the content routing/peer routing implementations at the content routing/peer routing interface level. Better to somehow aggregate the types based on the configuration passed to the libp2p factory function in a similar way to #1563

@achingbrain
Copy link
Member Author

Closing in favour of #1975

@achingbrain achingbrain deleted the fix/call-progress-callback-for-content-and-peer-routing branch August 16, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants