The aim of btdht is to provide a powerful implementation of the Bittorrent mainline DHT easily extended to build application over the DHT. The author currently uses it to crawl the dht and has been able to retrieve more than 200.000 torrents files a day.
The implementation is fully compliant with the BEP5 and the kademlia paper  (with a predominance of the BEP5 over the paper) For example, this implementation uses a bucket-based approach for the routing table.
Table of Contents
The recommended installation mode is to use a virtualenv.
btdht using the last published release, run:
$ pip install btdht
Alternatively if you want to use the version of the git repository, you can clone it:
$ git clone https://github.com/nitmir/btdht $ cd btdht $ pip install -r requirements-dev.txt
make install to compile the sources and create a python package and install it with pip.
For installing or building on linux and unix systems, you will need a C compiler and the python
headers (installing the packages
python-dev should be enough on debian
like systems, you’ll probably gonna need
on centos like systems).
On windows systems, we provide pre-builded releases for python 2.7 and 3.5 so just running
pip install btdht should be fine. If you want to build from the sources of the repository or,
for another python version, you will also need a C compiler.
Search for the peers announcing the torrent
(Ubuntu 16.10 Desktop (64-bit))
>>> import btdht >>> import binascii >>> dht = btdht.DHT() >>> dht.start() # now wait at least 15s for the dht to boostrap init socket for 4c323257aa6c4c5c6ccae118db93ccce5bb05d92 Bootstraping >>> dht.get_peers(binascii.a2b_hex("0403fb4728bd788fbcb67e87d6feb241ef38c75a")) [ ('184.108.40.206', 17744), ('220.127.116.11', 3813), ('18.104.22.168', 32428), ('22.214.171.124', 61667), ('126.96.36.199', 6881), ('188.8.131.52', 38379), ('184.108.40.206', 32529), ('220.127.116.11', 10088), ('18.104.22.168', 10619), ('22.214.171.124', 33192), ('126.96.36.199', 5514), ('188.8.131.52', 14721), ('184.108.40.206', 31466), ('220.127.116.11', 32970), ('18.104.22.168', 2881), ('22.214.171.124', 6881), ('126.96.36.199', 31002) ]
Subsequent calls to get_peers may return more peers.
You may also inherit
btdht.DHT_BASE and overload some of the
functions. See the doc for a full overview of the
|||Maymounkov, P., & Mazieres, D. (2002, March). Kademlia: A peer-to-peer information system based on the xor metric. In International Workshop on Peer-to-Peer Systems (pp. 53-65). Springer Berlin Heidelberg.|