feat: add delegated peer and content routing support (#242)

* feat: allow for configuring content and peer routing

* feat: support multiple peer and content routing modules

* docs: add delegated routing example
This commit is contained in:
Jacob Heun
2018-10-19 16:28:28 +02:00
committed by GitHub
parent 3226632d83
commit a95389a28e
18 changed files with 1155 additions and 147 deletions

View File

@ -9,6 +9,8 @@ const PeerId = require('peer-id')
const waterfall = require('async/waterfall')
const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
const validateConfig = require('../src/config').validate
@ -98,6 +100,34 @@ describe('configuration', () => {
expect(validateConfig(options)).to.deep.equal(expected)
})
it('should allow for delegated content and peer routing', () => {
const peerRouter = new DelegatedPeerRouter()
const contentRouter = new DelegatedContentRouter(peerInfo)
const options = {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
peerRouting: [ peerRouter ],
contentRouting: [ contentRouter ]
},
config: {
peerDiscovery: {
bootstrap: {
interval: 1000,
enabled: true
}
}
}
}
expect(validateConfig(options).modules).to.deep.include({
peerRouting: [ peerRouter ],
contentRouting: [ contentRouter ]
})
})
it('should not allow for dht to be enabled without it being provided', () => {
const options = {
peerInfo,