Skip to content

Commit

Permalink
some fixes: redis type, code rearrangement, scrape route
Browse files Browse the repository at this point in the history
  • Loading branch information
RiadhKHEDHIRI committed Dec 18, 2011
1 parent b3a8d4b commit 6a7b48b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions routes/index.js
Expand Up @@ -49,6 +49,7 @@ exports.announce = function(req, res) {
, peer_ip = req.param('ip') || req.connection.remoteAddress
, compact = req.param('compact') || '1'
, no_peer_id = req.param('no_peer_id') || '0'
, numwant = parseInt(req.param('numwant')) || 50
, seeders_count = 0
, leechers_count = 0
, peers_count = 0
Expand All @@ -63,7 +64,7 @@ exports.announce = function(req, res) {

response['tracker id'] = 'Node BitTorrent Tracker';
response['warning message'] = 'the tracker is running an experimental version';
response['interval'] = 10;
response['interval'] = 600;

// handling some invalid requests

Expand All @@ -88,6 +89,11 @@ exports.announce = function(req, res) {
// saving peer parameters
rc.hmset('info_hash:' + info_hash + ':peer:' + peer_id, 'ip', peer_ip, 'port', peer_port);

// assigning some global metrics

rc.sadd('info_hashes', info_hash);
rc.sadd('peers', peer_id);


// handling the 'event' param

Expand All @@ -99,7 +105,7 @@ exports.announce = function(req, res) {
case 'stopped':
rc.srem('peers', peer_id);
if (req.param('left') !== undefined && req.param('left') == 0) {
rc.decr('seeders:' + info_hash);
rc.srem('seeders:' + info_hash, peer_id);
}
break;
}
Expand All @@ -117,11 +123,6 @@ exports.announce = function(req, res) {
if (compact == '1') response['peers'] = '';
else response['peers'] = [];

// assigning some global metrics

rc.sadd('info_hashes', info_hash);
rc.sadd('peers', peer_id);


// building the response body

Expand Down Expand Up @@ -196,6 +197,7 @@ exports.scrape = function(req, res) {
});
}
else {
res.end(bencode.encode(''), 'binary');
}
};

Expand Down

0 comments on commit 6a7b48b

Please sign in to comment.