SkillAgentSearch skills...

Bt

BitTorrent library and client with DHT, magnet links, encryption and more

Install / Use

/learn @atomashpolskiy/Bt
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<h1 align="center"> <a href="https://atomashpolskiy.github.io/bt/">Bt</a> <a href="https://twitter.com/intent/tweet?text=Bt%3A%20A%20Java%208%20BitTorrent%20library%20with%20DHT%2C%20magnet%20links%2C%20encryption%20and%20more&url=https://github.com/atomashpolskiy/bt&via=atomashpolskiy&hashtags=java,torrent,bittorrent,dht"> <img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social&logo=twitter" alt="Tweet"> </a> </h1> <p align="center"><strong> <sup> A full-featured BitTorrent implementation in Java 8 <br/><a href="http://bittorrent.org/beps/bep_0011.html">peer exchange</a> | <a href="http://bittorrent.org/beps/bep_0009.html">magnet links</a> | <a href="http://bittorrent.org/beps/bep_0005.html">DHT</a> | <a href="http://wiki.vuze.com/w/Message_Stream_Encryption">encryption</a> | <a href="http://bittorrent.org/beps/bep_0014.html">LSD</a> | <a href="http://bittorrent.org/beps/bep_0027.html">private trackers</a> | <a href="http://bittorrent.org/beps/bep_0010.html">extended protocol</a> | <a href="#partial-downloads">partial downloads</a> | <a href="https://en.wikipedia.org/wiki/Internet_Gateway_Device_Protocol">port forwarding</a> </sup> </strong></p> <p align="center"> <img src="https://atomashpolskiy.github.io/static/img/bt-cli-demo.gif" alt="Bt CLI"> </p> <p align="center"> <a href="https://travis-ci.com/github/atomashpolskiy/bt"> <img src="https://travis-ci.com/atomashpolskiy/bt.svg?branch=master" alt="Linux build"> </a> <a href="https://ci.appveyor.com/project/atomashpolskiy/bt"> <img src="https://img.shields.io/appveyor/ci/atomashpolskiy/bt/master.svg?label=Windows%20build" alt="Linux build"> </a> <a href="https://maven-badges.herokuapp.com/maven-central/com.github.atomashpolskiy/bt-core/"> <img src="https://maven-badges.herokuapp.com/maven-central/com.github.atomashpolskiy/bt-core/badge.svg" alt="Maven Central"> </a> <a href="https://atomashpolskiy.github.io/bt/javadoc/latest/"> <img src="https://img.shields.io/badge/javadoc-latest-orange.svg" alt="JavaDoc"> </a> <a href="https://codecov.io/gh/atomashpolskiy/bt"> <img src="https://img.shields.io/codecov/c/github/atomashpolskiy/bt/master.svg" alt="Coverage"> </a> </p>

Supported BEPs and extensions

Resources

  • HOME – website with documentation and tutorials
  • RELEASE NOTES – list of features, bugfixes and improments for each version
  • UPGRADE INSTRUCTIONS – version migration guide
  • FORUM – Google group for support and feedback
  • TROUBLESHOOTING - solutions for some common problems
  • LICENSE – licensed under Apache License 2.0

Runnable apps and demos

Media

Prerequisites

<sup>Currently, all peer connections are established via encryption negotation protocol (also called MSE handshake). If you're using Oracle JDK (pre 8u152), in order to be able to connect to peers you must install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy. The reason for this requirement is that the MSE RC4 cipher uses 160 bit keys, while default Java installation allows at most 128 bit keys.</sup>

Usage

Most recent version available in Maven Central is 1.10.

Declare the following dependencies in your project’s pom.xml:

<dependency>
    <groupId>com.github.atomashpolskiy</groupId>
    <artifactId>bt-core</artifactId>
    <version>${bt-version}</version>
</dependency>
<dependency>
    <groupId>com.github.atomashpolskiy</groupId>
    <artifactId>bt-http-tracker-client</artifactId>
    <version>${bt-version}</version>
</dependency>
<dependency>
    <groupId>com.github.atomashpolskiy</groupId>
    <artifactId>bt-dht</artifactId>
    <version>${bt-version}</version>
</dependency>
<dependency>
    <groupId>com.github.atomashpolskiy</groupId>
    <artifactId>bt-upnp</artifactId>
    <version>${bt-version}</version>
</dependency>

Building from source

git clone https://github.com/atomashpolskiy/bt.git
cd bt
mvn clean install -DskipTests

Code sample

Download a torrent from a magnet link

// enable multithreaded verification of torrent data
Config config = new Config() {
    @Override
    public int getNumOfHashingThreads() {
        return Runtime.getRuntime().availableProcessors() * 2;
    }
};

// enable bootstrapping from public routers
Module dhtModule = new DHTModule(new DHTConfig() {
    @Override
    public boolean shouldUseRouterBootstrap() {
        return true;
    }
});

// get download directory
Path targetDirectory = Paths.get(System.getProperty("user.home"), "Downloads");

// create file system based backend for torrent data
Storage storage = new FileSystemStorage(targetDirectory);

// create client with a private runtime
BtClient client = Bt.client()
        .config(config)
        .storage(storage)
        .magnet("magnet:?xt=urn:btih:af0d9aa01a9ae123a73802cfa58ccaf355eb19f1")
        .autoLoadModules()
        .module(dhtModule)
        .stopWhenDownloaded()
        .build();

// launch
client.startAsync().join();

Create a torrent

Path torrentRoot = Paths.get("/home/torrents/mytorrent");
Path file1 = Paths.get("/home/torrents/mytorrent/file1.bin");
Path file2 = Paths.get("/home/torrents/mytorrent/file2.bin");
Path dirToAdd = Paths.get("/home/torrents/mytorrent/dir_with_files");
byte[] torrentBytes = new TorrentBuilder()
        .rootPath(torrentRoot)
        .addFiles(file1, file2, dirToAdd)
        .announce("http://example.com/announce")
        .build();
Files.write(Paths.get("/home/torrents/mytorrent.torrent"), torrentBytes);

What makes Bt stand out from the crowd

Flexibility

Being built around the Guice DI, Bt provides many options for tailoring the system for your specific needs. If something is a part of Bt, then it can be modified or substituted for your custom code.

Custom backends

Bt is shipped with a standard file-system based backend (i.e. you can download the torrent file to a storage device). However, the backend details are abstracted from the message-level code. This means that you can use your own backend by providing a storage unit implementation.

Protocol extensions

One notable customization scenario is extending the standard BitTorrent protocol with your own messages. BitTorrent's BEP-10 provides a native support for protocol extensions, and implementation of this standard is already included in Bt. Contribute your own Messages, byte manipulating MessageHandlers, message consumers and producers; supply any additional info in ExtendedHandshake.

Test infrastructure

To allow you test the changes that you've made to the core, Bt ships with a specialized framework for integration tests. Create an arbitrary-sized swarm of peers inside a simple JUnit test, set the number of seeders and leechers and start a real torrent session on your localhost. E.g. create one seeder and many leechers to stress test the network overhead; use a really large file and multiple peers to stress test your newest laptop's expensive SSD storage; or just launch the whole swarm in no-files mode and test your protocol extensions.

Parallel downloads

Bt has out-of-the-box support for multiple simultaneous torrent sessions with minimal system overhead.

Related Skills

View on GitHub
GitHub Stars2.5k
CategoryDevelopment
Updated8d ago
Forks384

Languages

Java

Security Score

100/100

Audited on Mar 17, 2026

No findings