libp2p-kad-dht
Advanced tools
Comparing version 0.13.0 to 0.14.0
@@ -0,1 +1,18 @@ | ||
<a name="0.14.0"></a> | ||
# [0.14.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.13.0...v0.14.0) (2018-12-11) | ||
### Chores | ||
* update options timeout property ([#62](https://github.com/libp2p/js-libp2p-kad-dht/issues/62)) ([3046b54](https://github.com/libp2p/js-libp2p-kad-dht/commit/3046b54)) | ||
### BREAKING CHANGES | ||
* get, getMany, findProviders and findPeer do not accept a timeout number anymore. It must be a property of an object options. | ||
Co-Authored-By: vasco-santos <vasco.santos@ua.pt> | ||
<a name="0.13.0"></a> | ||
@@ -2,0 +19,0 @@ # [0.13.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.12.1...v0.13.0) (2018-12-05) |
{ | ||
"name": "libp2p-kad-dht", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "JavaScript implementation of the Kad-DHT for libp2p", | ||
@@ -86,6 +86,6 @@ "leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>", | ||
"Richard Schneider <makaretu@gmail.com>", | ||
"Vasco Santos <vasco.santos@ua.pt>", | ||
"Vasco Santos <vasco.santos@moxy.studio>", | ||
"Vasco Santos <vasco.santos@ua.pt>", | ||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>" | ||
] | ||
} |
@@ -206,3 +206,3 @@ 'use strict' | ||
* @param {Object} options - get options | ||
* @param {number} options.maxTimeout - optional timeout (default: 60000) | ||
* @param {number} options.timeout - optional timeout (default: 60000) | ||
* @param {function(Error, Buffer)} callback | ||
@@ -215,6 +215,2 @@ * @returns {void} | ||
options = {} | ||
} else if (typeof options === 'number') { // This will be deprecated in a next release | ||
options = { | ||
maxTimeout: options | ||
} | ||
} else { | ||
@@ -224,4 +220,6 @@ options = options || {} | ||
if (!options.maxTimeout) { | ||
options.maxTimeout = c.minute | ||
if (!options.maxTimeout && !options.timeout) { | ||
options.timeout = c.minute // default | ||
} else if (options.maxTimeout && !options.timeout) { // TODO this will be deprecated in a next release | ||
options.timeout = options.maxTimeout | ||
} | ||
@@ -238,3 +236,3 @@ | ||
* @param {Object} options - get options | ||
* @param {number} options.maxTimeout - optional timeout (default: 60000) | ||
* @param {number} options.timeout - optional timeout (default: 60000) | ||
* @param {function(Error, Array<{from: PeerId, val: Buffer}>)} callback | ||
@@ -247,6 +245,2 @@ * @returns {void} | ||
options = {} | ||
} else if (typeof options === 'number') { // This will be deprecated in a next release | ||
options = { | ||
maxTimeout: options | ||
} | ||
} else { | ||
@@ -256,4 +250,6 @@ options = options || {} | ||
if (!options.maxTimeout) { | ||
options.maxTimeout = c.minute | ||
if (!options.maxTimeout && !options.timeout) { | ||
options.timeout = 'c.minute' // default | ||
} else if (options.maxTimeout && !options.timeout) { // TODO this will be deprecated in a next release | ||
options.timeout = options.maxTimeout | ||
} | ||
@@ -331,3 +327,3 @@ | ||
// run our query | ||
timeout((cb) => query.run(rtp, cb), options.maxTimeout)(cb) | ||
timeout((cb) => query.run(rtp, cb), options.timeout)(cb) | ||
} | ||
@@ -495,3 +491,3 @@ ], (err) => { | ||
* @param {Object} options - findProviders options | ||
* @param {number} options.maxTimeout - how long the query should maximally run, in milliseconds (default: 60000) | ||
* @param {number} options.timeout - how long the query should maximally run, in milliseconds (default: 60000) | ||
* @param {number} options.maxNumProviders - maximum number of providers to find | ||
@@ -505,6 +501,2 @@ * @param {function(Error, Array<PeerInfo>)} callback | ||
options = {} | ||
} else if (typeof options === 'number') { // This will be deprecated in a next release | ||
options = { | ||
maxTimeout: options | ||
} | ||
} else { | ||
@@ -514,7 +506,12 @@ options = options || {} | ||
options.maxTimeout = options.maxTimeout || c.minute | ||
if (!options.maxTimeout && !options.timeout) { | ||
options.timeout = c.minute // default | ||
} else if (options.maxTimeout && !options.timeout) { // TODO this will be deprecated in a next release | ||
options.timeout = options.maxTimeout | ||
} | ||
options.maxNumProviders = options.maxNumProviders || c.K | ||
this._log('findProviders %s', key.toBaseEncodedString()) | ||
this._findNProviders(key, options.maxTimeout, options.maxNumProviders, callback) | ||
this._findNProviders(key, options.timeout, options.maxNumProviders, callback) | ||
} | ||
@@ -529,3 +526,3 @@ | ||
* @param {Object} options - findPeer options | ||
* @param {number} options.maxTimeout - how long the query should maximally run, in milliseconds (default: 60000) | ||
* @param {number} options.timeout - how long the query should maximally run, in milliseconds (default: 60000) | ||
* @param {function(Error, PeerInfo)} callback | ||
@@ -538,6 +535,2 @@ * @returns {void} | ||
options = {} | ||
} else if (typeof options === 'number') { // This will be deprecated in a next release | ||
options = { | ||
maxTimeout: options | ||
} | ||
} else { | ||
@@ -547,4 +540,6 @@ options = options || {} | ||
if (!options.maxTimeout) { | ||
options.maxTimeout = c.minute | ||
if (!options.maxTimeout && !options.timeout) { | ||
options.timeout = c.minute // default | ||
} else if (options.maxTimeout && !options.timeout) { // TODO this will be deprecated in a next release | ||
options.timeout = options.maxTimeout | ||
} | ||
@@ -610,3 +605,3 @@ | ||
query.run(peers, cb) | ||
}, options.maxTimeout)(cb) | ||
}, options.timeout)(cb) | ||
}, | ||
@@ -613,0 +608,0 @@ (result, cb) => { |
@@ -263,3 +263,3 @@ 'use strict' | ||
* @param {Object} options - get options | ||
* @param {number} options.maxTimeout - optional timeout (default: 60000) | ||
* @param {number} options.timeout - optional timeout (default: 60000) | ||
* @param {function(Error, Record)} callback | ||
@@ -273,3 +273,3 @@ * @returns {void} | ||
waterfall([ | ||
(cb) => dht.getMany(key, 16, options.maxTimeout, cb), | ||
(cb) => dht.getMany(key, 16, options, cb), | ||
(vals, cb) => { | ||
@@ -463,3 +463,3 @@ const recs = vals.map((v) => v.val) | ||
* @param {CID} key | ||
* @param {number} maxTimeout - How long the query should maximally run in milliseconds. | ||
* @param {number} providerTimeout - How long the query should maximally run in milliseconds. | ||
* @param {number} n | ||
@@ -471,3 +471,3 @@ * @param {function(Error, Array<PeerInfo>)} callback | ||
*/ | ||
_findNProviders (key, maxTimeout, n, callback) { | ||
_findNProviders (key, providerTimeout, n, callback) { | ||
let out = new LimitedPeerList(n) | ||
@@ -531,3 +531,3 @@ | ||
timeout((cb) => query.run(peers, cb), maxTimeout)((err) => { | ||
timeout((cb) => query.run(peers, cb), providerTimeout)((err) => { | ||
// combine peers from each path | ||
@@ -534,0 +534,0 @@ paths.forEach((path) => { |
@@ -28,9 +28,9 @@ 'use strict' | ||
* @param {number} [period=300000] - how often to run the the random-walk process, in milliseconds (5min) | ||
* @param {number} [maxTimeout=10000] - how long to wait for the the random-walk query to run, in milliseconds (10s) | ||
* @param {number} [timeout=10000] - how long to wait for the the random-walk query to run, in milliseconds (10s) | ||
* @returns {void} | ||
*/ | ||
start (queries, period, maxTimeout) { | ||
start (queries, period, timeout) { | ||
if (queries == null) { queries = 1 } | ||
if (period == null) { period = 5 * c.minute } | ||
if (maxTimeout == null) { maxTimeout = 10 * c.second } | ||
if (timeout == null) { timeout = 10 * c.second } | ||
// Don't run twice | ||
@@ -70,3 +70,3 @@ if (this._running) { return } | ||
runningHandle.runPeriodically((done) => { | ||
this._walk(queries, maxTimeout, () => done(period)) | ||
this._walk(queries, timeout, () => done(period)) | ||
}, period) | ||
@@ -97,3 +97,3 @@ this._runningHandle = runningHandle | ||
* @param {number} queries | ||
* @param {number} maxTimeout | ||
* @param {number} walkTimeout | ||
* @param {function(Error)} callback | ||
@@ -104,3 +104,3 @@ * @returns {void} | ||
*/ | ||
_walk (queries, maxTimeout, callback) { | ||
_walk (queries, walkTimeout, callback) { | ||
this._kadDHT._log('random-walk:start') | ||
@@ -113,3 +113,3 @@ | ||
this._query(id, cb) | ||
}, maxTimeout)(cb) | ||
}, walkTimeout)(cb) | ||
], (err) => { | ||
@@ -116,0 +116,0 @@ if (err) { |
@@ -80,3 +80,3 @@ /* eslint-env mocha */ | ||
function waitForWellFormedTables (dhts, minPeers, avgPeers, maxTimeout, callback) { | ||
function waitForWellFormedTables (dhts, minPeers, avgPeers, waitTimeout, callback) { | ||
timeout((cb) => { | ||
@@ -102,3 +102,3 @@ retry({ times: 50, interval: 200 }, (cb) => { | ||
}, cb) | ||
}, maxTimeout)(callback) | ||
}, waitTimeout)(callback) | ||
} | ||
@@ -272,3 +272,3 @@ | ||
(cb) => dhtA.put(Buffer.from('/v/hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb), | ||
(cb) => dhtB.get(Buffer.from('/v/hello'), { timeout: 1000 }, cb), | ||
(res, cb) => { | ||
@@ -297,3 +297,3 @@ expect(res).to.eql(Buffer.from('world')) | ||
(cb) => dhtA.put(Buffer.from('hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('hello'), { maxTimeout: 1000 }, cb), | ||
(cb) => dhtB.get(Buffer.from('hello'), { timeout: 1000 }, cb), | ||
(res, cb) => { | ||
@@ -331,3 +331,3 @@ expect(res).to.eql(Buffer.from('world')) | ||
(cb) => dhtA.put(Buffer.from('/ipns/hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('/ipns/hello'), { maxTimeout: 1000 }, cb), | ||
(cb) => dhtB.get(Buffer.from('/ipns/hello'), { timeout: 1000 }, cb), | ||
(res, cb) => { | ||
@@ -356,3 +356,3 @@ expect(res).to.eql(Buffer.from('world')) | ||
(cb) => dhtA.put(Buffer.from('/v2/hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('/v2/hello'), { maxTimeout: 1000 }, cb) | ||
(cb) => dhtB.get(Buffer.from('/v2/hello'), { timeout: 1000 }, cb) | ||
], (err) => { | ||
@@ -385,4 +385,4 @@ expect(err).to.exist() | ||
series([ | ||
(cb) => dhtA.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb), | ||
(cb) => dhtB.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb) | ||
(cb) => dhtA.get(Buffer.from('/v/hello'), { timeout: 1000 }, cb), | ||
(cb) => dhtB.get(Buffer.from('/v/hello'), { timeout: 1000 }, cb) | ||
], (err, results) => { | ||
@@ -422,3 +422,3 @@ expect(err).to.not.exist() | ||
n = (n + 1) % 3 | ||
dhts[n].findProviders(v.cid, { maxTimeout: 5000 }, (err, provs) => { | ||
dhts[n].findProviders(v.cid, { timeout: 5000 }, (err, provs) => { | ||
expect(err).to.not.exist() | ||
@@ -518,3 +518,3 @@ expect(provs).to.have.length(1) | ||
), | ||
(cb) => dhts[0].get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb), | ||
(cb) => dhts[0].get(Buffer.from('/v/hello'), { timeout: 1000 }, cb), | ||
(res, cb) => { | ||
@@ -546,3 +546,3 @@ expect(res).to.eql(Buffer.from('world')) | ||
(cb) => connect(dhts[2], dhts[3], cb), | ||
(cb) => dhts[0].findPeer(ids[3], { maxTimeout: 1000 }, cb), | ||
(cb) => dhts[0].findPeer(ids[3], { timeout: 1000 }, cb), | ||
(res, cb) => { | ||
@@ -891,3 +891,3 @@ expect(res.id.isEqual(ids[3])).to.eql(true) | ||
(cb) => connect(dhtA, dhtB, cb), | ||
(cb) => dhtA.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb) | ||
(cb) => dhtA.get(Buffer.from('/v/hello'), { timeout: 1000 }, cb) | ||
], (err) => { | ||
@@ -950,3 +950,3 @@ expect(err).to.exist() | ||
dhts[0].findPeer(ids[3], { maxTimeout: 1000 }, (err) => { | ||
dhts[0].findPeer(ids[3], { timeout: 1000 }, (err) => { | ||
expect(err).to.exist() | ||
@@ -953,0 +953,0 @@ expect(err.code).to.eql('ERR_LOOKUP_FAILED') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172779
5289