dht-rpc 6.13.0 → 6.14.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/README.md CHANGED
@@ -110,7 +110,7 @@ Options include:
110
110
 
111
111
  ``` js
112
112
  {
113
- // A list of bootstrap nodes
113
+ // A list of bootstrap nodes. Optionally prefix a suggested-IP, i.e. '192.168.1.10@bootstrap-node.com:24242'
114
114
  bootstrap: [ 'bootstrap-node.com:24242', ... ],
115
115
  // Optionally pass in array of { host, port } to add to the routing table if you know any peers
116
116
  nodes: [{ host, port }, ...],
package/index.js CHANGED
@@ -661,18 +661,34 @@ class DHT extends EventEmitter {
661
661
  }
662
662
 
663
663
  async * _resolveBootstrapNodes () {
664
- for (const node of this.bootstrapNodes) {
665
- let address
666
- try {
667
- address = await this.udx.lookup(node.host, { family: 4 })
668
- } catch {
669
- continue
664
+ for (let { host, port } of this.bootstrapNodes) {
665
+ let doLookup = false
666
+
667
+ if (host.indexOf('@') === -1) {
668
+ doLookup = true
669
+ } else {
670
+ const [suggestedIP, fallbackHost] = host.split('@')
671
+ try {
672
+ await this.ping({ host: suggestedIP, port })
673
+ host = suggestedIP
674
+ } catch {
675
+ host = fallbackHost
676
+ doLookup = true
677
+ }
678
+ }
679
+
680
+ if (doLookup) {
681
+ try {
682
+ host = UDX.isIPv4(host) ? host : (await this.udx.lookup(host, { family: 4 })).host
683
+ } catch {
684
+ continue
685
+ }
670
686
  }
671
687
 
672
688
  yield {
673
- id: peer.id(address.host, node.port),
674
- host: address.host,
675
- port: node.port
689
+ id: peer.id(host, port),
690
+ host,
691
+ port
676
692
  }
677
693
  }
678
694
  }
package/lib/io.js CHANGED
@@ -497,6 +497,6 @@ function decodeReply (from, state) {
497
497
  }
498
498
 
499
499
  function validateId (id, from) {
500
- const expected = peer.id(from.host, from.port, b4a.allocUnsafeSlow(32))
500
+ const expected = peer.id(from.host, from.port)
501
501
  return b4a.equals(expected, id) ? expected : null
502
502
  }
package/lib/peer.js CHANGED
@@ -17,7 +17,7 @@ const ipv4 = {
17
17
 
18
18
  module.exports = { id, ipv4, ipv4Array: c.array(ipv4) }
19
19
 
20
- function id (host, port, out = b4a.allocUnsafe(32)) {
20
+ function id (host, port, out = b4a.allocUnsafeSlow(32)) {
21
21
  const addr = out.subarray(0, 6)
22
22
  ipv4.encode(
23
23
  { start: 0, end: 6, buffer: addr },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dht-rpc",
3
- "version": "6.13.0",
3
+ "version": "6.14.1",
4
4
  "description": "Make RPC calls over a Kademlia based DHT",
5
5
  "main": "index.js",
6
6
  "files": [