1 [Note: I have no idea how up to date the code examples are -- icepick ]
3 Khashmir is a distributed hash table that uses an XOR distance metric and a
4 routing table similar to Kademlia [1]. Use Khashmir to build distributed
5 applications. Note that Khashmir currently isn't very attack resistant.
7 1 - http://kademlia.scs.cs.nyu.edu/
9 Khashmir is implemented in Python using the Twisted [2] asynchronous networking
10 framework. Network deliver is done using Airhook [3]. PySQLite is used for each
11 peer's backing store of keys and values. The backing store is currently
12 held in memory but it could easily be placed on disk. Values expire after
13 24 hours, by default. Each peer stores multiple values for a key and
14 currently returns all available values when requested.
16 2 - http://twistedmatrix.com
17 3 - http://airhook.org/
19 If you just want to watch it build a test network of peers, run "python
20 khashmir.py <num peers>" This script will create the specified number of
21 peers, give each one three random contacts, tell each one to find the
22 closest nodes, then pick a random peer and have it find another random peer
23 (ten times), then pick a random peer to insert a key/value and have three
24 random peers try to find it (ten times.)
28 >>> k = khashmir.test_one('<ip>', 4444) # choose any port
30 - which is the same thing as -
32 >>> import thread, khashmir
33 >>> k = khashmir.Khashmir('<ip>', <port>) # choose any port
34 >>> thread.start_new_thread(k.app.run, ())
37 If you want to make another peer in the same session, use
39 >>> peer = khashmir.Khashmir(host, port)
45 to register with the already running thread.
48 Now you need some contacts. Add as some contacts and try to find close
51 >>> k.addContact('127.0.0.1', 8080) # locate another peer
52 >>> k.findCloseNodes() # query the network to bootstrap our table
54 Keys are always 20-character strings (sha1 hashes) currently there is no
55 limit to value sizes, something will go in ASAP
57 Now try storing and retrieving values.
59 # callback returns node info dictionaries and actual connection information
60 # for peers that accepted the value. Currently finds the K closest nodes and
61 # makes one attempt to store them
62 >>> k.storeValueForKey(key, value, callback=None)
64 # callback returns lists of values, will fire multiple times, last time will
66 >>> k.valueForKey(key, callback)
73 K - the size of routing table buckets, how many nodes to return
74 in response to find-node/value request, and how many nodes to issue
75 storeValue to; default is 8, which should work for hundreds of
76 nodes, you might want to bump it if you think your network is going
79 A bunch of other tweakables are in const.py