the8472 / mldht

Bittorrent Mainline DHT implementation in java
Mozilla Public License 2.0
147 stars 45 forks source link
bittorrent cli dht kademlia library p2p

mldht

Build Status (travis) Build Status (gitlab) Jitpack maven repo bintray maven repo

A java library and standalone node implementing the Kademlia-based bittorrent mainline DHT, with long-running server-class nodes in mind.

Originally developed as DHT plugin for Azureus/Vuze

Features

Implemented specs:

Spec Title Status
BEP5 Bittorrent DHT Yes
BEP32 IPv6 Yes
BEP33 Scrapes Yes
BEP42 DHT Announce Security Partial; only the ip fields for external address discovery are supported
BEP9 Metadata exchange Partial; only fetching is supported
libtorrent.org Extended get_peers response
Forward compatibility
Client identification
Yes
BEP45 multi-homing/multi-address mode Yes
BEP44 Arbitrary data storage Yes
BEP50 Pub/Sub No
BEP51 DHT Infohash Indexing Yes

Additional:

Dependencies

installed via maven:

build

git clone https://github.com/the8472/mldht.git .
mvn package dependency:copy-dependencies appassembler:assemble
# install symlink scripts to ~/bin/ 
mvn antrun:run@link

embedding as library

See docs/use-as-library.md for further information. Maven repos are linked in the badges.

run in standalone mode

mkdir -p work
cd work
../bin/mldht-daemon
# or manually
# java -cp "../target/*:../target/dependency/*" the8472.mldht.Launcher &

this will create various files in the current working directory

Security note: the shell script launches the JVM with a debug port bound to localhost for easier maintenance, thus allowing arbitrary code execution with the current user's permissions. In a multi-user environment a custom script with debugging disabled should be used

network configuration

optional components

Some features are not enabled out of the box because they only require external infrastructure, provide public services or would cause extra traffic.

They are enabled by adding or uncommenting a <component><className>...</className></component> entry to the config.xml

remote-cli

launch daemon with

    <component>
      <className>the8472.mldht.cli.Server</className>
    </component>

run CLI client with

bin/mldht-remote-cli help
# or manually:
# java -cp "target/*" the8472.mldht.cli.Client help

available commands (subject to change):

HELP                                                 - prints this help
PING ip port                                         - continuously pings a DHT node with a 1 second interval
GET hash [salt]                                      - perform a BEP44 get
PUT -f <input-path> [-keyfile <path>] [-salt <salt>]
PUT <input> [-keyfile <path>] [-salt <salt>]         - perform a BEP44 put, specifying a salt or keyfile implies a mutable put, immutable otherwise. data will be read from file or as single argument
GETTORRENT [infohash...]                             - peer lookup for <infohash(es)>, then attempt metadata exchange, then write .torrent file(s) to the current working directory
GETPEERS [infohash...] [-fast]                       - peer lookup for <infohash(es)>, print ip address/port tuples
BURST [count]                                        - run a batch of find_node lookups to random target IDs. intended test the attainable throughput for active lookups, subject to internal throttling

Security note: The CLI Server component listens on localhost, accepting commands without authentication from any user on the system. It is recommended to not use this component in a multi-user environment.

redis statistics export

    <component xsi:type="mldht:redisIndexerType">
      <className>the8472.mldht.PassiveRedisIndexer</className>
      <address>127.0.0.1</address><!-- additional parameter to allow exporting to other hosts -->
    </component>

custom components

Simply implement Component and configure the launcher to include it on startup through the config.xml:

    <component>
      <className>your.class.name.Here</className>
    </component>