Simple, robust, BitTorrent tracker (client & server) implementation
features
- Includes client & server implementations
- Supports all mainstream tracker types:
- HTTP trackers
- UDP trackers (BEP 15)
- WebTorrent trackers (BEP forthcoming)
- 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: WebTorrent, peerflix, and playback
- Tracker statistics available via web interface at
/stats
or JSON data at/stats.json
Tracker stats
install
npm install bittorrent-tracker
usage
client
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
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
/announce
, /scrape
. Requests for other paths will not be handled.multi scrape
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
bittorrent-tracker
globally:$ npm install -g bittorrent-tracker
$ bittorrent-tracker
http server listening on 8000
udp server listening on 8000
ws server listening on 8000
$ 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 https://webtorrent.io
WebTorrent
The streaming torrent client. For node.js and the web.
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.
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.
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
- magnet uri support via ut_metadata
- peer discovery via dht, tracker, and ut_pex
- protocol extension api for adding new extensions
- 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)
ormp4 (h.264)
) - Supports Chrome, Firefox, Opera and Safari.
Install
require('webtorrent')
, run:npm install webtorrent
webtorrent
command line program, run:npm install webtorrent-cli -g
Ways to help
- Join us in Gitter or on freenode at
#webtorrent
to help with development or to hang out with some mad science hackers :) - Create a new issue to report bugs
- Fix an issue. WebTorrent is an OPEN Open Source Project!
Who is using WebTorrent today?
WebTorrent API Documentation
Usage
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)
})
})
Browserify
Webpack
{
target: 'web',
node: {
fs: 'empty'
}
}
json-loader
:{
module: {
loaders: [
// make sure to install the 'json-loader' package: npm install json-loader
{
test: /\.json$/,
loader: 'json'
}
]
}
}
require('webtorrent/webtorrent.min')
.Script tag
webtorrent.min.js
) which exposes WebTorrent
on the window
object, so it can be used with just a script tag:<script src="webtorrent.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
In Node.js
As a command line app
$ npm install webtorrent-cli -g
$ webtorrent --help
$ webtorrent magnet_uri
$ webtorrent magnet_uri --airplay
--airplay Apple TV
--chromecast Chromecast
--mplayer MPlayer
--mpv MPV
--omx [jack] omx [default: hdmi]
--vlc VLC
--xbmc XBMC
--stdout standard out [implies --quiet]
Talks about WebTorrent
- Sep 2017 - Nordic JS - Get Rich Quick With P2P Crypto Currency
- May 2017 - Char.la - WebTorrent and Peerify (Spanish)
- Nov 2016 - NodeConf Argentina - Real world Electron: Building Cross-platform desktop apps with JavaScript
- May 2016 - SIGNAL Conference - BitTorrent in the Browser
- May 2015 - Data Terra Nemo - WebTorrent: Mother of all demos
- May 2015 - Data Terra Nemo - WebRTC Everywhere
- Nov 2014 - JSConf Asia - How WebTorrent Works
- Sep 2014 - NodeConf EU - WebRTC Mad Science (first working WebTorrent demo)
- Apr 2014 - CraftConf - Bringing BitTorrent to the Web
- May 2014 - JS.LA - How I Built a BitTorrent Client in the Browser (progress update; node client working)
- Oct 2013 - RealtimeConf - WebRTC Black Magic (first mention of idea for WebTorrent)
Modules
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"
Modules
module | tests | version | description |
---|---|---|---|
webtorrent | torrent client (this module) | ||
bittorrent-dht | distributed hash table client | ||
bittorrent-peerid | identify client name/version | ||
bittorrent-protocol | bittorrent protocol stream | ||
bittorrent-tracker | bittorrent tracker server/client | ||
create-torrent | create .torrent files | ||
magnet-uri | parse magnet uris | ||
parse-torrent | parse torrent identifiers | ||
render-media | intelligently render media files | ||
torrent-discovery | find peers via dht and tracker | ||
ut_metadata | metadata for magnet uris (protocol extension) | ||
ut_pex | peer discovery (protocol extension) |
Enable debug logs
DEBUG
environment variable to the name of the module you want to debug (e.g. bittorrent-protocol
, or *
to print all logs).DEBUG=* webtorrent
localStorage.debug = '*'
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 客户端特性
- magnet uri 支持,通过 ut_metadata
- 点发现,通过 dht, tracker 和 ut_pex
- 协议扩展 api,添加新扩展
- 完整的测试套件 (完全支持离线运行,非常可靠快速)
仅浏览器支持的特性:
- 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