How webtorrent/webtorrent works
WebTorrent is a JavaScript BitTorrent client for Node.js and browsers. Its main workflow is to add or seed a torrent, discover peers, exchange and verify pieces, then expose files as streams or HTTP responses. The README also documents magnet metadata, DHT/tracker/LSD/PEX discovery, protocol extensions, and browser WebRTC. Edges reflect sampled calls and explicit README statements; some documented integrations are not directly shown in the excerpts.
Main entry points: torrent.js Torrent lifecycle · index.js WebTorrent client · file.js Torrent files · peer.js Peer protocol
Components 18
Client and torrents
- WebTorrent client
index.js - Torrent lifecycle
lib/torrent.js
Peer networking
- Peer discovery
lib/torrent.js - Trackers and DHT
- Local discovery
- WebRTC transport
lib/webconn.js - TCP and uTP pool
lib/conn-pool.js - Peer protocol
lib/peer.js
Pieces and files
- Piece selection
lib/selections.js - Rarity map
lib/rarity-map.js - Piece storage
lib/torrent.js - Torrent files
lib/file.js - File iterator
lib/file-iterator.js
File serving
- HTTP file server
lib/server.js - Service worker
lib/worker.js - Worker request relay
lib/worker-server.js
Other components
- Application
- File consumer
Connections 21
- Application → WebTorrent client: adds or seeds
README.md - WebTorrent client → Torrent lifecycle: creates
index.js - WebTorrent client → TCP and uTP pool: initializes
index.js - Torrent lifecycle → Peer discovery: finds peers
README.md - Peer discovery → Trackers and DHT: queries
README.md - Peer discovery → Local discovery: discovers locally
README.md - Torrent lifecycle → Peer protocol: manages peers
lib/torrent.js - TCP and uTP pool → Peer protocol: creates incoming peers
lib/conn-pool.js - WebRTC transport → Peer protocol: uses WebRTC peers
- Peer protocol → Torrent lifecycle: exchanges pieces
lib/torrent.js - Torrent lifecycle → Piece selection: selects pieces
lib/torrent.js - Torrent lifecycle → Rarity map: ranks pieces
lib/torrent.js - Torrent lifecycle → Piece storage: verifies and stores
lib/torrent.js - Torrent lifecycle → Torrent files: creates files
lib/torrent.js - Torrent files → File iterator: creates iterator
lib/file.js - Torrent files → Piece storage: reads pieces
lib/file.js - File consumer → Torrent files: reads stream
README.md - WebTorrent client → HTTP file server: serves files
index.js - HTTP file server → Torrent files: streams file
lib/server.js - Service worker → Worker request relay: routes fetch
lib/worker.js - Worker request relay → WebTorrent client: relays request
lib/worker-server.js