hyperswarm
Advanced tools
Comparing version 2.0.3 to 2.0.4
{ | ||
"name": "hyperswarm", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A distributed networking stack for connecting peers", | ||
@@ -8,3 +8,3 @@ "main": "swarm.js", | ||
"@hyperswarm/discovery": "^1.1.0", | ||
"@hyperswarm/guts": "1.0.0", | ||
"@hyperswarm/network": "1.0.0", | ||
"shuffled-priority-queue": "^2.1.0", | ||
@@ -18,7 +18,8 @@ "utp-native": "^2.1.3" | ||
"standard": "^12.0.1", | ||
"tap": "^14.1.11" | ||
"tap": "^14.3.1" | ||
}, | ||
"scripts": { | ||
"test": "tap -j 1 -R classic test/*.test.js && standard --fix", | ||
"cov": "tap -j 1 -R classic --coverage-report=html test/*.test.js" | ||
"cov": "tap -j 1 -R classic --coverage-report=html test/*.test.js", | ||
"ci": "standard && npm test" | ||
}, | ||
@@ -25,0 +26,0 @@ "repository": { |
11
swarm.js
@@ -5,3 +5,3 @@ 'use strict' | ||
const { EventEmitter } = require('events') | ||
const guts = require('@hyperswarm/guts') | ||
const network = require('@hyperswarm/network') | ||
@@ -36,3 +36,3 @@ const MAX_SERVER_SOCKETS = Infinity | ||
const network = guts({ | ||
this.network = network({ | ||
bootstrap, | ||
@@ -56,4 +56,4 @@ ephemeral, | ||
network.tcp.maxConnections = maxServerSockets | ||
network.utp.maxConnections = maxServerSockets | ||
this.network.tcp.maxConnections = maxServerSockets | ||
this.network.utp.maxConnections = maxServerSockets | ||
@@ -72,3 +72,2 @@ this.destroyed = false | ||
this.network = network | ||
this[kQueue] = peerQueue(queue) | ||
@@ -163,2 +162,3 @@ this[kQueue].on('readable', this[kDrain](this[kQueue])) | ||
} | ||
this.emit('join', key, opts) | ||
}) | ||
@@ -173,2 +173,3 @@ } | ||
this[kLeave](key) | ||
this.emit('leave', key) | ||
}) | ||
@@ -175,0 +176,0 @@ } |
'use strict' | ||
const { EventEmitter } = require('events') | ||
const { randomBytes } = require('crypto') | ||
const { NetworkResource } = require('@hyperswarm/guts') | ||
const { NetworkResource } = require('@hyperswarm/network') | ||
const { test } = require('tap') | ||
@@ -146,3 +146,3 @@ const { once, done, promisifyMethod, whenifyMethod } = require('nonsynchronous') | ||
process.nextTick(() => topic.emit('update')) | ||
await once(swarm, 'update') | ||
await once(swarm, 'updated') | ||
pass('event emitted') | ||
@@ -223,4 +223,4 @@ swarm.destroy() | ||
const swarm = hyperswarm() | ||
const key = Buffer.concat([Buffer.alloc(20), Buffer.from('key1')]) | ||
const key2 = Buffer.concat([Buffer.alloc(20), Buffer.from('key2')]) | ||
const key = Buffer.concat([Buffer.alloc(28), Buffer.from('key1')]) | ||
const key2 = Buffer.concat([Buffer.alloc(28), Buffer.from('key2')]) | ||
const { lookup } = swarm.network | ||
@@ -241,2 +241,3 @@ var topicDestroyed = false | ||
swarm.leave(key) | ||
await once(swarm, 'leave') | ||
is(topicDestroyed, true) | ||
@@ -243,0 +244,0 @@ swarm.destroy() |
@@ -93,4 +93,6 @@ 'use strict' | ||
}) | ||
await once(s, 'listening') | ||
await once(swarm, 'connection') | ||
await Promise.all([ | ||
once(s, 'listening'), | ||
once(swarm, 'connection') | ||
]) | ||
} | ||
@@ -161,4 +163,6 @@ is(swarm.peers, maxPeers) | ||
}) | ||
await once(s, 'listening') | ||
await once(swarm, 'connection') | ||
await Promise.all([ | ||
await once(s, 'listening'), | ||
await once(swarm, 'connection') | ||
]) | ||
} | ||
@@ -236,4 +240,6 @@ | ||
}) | ||
await once(s, 'listening') | ||
await once(swarm, 'connection') | ||
await Promise.all([ | ||
once(s, 'listening'), | ||
once(swarm, 'connection') | ||
]) | ||
} | ||
@@ -265,77 +271,1 @@ is(swarm.peers, maxPeers) | ||
}) | ||
test('after maxPeers is exceeded, new peers can connect once existing peers have disconnected and peer count is below threshhold again', async ({ is, fail }) => { | ||
const { bootstrap, closeDht } = await dhtBootstrap() | ||
const swarm = hyperswarm({ | ||
bootstrap, | ||
maxPeers: 8 | ||
}) | ||
const key = randomBytes(32) | ||
const swarms = [] | ||
const { maxPeers } = swarm | ||
is(maxPeers, 8) | ||
is(swarm.peers, 0) | ||
is(swarm.open, true) | ||
const announcingPeers = maxPeers / 2 | ||
const lookupPeers = maxPeers / 2 | ||
for (var i = 0; i < announcingPeers; i++) { | ||
const s = hyperswarm({ bootstrap }) | ||
swarms.push(s) | ||
s.join(key, { | ||
announce: true, | ||
lookup: false | ||
}) | ||
await once(s, 'listening') | ||
} | ||
swarm.join(key, { | ||
announce: true, | ||
lookup: true | ||
}) | ||
is(swarm.peers, 0) | ||
await once(swarm, 'listening') | ||
for (var c = 0; c < announcingPeers; c++) { | ||
await once(swarm, 'connection') | ||
} | ||
is(swarm.peers, announcingPeers) | ||
is(swarm.open, true) | ||
for (var n = 0; n < lookupPeers; n++) { | ||
const s = hyperswarm({ bootstrap }) | ||
swarms.push(s) | ||
s.join(key, { | ||
announce: false, | ||
lookup: true | ||
}) | ||
await once(s, 'listening') | ||
await once(swarm, 'connection') | ||
} | ||
is(swarm.peers, maxPeers) | ||
is(swarm.open, false) | ||
swarms[0].destroy() | ||
await once(swarms[0], 'close') | ||
await once(swarm, 'disconnection') | ||
is(swarm.peers, maxPeers - 1) | ||
const swarm2 = hyperswarm({ bootstrap }) | ||
swarm2.join(key, { | ||
announce: false, | ||
lookup: true | ||
}) | ||
await once(swarm2, 'listening') | ||
await once(swarm, 'connection') | ||
is(swarm.peers, maxPeers) | ||
is(swarm.open, false) | ||
swarm2.destroy() | ||
swarm.leave(key) | ||
swarm.destroy() | ||
for (const s of swarms) { | ||
s.leave(key) | ||
s.destroy() | ||
} | ||
closeDht() | ||
}) |
@@ -120,3 +120,3 @@ 'use strict' | ||
} | ||
delete require.cache[require.resolve('@hyperswarm/guts')] | ||
delete require.cache[require.resolve('@hyperswarm/network')] | ||
const { connect } = net | ||
@@ -182,3 +182,3 @@ net.connect = () => { | ||
delete require.cache[require.resolve('..')] | ||
delete require.cache[require.resolve('@hyperswarm/guts')] | ||
delete require.cache[require.resolve('@hyperswarm/network')] | ||
net.connect = connect | ||
@@ -185,0 +185,0 @@ hyperswarm = require('../swarm') |
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
74709
20
2352
+ Added@hyperswarm/network@1.0.0
+ Added@hyperswarm/network@1.0.0(transitive)
- Removed@hyperswarm/guts@1.0.0
- Removed@hyperswarm/guts@1.0.0(transitive)