kademlia/README.markdown

68 lines
2.4 KiB
Markdown
Raw Normal View History

# Python Distributed Hash Table
2014-01-04 20:27:45 +01:00
[![Build Status](https://secure.travis-ci.org/bmuller/kademlia.png?branch=master)](https://travis-ci.org/bmuller/kademlia)
2015-01-05 19:51:33 +01:00
[![Docs Status](https://readthedocs.org/projects/kademlia/badge/?version=latest)](http://kademlia.readthedocs.org)
**Documentation can be found at [kademlia.readthedocs.org](http://kademlia.readthedocs.org/).**
2014-01-03 03:39:06 +01:00
2014-03-25 13:37:25 +01:00
This library is an asynchronous Python implementation of the [Kademlia distributed hash table](http://en.wikipedia.org/wiki/Kademlia). It uses [Twisted](https://twistedmatrix.com) to provide asynchronous communication. The nodes communicate using [RPC over UDP](https://github.com/bmuller/rpcudp) to communiate, meaning that it is capable of working behind a [NAT](http://en.wikipedia.org/wiki/NAT).
This library aims to be as close to a reference implementation of the [Kademlia paper](http://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf) as possible.
2014-01-03 03:39:06 +01:00
## Installation
```
2014-01-04 20:27:45 +01:00
pip install kademlia
2014-01-03 03:39:06 +01:00
```
## Usage
*This assumes you have a working familiarity with [Twisted](https://twistedmatrix.com).*
2014-01-03 03:39:06 +01:00
2014-01-04 20:27:45 +01:00
Assuming you want to connect to an existing network (run the standalone server example below if you don't have a network):
2014-01-03 03:39:06 +01:00
```python
from twisted.internet import reactor
2014-01-04 20:27:45 +01:00
from twisted.python import log
from kademlia.network import Server
import sys
# log to std out
log.startLogging(sys.stdout)
def quit(result):
print "Key result:", result
reactor.stop()
def get(result, server):
return server.get("a key").addCallback(quit)
2014-01-04 20:27:45 +01:00
def done(found, server):
log.msg("Found nodes: %s" % found)
return server.set("a key", "a value").addCallback(get, server)
2014-01-03 03:39:06 +01:00
2014-01-04 20:27:45 +01:00
server = Server()
# next line, or use reactor.listenUDP(5678, server.protocol)
2014-01-04 20:27:45 +01:00
server.listen(5678)
server.bootstrap([('127.0.0.1', 1234)]).addCallback(done, server)
2014-01-04 20:27:45 +01:00
reactor.run()
```
2014-01-20 05:04:22 +01:00
Check out the examples folder for other examples.
2014-01-04 20:27:45 +01:00
## Stand-alone Server
If all you want to do is run a local server, just start the example server:
```
2014-01-20 05:04:22 +01:00
twistd -noy examples/server.tac
2014-01-03 03:39:06 +01:00
```
## Running Tests
To run tests:
```
trial kademlia
```
2014-01-19 20:05:26 +01:00
## Fidelity to Original Paper
2014-01-20 04:27:12 +01:00
The current implementation should be an accurate implementation of all aspects of the paper save one - in Section 2.3 there is the requirement that the original publisher of a key/value republish it every 24 hours. This library does not do this (though you can easily do this manually).