-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
57 lines (47 loc) · 1.45 KB
/
generate.js
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
var v = require('ssb-validate')
var crypto = require('crypto')
var ssbKeys = require('ssb-keys')
var timestamp = require('monotonic-timestamp')
var RNG = require('rng')
var mt = new RNG.MT(0)
function hash (h) {
return crypto.createHash('sha256').update(''+h).digest()
}
function createFeeds (n) {
var feeds = []
for(var i = 0; i < n; i++)
feeds.push(ssbKeys.generate(null, hash(i)))
return feeds
}
function network (peers, n) {
var roots = []
var state = v.initial()
var time = +new Date('2018-05-23T00:33:05.480Z')
for(var i = 0; i < peers.length; i++) {
var _peer = peers[~~(Math.pow(mt.random(), 2)*i)]
var peer = peers[i]
state = v.appendNew(state, null, _peer, {
type: 'contact', contact: peer.id,
following: true
}, time+=1000)
state = v.appendNew(state, null, peer, {
type: 'contact', contact: _peer.id,
following: true
}, time+=1000)
for(var j = 0; j < peers.length/n; j++) {
state = v.appendNew(state, null, peer, {
type: 'test', date: 'hello world:' + hash(j).toString('base64'),
root:
mt.random() < 0.3 ? undefined : roots[~~(mt.random()*roots.length)],
value: j
}, time+=1000)
var msg = state.queue[state.queue.length - 1]
if(!msg.content.root)
roots.push(state.feeds[msg.author].id)
}
}
return state
}
network(createFeeds(1000), 100).queue.forEach(function (e) {
console.log(JSON.stringify(e, null, 2)+'\n')
})