Skip to content
Brad edited this page May 24, 2024 · 1 revision

Welcome to the rKad4 wiki!

Why / About

Distributed Hash tables don't have allot of documentation online nor are their many libraries that are easy to use and customization. This library offers an easy to use approach to DHTs. You can create your own RoutingTable, Messages, EventHandlers, and Refresh Tasks.

Supports

  • MainLine
  • Bogon Blocking
  • IPv6
  • Teredo

What is Kademlia

Kademlia is a DHT (Distributed Hash Table) which means it stores data using hashes of the values as keys and it is stored distributed. Hash Table Example

Key Value
2aae6c35c94fcfb415dbe95f408b9ce91ee846ed hello world
5c886dd284a2ae7d3d57a2b914b7d04a4429053f bla bla bla
848fa957aafd15d1e2552cf8d9cc994262765f14 next one

Each key is unique to the value and the value will always generate the same hash. Now for the distributed portion, once we have a hash for a value we will store this value based off of the XOR of the hash. The way this works is that each node generates its own UID based off of its IP Address and a random number 0-100 (We choose random number as it limits users behind NATs while still allowing NATs). Each node has their own Routing Table in which it stores the nodes in buckets, typically each bucket is about 5 nodes in size with a 5 node cache. The Routing Table stores the UID length (160 in length) of buckets so in this case 160 buckets. Routing Tables put nodes into these buckets based off of the XOR of the nodes UID compared to its own UID. Nodes will find each other by doing a FIND_NODE, this will occur on a Bucket Refresh where the node will generate UIDs based off the distance of itself to try to fill a routing table bucket if its not already full. To store data we send a PUT to the XOR of 5 nodes that are closest to our datas hash, getting the value is the same just in reverse. Here is some more documentation: Stanford Paper, Wikipedia Kademlia Link, Wikipedia MainLine Link

History of Kad4

I have created multiple versions of Kademlia and other DHTs, each better than the last. I started with TCP as I didn't understand UDP nore did I understand the benefits of UDP to start. This is the 4rth revision and likely the last of the Kad projects for me. If you are interested in my previous DHT projects I have linked them below. JChord Kad2 Kad3

Implementation

Implementing Kad4 is very easy, just download the JAR and add it as a library to your project. Here are some Example usages or you can take a look at our Documentation

Clone this wiki locally