/
muckin_around.js
40 lines (34 loc) · 1000 Bytes
/
muckin_around.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
var BTCNetwork = require('btc-p2p').BTCNetwork
, network = new BTCNetwork()
, logfmt = require('logfmt')
, totals = {}
, peers = 1
network.on('transactionInv', function(data){
hex = data.hash.toString('hex')
ip = data.peer.host.host
if (totals[hex]) {
if (totals[hex].indexOf(ip) < 0) totals[hex].push(ip)
if (peers < totals[hex].length) peers = totals[hex].length
} else {
totals[hex] = [ip]
}
logfmt.log({
'tx': hex,
'nodes': totals[hex].length,
'total_nodes': peers,
'percent_of_nodes': Math.round((totals[hex].length / peers) * 100) + '%'
})
})
network.on('peerStatus', function(data) {
peers = data.numActive
})
network.on('error', function(data){
logfmt.log({error: data.message})
})
process.once('SIGINT', function(){
network.shutdown()
process.exit(0)
})
network.options.minPeers = process.env.minPeers || 20;
network.options.maxPeers = process.env.maxPeers || 3000;
network.launch()