Giter VIP home page Giter VIP logo

torrent_tracker's Introduction

About

Dart implementation of a BitTorrent Http/Https and UDP tracker/scrape client

Support

How to use it

Tracker

To create the TorrentAnnounceTracker instance, the parameter AnnounceOptionProvider should be provided. Howerver, there is not any implements , user have to implement it manually:

class SimpleProvider implements AnnounceOptionsProvider {
  SimpleProvider(this.torrent, this.peerId, this.port);
  String peerId;
  int port;
  String infoHash;
  Torrent torrent;
  int compact = 1;
  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,// it should be 1
      'numwant': numwant, // max is 50
      'peerId': peerId,
      'port': port
    });
  }
}

When we have the AnnounceOptionsProvider instance, we can create a TorrentAnnounceTracker like this:

    var torrentTracker = TorrentAnnounceTracker(SimpleProvider(....));

TorrentAnnounceTracker have some methods to run started,stopped,completed announce event:

    torrentTracker.runTracker(url,infohash,event:'started');

We can add some listener on the torrentTracker to get the announce result:

    torrentTracker.onAnnounceError((source, error) {
      log('announce error:', error: error);
    });
    torrentTracker.onPeerEvent((source, event) {
      print('${source.announceUrl} peer event: $event');
    });

    torrentTracker.onAnnounceOver((source, time) {
      print('${source.announceUrl} announce over!: $time');
      source.dispose();
    });

Scrape

Create a TorrentScrapeTracker instance:

var scrapeTracker = TorrentScrapeTracker();

Then add the scrape url (same with the announce tracker url, TorrentScrapeTracker will transform it) and infohash buffer to create a Scrape:

scrapeTracker.addScrapes(torrent.announces, torrent.infoHashBuffer);

NOTE: The Scrape can add more than one infoHashbuffer , because it can "scrape" multiple torrent informations at one time, so if user invoke addScrapes or addScrape with same url but different infohashbuffer , it will return the same Scrape instance.

To get the scrape result:

scrapeTracker.scrape(torrent.infoHashBuffer).listen((event) {
    print(event);
});

The method scrape need a infoHashbuffer as the parameter and return a Stream , user can listen the Stream event to get the result.

torrent_tracker's People

Contributors

eclipseglory avatar

Stargazers

 avatar Andy Chentsov avatar Zvezda avatar Mitchell Tannenbaum avatar  avatar ekibun avatar

Watchers

Mitchell Tannenbaum avatar  avatar

Forkers

xhns uoares moham96

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.