dht-rpc 6.9.1 → 6.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/io.js CHANGED
@@ -27,6 +27,7 @@ module.exports = class IO {
27
27
  this.ephemeral = true
28
28
  this.congestion = new CongestionWindow(maxWindow)
29
29
  this.networkInterfaces = udx.watchNetworkInterfaces()
30
+ this.suspended = false
30
31
 
31
32
  this.onrequest = onrequest
32
33
  this.onresponse = onresponse
@@ -47,7 +48,7 @@ module.exports = class IO {
47
48
  }
48
49
 
49
50
  onmessage (socket, buffer, { host, port }) {
50
- if (buffer.byteLength < 2 || !(port > 0 && port < 65536)) return
51
+ if (buffer.byteLength < 2 || !(port > 0 && port < 65536) || this.suspended === true) return
51
52
 
52
53
  const from = { id: null, host, port }
53
54
  const state = { start: 1, end: buffer.byteLength, buffer }
@@ -151,6 +152,7 @@ module.exports = class IO {
151
152
  }
152
153
 
153
154
  suspend () {
155
+ this.suspended = true
154
156
  if (this._drainInterval) {
155
157
  clearInterval(this._drainInterval)
156
158
  this._drainInterval = null
@@ -158,6 +160,7 @@ module.exports = class IO {
158
160
  }
159
161
 
160
162
  resume () {
163
+ this.suspended = false
161
164
  const binding = this._binding
162
165
  this._binding = this._rebind(binding)
163
166
  return this._binding
package/lib/query.js CHANGED
@@ -33,6 +33,7 @@ module.exports = class Query extends Readable {
33
33
  this._commiting = false
34
34
  this._session = opts.session || dht.session()
35
35
  this._autoDestroySession = !opts.session
36
+ this._onlyClosestNodes = false
36
37
 
37
38
  this._onvisitbound = this._onvisit.bind(this)
38
39
  this._onerrorbound = this._onerror.bind(this)
@@ -52,6 +53,8 @@ module.exports = class Query extends Readable {
52
53
  this._addPending(replies[i].from, null)
53
54
  }
54
55
  }
56
+
57
+ if (opts.onlyClosestNodes) this._onlyClosestNodes = true
55
58
  }
56
59
 
57
60
  get closestNodes () {
@@ -113,6 +116,8 @@ module.exports = class Query extends Readable {
113
116
  }
114
117
 
115
118
  _addPending (node, ref) {
119
+ if (this._onlyClosestNodes) return false
120
+
116
121
  const addr = node.host + ':' + node.port
117
122
  const refs = this._seen.get(addr)
118
123
  const isCloser = this._isCloser(node.id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dht-rpc",
3
- "version": "6.9.1",
3
+ "version": "6.10.1",
4
4
  "description": "Make RPC calls over a Kademlia based DHT",
5
5
  "main": "index.js",
6
6
  "files": [