diff --git a/README.md b/README.md index 2f0d99c1..145a4d77 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg [standard-url]: https://standardjs.com +# UPDATED STATS INDEX # + #### Simple, robust, BitTorrent tracker (client & server) implementation ![tracker visualization](img/img.png) @@ -40,12 +42,12 @@ Also see [bittorrent-dht](https://www.npmjs.com/package/bittorrent-dht). ### Tracker stats -![Screenshot](img/trackerStats.png) +![Screenshot](https://babico.s-ul.eu/10VVv0sn) ## install -``` -npm install bittorrent-tracker +```sh +npm install https://github.com/babico/bittorrent-tracker.git --save ``` ## usage @@ -283,7 +285,7 @@ Client.scrape({ announce: announceUrl, infoHash: [ infoHash1, infoHash2 ]}, func Install `bittorrent-tracker` globally: ```sh -$ npm install -g bittorrent-tracker +$ npm install -g https://github.com/babico/bittorrent-tracker.git --save ``` Easily start a tracker server: diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 00000000..652dd231 Binary files /dev/null and b/favicon.ico differ diff --git a/package.json b/package.json index f04ef3dc..d91d87f8 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "cross-fetch-ponyfill": "^1.0.1", "debug": "^4.1.1", "ip": "^1.1.5", + "jsdom": "^22.1.0", "lru": "^3.1.0", "minimist": "^1.2.5", "once": "^1.4.0", diff --git a/server.js b/server.js index f7023d99..dba45cda 100644 --- a/server.js +++ b/server.js @@ -41,7 +41,7 @@ class Server extends EventEmitter { this.intervalMs = opts.interval ? opts.interval - : 10 * 60 * 1000 // 10 min + : 30 * 60 * 1000 // 10 min this._trustProxy = !!opts.trustProxy if (typeof opts.filter === 'function') this._filter = opts.filter @@ -265,15 +265,95 @@ class Server extends EventEmitter { } else if (req.url === '/stats') { res.setHeader('Content-Type', 'text/html') res.end(` -

${stats.torrents} torrents (${stats.activeTorrents} active)

-

Connected Peers: ${stats.peersAll}

-

Peers Seeding Only: ${stats.peersSeederOnly}

-

Peers Leeching Only: ${stats.peersLeecherOnly}

-

Peers Seeding & Leeching: ${stats.peersSeederAndLeecher}

-

IPv4 Peers: ${stats.peersIPv4}

-

IPv6 Peers: ${stats.peersIPv6}

-

Clients:

- ${printClients(stats.clients)} + + + Tracker Stats + + + + +
+
Tracker Stats
+
There are
${stats.torrents}
torrents,
${stats.activeTorrents}
are active.
+
Connected Peers:
${stats.peersAll}
+
+ +
+
Peers Seeding Only:
${stats.peersSeederOnly}
+
Peers Leeching Only:
${stats.peersLeecherOnly}
+
Peers Seeding & Leeching:
${stats.peersSeederAndLeecher}
+
+ +
+
IPv4 Peers:
${stats.peersIPv4}
+
IPv6 Peers:
${stats.peersIPv6}
+
+ +
+
+

Clients:

+
${printClients(stats.clients)}
+
+
+ + `.replace(/^\s+/gm, '')) // trim left } } diff --git a/test/stats.js b/test/stats.js index 7223da01..27e0e380 100644 --- a/test/stats.js +++ b/test/stats.js @@ -3,29 +3,23 @@ import commonTest from './common.js' import fixtures from 'webtorrent-fixtures' import fetch from 'cross-fetch-ponyfill' import test from 'tape' +import jsdom from 'jsdom' const peerId = Buffer.from('-WW0091-4ea5886ce160') const unknownPeerId = Buffer.from('01234567890123456789') function parseHtml (html) { - const extractValue = /[^v^h](\d+)/ - const array = html.replace('torrents', '\n').split('\n').filter(line => line && line.trim().length > 0).map(line => { - const a = extractValue.exec(line) - if (a) { - return parseInt(a[1]) - } - return null - }) - let i = 0 + const dom = new jsdom.JSDOM(html) + return { - torrents: array[i++], - activeTorrents: array[i++], - peersAll: array[i++], - peersSeederOnly: array[i++], - peersLeecherOnly: array[i++], - peersSeederAndLeecher: array[i++], - peersIPv4: array[i++], - peersIPv6: array[i] + torrents: parseInt(dom.window.document.getElementById('torrents').textContent), + activeTorrents: parseInt(dom.window.document.getElementById('activeTorrents').textContent), + peersAll: parseInt(dom.window.document.getElementById('peersAll').textContent), + peersSeederOnly: parseInt(dom.window.document.getElementById('peersSeederOnly').textContent), + peersLeecherOnly: parseInt(dom.window.document.getElementById('peersLeecherOnly').textContent), + peersSeederAndLeecher: parseInt(dom.window.document.getElementById('peersSeederAndLeecher').textContent), + peersIPv4: parseInt(dom.window.document.getElementById('peersIPv4').textContent), + peersIPv6: parseInt(dom.window.document.getElementById('peersIPv6').textContent) } }