This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Merged
feat: add KadDHT #100
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e722d76
feat: add KadDHT
daviddias 9f56eca
tests
daviddias a75d506
test: disable mdns
daviddias 9e65458
moaaar testsing
daviddias bb73469
unomas
daviddias 44a9670
debug
daviddias c9aeca9
some tests passing (still requires timeout)
daviddias 0d86fdb
moar
daviddias ebeb629
chore: update deps
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
const expect = chai.expect | ||
const parallel = require('async/parallel') | ||
const utils = require('./utils') | ||
const createNode = utils.createNode | ||
const _times = require('lodash.times') | ||
const CID = require('cids') | ||
|
||
describe('.contentRouting', () => { | ||
let nodeA | ||
let nodeB | ||
let nodeC | ||
let nodeD | ||
let nodeE | ||
|
||
before((done) => { | ||
const tasks = _times(5, () => (cb) => { | ||
createNode('/ip4/0.0.0.0/tcp/0', { mdns: false }, (err, node) => { | ||
expect(err).to.not.exist() | ||
node.start((err) => cb(err, node)) | ||
}) | ||
}) | ||
|
||
parallel(tasks, (err, nodes) => { | ||
expect(err).to.not.exist() | ||
nodeA = nodes[0] | ||
nodeB = nodes[1] | ||
nodeC = nodes[2] | ||
nodeD = nodes[3] | ||
nodeE = nodes[4] | ||
|
||
parallel([ | ||
(cb) => nodeA.dial(nodeB.peerInfo, cb), | ||
(cb) => nodeB.dial(nodeC.peerInfo, cb), | ||
(cb) => nodeC.dial(nodeD.peerInfo, cb), | ||
(cb) => nodeD.dial(nodeE.peerInfo, cb), | ||
(cb) => nodeE.dial(nodeA.peerInfo, cb) | ||
], done) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
parallel([ | ||
(cb) => nodeA.stop(cb), | ||
(cb) => nodeB.stop(cb), | ||
(cb) => nodeC.stop(cb), | ||
(cb) => nodeD.stop(cb), | ||
(cb) => nodeE.stop(cb) | ||
], done) | ||
}) | ||
|
||
describe('le ring', () => { | ||
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSySnL') | ||
|
||
it('nodeA.contentRouting.provide', (done) => { | ||
nodeA.contentRouting.provide(cid, done) | ||
}) | ||
|
||
it('nodeE.contentRouting.findProviders for existing record', (done) => { | ||
nodeE.contentRouting.findProviders(cid, 5000, (err, providers) => { | ||
expect(err).to.not.exist() | ||
expect(providers).length.to.be.above(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => { | ||
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn') | ||
|
||
nodeE.contentRouting.findProviders(cid, 5000, (err, providers) => { | ||
expect(err).to.exist() | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
const expect = chai.expect | ||
const parallel = require('async/parallel') | ||
const utils = require('./utils') | ||
const createNode = utils.createNode | ||
const _times = require('lodash.times') | ||
|
||
describe.only('.peerRouting', () => { | ||
let nodeA | ||
let nodeB | ||
let nodeC | ||
let nodeD | ||
let nodeE | ||
|
||
before((done) => { | ||
const tasks = _times(5, () => (cb) => { | ||
createNode('/ip4/0.0.0.0/tcp/0', { mdns: false }, (err, node) => { | ||
expect(err).to.not.exist() | ||
node.start((err) => cb(err, node)) | ||
}) | ||
}) | ||
|
||
parallel(tasks, (err, nodes) => { | ||
expect(err).to.not.exist() | ||
nodeA = nodes[0] | ||
nodeB = nodes[1] | ||
nodeC = nodes[2] | ||
nodeD = nodes[3] | ||
nodeE = nodes[4] | ||
|
||
parallel([ | ||
(cb) => nodeA.dial(nodeB.peerInfo, cb), | ||
(cb) => nodeB.dial(nodeC.peerInfo, cb), | ||
(cb) => nodeC.dial(nodeD.peerInfo, cb), | ||
(cb) => nodeD.dial(nodeE.peerInfo, cb), | ||
(cb) => nodeE.dial(nodeA.peerInfo, cb) | ||
], done) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
parallel([ | ||
(cb) => nodeA.stop(cb), | ||
(cb) => nodeB.stop(cb), | ||
(cb) => nodeC.stop(cb), | ||
(cb) => nodeD.stop(cb), | ||
(cb) => nodeE.stop(cb) | ||
], done) | ||
}) | ||
|
||
describe('el ring', () => { | ||
it('time', (done) => setTimeout(done, 5000)) | ||
|
||
it('nodeA.dial by Id to node C', (done) => { | ||
nodeA.dial(nodeC.peerInfo.id, done) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dignifiedquire this simple test is failing with:
Any clue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added some delay in order to ensure that the network is stabilized (which should not be required) and now I'm getting a different error. The peerRouting.findPeer is returning undefined as the peer and not a error in case of peer not found, making swarm to fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #100 (comment) still persists |
||
|
||
it.skip('nodeB.dial by Id to node D', (done) => {}) | ||
it.skip('nodeC.dial by Id to node E', (done) => {}) | ||
it.skip('nodeB.peerRouting.findPeer(nodeE.peerInfo.id)', (done) => {}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is yielding an empty array of providers immediately, meaning that it failing to find the peer and it is also not respective timeout.