Skip to content

MrLongBz/torrentcore

 
 

Repository files navigation

TorrentCore

Build Status Build status NuGet

A BitTorrent library that runs on all platforms supporting .NET Standard 2.0.

Feature Progress

This project is currently work-in-progress and there are likely to be bugs and missing features.

  • Open .torrent files
  • Upload/download torrents
  • Contact HTTP trackers
  • Compact peer lists BEP 23
  • UDP trackers BEP 15
  • Peer ID conventions BEP 20
  • Multitracker metadata extension BEP 12
  • Extension protocol BEP 10
  • Peer exchange BEP 11
  • Extension for Peers to Send Metadata Files BEP 9
  • UPnP port forwarding
  • IPv6 trackers BEP 7
  • DHT for trackerless torrents BEP 5
  • uTorrent Transport Protocol BEP 29

Usage

TorrentCore is designed to be easy to use, while supporting more advanced features if required.

There are no stable releases yet, but you can reference TorrentCore from NuGet, or directly from AppVeyor. For more information, see getting started.

var client = TorrentClient.Create();
var download = client.Add("sintel.torrent",
                          @"C:\Downloads\sintel");
download.Start();
await download.WaitForDownloadCompletionAsync();

For more customisation of the TorrentClient, use TorrentClientBuilder:

var client = TorrentClientBuilder.CreateDefaultBuilder()
    .UsePort(8000)
    .Build();

See the examples directory for more in-depth examples.

Extensible and Modular

TorrentCore is designed to allow custom extensions to be added and parts of the built-in functionality to be swapped out. TorrentCore uses the same dependency injection framework as ASP.NET Core to make this possible. Below are some examples of the ways in which functionality can be added or changed.

The public interface for extensions is unstable and subject to change while TorrentCore is under pre-release development.

Custom Transport Protocol

TorrentCore includes built-in support for communicating with peers over TCP. You can add support for any custom communication protocol that is able to expose connections to peers as a System.IO.Stream. (Of course, protocols other than TCP and uTP are incompatible with other BitTorrent clients.)

For more information, see custom transport protocols.

The CustomTransportProtocol example demonstrates a custom transport protocol by sending data as files on disk without any use of TCP or sockets.

BitTorrent Extension Protocol

Custom BEP 10 message handlers can be provided by implementing an IExtensionProtocolMessageHandler. You can then register your custom extension message handler to handle custom message types.

For more information, see custom extension protocol messages.

Modules

Modules are a general-purpose low-level mechanism to add functionality by hooking into events. Examples of things that modules can do include:

  • Modify the connection handshake sent to peers
  • Add a new type of message
  • Send raw BitTorrent messages to peers
  • Override the behaviour of messages built into the BitTorrent protocol itself

Some of the core functionality is implemented through modules, including the core protocol messages and the BEP 10 extension protocol. For more information, see custom modules.

Pipeline Stages

When a torrent is started, it is managed by a number of sequential stages in a pipeline that take it from checking the existing downloaded data to seeding to other peers. New stages can be added to the pipeline and built-in stages can be swapped for custom implementations.

For more information, see pipeline stages.

Data Storage

The file data for torrents is usually stored on disk. TorrentCore includes mechanisms to store the data on disk and in-memory, but you can provide custom storage mechanisms by implementing an IFileHandler.

For more information, see data storage.

Piece Picking Algorithms

A custom algorithm for deciding which pieces to request from peers can be used by implementing an IPiecePicker.

For more information, see piece picking.

Web UI

Web UI is work in progress. Package not currently published.

TorrentCore includes an optional web UI that can be used for detailed monitoring of Torrent downloads. It does not provide any functionality to control downloads.

It can be enabled by referencing TorrentCore.Web and calling:

client.EnableWebUI();

This starts a web interface on http://localhost:5001/.

/webui-screenshot.png

Command-Line Client

In addition to a library, TorrentCore provides a basic command-line client for downloading torrents. Usage is as follows:

torrentcorecli --help

usage: torrentcorecli [-p <arg>] [-o <arg>] [-v] [--ui [arg]] [--]
                      <input>

    -p, --port <arg>      Port to listen for incoming connections on.
    -o, --output <arg>    Path to save downloaded files to.
    -v, --verbose         Show detailed logging information.
    --ui [arg]            Run a web UI, optionally specifying the port
                          to listen on (default: 5001).
    <input>               Path of torrent file to download.

Contributing

Contributions are welcome! Please submit a pull request.

Releases

No releases published

Packages

No packages published

Languages

  • C# 94.6%
  • TypeScript 4.4%
  • Other 1.0%