Skip to content

Commit

Permalink
refactor around promises so it can be used in other apps
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvt authored and roks0n committed May 5, 2019
1 parent 9e6c8a5 commit a489b3d
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 107 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Crawler

Network scanning tool for Ark (v2)
Network scanning tool for ARK.

This currently works for ARK v1 and will be updated to work with V2's API structure shortly.

## Installation

`npm install`

## Usage

`node app.js http://<ip>:<port>`
`npm start http://<ip>:<port>`
32 changes: 31 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
const Crawler = require('./src/crawler')
const { URL } = require('url')
const { forEach, keys } = require('lodash')

const crawler = new Crawler()
const args = process.argv.slice(2)

const report = (crawler) => {
let blockStats = {}

forEach(crawler.heights, (item) => {
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
}
})

console.log(`===========================================`)
console.log(`Total nodes visited: ${keys(crawler.nodes).length}`)
console.log(`Total nodes online: ${crawler.heights.length}`)
console.log(`------------------------------------------`)
console.log(`Block stats:`)
console.log(blockStats)
console.log(`------------------------------------------`)
console.log(`Finished scanning in ${new Date() - crawler.startTime}ms`)
process.exit(0)
}

let node = {ip: '167.99.243.111', port: 4003}

if (args.length === 1) {
const url = new URL(args[0])
node.ip = url.hostname
node.port = url.port
}
crawler.run(node)

crawler.run(node).then(report)
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
{
"name": "crawler",
"version": "0.0.1",
"description": "loops through the ARK network to get the height of connected peers",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/roks0n/crawler.git"
},
"engines": {
"node": "^8.11.2"
},
"keywords": [],
"author": "A(rk)-Team",
"license": "Apache-2.0",
"homepage": "https://github.com/roks0n/crawler#readme",
"devDependencies": {},
"dependencies": {
"axios": "^0.18.0",
"delay": "^4.0.1",
"lodash": "^4.17.11"
}
}
Loading

0 comments on commit a489b3d

Please sign in to comment.