libdht

A simple helper library for distributed hash tables.
git clone git://r-36.net/libdht
Log | Files | Refs | LICENSE

README.md (1083B)


      1 # libdht - a kadmelia helper function library
      2 
      3 The algorithm was taken from [here](https://gist.github.com/240988).
      4 
      5 ## Kadmelia protocol
      6 
      7 * [good description](http://xlattice.sourceforge.net/components/protocol/kademlia/specs.html)
      8 * [original paper](http://xlattice.sourceforge.net/components/protocol/kademlia/references.html#maymo02)
      9 
     10 ## Installation
     11 
     12 	make
     13 	make install
     14 
     15 ## How to use it
     16 
     17 	#include <dht.h>
     18 
     19 	dht_t *dht;
     20 	dhtnode_t *node;
     21 	char id[IDLENGTH];
     22 	llist_t *llist;
     23 
     24 	dht = dht_new("localhost");
     25 
     26 	/*
     27 	 * Set some node, which appeared on the network.
     28 	 */
     29 	node = dhtnode_new();
     30 	dhtnode_setid(node);
     31 	dhtnode_setaddr("127.0.0.1:7689");
     32 	dht_update(dht, node);
     33 	dhtnode_free(node);
     34 
     35 	/*
     36 	 * Get at maximum five nodes next to the target node
     37 	 */
     38 	dhtnode_setid(node);
     39 	dhtnode_setaddr("8.8.8.8:6669");
     40 	llist = dht_getclosest(dht, node, 5);
     41 	forllist(llist, elem)
     42 		dosomething(((dhtnode_t *)elem->data)->addr);
     43 	dhtnode_free(node);
     44 
     45 	/*
     46 	 * Cleanup.
     47 	 */
     48 	dht_free(dht);
     49 
     50 ## Thread safety
     51 
     52 This library is not thread safe. The critical part is the list hand-
     53 ling.
     54