kademlia/README.markdown

50 lines
1.2 KiB
Markdown
Raw Normal View History

2014-01-03 03:39:06 +01:00
# [Kademlia](http://en.wikipedia.org/wiki/Kademlia) in Python
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)
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.*
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):
reactor.stop()
#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)
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)
server.listen(5678)
server.bootstrap([('127.0.0.1', 1234)]).addCallback(done, two)
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
2014-01-03 03:39:06 +01:00
```