bittorent干线dht的高效全面实现
btdht的Python项目详细描述
BTDHT的目的是提供一个强大的BitTorrent实现 主线dht很容易扩展到在dht上构建应用程序。 作者目前使用它来抓取dht,并且能够检索 每天有超过20万个Torrent文件。
实现完全符合BEP5 以及kademlia的论文[1](bep5占优势) 例如,此实现对路由表使用基于bucket的方法。
Build dependencies
- C编译器
- cython
- python头文件
Installation
建议的安装模式是使用virtualenv。
要使用上次发布的版本安装btdht,请运行:
$ pip install btdht
或者,如果您想使用git存储库的版本,可以克隆它:
$ git clone https://github.com/nitmir/btdht $ cd btdht $ pip install -r requirements-dev.txt
然后,运行make install来编译源代码,创建一个python包并用pip安装它。
在linux和unix系统上安装或构建时,需要一个c编译器和python 在debian上安装包build-essential和python-dev就足够了 像系统一样,您可能需要make、gcc、python2-devel和redhat-rpm-config 在类似centos的系统上)。
在windows系统上,我们为python 2.7和3.5提供了预先构建的版本,所以只需运行 pip install btdht应该没问题。如果要从存储库的源代码生成,或者, 对于另一个python版本,还需要一个C compiler。
Usage examples
搜索宣布Torrent的对等方0403fb4728bd788fbcb67e87d6feb241ef38c75a (Ubuntu 16.10 Desktop (64-bit))
>>>importbtdht>>>importbinascii>>>dht=btdht.DHT()>>>dht.start()# now wait at least 15s for the dht to boostrapinitsocketfor4c323257aa6c4c5c6ccae118db93ccce5bb05d92Bootstraping>>>dht.get_peers(binascii.a2b_hex("0403fb4728bd788fbcb67e87d6feb241ef38c75a"))[('81.171.107.75',17744),('94.242.250.86',3813),('88.175.164.228',32428),('82.224.107.213',61667),('85.56.118.178',6881),('78.196.28.4',38379),('82.251.140.70',32529),('78.198.108.3',10088),('78.235.153.136',10619),('88.189.113.32',33192),('81.57.9.183',5514),('82.251.17.155',14721),('88.168.207.178',31466),('82.238.89.236',32970),('78.226.209.88',2881),('5.164.219.48',6881),('78.225.252.39',31002)]
随后调用get_peers可能会返回更多的peers。
您还可以继承btdht.DHT_BASE,并重载一些on_`msg`_(query|response) 功能。有关btdhtapi的完整概述,请参见doc。
[1] | 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. |