A DHT in Python using asyncio
Go to file
2014-01-18 12:55:34 -05:00
example added travis file and some more tests 2014-01-04 14:27:45 -05:00
kademlia set now returns true only if value set in at least one other place 2014-01-18 12:55:34 -05:00
.gitignore fixed a few bugs 2014-01-13 21:44:44 -05:00
.travis.yml added travis file and some more tests 2014-01-04 14:27:45 -05:00
LICENSE first commit 2014-01-02 21:39:06 -05:00
Makefile added travis file and some more tests 2014-01-04 14:27:45 -05:00
README.markdown set now returns true only if value set in at least one other place 2014-01-18 12:55:34 -05:00
server.tac fixed a few bugs 2014-01-14 18:21:40 -05:00
setup.py added travis file and some more tests 2014-01-04 14:27:45 -05:00

Kademlia Distributed Hash Table in Python

Build Status

This library is an asynchronous Python implementation of the Kademlia distributed hash table. It uses Twisted to provide asynchronous communication. The nodes communicate using RPC over UDP to communiate, meaning that it is capable of working behind a NAT.

Installation

pip install kademlia

Usage

This assumes you have a working familiarity with Twisted.

Assuming you want to connect to an existing network (run the standalone server example below if you don't have a network):

from twisted.internet import reactor
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)

def done(found, server):
    log.msg("Found nodes: %s" % found)
    return server.set("a key", "a value").addCallback(get, server)

server = Server()
# next line, or use reactor.listenUDP(5678, server.protocol)
server.listen(5678)
server.bootstrap([('127.0.0.1', 1234)]).addCallback(done, server)

reactor.run()

Stand-alone Server

If all you want to do is run a local server, just start the example server:

twistd -noy server.tac

Running Tests

To run tests:

trial kademlia