Skip to content

Commit d6bdd0e

Browse files
committed
Merge branch 'master' of git://github.com/jakefb/bittorrent-tracker into jakefb-master
2 parents 52aacc1 + 7906848 commit d6bdd0e

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

server.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function Server (opts) {
150150
return count
151151
}
152152

153-
if (req.method === 'GET' && req.url === '/stats') {
153+
if (req.method === 'GET' && req.url === '/stats' || 'stats.json') {
154154
infoHashes.forEach(function (infoHash) {
155155
var peers = self.torrents[infoHash].peers
156156
var keys = Object.keys(peers)
@@ -185,13 +185,37 @@ function Server (opts) {
185185
var isIPv4 = function (peer) { return peer.ipv4 }
186186
var isIPv6 = function (peer) { return peer.ipv6 }
187187

188-
res.end('<h1>' + infoHashes.length + ' torrents (' + activeTorrents + ' active)</h1>\n' +
189-
'<h2>Connected Peers: ' + Object.keys(allPeers).length + '</h2>\n' +
190-
'<h3>Peers Seeding Only: ' + countPeers(isSeederOnly) + '</h3>\n' +
191-
'<h3>Peers Leeching Only: ' + countPeers(isLeecherOnly) + '</h3>\n' +
192-
'<h3>Peers Seeding & Leeching: ' + countPeers(isSeederAndLeecher) + '</h3>\n' +
193-
'<h3>IPv4 Peers: ' + countPeers(isIPv4) + '</h3>\n' +
194-
'<h3>IPv6 Peers: ' + countPeers(isIPv6) + '</h3>\n')
188+
var torrents = infoHashes.length
189+
var peersAll = Object.keys(allPeers).length
190+
var peersSeederOnly = countPeers(isSeederOnly)
191+
var peersLeecherOnly = countPeers(isLeecherOnly)
192+
var peersSeederAndLeecher = countPeers(isSeederAndLeecher)
193+
var peersIPv4 = countPeers(isIPv4)
194+
var peersIPv6 = countPeers(isIPv6)
195+
196+
if (req.url === '/stats') {
197+
res.end('<h1>' + torrents + ' torrents (' + activeTorrents + ' active)</h1>\n' +
198+
'<h2>Connected Peers: ' + peersAll + '</h2>\n' +
199+
'<h3>Peers Seeding Only: ' + peersSeederOnly + '</h3>\n' +
200+
'<h3>Peers Leeching Only: ' + peersLeecherOnly + '</h3>\n' +
201+
'<h3>Peers Seeding & Leeching: ' + peersSeederAndLeecher + '</h3>\n' +
202+
'<h3>IPv4 Peers: ' + peersIPv4 + '</h3>\n' +
203+
'<h3>IPv6 Peers: ' + peersIPv6 + '</h3>\n')
204+
}
205+
206+
if (req.url === '/stats.json') {
207+
res.write(JSON.stringify({
208+
torrents: torrents,
209+
activeTorrents: activeTorrents,
210+
peersAll: peersAll,
211+
peersSeederOnly: peersSeederOnly,
212+
peersLeecherOnly: peersLeecherOnly,
213+
peersSeederAndLeecher: peersSeederAndLeecher,
214+
peersIPv4: peersIPv4,
215+
peersIPv6: peersIPv6
216+
}))
217+
res.end()
218+
}
195219
}
196220
})
197221
}

0 commit comments

Comments
 (0)