-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
64 lines (51 loc) · 1.59 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Killa Beez</title>
<script src="bundle.js"></script>
<script>
console.log("in script.")
let opts = {signalHost: undefined}
let node1 = new Swarm(opts)
let node2 = new Swarm(opts)
let node3 = new Swarm(opts)
let start = Date.now()
var delayed = false
node1.rpc.ping = cb => {
if (!delayed) setTimeout(() => cb(null), 3000)
else cb(null)
delayed = true
}
function complete () {
return nodes.map(n => Object.keys(n.remotes).length).reduce((x,y) => x+y, 0) === nodes.length * 5
}
function _print (n) {
let _ret = peer => {
let delay = (Date.now() - start) / 1000
console.log(`peer${n} got ${peer.publicKey.slice(0, 10)} @ ${delay}s`)
if (complete()) console.log('complete')
}
return _ret
}
node1.on('remote', _print(1))
node2.on('remote', _print(2))
node3.on('remote', _print(3))
node1.call(node2.publicKey)
node3.call(node1.publicKey)
let node4 = new Swarm(opts)
let node5 = new Swarm(opts)
let node6 = new Swarm(opts)
node4.on('remote', _print(4))
node5.on('remote', _print(5))
node6.on('remote', _print(6))
node4.call(node5.publicKey)
node5.call(node6.publicKey)
node6.call(node1.publicKey)
window.nodes = [node1, node2, node3, node4, node5, node6]
window.nodes.forEach(n => n.on('disconnect', p => console.log('disconnect', p)))
</script>
</head>
<body>
</body>
</html>