Skip to content

Commit

Permalink
Retry indefinitely until bootstrap nodes respond (fix #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Jul 8, 2015
1 parent fa75545 commit c211011
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions client.js
Expand Up @@ -83,6 +83,7 @@ function DHT (opts) {
self._binding = false
self._port = null
self._ipv = opts.ipv || 4
self._rotateInterval = null

/**
* Query Handlers table
Expand Down Expand Up @@ -280,7 +281,6 @@ DHT.prototype.destroy = function (cb) {
self.transactions = null
self.peers = null

clearTimeout(self._bootstrapTimeout)
clearInterval(self._rotateInterval)

self.socket.on('close', cb)
Expand Down Expand Up @@ -480,19 +480,21 @@ DHT.prototype._bootstrap = function (nodes) {
self.emit('ready')
}
})
startBootstrapTimeout()
}
lookup()

// TODO: keep retrying after one failure
self._bootstrapTimeout = setTimeout(function () {
if (self.destroyed) return
// If 0 nodes are in the table after a timeout, retry with bootstrap nodes
if (self.nodes.count() === 0) {
self._debug('No DHT bootstrap nodes replied, retry')
lookup()
}
}, BOOTSTRAP_TIMEOUT)
if (self._bootstrapTimeout.unref) self._bootstrapTimeout.unref()
function startBootstrapTimeout () {
setTimeout(function () {
if (self.destroyed) return
// If 0 nodes are in the table after a timeout, retry with bootstrap nodes
if (self.nodes.count() === 0) {
self._debug('No DHT bootstrap nodes replied, retry')
lookup()
}
}, BOOTSTRAP_TIMEOUT).unref()
}

lookup()
})
}

Expand Down

0 comments on commit c211011

Please sign in to comment.