Browse Source

persistent method, rm setEphemeral (#19)

* persistent method, rm setEphemeral

* docs: persistent
v4
David Mark Clements 5 years ago
committed by GitHub
parent
commit
03c5eb512b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      README.md
  2. 8
      index.js
  3. 4
      test.js

4
README.md

@ -242,9 +242,9 @@ as it is more reliable the more routing information the node has.
Explicitly bind the dht node to a certain port/address.
#### `node.setEpehemeral(boolean)`
#### `node.persistent()`
Dynamically convert the node into ephemeral (leave the DHT) or non-ephemeral (join the DHT).
Dynamically convert the node from ephemeral to non-ephemeral (join the DHT).
#### `node.on('ready')`

8
index.js

@ -386,13 +386,7 @@ class DHT extends EventEmitter {
}
}
setEphemeral (ephemeral = false, cb) {
if (ephemeral === true) {
this._io.id = null
this.ephemeral = true
if (cb) process.nextTick(cb)
return
}
persistent (cb) {
this._io.id = this.id
this.bootstrap((err) => {
if (err) {

4
test.js

@ -212,7 +212,7 @@ tape('timeouts', function (t) {
})
})
tape('setEphemeral(false)', function (t) {
tape('persistent', function (t) {
bootstrap(function (port, node) {
const a = dht({ bootstrap: port, ephemeral: true })
const b = dht({ bootstrap: port })
@ -228,7 +228,7 @@ tape('setEphemeral(false)', function (t) {
b.query('hello', key, (err, result) => {
t.error(err)
t.is(result.length, 0)
a.setEphemeral(false, (err) => {
a.persistent((err) => {
t.error(err)
b.query('hello', key, (err, result) => {
t.error(err)

Loading…
Cancel
Save