* adding setup.py, and __init__.py to make this installable package.
[quix0rs-apt-p2p.git] / README.txt
1 [Note: I have no idea how up to date the code examples are -- icepick ]
2
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.
6
7   1 - http://kademlia.scs.cs.nyu.edu/
8   
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.
15   
16   2 - http://twistedmatrix.com
17   3 - http://airhook.org/
18
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.)
25
26 quick example:
27
28 >>> k = khashmir.test_one('<ip>', 4444)  # choose any port
29
30 - which is the same thing as - 
31
32 >>> import thread, khashmir
33 >>> k = khashmir.Khashmir('<ip>', <port>) # choose any port
34 >>> thread.start_new_thread(k.app.run, ())
35
36
37 If you want to make another peer in the same session, use 
38
39 >>> peer = khashmir.Khashmir(host, port) 
40
41 then do 
42
43 >>> peer.app.run() 
44
45 to register with the already running thread.
46
47
48 Now you need some contacts.  Add as some contacts and try to find close
49 nodes in the network.
50
51 >>> k.addContact('127.0.0.1', 8080)  # locate another peer
52 >>> k.findCloseNodes()  # query the network to bootstrap our table
53
54 Keys are always 20-character strings (sha1 hashes) currently there is no
55 limit to value sizes, something will go in ASAP
56
57 Now try storing and retrieving values.
58
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)  
63
64 # callback returns lists of values, will fire multiple times, last time will
65 # be an empty list
66 >>> k.valueForKey(key, callback)
67
68
69
70 TWEAKABLE SETTINGS:
71
72 ktable.py: 
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
77             to be large
78
79 A bunch of other tweakables are in const.py
80