torrent
High-level user-facing BitTorrent library. Provides async I/O, session
management, tracker communication, and file storage — built on top of
torrent-core.
Modules
| Module | Description | BEP |
|---|---|---|
session |
Session, download/upload loops, peer manager | — |
peer |
Async PeerConnection, re-exports core types |
BEP 3 |
tracker |
HTTP (manual) + UDP tracker announce | BEP 3, 15, 23 |
dht |
Async DHT RPC, query helpers (find_node, etc.) |
BEP 5 |
storage |
FileStorage (async file I/O) |
— |
Quick Start
use PathBuf;
use ;
async
Re-exports from torrent-core
All commonly used core types are re-exported so you only need torrent as a
dependency:
use ;
use Metainfo;
use MagnetUri;
use ;
use ;
use PieceManager;
Examples
See the examples/ directory for runnable scenario guides:
| Example | Scenario |
|---|---|
parse_metainfo.rs |
Parse a .torrent file and inspect metadata |
tracker_announce.rs |
Query HTTP/UDP trackers for peer lists |
dht_discovery.rs |
Discover peers via the DHT (Kademlia) |
peer_connect.rs |
Low-level peer wire protocol (handshake + messages) |
Run with:
Relationship with torrent-core
┌─────────────────────────────────────────────────────┐
│ torrent (async) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────┐ │
│ │ session │ │ tracker │ │ dht/rpc │ │storage/ │ │
│ │ │ │ http/udp │ │ query │ │fs │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬────┘ │
│ │ │ │ │ │
│ └────────────┴────────────┴────────────┘ │
│ │ │
│ depends on torrent_core │
│ │ │
├────────────────────────┼────────────────────────────┤
│ torrent-core (sync, no tokio) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────┐ │
│ │ bencode │ │ metainfo │ │ peer │ │ dht/ │ │
│ │ error │ │ magnet │ │ handshake│ │ krpc │ │
│ │ │ │ │ │ message │ │ routing │ │
│ └──────────┘ └──────────┘ └──────────┘ └─────────┘ │
│ ┌──────────┐ ┌──────────┐ ┌──────────────────────┐ │
│ │ tracker │ │ piece │ │ storage │ │
│ │ data │ │ manager │ │ trait (read/write) │ │
│ │ types │ │ selector │ │ │ │
│ └──────────┘ └──────────┘ └──────────────────────┘ │
└─────────────────────────────────────────────────────┘
Testing
License
MIT — see LICENSE.