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

Delegated Peer and Content Routing #242

Merged
merged 19 commits into from
Oct 19, 2018
Merged

Conversation

jacobheun
Copy link
Contributor

@jacobheun jacobheun commented Aug 22, 2018

This is ready!

This PR adds the ability to configure delegate routing modules, #120.

I've included an example of the delegated routing working.

Note: until ipfs/kubo#4595 is released, running a compatible local node for the example requires building go-ipfs from the feat/delegated-routing branch and running that locally. This will also not work in production until a Gateway node is deployed with delegated routing support: ipfs/infra#426.

This also provides libp2p users with the ability to create and supply their own peer and content routing modules.

@ghost ghost assigned jacobheun Aug 22, 2018
@ghost ghost added the status/in-progress In progress label Aug 22, 2018
src/index.js Outdated
this.contentRouting = contentRouting(this)
// If peer or content routing modules have been provided, use those, otherwise use the dht
this.peerRouting = this._modules.peerRouting || peerRouting(this)
this.contentRouting = this._modules.contentRouting || contentRouting(this)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@diasdavid my original thought was to either use the provided peer and content routing modules, or the dht. After finishing up the core of the work and thinking more about the example and usage I feel like it would be better to use both if they are enabled. The thought being that leveraging a delegate is a good way to bootstrap a node into the network while it grows its own network, but that overtime its network would have a lot of the information. We could also change peer and content routing to allow for multiple modules and in the future potentially introduce some priority logic for ordering the calls to prevent flooding the network, if that becomes an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Think of it as a Stream Muxer or a Transport, you can use one, many, all the same time, disable some, you name it :)

@jacobheun
Copy link
Contributor Author

Delegated routing is ready for review! The IPFS updates aren't finished or deployed yet, but this is ready for when it is!

cc: @lgierth

@jacobheun jacobheun changed the title WIP: Feat/peer content routing Delegated Peer and Content routing Sep 27, 2018
@jacobheun jacobheun changed the title Delegated Peer and Content routing Delegated Peer and Content Routing Sep 27, 2018
Copy link
Member

@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.

@jacobheun the PR seems good! The example rocks 💪

Added just some small notes.

Note, some of them are the same problem but in different files. I reported all of them (I hope), to guarantee that you do not forget any.

import WebRTCStar from 'libp2p-webrtc-star';
import MPLEX from 'libp2p-mplex';
import SECIO from 'libp2p-secio';
import KadDHT from 'libp2p-kad-dht';
Copy link
Member

Choose a reason for hiding this comment

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

Not problematic, but since it is disabled, we could not have it has a dependency and have null in the config.

if (typeof options === 'function') {
callback = options
options = {}
} else if (typeof options === 'number') {
Copy link
Member

Choose a reason for hiding this comment

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

Can you just add a comment here for future deprecation?


// If we don't have any results, we need to provide an error to keep trying
if (!results || Object.keys(results).length === 0) {
return cb(Object.assign(new Error('not found'), {
Copy link
Member

Choose a reason for hiding this comment

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

use err-code module here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I completely forgot to switch that over!

*/
findProviders: (key, options, callback) => {
if (routers.length === 0) {
return callback(new Error('No content routers available'))
Copy link
Member

Choose a reason for hiding this comment

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

add err-code here?

* @returns {void}
*/
findProviders: (key, options, callback) => {
if (routers.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I would simply use

if (!routers.length)

But it is a detail. You have this in several places if you agree please change them all, otherwise leave like this

if (err && err.code !== 'NOT_FOUND') {
return callback(err)
}
results = results || null
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be?

results = results || []

})

it('nodeE.contentRouting.findProviders for existing record', (done) => {
nodeE.contentRouting.findProviders(cid, 5000, (err, providers) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use themaxTimeout instead of 5000, as we intend to deprecate it in the future.

it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => {
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')

nodeE.contentRouting.findProviders(cid, 5000, (err, providers) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use themaxTimeout instead of 5000, as we intend to deprecate it in the future.

expect(err).to.not.exist()
expect(providers).to.have.length(0)
done()
nodeA.contentRouting.findProviders('a cid', 5000, (err, results) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use themaxTimeout instead of 5000, as we intend to deprecate it in the future.

const dhtStub = sinon.stub(nodeA._dht, 'findProviders').callsArgWith(2, null, [])
const delegateStub = sinon.stub(delegate, 'findProviders').callsArgWith(2, null, results)

nodeA.contentRouting.findProviders('a cid', 5000, (err, results) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use themaxTimeout instead of 5000, as we intend to deprecate it in the future.

@jacobheun
Copy link
Contributor Author

@vasco-santos I pushed updates from your feedback. I also needed to re-work some of the code in the docs to fix linting there. The logic is unchanged though.

@vasco-santos
Copy link
Member

Looks good to me!

@jacobheun jacobheun force-pushed the feat/peer-content-routing branch 2 times, most recently from bfb527c to f05e612 Compare October 1, 2018 15:29
@jacobheun jacobheun merged commit a95389a into master Oct 19, 2018
@ghost ghost removed the status/in-progress In progress label Oct 19, 2018
@jacobheun jacobheun deleted the feat/peer-content-routing branch October 19, 2018 14:28
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
Increases default inactivity timeout to 5 minutes.

closes libp2p#239
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
## [6.0.9](libp2p/js-libp2p-tcp@v6.0.8...v6.0.9) (2023-01-17)

### Bug Fixes

* increase default socket close timeout ([libp2p#242](libp2p/js-libp2p-tcp#242)) ([a64ba41](libp2p/js-libp2p-tcp@a64ba41)), closes [libp2p#239](libp2p/js-libp2p-tcp#239)

### Trivial Changes

* replace err-code with CodeError ([libp2p#240](libp2p/js-libp2p-tcp#240)) ([5c44562](libp2p/js-libp2p-tcp@5c44562)), closes [js-libp2p#1269](libp2p#1269)
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
## [7.1.2](libp2p/js-libp2p-mplex@v7.1.1...v7.1.2) (2023-03-21)

### Trivial Changes

* replace err-code with CodeError ([libp2p#242](libp2p/js-libp2p-mplex#242)) ([8d58a3b](libp2p/js-libp2p-mplex@8d58a3b)), closes [js-libp2p#1269](libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([54de88d](libp2p/js-libp2p-mplex@54de88d))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([df03e8d](libp2p/js-libp2p-mplex@df03e8d))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([9c3f235](libp2p/js-libp2p-mplex@9c3f235))

### Dependencies

* **dev:** bump typescript from 4.9.5 to 5.0.2 ([libp2p#256](libp2p/js-libp2p-mplex#256)) ([a3590af](libp2p/js-libp2p-mplex@a3590af))
* **dev:** Upgrade aegir to 38.1.7 ([libp2p#257](libp2p/js-libp2p-mplex#257)) ([e0bf45a](libp2p/js-libp2p-mplex@e0bf45a))
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.

None yet

3 participants