PyDHT is a Python implementation of distributed hashtable stored on a local machine. The implementation supports the DHT being stored in memory, on disk, or in a database. The DHT contains a list of hash values and their number of occurrences.
Follow the following steps to install PyDHT on Ubuntu:
$ git clone [email protected]:cesarghali/PyDHT.git
$ cd PyDHT
$ make
$ make test
$ sudo make install
PyDHT provides three flavors of a distributed hashtable stored on a single machine.
This class implements a DHT stored in text files on disk. Each hashtable is stored in a separate text file and includes a list of hash values and their number of occurrences in the format <hashValue:occurrences>. This class constructor expects the following parameters:
hashSize-- the size of the hash value in bits.numOfHT-- the number of hashtables.path-- the directory path where the hashtables will be stored on disk.
One drawback of this class is that each time the number of occurrences of a specific hash value is increased, the whole corresponding hashtable file is copied.
For a usage example see LocalDiskDHTTest.
This class implements a DHT stored in memory. Each hashtable is represented as a python dictionary object. The dictionary key is the hash value itself, while the dictionary value is the number of occurrences. This class constructor expects the following parameters:
hashSize-- the size of the hash value in bits.numOfHT-- the number of hashtables.
For a usage example see LocalDiskDHTTest.
This class implements a DHT stored in database on disk. Each hashtable is stored in a separate python shelve object. This class constructor expects the following parameters:
hashSize-- the size of the hash value in bits.numOfHT-- the number of hashtables.path-- the directory path where the hashtable database files will be stored.syncLimit-- is the number of inserts before the corresponding shelve object is being synced.
For a usage example see LocalDiskDHTTest.
Each of the above three classes provides the following APIs.
insert-- takes a hash value as a positive integer (or long integer) parameter and (1) inserts it in the corresponding hashtable with 1 as its number of occurrences, or (2) increases the number of occurrences by one if the hash value already exists.read-- takes a hash value as a positive integer (or long integer) parameter and returns its number of occurrences. If the hash value does not exist, 0 is returned.exists-- takes a hash value as a positive integer (or long integer) parameter and returnsTrueif such value exists in the distributed hashtable, orFalseotherwise.calculateCollision-- calculates the probability of collisions in the current DHT.countCollision-- counts the hash buckets that have collision, the number of inserted hash values that collide, and the total number of hash values inserted into the DHT.
Additionally, LocalDbDHT provides a close API that closes all shelve instances.
PyDHT is licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html.
PyDHT is developed and tested in Ubuntu 14.04 TLS. It should theoretically work in other environments.