Skip to content

Commit

Permalink
Merge pull request #1 from nitmir/dev
Browse files Browse the repository at this point in the history
Update to version 0.3.0

* Python 3 compatibility
* Windows compatibility
* Document using sphinx
* Refactor to use weightless thread, introduce a Scheduler class
* Only send error message upon bad query. Always put a valid t in error message
* Then called _add_peer_queried, check that port number is > 0
* Style
  • Loading branch information
nitmir authored Dec 6, 2016
2 parents b4833b1 + fd46726 commit 0b3605d
Show file tree
Hide file tree
Showing 24 changed files with 4,955 additions and 1,153 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
build/*
build/
dist/
test_venv/
docs/_build/
*.c
*~
*.pyc

btdht.egg-info
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
recursive-include btdht *
recursive-include btdht *.c *.py *.pyx *.pxd
include setup.cfg
include Makefile
include LICENSE
Expand Down
43 changes: 40 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.PHONY: build dist docs
VERSION=`python setup.py -V`

WHL_FILES := $(wildcard dist/*.whl)
WHL_ASC := $(WHL_FILES:=.asc)
DIST_FILE := $(wildcard dist/*.tar.gz)
DIST_ASC := $(DIST_FILE:=.asc)

build:
python setup.py build

Expand All @@ -9,17 +14,49 @@ dist:

install: dist
pip -V
pip install --no-deps --upgrade --force-reinstall --find-links ./dist/btdht-${VERSION}.tar.gz btdht
pip install --no-cache-dir --no-deps --upgrade --force-reinstall --find-links ./dist/btdht-${VERSION}.tar.gz btdht

uninstall:
pip uninstall btdht || true


dist/%.asc:
gpg --detach-sign -a $(@:.asc=)

publish_pypi_release: test_venv test_venv/bin/twine dist sign_release
test_venv/bin/twine upload --sign dist/*

sign_release: $(WHL_ASC) $(DIST_ASC)

test_venv/bin/twine:
test_venv/bin/pip install twine

test_venv: test_venv/bin/python

test_venv/bin/python:
virtualenv test_venv
test_venv/bin/pip install -U --requirement requirements-dev.txt

test_venv/lib/python2.7/site-packages/btdht:
python setup.py sdist
test_venv/bin/pip install --no-cache-dir --no-deps --upgrade --force-reinstall --find-links ./dist/btdht-${VERSION}.tar.gz btdht

test_venv/bin/sphinx-build: test_venv
test_venv/bin/pip install Sphinx sphinx_rtd_theme

docs: test_venv/bin/sphinx-build test_venv/lib/python2.7/site-packages/btdht
bash -c "source test_venv/bin/activate; cd docs; make html"

clean:
rm -rf build dist btdht.egg-info
find ./btdht/ -name '*.c' -delete
find ./ -name '*.pyc' -delete
find ./ -name '*~' -delete

publish_pypi_release:
python setup.py sdist upload --sign
clean_docs:
cd docs; make clean

clean_test_venv:
rm -rf test_venv

clean_all: clean clean_test_venv clean_docs
104 changes: 98 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
btdht: An event based implementation of the Bittorrent distributed hash table
=============================================================================
btdht: A python implementation of the Bittorrent distributed hash table
=======================================================================

|github_version| |pypi_version| |licence| |doc|

The aim of btdht is to provide a powerful implementation of the Bittorrent
mainline DHT easily extended to build application over the DHT.
Expand All @@ -11,15 +12,106 @@ The implementation is fully compliant with the `BEP5 <http://www.bittorrent.org/
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.

Requirements

.. contents:: Table of Contents

Dependencies
------------

* python 2.7 or 3.4 or above
* `datrie <https://pypi.python.org/pypi/datrie>`_
* `netaddr <https://pypi.python.org/pypi/netaddr>`_


Build dependencies
------------------

* A C compiler
* `cython <https://pypi.python.org/pypi/Cython>`_
* python header files


Installation
------------
* `cython <https://pypi.python.org/pypi/Cython>`_
* `datrie <https://pypi.python.org/pypi/datrie>`_
* `netaddr <https://pypi.python.org/pypi/netaddr>`_

The recommended installation mode is to use a `virtualenv <https://virtualenv.pypa.io/en/stable/>`__.

To Install ``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

Then, run ``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 ``build-essential`` and ``python-dev`` should be enough on debian
like systems, you'll probably gonna need ``make``, ``gcc``, ``python2-devel`` and ``redhat-rpm-config``
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 <https://wiki.python.org/moin/WindowsCompilers>`__.


Usage examples
--------------

Search for the peers announcing the torrent ``0403fb4728bd788fbcb67e87d6feb241ef38c75a``
(`Ubuntu 16.10 Desktop (64-bit) <http://releases.ubuntu.com/16.10/ubuntu-16.10-desktop-amd64.iso.torrent>`__)

.. code-block:: python
>>> 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"))
[
('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)
]
Subsequent calls to get_peers may return more peers.
You may also inherit ``btdht.DHT_BASE`` and overload some of the ``on_`msg`_(query|response)``
functions. See the `doc <http://btdht.readthedocs.io>`_ for a full overview of the ``btdht`` API.
.. [#] 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.
.. |pypi_version| image:: https://badges.genua.fr/pypi/v/btdht.svg
:target: https://pypi.python.org/pypi/btdht
.. |github_version| image:: https://badges.genua.fr/github/tag/nitmir/btdht.svg?label=github
:target: https://github.com/nitmir/btdht/releases/latest
.. |licence| image:: https://badges.genua.fr/pypi/l/btdht.svg
:target: https://www.gnu.org/licenses/gpl-3.0.html
.. |doc| image:: https://badges.genua.fr/local/readthedocs/?version=latest
:target: http://btdht.readthedocs.io
4 changes: 3 additions & 1 deletion btdht/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
#
# (c) 2015 Valentin Samir

from .dht import DHT, DHT_BASE, ID, Node, Bucket, RoutingTable, NotFound, BucketFull, NoTokenError
from btdht.dht import DHT, DHT_BASE, Node, Bucket, RoutingTable
from btdht.utils import ID
from btdht.exceptions import NotFound, BucketFull, NoTokenError
Loading

0 comments on commit 0b3605d

Please sign in to comment.