Total Pageviews

Tuesday, 27 November 2018

bittorrent-tracker

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

 travis npm downloads javascript style guide

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

tracker visualization
Node.js implementation of a BitTorrent tracker, client and server.
BitTorrent tracker is a web service which responds to requests from BitTorrent clients. The requests include metrics from clients that help the tracker keep overall statistics about the torrent. The response includes a peer list that helps the client participate in the torrent swarm.
This module is used by WebTorrent.

features

  • Includes client & server implementations
  • Supports all mainstream tracker types:
  • Supports ipv4 & ipv6
  • Supports tracker "scrape" extension
  • Robust and well-tested
    • Comprehensive test suite (runs entirely offline, so it's reliable)
    • Used by popular clients: WebTorrentpeerflix, and playback
  • Tracker statistics available via web interface at /stats or JSON data at /stats.json
Also see bittorrent-dht.

Tracker stats

Screenshot

install

npm install bittorrent-tracker

usage

client

To connect to a tracker, just do this:
var Client = require('bittorrent-tracker')

var requiredOpts = {
  infoHash: new Buffer('012345678901234567890'), // hex string or Buffer
  peerId: new Buffer('01234567890123456789'), // hex string or Buffer
  announce: [], // list of tracker server urls
  port: 6881 // torrent client port, (in browser, optional)
}

var optionalOpts = {
  getAnnounceOpts: function () {
    // Provide a callback that will be called whenever announce() is called
    // internally (on timer), or by the user
    return {
      uploaded: 0,
      downloaded: 0,
      left: 0,
      customParam: 'blah' // custom parameters supported
    }
  },
  // RTCPeerConnection config object (only used in browser)
  rtcConfig: {},
  // User-Agent header for http requests
  userAgent: '',
  // Custom webrtc impl, useful in node to specify [wrtc](https://npmjs.com/package/wrtc)
  wrtc: {},
}

var client = new Client(requiredOpts)

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

client.on('warning', function (err) {
  // a tracker was unavailable or sent bad data to the client. you can probably ignore it
  console.log(err.message)
})

// start getting peers from the tracker
client.start()

client.on('update', function (data) {
  console.log('got an announce response from tracker: ' + data.announce)
  console.log('number of seeders in the swarm: ' + data.complete)
  console.log('number of leechers in the swarm: ' + data.incomplete)
})

client.once('peer', function (addr) {
  console.log('found a peer: ' + addr) // 85.10.239.191:48623
})

// announce that download has completed (and you are now a seeder)
client.complete()

// force a tracker announce. will trigger more 'update' events and maybe more 'peer' events
client.update()

// provide parameters to the tracker
client.update({
  uploaded: 0,
  downloaded: 0,
  left: 0,
  customParam: 'blah' // custom parameters supported
})

// stop getting peers from the tracker, gracefully leave the swarm
client.stop()

// ungracefully leave the swarm (without sending final 'stop' message)
client.destroy()

// scrape
client.scrape()

client.on('scrape', function (data) {
  console.log('got a scrape response from tracker: ' + data.announce)
  console.log('number of seeders in the swarm: ' + data.complete)
  console.log('number of leechers in the swarm: ' + data.incomplete)
  console.log('number of total downloads of this torrent: ' + data.downloaded)
})

server

To start a BitTorrent tracker server to track swarms of peers:
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.

    var allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa')
    if (allowed) {
      // If the callback is passed `null`, the torrent will be allowed.
      cb(null)
    } else {
      // If the callback is passed an `Error` object, the torrent will be disallowed
      // and the error's `message` property will be given as the reason.
      cb(new Error('disallowed torrent'))
    }
  }
})

// Internal http, udp, and websocket servers exposed as public properties.
server.http
server.udp
server.ws

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)
})

server.on('listening', function () {
  // fired when all requested servers are listening
  console.log('listening on http port:' + server.http.address().port)
  console.log('listening on udp port:' + server.udp.address().port)
})

// start tracker server listening! Use 0 to listen on a random free port.
server.listen(port, hostname, onlistening)

// listen for individual tracker messages from peers:

server.on('start', function (addr) {
  console.log('got start message from ' + addr)
})

server.on('complete', function (addr) {})
server.on('update', function (addr) {})
server.on('stop', function (addr) {})

// get info hashes for all torrents in the tracker server
Object.keys(server.torrents)

// get the number of seeders for a particular torrent
server.torrents[infoHash].complete

// get the number of leechers for a particular torrent
server.torrents[infoHash].incomplete

// get the peers who are in a particular torrent swarm
server.torrents[infoHash].peers
The http server will handle requests for the following paths: /announce/scrape. Requests for other paths will not be handled.

multi scrape

Scraping multiple torrent info is possible with a static Client.scrape method:
var Client = require('bittorrent-tracker')
Client.scrape({ announce: announceUrl, infoHash: [ infoHash1, infoHash2 ]}, function (err, results) {
  results[infoHash1].announce
  results[infoHash1].infoHash
  results[infoHash1].complete
  results[infoHash1].incomplete
  results[infoHash1].downloaded

  // ...
})

command line

Install bittorrent-tracker globally:
$ npm install -g bittorrent-tracker
Easily start a tracker server:
$ bittorrent-tracker
http server listening on 8000
udp server listening on 8000
ws server listening on 8000
Lots of options:
$ bittorrent-tracker --help
  bittorrent-tracker - Start a bittorrent tracker server

  Usage:
    bittorrent-tracker [OPTIONS]

  If no --http, --udp, or --ws option is supplied, all tracker types will be started.

  Options:
    -p, --port [number]  change the port [default: 8000]
        --trust-proxy    trust 'x-forwarded-for' header from reverse proxy
        --interval       client announce interval (ms) [default: 600000]
        --http           enable http server
        --udp            enable udp server
        --ws             enable websocket server
    -q, --quiet          only show error output
    -s, --silent         show no output
    -v, --version        print the current version
from https://github.com/webtorrent/bittorrent-tracker
(https://github.com/OpenWebTorrent/openwebtorrent-tracker)
-------
Streaming torrent client for the web 

WebTorrent  WebTorrent 

The streaming torrent client. For node.js and the web.

gitter travis appveyor npm version npm downloads Standard - JavaScript Style Guide
WebTorrent is a streaming torrent client for node.js and the browser. YEP, THAT'S RIGHT. THE BROWSER. It's written completely in JavaScript – the language of the web – so the same code works in both runtimes.
In node.js, this module is a simple torrent client, using TCP and UDP to talk to other torrent clients.
In the browser, WebTorrent uses WebRTC (data channels) for peer-to-peer transport. It can be used without browser plugins, extensions, or installations. It's Just JavaScript™. Note: WebTorrent does not support UDP/TCP peers in browser.
Simply include the webtorrent.min.js script on your page to start fetching files over WebRTC using the BitTorrent protocol, or require('webtorrent') with browserify. See demo apps and code examples below.
jsdelivr download count
To make BitTorrent work over WebRTC (which is the only P2P transport that works on the web) we made some protocol changes. Therefore, a browser-based WebTorrent client or "web peer" can only connect to other clients that support WebTorrent/WebRTC.
To seed files to web peers, use a client that supports WebTorrent, e.g. WebTorrent Desktop, a desktop client with a familiar UI that can connect to web peers, webtorrent-hybrid, a command line program, or Instant.io, a website. Established torrent clients like Vuze have already added WebTorrent support so they can connect to both normal and web peers. We hope other clients will follow.
Network

Open Source Sponsors

Features

  • Torrent client for node.js & the browser (same npm package!)
  • Insanely fast
  • Download multiple torrents simultaneously, efficiently
  • Pure Javascript (no native dependencies)
  • Exposes files as streams
    • Fetches pieces from the network on-demand so seeking is supported (even before torrent is finished)
    • Seamlessly switches between sequential and rarest-first piece selection strategy
  • Supports advanced torrent client features
  • Comprehensive test suite (runs completely offline, so it's reliable and fast)

Browser/WebRTC environment features

  • WebRTC data channels for lightweight peer-to-peer communication with no plugins
  • No silos. WebTorrent is a P2P network for the entire web. WebTorrent clients running on one domain can connect to clients on any other domain.
  • Stream video torrents into a <video> tag (webm (vp8, vp9) or mp4 (h.264))
  • Supports Chrome, Firefox, Opera and Safari.
Sauce Labs

Install

To install WebTorrent for use in node or the browser with require('webtorrent'), run:
npm install webtorrent
To install a webtorrent command line program, run:
npm install webtorrent-cli -g
To install a WebTorrent desktop application for Mac, Windows, or Linux, see WebTorrent Desktop.

Ways to help

Who is using WebTorrent today?

WebTorrent API Documentation

Usage

WebTorrent is the first BitTorrent client that works in the browser, using open web standards (no plugins, just HTML5 and WebRTC)! It's easy to get started!

In the browser

Downloading a file is simple:
var WebTorrent = require('webtorrent')

var client = new WebTorrent()
var magnetURI = '...'

client.add(magnetURI, function (torrent) {
  // Got torrent metadata!
  console.log('Client is downloading:', torrent.infoHash)

  torrent.files.forEach(function (file) {
    // Display the file by appending it to the DOM. Supports video, audio, images, and
    // more. Specify a container element (CSS selector or reference to DOM node).
    file.appendTo('body')
  })
})
Seeding a file is simple, too:
var dragDrop = require('drag-drop')
var WebTorrent = require('webtorrent')

var client = new WebTorrent()

// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop('body', function (files) {
  client.seed(files, function (torrent) {
    console.log('Client is seeding:', torrent.infoHash)
  })
})
There are more examples in docs/get-started.md.
Browserify
WebTorrent works great with browserify, an npm package that let's you use node-style require() to organize your browser code and load modules installed by npm (as seen in the previous examples).
Webpack
WebTorrent also works with webpack, a module bundler similar to browserify. However, webpack requires the following extra configuration:
{
  target: 'web',
  node: {
    fs: 'empty'
  }
}
If you are on webpack 1.x, you will also need to add the json-loader:
{
  module: {
    loaders: [
      // make sure to install the 'json-loader' package: npm install json-loader
      {
        test: /\.json$/,
        loader: 'json'
      }
    ]
  }
}
Otherwise you could also directly use the pre-built version via require('webtorrent/webtorrent.min').
Script tag
WebTorrent is also available as a standalone script (webtorrent.min.js) which exposes WebTorrent on the windowobject, so it can be used with just a script tag:
<script src="webtorrent.min.js"></script>
The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare and MaxCDN) for easy inclusion on your site:
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>

In Node.js

WebTorrent also works in node.js, using the same npm package! It's mad science!
NOTE: To connect to "web peers" (browsers) in addition to normal BitTorrent peers, use webtorrent-hybrid which includes WebRTC support for node.

As a command line app

WebTorrent is also available as a command line app. Here's how to use it:
$ npm install webtorrent-cli -g
$ webtorrent --help
To download a torrent:
$ webtorrent magnet_uri
To stream a torrent to a device like AirPlay or Chromecast, just pass a flag:
$ webtorrent magnet_uri --airplay
There are many supported streaming options:
--airplay               Apple TV
--chromecast            Chromecast
--mplayer               MPlayer
--mpv                   MPV
--omx [jack]            omx [default: hdmi]
--vlc                   VLC
--xbmc                  XBMC
--stdout                standard out [implies --quiet]
In addition to magnet uris, WebTorrent supports many ways to specify a torrent.

Talks about WebTorrent

Modules

Most of the active development is happening inside of small npm packages which are used by WebTorrent.

The Node Way™

"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons." — substack from "how I write modules"
node.js is shiny

Modules

These are the main modules that make up WebTorrent:
moduletestsversiondescription
webtorrenttorrent client (this module)
bittorrent-dhtdistributed hash table client
bittorrent-peerididentify client name/version
bittorrent-protocolbittorrent protocol stream
bittorrent-trackerbittorrent tracker server/client
create-torrentcreate .torrent files
magnet-uriparse magnet uris
parse-torrentparse torrent identifiers
render-mediaintelligently render media files
torrent-discoveryfind peers via dht and tracker
ut_metadatametadata for magnet uris (protocol extension)
ut_pexpeer discovery (protocol extension)

Enable debug logs

In node, enable debug logs by setting the DEBUG environment variable to the name of the module you want to debug (e.g. bittorrent-protocol, or * to print all logs).
DEBUG=* webtorrent
In the browser, enable debug logs by running this in the developer console:
localStorage.debug = '*'
Disable by running this:
localStorage.removeItem('debug')
from https://github.com/webtorrent/webtorrent
-------------

WebTorrent:基于浏览器的流 BT 客户端

WebTorrent 是用于 Node.js 和浏览器的流 torrent 客户端,完全使用 JavaScript 编写。WebTorrent 是个轻量级,快速的开源 BT 客户端,拥有非常棒的用户体验。

在 node.js 中,模块只是简单的 torrent 客户端,使用 TCP 和 UDP 来和其他 torrent 客户端进行通讯。

在浏览器中,WebTorrent 使用 WebRTC  (数据通道)进行点对点的传输,无需任何浏览器插件,扩展或者安装。注意:在浏览器上,WebTorrent 支持 UDP/TCP 点对点传输。

WebTorrent Desktop 连接 BitTorrent 和WebTorrent 端点。

特性

  • Node.js &浏览器的 BT 客户端 (相同的 npm 包)
  • 速度非常快
  • 可同时,高效的下载多个 torrents
  • 纯 Javascript (无原生依赖)
  • streams 一样表示文件
  • 支持高级 BT 客户端特性
  • 完整的测试套件 (完全支持离线运行,非常可靠快速)

仅浏览器支持的特性:

  • WebRTC 数据通道
  • P2P 网络
  • 流视频 torrent 为 <video> 标签 (webm (vp8, vp9) 或者 mp4 (h.264))
  • 支持 Chrome, Firefox 和 Opera

仅 NodeJS 支持的特性:

  • 支持 AirPlay, Chromecast, VLC player 流和其他设备/播放器

---------------------------------------------------


直接播放种子的视频播放器TorrenTV

跨平台流媒体应用程序TorrenTV, 允许用户直接在软件上播放种子视频文件,这款开源的应用程序只有简洁的界面,用户通过拖拽将种子放入框中就能自动对视频种子进行解析,用户无需等待可以边下边看。

TorrenTV作为免费的开源软件,支持windows, Linux和Mac系统(包括Apple TV),  作者Carlos是把开源Popcorn Time 进行了重新编码. Carlos接受外媒TorrentFreak采访时候表示:“Popcorn Time的代码非常优秀,但却不能达到我的两个要求。直接在我的Apple TV上观看电影和增加新的种子。”

官网: http://torrentv.github.io

-----
相关帖子:https://briteming.blogspot.com/2017/12/bittorrent-trackers.html

No comments:

Post a Comment