Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cabal-core

Package Overview
Dependencies
Maintainers
4
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cabal-core - npm Package Compare versions

Comparing version 7.0.1 to 7.1.0

2

package.json
{
"name": "cabal-core",
"version": "7.0.1",
"version": "7.1.0",
"description": " p2p db functions for chat ",

@@ -5,0 +5,0 @@ "main": "index.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)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc