About
Dart implementation of a BitTorrent HTTP/HTTPS and UDP tracker/scrape client library.
Supported Protocols
How to use it
Tracker
To create a TorrentAnnounceTracker instance, you need to provide an AnnounceOptionsProvider. Since there is no default implementation, you need to implement it manually:
class SimpleProvider implements AnnounceOptionsProvider {
SimpleProvider(this.torrent, this.peerId, this.port);
final String peerId;
final int port;
final Torrent torrent;
final int compact = 1;
final int numwant = 50;
@override
Future<Map<String, dynamic>> getOptions(Uri uri, String infoHash) {
return Future.value({
'downloaded': 0,
'uploaded': 0,
'left': torrent.length,
'compact': compact, // Must be 1
'numwant': numwant, // Maximum is 50
'peerId': peerId,
'port': port
});
}
}
Create a TorrentAnnounceTracker instance:
var torrentTracker = TorrentAnnounceTracker(SimpleProvider(torrent, peerId, port));
Start tracker with different events:
torrentTracker.runTracker(url, infoHash, event: 'started');
torrentTracker.runTracker(url, infoHash, event: 'completed');
torrentTracker.runTracker(url, infoHash, event: 'stopped');
Listen to tracker events:
torrentTracker.onAnnounceError((source, error) {
log('Announce error: $error');
});
torrentTracker.onPeerEvent((source, event) {
print('${source.announceUrl} peer event: $event');
});
torrentTracker.onAnnounceOver((source, time) {
print('${source.announceUrl} announce completed in $time seconds');
source.dispose();
});
Scrape
Create a TorrentScrapeTracker instance:
var scrapeTracker = TorrentScrapeTracker();
Add scrape URLs and info hash. The tracker will automatically transform announce URLs to scrape URLs:
scrapeTracker.addScrapes(torrent.announces, torrent.infoHashBuffer);
Note: A single Scrape instance can handle multiple info hashes. If you call addScrapes or addScrape with the same URL but different info hash buffers, it will return the same Scrape instance, allowing you to scrape multiple torrents in one request.
Get scrape results:
scrapeTracker.scrape(torrent.infoHashBuffer).listen((event) {
print(event);
});
The scrape method takes an info hash buffer as a parameter and returns a Stream. Listen to the stream to receive scrape results.
Libraries
- dtorrent_tracker_v2
- Bittorrent Tracker. Include UDP tracker and Http/Https tracker