diff --git a/CHANGELOG.md b/CHANGELOG.md index 892e34b..18357b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.0.0] - 2020-04-07 + +- Support for Hydra peers + +## [1.3.0] - 2020-02-04 + +- Support for ARK 2.6 peers ## [1.2.10] - 2019-08-06 diff --git a/README.md b/README.md index 738bf99..0828d65 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,8 @@ -# Crawler +# Hydra Crawler -Crawler scans the ARK network to get information about the peers in the network. - -#### ❤️ Support maintenance and development of plugins -If you find this or other plugins useful please consider - -- voting for `deadlock` delegate -- donating to `AWtgFYbvtLDYccJvC5MChk4dpiUy2Krt2U` - -to support development new plugins and tools for Ark's Ecosystem and maintenance of existing ones. Full list of contributions can be found on [https://arkdelegatesio/delegate/deadlock/](https://arkdelegates.io/delegate/deadlock/contributions/). 🖖 +Hydra Crawler scans the Hydra network to get information about the peers in the network. +This is a fork of the [ARK Crawler](https://github.com/deadlock-delegate/crawler/) so make sure +you sponsor them for their hard work. ## Installation @@ -16,16 +10,19 @@ to support development new plugins and tools for Ark's Ecosystem and maintenance ## Usage -`npm start http://:` +`node . http://:` -For port use the p2p port, which is 4001 for Ark's mainnet or 4002 for Ark's devnet. +For port use the p2p port, which is 4701 for [Hydra mainnet](http://hydra.iop.global/) or +4702 for [Hydra devnet](http://dev.hydra.iop.global/). ## Credits - [roks0n](https://github.com/roks0n) - [dmvt](https://github.com/dmvt) -- [All Contributors](../../../../contributors) +- [wigy](https://github.com/wigy-opensource-developer/) +- [All Contributors](../../contributors) ## License -[MIT](LICENSE) © roks0n +ARK Delegate: [MIT](LICENSE) © roks0n +Hydra patches: [MIT](LICENSE) © Decentralized Society Foundation, Panama diff --git a/package-lock.json b/package-lock.json index b45cdc2..6ae3261 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@deadlock-delegate/crawler", - "version": "1.3.0", + "name": "@internet-of-people/hydra-crawler", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -24,10 +24,16 @@ "js-tokens": "^4.0.0" } }, + "@types/lodash": { + "version": "4.14.149", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.149.tgz", + "integrity": "sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==", + "dev": true + }, "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true }, "acorn-jsx": { @@ -1013,18 +1019,18 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "dev": true, "requires": { - "minimist": "0.0.8" + "minimist": "^1.2.5" } }, "ms": { diff --git a/package.json b/package.json index a29a4db..9676281 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,31 @@ { - "name": "@deadlock-delegate/crawler", - "version": "1.3.0", - "description": "Crawler scans the ARK network to get information about the peers in the network.", - "main": "src/crawler.js", + "name": "@internet-of-people/hydra-crawler", + "version": "2.0.0", + "description": "Crawler scans the Hydra network to get information about the peers in the network.", + "main": "app.js", "scripts": { - "start": "node app.js", "lint": "eslint ./ --fix" }, "repository": { "type": "git", - "url": "git+https://github.com/deadlock-delegate/crawler.git" + "url": "git+https://github.com/wigy-opensource-developer/hydra-crawler.git" }, "engines": { - "node": "^8.11.2" + "node": "12.16.0" }, "keywords": [ - "ark acosystem", + "ark ecosystem", "network", "scanner", - "blockchain" + "blockchain", + "hydra", + "iop" ], "author": "roks0n", "license": "MIT", - "homepage": "https://github.com/deadlock-delegate/crawler#readme", + "homepage": "https://github.com/wigy-opensource-developer/hydra-crawler#readme", "devDependencies": { + "@types/lodash": "^4.14.149", "eslint": "^6.8.0", "eslint-config-standard": "^14.1.0", "eslint-plugin-import": "^2.20.1", diff --git a/src/crawler.js b/src/crawler.js index 9e16682..a9d0498 100644 --- a/src/crawler.js +++ b/src/crawler.js @@ -1,8 +1,8 @@ const { map } = require('lodash') -const Peers = require('./peer') +const Connections = require('./peer') -const VISITED = 1 const NOT_VISITED = 0 +const VISITED = 1 let NETWORK_P2P_PORT = null class Crawler { @@ -11,9 +11,6 @@ class Crawler { * @method constructor */ constructor (timeout = 2500, disconnect = true, sampleSize = 10) { - this.headers = {} - this.timeout = timeout - this.socket = undefined this.disconnect = disconnect this.request = { data: {}, @@ -22,8 +19,7 @@ class Crawler { } } this.sampleSize = sampleSize - - this.peers = new Peers(this.timeout) + this.connections = new Connections(timeout) } /** @@ -40,8 +36,8 @@ class Crawler { NETWORK_P2P_PORT = peer.port - if (!this.peers.get(peer.ip)) { - this.peers.add(peer.ip, NETWORK_P2P_PORT) + if (!this.connections.get(peer.ip)) { + this.connections.add(peer.ip, NETWORK_P2P_PORT) } try { @@ -51,7 +47,7 @@ class Crawler { await this.scanNetwork() if (this.disconnect) { console.log('... disconnecting from all peers') - this.peers.disconnectAll() + this.connections.disconnectAll() } } catch (err) { console.error(err) @@ -60,23 +56,23 @@ class Crawler { return this } - async discoverPeers (peer) { + async discoverPeers (currentNode) { return new Promise((resolve, reject) => { - const connection = this.peers.get(peer.ip) + const connection = this.connections.get(currentNode.ip) if (!connection) { - reject(new Error(`No connection exists for ${peer.ip}:${peer.port}`)) + reject(new Error(`No connection exists for ${currentNode.ip}:${currentNode.port}`)) } connection.emit( 'p2p.peer.getPeers', this.request, (err, response) => { if (err) { - console.error(`Error when calling p2p.peer.getPeers on ${peer.ip}: ${err}`) + console.error(`Error when calling p2p.peer.getPeers on ${currentNode.ip}: ${err}`) return resolve() } - if (peer.ip in this.samplePeers) { - this.samplePeers[peer.ip] = VISITED + if (currentNode.ip in this.samplePeers) { + this.samplePeers[currentNode.ip] = VISITED } response.data.map((peer) => { @@ -84,22 +80,23 @@ class Crawler { this.nodes[peer.ip] = peer } - if (!this.peers.get(peer.ip)) { - this.peers.add(peer.ip, NETWORK_P2P_PORT) + if (!this.connections.get(peer.ip)) { + this.connections.add(peer.ip, NETWORK_P2P_PORT) } }) - if (this.samplePeers[peer.ip] === VISITED) { + if (this.samplePeers[currentNode.ip] === VISITED) { return resolve() } // note: this is not very efficient on large arrays const samplePeers = response.data + .filter(p => this.samplePeers[p.ip] !== VISITED) .map(x => ({ x, r: Math.random() })) .sort((a, b) => a.r - b.r) .map(a => a.x) .slice(0, this.sampleSize) - .filter(a => a.ip !== peer.ip) + .filter(a => a.ip !== currentNode.ip) .map((peer) => { this.samplePeers[peer.ip] = NOT_VISITED return this.discoverPeers(peer) @@ -113,7 +110,7 @@ class Crawler { scanNetwork () { const promises = map(this.nodes, (peer) => { return new Promise((resolve, reject) => { - const connection = this.peers.get(peer.ip) + const connection = this.connections.get(peer.ip) if (!connection) { return resolve() } @@ -129,8 +126,8 @@ class Crawler { height: response.data.state.header.height, id: response.data.state.header.id }) - this.nodes[peer.ip].height = response.data.state.header.height - this.nodes[peer.ip].id = response.data.state.header.id + peer.height = response.data.state.header.height + peer.id = response.data.state.header.id return resolve() } ) diff --git a/src/peer.js b/src/peer.js index f88b809..450c1b1 100644 --- a/src/peer.js +++ b/src/peer.js @@ -38,10 +38,6 @@ class Peers { return this.connections.get(ip) } - map () { - return this.connections - } - disconnectAll () { for (const [ip, connection] of this.connections.entries()) { connection.destroy()