Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dht-rpc

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dht-rpc - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

32

index.js

@@ -102,5 +102,6 @@ var udp = require('udp-request')

DHT.prototype.closest = function (query, opts, cb) {
if (typeof opts === 'function') return this.closest(query, null, opts)
DHT.prototype.update = function (query, opts, cb) {
if (typeof opts === 'function') return this.update(query, null, opts)
if (!opts) opts = {}
if (opts.query) opts.verbose = true
opts.token = true

@@ -124,27 +125,2 @@ return collect(queryStream(this, query, opts), cb)

DHT.prototype._closestNodes = function (target, opts, cb) {
var nodes = opts.nodes || opts.node
if (nodes) {
if (!Array.isArray(nodes)) nodes = [nodes]
process.nextTick(function () {
cb(null, nodes)
})
return null
}
var qs = this.get({
command: '_find_node',
target: target
})
qs.resume()
qs.on('error', noop)
qs.on('end', function () {
cb(null, qs.closest)
})
return qs
}
DHT.prototype.holepunch = function (peer, referrer, cb) {

@@ -302,3 +278,3 @@ this._holepunch(parseAddr(peer), parseAddr(referrer), cb)

var method = request.roundtripToken ? 'closest' : 'query'
var method = request.roundtripToken ? 'update' : 'query'

@@ -305,0 +281,0 @@ if (!this.emit(method + ':' + request.command, query, callback) && !this.emit(method, query, callback)) callback()

2

package.json
{
"name": "dht-rpc",
"version": "1.0.3",
"version": "2.0.0",
"description": "Make RPC calls over a Kademlia based DHT.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -42,3 +42,3 @@ # dht-rpc

// When we are the closest node and someone is sending us a "store" command
node.on('closest:store', function (query, cb) {
node.on('update:values', function (query, cb) {
if (!query.value) return cb()

@@ -54,3 +54,3 @@

// When someone is querying for a "lookup" command
node.on('query:lookup', function (query, cb) {
node.on('query:values', function (query, cb) {
var value = values[query.target.toString('hex')]

@@ -72,3 +72,3 @@ cb(null, value)

node.closest({command: 'store', target: sha256(val), value: val}, function (err, res) {
node.update({command: 'values', target: sha256(val), value: val}, function (err, res) {
if (err) throw err

@@ -82,3 +82,3 @@ console.log('Inserted', sha256(val).toString('hex'))

``` js
node.query({command: 'lookup', target: new Buffer(hexFromAbove, 'hex')})
node.query({command: 'values', target: new Buffer(hexFromAbove, 'hex')})
.on('data', function (data) {

@@ -135,6 +135,6 @@ if (data.value && sha256(data.value).toString('hex') === hexFromAbove) {

#### `var stream = node.closest(query, [options], [callback])`
#### `var stream = node.update(query, [options], [callback])`
Same as a query but will trigger a closest query on the 20 closest nodes (distance between node ids and target) after the query finishes.
Per default the stream will only contain results from the closest query. To include the query results also pass the `verbose: true` option.
Same as a query but will trigger an update query on the 20 closest nodes (distance between node ids and target) after the query finishes.
Per default the stream will only contain results from the closest query. To include the query results also pass the `query: true` option.

@@ -147,5 +147,5 @@ #### `node.on('query:{command}', data, callback)`

#### `node.on('closest:{command}', data, callback)`
#### `node.on('update:{command}', data, callback)`
Called when a closest query is invoked. The `data.node` is also guaranteed to have roundtripped to this dht before, meaning that you can trust that the host, port was not spoofed.
Called when an update query is invoked. The `data.node` is also guaranteed to have roundtripped to this dht before, meaning that you can trust that the host, port was not spoofed.

@@ -152,0 +152,0 @@ #### `node.ready(callback)`

@@ -5,3 +5,3 @@ var tape = require('tape')

tape('simple closest', function (t) {
tape('simple update', function (t) {
bootstrap(function (port, node) {

@@ -11,3 +11,3 @@ var a = dht({bootstrap: port})

a.on('closest:echo', function (data, callback) {
a.on('update:echo', function (data, callback) {
t.ok(data.roundtripToken, 'has roundtrip token')

@@ -25,3 +25,3 @@ t.same(data.value, new Buffer('Hello, World!'), 'expected data')

b.closest(data, function (err, responses) {
b.update(data, function (err, responses) {
a.destroy()

@@ -115,7 +115,7 @@ b.destroy()

tape('targeted closest', function (t) {
tape('targeted update', function (t) {
bootstrap(function (port, node) {
var a = dht({bootstrap: port})
a.on('closest:echo', function (data, cb) {
a.on('update:echo', function (data, cb) {
t.pass('in echo')

@@ -127,3 +127,3 @@ cb(null, data.value)

b.on('closest:echo', function (data, cb) {
b.on('update:echo', function (data, cb) {
t.fail('should not hit me')

@@ -137,3 +137,3 @@ cb()

client.closest({
client.update({
command: 'echo',

@@ -175,3 +175,3 @@ value: new Buffer('hi'),

me.closest({command: 'kv', target: key, value: new Buffer('hello')}, function (err, responses) {
me.update({command: 'kv', target: key, value: new Buffer('hello')}, function (err, responses) {
t.error(err, 'no error')

@@ -205,3 +205,3 @@ t.same(closest, 20, '20 closest nodes')

node.on('closest:kv', function (data, cb) {
node.on('update:kv', function (data, cb) {
closest++

@@ -208,0 +208,0 @@ value = data.value

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