cabal-core
Advanced tools
Comparing version 7.0.1 to 7.1.0
{ | ||
"name": "cabal-core", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"description": " p2p db functions for chat ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
30
swarm.js
@@ -6,5 +6,14 @@ var pump = require('pump') | ||
// If a peer triggers one of these, don't just throttle them: block them for | ||
// the rest of the session. | ||
var knownIncompatibilityErrors = { | ||
'First shared hypercore must be the same': true | ||
} | ||
module.exports = function (cabal, cb) { | ||
cb = cb || function () {} | ||
var blocked = {} | ||
var connected = {} | ||
cabal.getLocalKey(function (err, key) { | ||
@@ -17,4 +26,6 @@ if (err) return cb(err) | ||
var remoteKey = info.id.toString('hex') | ||
conn.once('error', function () { if (remoteKey) cabal._removeConnection(remoteKey) }) | ||
conn.once('end', function () { if (remoteKey) cabal._removeConnection(remoteKey) }) | ||
var netId = info.host + ':' + info.port | ||
if (blocked[netId]) return | ||
blocked[netId] = true | ||
connected[netId] = connected[netId] ? connected[netId]+1 : 1 | ||
@@ -24,2 +35,17 @@ var r = cabal.replicate() | ||
if (err) debug('ERROR', err) | ||
cabal._removeConnection(remoteKey) | ||
// If the error is one that indicates incompatibility, just leave them | ||
// blocked for the rest of this session. | ||
if (err && knownIncompatibilityErrors[err.message]) { | ||
return | ||
} | ||
// Each disconnects adds 2 powers of two, so: 16 seconds, 64 seconds, | ||
// 256 seconds, etc. | ||
var blockedDuration = Math.pow(2, (connected[netId] + 1) * 2) * 1000 | ||
setTimeout(function () { | ||
delete blocked[netId] | ||
}, blockedDuration) | ||
}) | ||
@@ -26,0 +52,0 @@ |
@@ -273,3 +273,3 @@ var collect = require('collect-stream') | ||
a.on('peer-added', function (key) { | ||
a.once('peer-added', function (key) { | ||
console.log('a-add', key) | ||
@@ -279,3 +279,3 @@ setTimeout(end, 2000) | ||
b.on('peer-added', function (key) { | ||
b.once('peer-added', function (key) { | ||
console.log('b-add', key) | ||
@@ -282,0 +282,0 @@ setTimeout(end, 2000) |
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
61983
744