How to use the bittorrent-tracker.Server function in bittorrent-tracker

To help you get started, we’ve selected a few bittorrent-tracker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github philipphenkel / docker-bittorrent-tracker / server.js View on Github external
// Copyright (C) 2016 Philipp Henkel
// Licensed under the MIT License (MIT). See LICENSE file for more details.

var config = require('./config.js');
var filter = require('./filter')
var Server = require('bittorrent-tracker').Server

var server = new Server({
  trustProxy: config.get('trustProxy'),
  udp: config.get('udp'),
  http: config.get('http'),
  ws: config.get('websocket'),
  stats: config.get('stats'),
  filter: function (infoHash, params, cb) {
    var whitelist = config.get('torrentWhitelist')
    cb(filter.isTorrentAllowed(infoHash, whitelist))
  }
})

server.on('error', function (err) {
  console.error('error: ' + err.message)
})

server.on('warning', function (err) {
github binux / webtorrent-share / hybrid-server.js View on Github external
connect().use(serveStatic(__dirname)).listen(8000);

// bt hybrid server
var Server = require('bittorrent-tracker').Server
var WebTorrent = require('webtorrent-hybrid')
var parseTorrent = require('parse-torrent')

global.WEBTORRENT_ANNOUNCE = ["ws://127.0.0.1:8900/announce"]
//global.WEBTORRENT_ANNOUNCE = [ 'wss://tracker.webtorrent.io', 'wss://tracker.btorrent.xyz' ]

var client = new WebTorrent({
  dht: false,
  tracker: true
})

var server = new Server({
  udp: false,
  http: true,
  ws: true,
  filter: function(info_hash, params, cb) {
    // add to web torrent client here
    console.log('adding torrent: ' + info_hash)
    client.add(info_hash, {
      announce: ["https://tr.bangumi.moe:9696/announce", "http://tr.bangumi.moe:6969/announce", "http://127.0.0.1:8900/announce"]
    }, function(torrent) {
      console.log('added torrent: ' + torrent.magnetURI)
      // select pieces in file streaming order
      torrent.critical(0, Math.min(10, torrent.pieces.length - 1))
      for (var i = 10; i < torrent.pieces.length - 1; i += 10) {
        torrent.select(i, Math.min(i + 10, torrent.pieces.length - 1), torrent.pieces.length / 10 - i / 10)
      }
      torrent.on('wire', function(wire, addr) {
github gridcontrol / gridcontrol / research / bittorrent / tracker.js View on Github external
var Server = require('bittorrent-tracker').Server;

var server = new Server({
  udp: true, // enable udp server? [default=true]
  http: true, // enable http server? [default=true]
  ws: true, // enable websocket server? [default=true]
  stats: true // enable web-based statistics? [default=true]
});

server.on('error', function (err) {
  // fatal server error!
  console.log(err.message);
});

server.on('warning', function (err) {
  // client sent bad data. probably not a problem, just a buggy client.
  console.log(err.message);
});
github ZeroNetJS / zeronet-js / tools / debug / torrent-server.js View on Github external
var Server = require('bittorrent-tracker').Server

var server = new Server({
  udp: true, // enable udp server? [default=true]
  http: true, // enable http server? [default=true]
  ws: true, // enable websocket server? [default=true]
  stats: true, // enable web-based statistics? [default=true]
  filter: function (infoHash, params, cb) {
    // Blacklist/whitelist function for allowing/disallowing torrents. If this option is
    // omitted, all torrents are allowed. It is possible to interface with a database or
    // external system before deciding to allow/deny, because this function is async.

    // It is possible to block by peer id (whitelisting torrent clients) or by secret
    // key (private trackers). Full access to the original HTTP/UDP request parameters
    // are available in `params`.

    // This example only allows one torrent.

    if (true) {
github axiom-org / axiom / ts / src / node / Tracker.ts View on Github external
constructor(port) {
    this.server = new Server({
      udp: true,
      http: true,
      ws: true,
      stats: true,
      filter: (infoHash, params, callback) => {
        // Any content you don't want to host, you can reject here based on infoHash.
        // TODO: validate prepareUpdateBucket calls and only allow tracking torrents
        // that have previously sent this validation.
        callback(null);
      }
    });

    this.server.http.on("request", (req, res) => {
      let parsed = url.parse(req.url, true);
      if (parsed.pathname !== "/prepareUpdateBucket") {
        return;
github mafintosh / torrent-stream / test / tracker.js View on Github external
var test = require('tap').test
var torrents = require('../')
var fs = require('fs')
var path = require('path')
var rimraf = require('rimraf')
var tracker = require('bittorrent-tracker')
var server = new tracker.Server()

var torrent = fs.readFileSync(path.join(__dirname, 'data', 'test.torrent'))
var tmpPath = path.join(__dirname, '..', 'torrents', 'test')
rimraf.sync(tmpPath)

var fixture

server.on('error', function () {})

test('seed should connect to the tracker', function (t) {
  t.plan(3)

  server.once('listening', function () {
    t.ok(true, 'tracker should be listening')
    fixture = torrents(torrent, {
      dht: false,
github mafintosh / torrent-stream / test / blocklist.js View on Github external
var test = require('tap').test
var torrents = require('../')
var fs = require('fs')
var path = require('path')
var rimraf = require('rimraf')
var tracker = require('bittorrent-tracker')
var server = new tracker.Server()

var torrent = fs.readFileSync(path.join(__dirname, 'data', 'test.torrent'))
var tmpPath = path.join(__dirname, '..', 'torrents', 'test')
rimraf.sync(tmpPath)

var seed

server.on('error', function () {})

test('seed should connect to the tracker', function (t) {
  t.plan(3)

  server.once('listening', function () {
    t.ok(true, 'tracker should be listening')
    seed = torrents(torrent, {
      dht: false,
github mafintosh / torrent-stream / test / tracker.js View on Github external
test('peer should connect to an alternate tracker', function (t) {
  t.plan(5)
  var engine = null
  var server = new tracker.Server()
  server.once('listening', function () {
    t.ok(true, 'tracker should be listening')

    engine = torrents(torrent, { dht: false, trackers: ['http://127.0.0.1:54321/announce'] })
    engine.once('ready', function () {
      t.ok(true, 'should be ready')
    })
  })
  server.once('start', function (addr) {
    t.equal(addr, '127.0.0.1:6881')

    engine.destroy(function () {
      engine.remove(t.ok.bind(t, true, 'should be destroyed'))
    })
    server.close(t.ok.bind(t, true, 'tracker should be closed'))
  })
github mafintosh / torrent-blob-store / test / rw.js View on Github external
test('rw', function (t) {
  t.plan(3)
  t.once('end', function () {
    server.http.close()
    server.udp.close()
  })

  var server = new Tracker({ http: true })
  server.listen(0, '127.0.0.1', function () {
    var store = blob({
      trackers: [
        'http://localhost:' + server.http.address().port,
        'udp://localhost:' + server.udp.address().port
      ]
    })
    var w = store.createWriteStream(function (err, res) {
      t.ifError(err)
      t.ok(/^magnet:/.test(res.link), 'magnet link')
      store.createReadStream(res.link).pipe(concat(function (body) {
        t.equal(body.toString(), 'whatever')
      }))
    })
    w.end('whatever')
  })

bittorrent-tracker

Simple, robust, BitTorrent tracker (client & server) implementation

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis