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.12.0 to 0.12.1

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="0.12.1"></a>
## [0.12.1](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.12.0...v0.12.1) (2018-11-30)
### Features
* allow configurable validators and selectors ([#57](https://github.com/libp2p/js-libp2p-kad-dht/issues/57)) ([b731a1d](https://github.com/libp2p/js-libp2p-kad-dht/commit/b731a1d))
<a name="0.12.0"></a>

@@ -2,0 +12,0 @@ # [0.12.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.11.1...v0.12.0) (2018-11-22)

2

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

@@ -5,0 +5,0 @@ "leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",

@@ -39,2 +39,4 @@ 'use strict'

* @param {boolean} options.enabledDiscovery enable dht discovery (default true)
* @param {object} options.validators validators object with namespace as keys and function(key, record, callback)
* @param {object} options.selectors selectors object with namespace as keys and function(key, records)
*/

@@ -44,2 +46,4 @@ constructor (sw, options) {

options = options || {}
options.validators = options.validators
options.selectors = options.selectors

@@ -88,5 +92,12 @@ /**

this.validators = { pk: libp2pRecord.validator.validators.pk }
this.selectors = { pk: libp2pRecord.selection.selectors.pk }
this.validators = {
pk: libp2pRecord.validator.validators.pk,
...options.validators
}
this.selectors = {
pk: libp2pRecord.selection.selectors.pk,
...options.selectors
}
this.network = new Network(this)

@@ -93,0 +104,0 @@

@@ -142,2 +142,25 @@ /* eslint-env mocha */

it('create with validators and selectors', () => {
const sw = new Switch(peerInfos[0], new PeerBook())
sw.transport.add('tcp', new TCP())
sw.connection.addStreamMuxer(Mplex)
sw.connection.reuse()
const dht = new KadDHT(sw, {
validators: {
ipns: {
func: (key, record, cb) => cb()
}
},
selectors: {
ipns: (key, records) => 0
}
})
expect(dht).to.have.property('peerInfo').eql(peerInfos[0])
expect(dht).to.have.property('switch').eql(sw)
expect(dht).to.have.property('routingTable')
expect(dht.validators).to.have.property('ipns')
expect(dht.selectors).to.have.property('ipns')
})
it('should be able to start and stop', function (done) {

@@ -284,2 +307,35 @@ const sw = new Switch(peerInfos[0], new PeerBook())

it('put - get using key from provided validator and selector', function (done) {
this.timeout(10 * 1000)
const tdht = new TestDHT()
tdht.spawn(2, {
validators: {
ipns: {
func: (key, record, cb) => cb()
}
},
selectors: {
ipns: (key, records) => 0
}
}, (err, dhts) => {
expect(err).to.not.exist()
const dhtA = dhts[0]
const dhtB = dhts[1]
waterfall([
(cb) => connect(dhtA, dhtB, cb),
(cb) => dhtA.put(Buffer.from('/ipns/hello'), Buffer.from('world'), cb),
(cb) => dhtB.get(Buffer.from('/ipns/hello'), { maxTimeout: 1000 }, cb),
(res, cb) => {
expect(res).to.eql(Buffer.from('world'))
cb()
}
], (err) => {
expect(err).to.not.exist()
tdht.teardown(done)
})
})
})
it('put - get should fail if unrecognized key prefix in get', function (done) {

@@ -286,0 +342,0 @@ this.timeout(10 * 1000)

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