What does it mean by Kademlia keys are used to identify nodes as well as data? - p2p

Okay, I've been reading articles and the paper about Kademlia recently to implement a simple p2p program that uses kademlia dht algorithm. And those papers are saying, those 160-bit key in a Kademlia Node is used to identify both nodes (Node ID) and the data (which are stored in a form of tuple).
I'm quite confused on that 'both' part.
As far as my understanding goes, each node in a Kademlia binary tree uniquely represents a client(IP, port) who each holds a list of files.
Here is the general flow on my understanding.
Client (.exe) gets booted
Creates a node component
Newly created node joins the network (bootstrapping)
Sends find_node(filehash) to k-closest nodes
Let's say hash is generated by hashing file binary named file1.txt
Received nodes each finds the queried filehash in its different hash table
Say, a hash map that has a list of files(File Hash, file location)
Step 4,5 repeated until the node is found (meanwhile all associated nodes are updating the buckets)
Does this flow look all right?
Additionally, bootstrapping method of Kademlia too confuses me.
When the node gets created (user executes the program), It seems like it uses bootstrapping node to fill up the buckets. But then what's bootstrapping node? Is it another process that's always running? What if the bootstrapping node gets turned off?
Can someone help me better understand the concept?
Thanks for the help in advance.

Does this flow look all right?
It seems roughly correct, but your wording is not very precise.
Each node has a routing table by which it organizes the neighbors it knows about and another table in which it organizes the data it is asked to store by others. Nodes have a quasi-random ID that determines their position in the routing keyspace. The hashes of keys for stored data don't precisely match any particular node ID, so the data is stored on the nodes whose ID is closest to the hash, as determined by the distance metric. That's how node IDs and key hashes are used for both.
When you perform a lookup for data (i.e. find_value) you ask the remote nodes for the k-closest neighbor set they have in their routing table, which will allow you to home in on the k-closest set for a particular target key. The same query also asks the remote node to return any data they have matching that target ID.
When you perform a find_node on the other hand you're only asking them for the closest neighbors but not for data. This is primarily used for routing table maintenance where you're not looking for any data.
Those are the abstract operations, if needed an actual implementation could separate the lookup from the data retrieval, i.e. first perform a find_node and then use the result set to perform one or more separate get operations that don't involve additional neighbor lookups (similar to the store operation).
Since kademlia is UDP-based you can't really serve arbitrary files because those could easily exceed reasonable UDP packet sizes. So in practice kademlia usually just serves as a hash table for small binary values (e.g. contact information, public keys and such). Bulk operations are either performed by other protocols bootstrapped off those values or by additional operations beyond those mentioned in the kademlia paper.
What the paper describes is only the basic functionality for a routing algorithm and most basic key value storage. It is a spherical cow in a vacuum. Actual implementations usually need additional features or work around security and reliability problems faced on the public internet.
But then what's bootstrapping node? Is it another process that's always running? What if the bootstrapping node gets turned off?
That's covered in this question (by example of the bittorrent DHT)

Related

Implementation of Kademlia node id

I m trying to implement a DHT using Kademlia paper as a way of understanding better how these systems work.
I have read some other articles that referes to this way of implementing a distributed hash table but there is something I can't wrap my head around.
In a p2p exchange files network, key ids could be implemented as digest of filename for consistency throught search mecanism.
But what about node id itself ?
Should I, for example, take the digest of "WAN-IP:PORT" combination or simply generate a completly random id from scratch ?
In the second case scenario, there is alway a risk that two nodes generate the same id. But using my WAN-IP:PORT I rely on the fact that my client is running a node behind a WAN-IP that should never change.
How should it come from the network itself ? I mean, on first contact, the peer work some magic and give the new node an id ?
I would appreciate some inputs on how to implement Kademlia node id generation.
As stated in Kademlia paper, "Node IDs are currently just random 160-bit identifiers, though they could equally be constructed as in Chords".
Chords uses the SHA-1 digest of a node IP.

Distributed computing in NodeJS - Mathematical expressions

I want to make a distributed system with many nodes that compute mathematical equations.
I was thinking about one "leader" as a gateway (similar to what eg. Apache does with distributed clustered websites) and many nodes. This leader will send work to nodes depending on which are not working.
My question is about the physical functionality of posting equations to nodes. Is there any npm module or well-known pattern to sending them?
I was thinking, that I will just send JSON formatted document filled with equations and data to nodes to compute, but this looks bulky to me.
Any other ideas? It would be awesome :)
This could help you https://github.com/pioardi/ring-election , with this project you can divide your data in partitions and each node can take care of a partition range .
Let me know if you have questions

How Kademlia tree of nodes relates to the infohash of a torrent file?

I'm trying to understand how Kademlia works in regards to finding a resource. There is pretty good description of now to build a node tree which is closest to the self node, how to find the distance between nodes, how to initiate the process etc. What I don't understand is how the file infohash fits into this picture. All descriptions tell us how to get into the play and build your own part of the distributed hash table but it is not it. We are doing this to actually find a resource, a file with a certain infohash. How it is stored in this node tree or there is a separate one? How is it works to find nodes which have this infohash, consequently having the file.
There is brief mentioning of the fact that the node id and infohash having the same 20 bytes length codes and something that node id XOR infohash is the distance between the node and the resource but I cannot imagine how is that and how it helps to find the resource? After all a node id actually having the resource can have the greatest XOR distance to the resource.
Thank you,
Alex
I recommend that you don't just read the bittorrent DHT specification but also the original kademlia paper, since the former is fairly concise and only mentions some things in passing.
Bittorrent's get_peers lookup is equivalent to the find_value operation described in the paper.
In short: just like you can do an iterative lookup to find the K-closest-node-set - closest based on xor-distance relative to the target key - for your own node's ID you can do so for any other ID.
For get_peers you simply use the infohash as target key.
The K-closest-node-set for a particular infohash is the set of nodes considered responsible to store the data for said infohash. Although due to inaccuracies of implementations and node churn more than K nodes around the target key may be storing data of interest.

In co-located caching, how is determined the location of a key?

This a design question about the Caching component, I can see two approaches in determining where is the data:
Each role instance maintains a table containing the entire set of keys, tracking the corresponding instance holding the data.
The location of the data is determined by the hash code of the key.
In the first case, it would mean that it's important to keep a reasonable set of keys.
In the second case, that testing the existence of a key would generate a network round trip...
My guess is 2), it utilize hash to determine the location, maybe consistent hashing.
And I think yes, testing the existence of a key would generate a network I/O, but I don't think it needs to call all you co-location server since from the hash it should know which server contains your data and just need to connect to it.

How to update entries in a DHT

I know how data is (in theory) stored in a DHT. However, I am uncertain as to how one might go about updating a piece of data associated with a key. Is this possible? Also, how are conflicts handled in a DHT.
A DHT simply defines put(key,value) and get(key) operations and the core of the various DHT algorithms revolve around how to locate the nodes responsible for a specific key.
What those nodes do on an incoming put request for a value already stored largely depends on the purpose and implementation of the DHT network, not on the algorithm itself.
E.g. a node might opt to timestamp all incoming values and return lists with multiple separate timestamped issues. Or it might return lists that also include the source address for each value. Or they might just overwrite the stored value.
If you have some relation between the key and a signature within the value or the source ID or something like that you can put enough intelligence into the nodes to verify the data cryptographically and thus allow them to keep a single canonical value for each key by replacing the old data.
In the case of bittorrent's DHT you wouldn't want that. Many different bittorrent peers announce their presence to a single key from different source addresses. Therefore the nodes actually store unique <key,IP,port> tuples where <IP,port> can be considered the value. Which means it'll return lists of IPs and ports on each lookup. And since a DHT will have multiple nodes responsible for one key you will actually have K (bucket size) nodes responding with varying lists.
TL;DR: It's implementation-dependent
It is possible. I've researched pastrys dht. It is possible to alter data stored under a given key but pastrys developers advise against it as it can have nasty side effects, mainly with replications of the altered piece of data which is stored on other nodes. (see the FAQ on freepastrys home page).
I'm not sure about how it would effect other dhts such as chord or tapestry however.
With regard to conflicts, again I have only experience with pastry. If you try to store data under a key that's already in use an exception will be thrown.

Resources