Last active
August 29, 2015 14:14
-
-
Save copleykj/82e13367360464d4a78f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Fiber = Npm.require('fibers') | |
var Server = Meteor.npmRequire('bittorrent-tracker').Server; | |
Tracker = function () { | |
Server.prototype.constructor.call(this); | |
}; | |
Tracker.prototype = Object.create(Server.prototype); | |
Tracker.prototype.constructor = Tracker; | |
Tracker.prototype.getSwarm = function (infoHash) { | |
if (Buffer.isBuffer(infoHash)) infoHash = infoHash.toString('hex'); | |
var torrent; | |
console.log('got request for info hash "' + infoHash + '"'); | |
console.log('got the following info hashes:'); | |
Torrents.find({}).forEach(function (torrent) { | |
console.log('"' + torrent.infoHash + '"'); | |
}); | |
torrent = Torrents.findOne({infoHash: infoHash}); | |
if (!torrent) { | |
this.emit('warning', new Error('unknown torrent ' + infoHash)); | |
infoHash = -1; | |
delete this.torrents[infoHash]; | |
} | |
return Server.prototype.getSwarm.apply(this, arguments); | |
}; | |
var tracker = new Tracker(); | |
tracker.on('error', function (err) { | |
console.log(err.message); | |
}); | |
tracker.on('warning', function (err) { | |
console.log(err.message); | |
}); | |
tracker.on('listening', function (port) { | |
console.log('tracker is listening on port ' + port); | |
}); | |
Meteor.startup(Meteor.bindEnvironment(function () { | |
tracker.listen(3002); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment