Socket
Socket
Sign inDemoInstall

libp2p-kad-dht

Package Overview
Dependencies
Maintainers
2
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libp2p-kad-dht - npm Package Compare versions

Comparing version 0.6.3 to 0.8.0

20

CHANGELOG.md

@@ -0,1 +1,21 @@

<a name="0.8.0"></a>
# [0.8.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.7.0...v0.8.0) (2018-02-07)
<a name="0.7.0"></a>
# [0.7.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.6.0...v0.7.0) (2018-02-07)
### Bug Fixes
* release providers resources ([#23](https://github.com/libp2p/js-libp2p-kad-dht/issues/23)) ([ff87f4b](https://github.com/libp2p/js-libp2p-kad-dht/commit/ff87f4b))
### Features
* use libp2p-switch ([054e5e5](https://github.com/libp2p/js-libp2p-kad-dht/commit/054e5e5))
<a name="0.6.3"></a>

@@ -2,0 +22,0 @@ ## [0.6.3](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.6.2...v0.6.3) (2018-01-30)

12

package.json
{
"name": "libp2p-kad-dht",
"version": "0.6.3",
"version": "0.8.0",
"description": "JavaScript implementation of the Kad-DHT for libp2p",

@@ -8,3 +8,3 @@ "main": "src/index.js",

"lint": "aegir lint",
"test": "aegir test --target node",
"test": "aegir test -t node",
"build": "aegir build",

@@ -21,3 +21,3 @@ "docs": "aegir docs",

},
"pre-commit": [
"pre-push": [
"lint",

@@ -72,5 +72,5 @@ "test"

"libp2p-multiplex": "~0.5.1",
"libp2p-swarm": "~0.35.1",
"libp2p-tcp": "~0.11.2",
"lodash": "^4.17.4",
"libp2p-switch": "~0.36.0",
"libp2p-tcp": "~0.11.5",
"lodash": "^4.17.5",
"lodash.random": "^3.2.0",

@@ -77,0 +77,0 @@ "lodash.range": "^3.2.0",

@@ -32,18 +32,18 @@ 'use strict'

*
* @param {Swarm} swarm
* @param {Switch} sw
* @param {object} options // {kBucketSize=20, datastore=MemoryDatastore}
*/
constructor (swarm, options) {
assert(swarm, 'libp2p-kad-dht requires a instance of swarmt a')
constructor (sw, options) {
assert(sw, 'libp2p-kad-dht requires a instance of Switch')
options = options || {}
/**
* Local reference to libp2p-swarm.
* Local reference to the libp2p-switch instance
*
* @type {Swarm}
* @type {Switch}
*/
this.swarm = swarm
this.switch = sw
/**
* k-bucket size, defaults to 20.
* k-bucket size, defaults to 20
*

@@ -134,7 +134,7 @@ * @type {number}

get peerInfo () {
return this.swarm._peerInfo
return this.switch._peerInfo
}
get peerBook () {
return this.swarm._peerBook
return this.switch._peerBook
}

@@ -141,0 +141,0 @@

@@ -44,3 +44,3 @@ 'use strict'

// TODO add a way to check if swarm has started or not
// TODO add a way to check if switch has started or not
if (!this.dht.isStarted) {

@@ -53,6 +53,6 @@ return cb(new Error('Can not start network'))

// handle incoming connections
this.dht.swarm.handle(c.PROTOCOL_DHT, this._rpc)
this.dht.switch.handle(c.PROTOCOL_DHT, this._rpc)
// handle new connections
this.dht.swarm.on('peer-mux-established', this._onPeerConnected)
this.dht.switch.on('peer-mux-established', this._onPeerConnected)

@@ -75,5 +75,5 @@ cb()

this._running = false
this.dht.swarm.removeListener('peer-mux-established', this._onPeerConnected)
this.dht.switch.removeListener('peer-mux-established', this._onPeerConnected)
this.dht.swarm.unhandle(c.PROTOCOL_DHT)
this.dht.switch.unhandle(c.PROTOCOL_DHT)
cb()

@@ -97,3 +97,3 @@ }

get isConnected () {
// TODO add a way to check if swarm has started or not
// TODO add a way to check if switch has started or not
return this.dht.isStarted && this.isStarted

@@ -103,3 +103,3 @@ }

/**
* Handle new connections in the swarm.
* Handle new connections in the switch.
*

@@ -115,3 +115,3 @@ * @param {PeerInfo} peer

this.dht.swarm.dial(peer, c.PROTOCOL_DHT, (err, conn) => {
this.dht.switch.dial(peer, c.PROTOCOL_DHT, (err, conn) => {
if (err) {

@@ -149,3 +149,3 @@ return this._log('%s does not support protocol: %s', peer.id.toB58String(), c.PROTOCOL_DHT)

this._log('sending to: %s', to.toB58String())
this.dht.swarm.dial(to, c.PROTOCOL_DHT, (err, conn) => {
this.dht.switch.dial(to, c.PROTOCOL_DHT, (err, conn) => {
if (err) {

@@ -174,3 +174,3 @@ return callback(err)

this.dht.swarm.dial(to, c.PROTOCOL_DHT, (err, conn) => {
this.dht.switch.dial(to, c.PROTOCOL_DHT, (err, conn) => {
if (err) {

@@ -177,0 +177,0 @@ return callback(err)

@@ -46,3 +46,3 @@ 'use strict'

/**
* Handle incoming streams from the swarm, on the dht protocol.
* Handle incoming streams from the Switch, on the dht protocol.
*

@@ -49,0 +49,0 @@ * @param {string} protocol

@@ -19,3 +19,3 @@ /* eslint-env mocha */

const PeerBook = require('peer-book')
const Swarm = require('libp2p-swarm')
const Switch = require('libp2p-switch')
const TCP = require('libp2p-tcp')

@@ -59,10 +59,10 @@ const Multiplex = require('libp2p-multiplex')

it('create', () => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm, { kBucketSize: 5 })
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw, { kBucketSize: 5 })
expect(dht).to.have.property('peerInfo').eql(peerInfos[0])
expect(dht).to.have.property('swarm').eql(swarm)
expect(dht).to.have.property('switch').eql(sw)
expect(dht).to.have.property('kBucketSize', 5)

@@ -207,4 +207,4 @@ expect(dht).to.have.property('routingTable')

parallel([
(cb) => dhtA.swarm.dial(peerB.id, cb),
(cb) => dhtB.swarm.dial(peerA.id, cb)
(cb) => dhtA.switch.dial(peerB.id, cb),
(cb) => dhtB.switch.dial(peerA.id, cb)
], done)

@@ -335,7 +335,7 @@ })

it('_nearestPeersToQuery', (done) => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw)

@@ -354,7 +354,7 @@ dht.peerBook.put(peerInfos[1])

it('_betterPeersToQuery', (done) => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw)

@@ -377,7 +377,7 @@ dht.peerBook.put(peerInfos[1])

it('invalid record (missing public key)', (done) => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw)

@@ -403,7 +403,7 @@ // Not putting the peer info into the peerbook

it('valid record - signed', (done) => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw)

@@ -425,7 +425,7 @@ dht.peerBook.put(peerInfos[1])

it('valid record - not signed', (done) => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw)

@@ -462,3 +462,3 @@ dht.peerBook.put(peerInfos[1])

target.id._privKey = null
a.swarm.dial(target, callback)
a.switch.dial(target, callback)
}

@@ -465,0 +465,0 @@

@@ -13,3 +13,3 @@ /* eslint-env mocha */

const PeerBook = require('peer-book')
const Swarm = require('libp2p-swarm')
const Switch = require('libp2p-switch')
const TCP = require('libp2p-tcp')

@@ -35,10 +35,10 @@ const Multiplex = require('libp2p-multiplex')

peerInfos = result
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
dht = new KadDHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
dht = new KadDHT(sw)
series([
(cb) => swarm.listen(cb),
(cb) => sw.start(cb),
(cb) => dht.start(cb)

@@ -53,3 +53,3 @@ ], done)

(cb) => dht.stop(cb),
(cb) => dht.swarm.close(cb)
(cb) => dht.switch.stop(cb)
], done)

@@ -70,3 +70,3 @@ })

// mock it
dht.swarm.dial = (peer, protocol, callback) => {
dht.switch.dial = (peer, protocol, callback) => {
expect(protocol).to.eql('/ipfs/kad/1.0.0')

@@ -112,3 +112,3 @@ const msg = new Message(Message.TYPES.FIND_NODE, Buffer.from('world'), 0)

// mock it
dht.swarm.dial = (peer, protocol, callback) => {
dht.switch.dial = (peer, protocol, callback) => {
expect(protocol).to.eql('/ipfs/kad/1.0.0')

@@ -115,0 +115,0 @@ const rawConn = {

@@ -9,3 +9,3 @@ /* eslint-env mocha */

const PeerBook = require('peer-book')
const Swarm = require('libp2p-swarm')
const Switch = require('libp2p-switch')
const TCP = require('libp2p-tcp')

@@ -31,7 +31,7 @@ const Multiplex = require('libp2p-multiplex')

peerInfos = result
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
dht = new DHT(swarm)
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
dht = new DHT(sw)

@@ -46,3 +46,3 @@ done()

// mock this so we can dial non existing peers
dht.swarm.dial = (peer, callback) => callback()
dht.switch.dial = (peer, callback) => callback()

@@ -79,3 +79,3 @@ let i = 0

// mock this so we can dial non existing peers
dht.swarm.dial = (peer, callback) => callback()
dht.switch.dial = (peer, callback) => callback()

@@ -96,3 +96,3 @@ const query = (p, cb) => cb(new Error('fail'))

// mock this so we can dial non existing peers
dht.swarm.dial = (peer, callback) => callback()
dht.switch.dial = (peer, callback) => callback()

@@ -99,0 +99,0 @@ const query = (p, cb) => {

@@ -17,3 +17,7 @@ /* eslint-env mocha */

describe('RoutingTable', () => {
function createPeers (n, callback) {
map(range(n), (i, cb) => PeerId.create({bits: 1024}, cb), callback)
}
describe('Routing Table', () => {
let table

@@ -33,4 +37,6 @@

this.timeout(20 * 1000)
createPeers(20, (err, peers) => {
expect(err).to.not.exist()
waterfall([

@@ -42,7 +48,7 @@ (cb) => each(range(1000), (n, cb) => {

const id = peers[random(peers.length - 1)]
utils.convertPeerId(id, (err, key) => {
expect(err).to.not.exist()
expect(
table.closestPeers(key, 5).length
).to.be.above(0)
expect(table.closestPeers(key, 5).length)
.to.be.above(0)
cb()

@@ -123,5 +129,1 @@ })

})
function createPeers (n, callback) {
map(range(n), (i, cb) => PeerId.create({bits: 1024}, cb), callback)
}

@@ -11,3 +11,3 @@ /* eslint-env mocha */

const PeerBook = require('peer-book')
const Swarm = require('libp2p-swarm')
const Switch = require('libp2p-switch')
const TCP = require('libp2p-tcp')

@@ -38,7 +38,7 @@ const Multiplex = require('libp2p-multiplex')

it('calls back with the response', (done) => {
const swarm = new Swarm(peerInfos[0], new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const dht = new KadDHT(swarm, { kBucketSize: 5 })
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(sw, { kBucketSize: 5 })

@@ -45,0 +45,0 @@ dht.peerBook.put(peerInfos[1])

@@ -14,3 +14,3 @@ 'use strict'

const crypto = require('libp2p-crypto')
const Swarm = require('libp2p-swarm')
const Switch = require('libp2p-switch')
const TCP = require('libp2p-tcp')

@@ -43,8 +43,8 @@ const Multiplex = require('libp2p-multiplex')

const swarm = new Swarm(p, new PeerBook())
swarm.transport.add('tcp', new TCP())
swarm.connection.addStreamMuxer(Multiplex)
swarm.connection.reuse()
const sw = new Switch(p, new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Multiplex)
sw.connection.reuse()
const dht = new KadDHT(swarm)
const dht = new KadDHT(sw)

@@ -61,3 +61,3 @@ dht.validators.v = {

series([
(cb) => swarm.listen(cb),
(cb) => sw.start(cb),
(cb) => dht.start(cb)

@@ -78,3 +78,3 @@ ], (err) => {

(cb) => n.stop(cb),
(cb) => n.swarm.close(cb)
(cb) => n.switch.stop(cb)
], cb)

@@ -81,0 +81,0 @@ }, (err) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc