1ced5c9d82aaa2b65e29ca08230372686f5a18a3
[quix0rs-apt-p2p.git] / README.txt
1 Khashmir is a distributed hash table that uses an XOR distance metric and a routing table similar to Kademlia.  Use Khashmir to build distributed applications.  Note that Khashmir currently isn't very attack resistant.
2
3 Khashmir is implemented in Python using the Twisted asynchronous networking framework.  IPC is done via HTTP/XML-RPC.  BerkeleyDB is used for each peer's backing store of keys and values.  The backing store is currently held in memory but it could easily be placed on disk.  Values expire after 24 hours, by default.  Each peer stores multiple values for a key and currently returns all available values when requested.
4
5 If you just want to watch it build a test network of peers, run "python khashmir.py <num peers>" 
6 This script will create the specified number of peers, give each one three random contacts, tell each one to find the closest nodes, then pick a random peer and have it find another random peer (ten times), then pick a random peer to insert a key/value and have three random peers try to find it (ten times.)
7
8
9 quick example:
10
11 >>> k = khashmir.test_one('<ip>', 4444)  # chosose any port
12
13 - which is the same thing as - 
14
15 >>> import thread, khashmir
16 >>> k = khashmir.Khashmir('<ip>', <port>) # choose any port
17 >>> thread.start_new_thread(k.app.run, ())
18
19
20 If you want to make another peer in the same session, use peer = khashmir.Khashmir(host, port) then do peer.app.run() to register with the already running thread.
21
22
23 Now you need some contacts.  Add as some contacts and try to find close nodes in the network.
24
25 >>> k.addContact('127.0.0.1', 8080)  # locate another peer
26 >>> k.findCloseNodes()  # query the network to bootstrap our table
27
28 Keys are always 20-character strings (sha1 hashes)
29 currently there is no limit to value sizes, something will go in ASAP
30
31
32 Now try storing and retrieving values.
33
34 # callback returns node info dictionaries and actual connection information for peers that accepted the value
35 # currently finds the K closest nodes and makes one attempt to store them
36 >>> k.storeValueForKey(key, value, callback=None)  
37
38 # callback returns lists of values, will fire multiple times, last time will be an empty list
39 >>> k.valueForKey(key, callback)
40
41
42
43 TWEAKABLE SETTINGS:
44
45 ktable.py:  K  - the size of routing table buckets, how many nodes to return in response to find-node/value request, and how many nodes to issue storeValue to;   default is 8, which should work for hundreds of nodes, you might want to bump it if you think your network is going to be large
46
47 A bunch of other tweakables are in const.py
48