forked from wigy-opensource-developer/hydra-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
79 lines (66 loc) · 2.32 KB
/
app.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const Crawler = require('./src/crawler')
const { URL } = require('url')
const { orderBy } = require('lodash/collection')
const crawler = new Crawler()
const args = process.argv.slice(2)
const report = (crawler) => {
const blockStats = {}
const versionStats = {}
for (const item of crawler.heights) {
if (blockStats[item.height]) {
blockStats[item.height].count += 1
blockStats[item.height].ids[item.id] += 1
} else {
blockStats[item.height] = {}
blockStats[item.height].count = 1
blockStats[item.height].ids = {}
blockStats[item.height].ids[item.id] = 1
}
if (versionStats[item.version]) {
versionStats[item.version].count += 1
} else {
versionStats[item.version] = {
count: 1,
version: item.version
}
}
}
const allDelays = crawler.heights.filter(item => item.delay).map(item => item.delay)
const averageDelay = allDelays.reduce((a, b) => a + b, 0) / allDelays.length
const maxDelay = Math.max(...allDelays)
const minDelay = Math.min(...allDelays)
console.log(`===========================================`)
console.log(`Total nodes visited: ${Object.keys(crawler.nodes).length}`)
console.log(`Total nodes online: ${crawler.heights.length}`)
console.log(`------------------------------------------`)
// height/block stats
console.log(`Height and block stats:`)
for (const stat in blockStats) {
console.log(` ${blockStats[stat].count} nodes on height ${stat} with hashes:`)
for (const hash in blockStats[stat].ids) {
console.log(` - ${hash} (${blockStats[stat].ids[hash]} nodes)`)
}
}
// version stats
console.log(``)
console.log(`Version stats:`)
for (const stat of orderBy(Object.values(versionStats))) {
console.log(` - ${stat.count} nodes on version ${stat.version}`)
}
// delay stats
console.log(``)
console.log(`Delay`)
console.log(` Average delay: ${averageDelay}`)
console.log(` Min delay: ${minDelay}`)
console.log(` Max delay: ${maxDelay}`)
console.log(`------------------------------------------`)
console.log(`Finished scanning in ${new Date() - crawler.startTime}ms`)
process.exit(0)
}
let node = { ip: undefined, port: undefined }
if (args.length === 1) {
const url = new URL(args[0])
node.ip = url.hostname
node.port = url.port
}
crawler.run(node).then(report)