hypercore 11.27.13 → 11.27.15
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/index.js +10 -1
- package/lib/replicator.js +13 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -171,7 +171,8 @@ class Hypercore extends EventEmitter {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
if (opts.ondiscoverykey) {
|
|
174
|
-
|
|
174
|
+
const ondiscoverykey = createDiscoveryKeyHandler(opts.ondiscoverykey)
|
|
175
|
+
noiseStream.userData.pair({ protocol: 'hypercore/alpha' }, ondiscoverykey)
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
return outerStream
|
|
@@ -1295,3 +1296,11 @@ function isEncryptionProvider(e) {
|
|
|
1295
1296
|
function isFunction(fn) {
|
|
1296
1297
|
return !!fn && typeof fn === 'function'
|
|
1297
1298
|
}
|
|
1299
|
+
|
|
1300
|
+
function createDiscoveryKeyHandler(fn) {
|
|
1301
|
+
return ondiscoverykey
|
|
1302
|
+
function ondiscoverykey(id) {
|
|
1303
|
+
if (!id || id.byteLength !== 32) throw BAD_ARGUMENT('Invalid discovery key')
|
|
1304
|
+
return fn(id)
|
|
1305
|
+
}
|
|
1306
|
+
}
|
package/lib/replicator.js
CHANGED
|
@@ -526,7 +526,8 @@ class Peer {
|
|
|
526
526
|
hotswaps: 0,
|
|
527
527
|
invalidData: 0,
|
|
528
528
|
invalidRequests: 0,
|
|
529
|
-
backoffs: 0
|
|
529
|
+
backoffs: 0,
|
|
530
|
+
notAvailableBackoffs: 0
|
|
530
531
|
}
|
|
531
532
|
|
|
532
533
|
this.receiverQueue = new ReceiverQueue()
|
|
@@ -1991,7 +1992,8 @@ module.exports = class Replicator {
|
|
|
1991
1992
|
hotswaps: 0,
|
|
1992
1993
|
invalidData: 0,
|
|
1993
1994
|
invalidRequests: 0,
|
|
1994
|
-
backoffs: 0
|
|
1995
|
+
backoffs: 0,
|
|
1996
|
+
notAvailableBackoffs: 0
|
|
1995
1997
|
}
|
|
1996
1998
|
|
|
1997
1999
|
this._attached = new Set()
|
|
@@ -2684,6 +2686,15 @@ module.exports = class Replicator {
|
|
|
2684
2686
|
}
|
|
2685
2687
|
|
|
2686
2688
|
_onnodata(peer, req, reason) {
|
|
2689
|
+
if (reason === NOT_AVAILABLE) {
|
|
2690
|
+
peer.stats.notAvailableBackoffs++
|
|
2691
|
+
this.stats.notAvailableBackoffs++
|
|
2692
|
+
|
|
2693
|
+
if (peer.stats.notAvailableBackoffs >= MAX_BACKOFFS) {
|
|
2694
|
+
peer.paused = true
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2687
2698
|
if (reason === INVALID_REQUEST) {
|
|
2688
2699
|
peer.stats.backoffs++
|
|
2689
2700
|
this.stats.backoffs++
|