Bt is a modern BitTorrent library in Java 8, perfect choice for both enterprise and home usage and experimentation. It offers good performance, reliability and is highly customizable. With Bt you can create a production-grade torrent client in a matter of minutes. Bt is still in its' early days, but is actively developed and designed with stability and maintainability in mind.
Introduction (contains a brief overview of Bt design and components)
JavaDoc (based on the latest commit in master)
- BEP-3: The BitTorrent Protocol Specification
- BEP-5: DHT Protocol (available in dht-experimental branch)
- BEP-10: Extension Protocol
- BEP-11: Peer Exchange (PEX)
- BEP-12: Multitracker metadata extension
- BEP-15: UDP Tracker Protocol
- BEP-20: Peer ID Conventions
- BEP-23: Tracker Returns Compact Peer Lists
- BEP-27: Private Torrents
- BEP-41: UDP Tracker Protocol Extensions
- Message Stream Encryption
Any thoughts, ideas, criticism, etc. are welcome, as well as votes for new features and BEPs to be added. You have the following options to share your ideas, receive help or report bugs:
- open a new GitHub issue
- post your question on the Bt forum
- join the Gitter chat
Release 1.1 includes a number of major performance and algorithmic improvements, critical bug fixes and API enhancements. Full list is available in release notes. It's strongly recommended for all users to switch to 1.1.
Available in dht-experimental branch. It's stable and already includes all changes from the 1.1 version.
- Clone the git repo:
git clone https://github.com/atomashpolskiy/bt.git
- Checkout dht-experimental (if you'd like to have DHT support)
git checkout dht-experimental
- Build
mvn clean install -Plgpl -DskipTests=true
- Download with CLI wrapper or use as a library
java -Xmx64m -jar bt-cli/target/bt-launcher.jar -f <path-to-torrent-file> -d <download-dir>
Declare the following dependencies in your project’s pom.xml:
<dependency>
<groupId>com.github.atomashpolskiy</groupId>
<artifactId>bt-core</artifactId>
<version>1.1</version>
</dependency>
<!-- for the sake of keeping the core with minimum number of 3-rd party
dependencies HTTP tracker support is shipped as a separate module;
you may omit this dependency if only UDP trackers are going to be used -->
<dependency>
<groupId>com.github.atomashpolskiy</groupId>
<artifactId>bt-http-tracker-client</artifactId>
<version>1.1</version>
</dependency>
<!-- bt-dht will be available if you've built the project manually
from dht-experimental branch-->
<dependency>
<groupId>com.github.atomashpolskiy</groupId>
<artifactId>bt-dht</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
// enable multithreaded verification of torrent data
Config config = new Config() {
@Override
public int getNumOfHashingThreads() {
return 8;
}
};
// enable bootstrapping from public routers
Module dhtModule = new DHTModule(new DHTConfig() {
@Override
public boolean shouldUseRouterBootstrap() {
return true;
}
});
// get torrent file URL and download directory
URL torrentUrl = getTorrentUrl();
File targetDirectory = getTargetDirectory();
// 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)
.torrent(torrentUrl)
.autoLoadModules()
.module(dhtModule)
.build();
// launch
client.startAsync(state -> {
if (state.getPiecesRemaining() == 0) {
client.stop();
}
}, 1000).join();
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.
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.
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.
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.
Bt has out-of-the-box support for multiple simultaneous torrent sessions with minimal system overhead. 1% CPU and 32M of RAM should be enough for everyone!
Client API leverages the asynchronous java.util.concurrent.CompletableFuture
to provide the most natural way for co-ordinating multiple torrent sessions. E.g. use CompletableFuture.allOf(client1.startAsync(...), client2.startAsync(...), ...).join()
. Or create a more sophisticated processing pipeline.
- check out Release Notes for details!