Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var Fiber = Npm.require('fibers')
  2. var Server = Meteor.npmRequire('bittorrent-tracker').Server;
  3. Tracker = function () {
  4. Server.prototype.constructor.call(this);
  5. };
  6. Tracker.prototype = Object.create(Server.prototype);
  7. Tracker.prototype.constructor = Tracker;
  8. Tracker.prototype.getSwarm = function (infoHash) {
  9. if (Buffer.isBuffer(infoHash)) infoHash = infoHash.toString('hex');
  10. var torrent;
  11. console.log('got request for info hash "' + infoHash + '"');
  12. console.log('got the following info hashes:');
  13. Torrents.find({}).forEach(function (torrent) {
  14. console.log('"' + torrent.infoHash + '"');
  15. });
  16. torrent = Torrents.findOne({infoHash: infoHash});
  17. if (!torrent) {
  18. this.emit('warning', new Error('unknown torrent ' + infoHash));
  19. infoHash = -1;
  20. delete this.torrents[infoHash];
  21. }
  22. return Server.prototype.getSwarm.apply(this, arguments);
  23. };
  24. var tracker = new Tracker();
  25. tracker.on('error', function (err) {
  26. console.log(err.message);
  27. });
  28. tracker.on('warning', function (err) {
  29. console.log(err.message);
  30. });
  31. tracker.on('listening', function (port) {
  32. console.log('tracker is listening on port ' + port);
  33. });
  34. Meteor.startup(Meteor.bindEnvironment(function () {
  35. tracker.listen(3002);
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement