Coder Social home page Coder Social logo

dreamonly-kell / bt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from atomashpolskiy/bt

0.0 1.0 0.0 46.09 MB

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

Home Page: http://atomashpolskiy.github.io/bt/

License: Apache License 2.0

Java 99.74% Shell 0.16% PowerShell 0.10%

bt's Introduction

Bt

A full-featured BitTorrent implementation in Java 8
peer exchange | magnet links | DHT | encryption | private trackers | extended protocol

Bt Example

Bt CLI

Linux build Linux build Maven Central JavaDoc Coverage

  • CLI – command-line downloader
  • HOME – website with documentation and tutorials
  • FORUM – Google group for support and feedback
  • LICENSE – licensed under Apache License 2.0

Prerequisites

Currently, all peer connections are established via encryption negotation protocol (also called MSE handshake). Therefore, 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.

Usage

Most recent version available in Maven Central is 1.3.

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>
<!-- 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>${bt-version}</version>
</dependency>
<dependency>
    <groupId>com.github.atomashpolskiy</groupId>
    <artifactId>bt-dht</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

// 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 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();

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. 1% CPU and 32M of RAM should be enough for everyone!

Java 8 CompletableFuture

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.

And much more...

Support and feedback

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:

List of supported BEPs

bt's People

Contributors

atomashpolskiy avatar

Watchers

 avatar

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.