Compare commits
No commits in common. "340cd467349457a01716a7eb1e6c3e513158ca63" and "4f8918f8e9768485a4b0d49f1feb4c565b745541" have entirely different histories.
340cd46734
...
4f8918f8e9
|
@ -18,7 +18,6 @@
|
||||||
"hyperswarm": "^4.3.5",
|
"hyperswarm": "^4.3.5",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"protoc": "^1.1.3",
|
"protoc": "^1.1.3",
|
||||||
"sleep-promise": "^9.1.0",
|
|
||||||
"sodium-universal": "^3.1.0",
|
"sodium-universal": "^3.1.0",
|
||||||
"tape": "^5.6.1"
|
"tape": "^5.6.1"
|
||||||
}
|
}
|
||||||
|
|
16
test.js
16
test.js
|
@ -1,5 +1,4 @@
|
||||||
const test = require("tape");
|
const test = require("tape");
|
||||||
const sleep = require("sleep-promise");
|
|
||||||
const Hyperswarm = require("hyperswarm");
|
const Hyperswarm = require("hyperswarm");
|
||||||
const sodium = require("sodium-universal");
|
const sodium = require("sodium-universal");
|
||||||
const b4a = require("b4a");
|
const b4a = require("b4a");
|
||||||
|
@ -9,13 +8,16 @@ const crypto = require("crypto");
|
||||||
const topicName = crypto.randomBytes(10);
|
const topicName = crypto.randomBytes(10);
|
||||||
|
|
||||||
test("Broadcast through several peers", (t) => {
|
test("Broadcast through several peers", (t) => {
|
||||||
|
const peer1 = createPeer();
|
||||||
|
const peer2 = createPeer();
|
||||||
|
const peer3 = createPeer();
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
|
|
||||||
Promise.all([createPeer(100), createPeer(300), createPeer(500)]).then(
|
Promise.all([peer1, peer2, peer3]).then((peers) => {
|
||||||
(peers) => {
|
|
||||||
const peer1 = peers.shift();
|
const peer1 = peers.shift();
|
||||||
const peer2 = peers.shift();
|
const peer2 = peers.shift();
|
||||||
const peer3 = peers.shift();
|
const peer3 = peers.shift();
|
||||||
|
|
||||||
const flood1 = new DHTFlood({ swarm: peer1 });
|
const flood1 = new DHTFlood({ swarm: peer1 });
|
||||||
const flood2 = new DHTFlood({ swarm: peer2 });
|
const flood2 = new DHTFlood({ swarm: peer2 });
|
||||||
const flood3 = new DHTFlood({ swarm: peer3 });
|
const flood3 = new DHTFlood({ swarm: peer3 });
|
||||||
|
@ -42,12 +44,10 @@ test("Broadcast through several peers", (t) => {
|
||||||
t.teardown(() => {
|
t.teardown(() => {
|
||||||
[peer1, peer2, peer3].forEach((item) => item.destroy());
|
[peer1, peer2, peer3].forEach((item) => item.destroy());
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createPeer(ms) {
|
async function createPeer() {
|
||||||
await sleep(ms / 2);
|
|
||||||
const swarm = new Hyperswarm();
|
const swarm = new Hyperswarm();
|
||||||
await swarm.dht.ready();
|
await swarm.dht.ready();
|
||||||
await swarm.listen();
|
await swarm.listen();
|
||||||
|
@ -57,7 +57,5 @@ async function createPeer(ms) {
|
||||||
|
|
||||||
swarm.join(topic);
|
swarm.join(topic);
|
||||||
|
|
||||||
await sleep(ms / 2);
|
|
||||||
|
|
||||||
return swarm;
|
return swarm;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue