The structure of a DHT can be decomposed into several main components. The foundation is an abstract
keyspace, such as the set of 160-bit
strings. A keyspace
partitioning scheme splits ownership of this keyspace among the participating nodes. An
overlay network then connects the nodes, allowing them to find the owner of any given key in the keyspace. Once these components are in place, a typical use of the DHT for storage and retrieval might proceed as follows. Suppose the keyspace is the set of 160-bit strings. To index a file with given and in the DHT, the
SHA-1 hash of is generated, producing a 160-bit key , and a message is sent to any node participating in the DHT. The message is forwarded from node to node through the overlay network until it reaches the single node responsible for key as specified by the keyspace partitioning. That node then stores the key and the data. Any other client can then retrieve the contents of the file by again hashing to produce and asking any DHT node to find the data associated with with a message . The message will again be routed through the overlay to the node responsible for , which will reply with the stored . The keyspace partitioning and overlay network components are described below with the goal of capturing the principal ideas common to most DHTs; many designs differ in the details.
Keyspace partitioning Most DHTs use some variant of
consistent hashing or
rendezvous hashing to map keys to nodes. The two algorithms appear to have been devised independently and simultaneously to solve the distributed hash table problem. Both consistent hashing and rendezvous hashing have the essential property that removal or addition of one node changes only the set of keys owned by the nodes with adjacent IDs, and leaves all other nodes unaffected. Contrast this with a traditional
hash table in which addition or removal of one bucket causes nearly the entire keyspace to be remapped. Since any change in ownership typically corresponds to bandwidth-intensive movement of objects stored in the DHT from one node to another, minimizing such reorganization is required to efficiently support high rates of
churn (node arrival and failure).
Consistent hashing Consistent hashing employs a function \delta(k_1, k_2) that defines an abstract notion of the distance between the keys k_1 and k_2, which is unrelated to geographical distance or
network latency. Each node is assigned a single key called its
identifier (ID). A node with ID i_x owns all the keys k_m for which i_x is the closest ID, measured according to \delta(k_m, i_x). For example, the
Chord DHT uses consistent hashing, which treats nodes as points on a circle, and \delta(k_1, k_2) is the distance traveling clockwise around the circle from k_1 to k_2. Thus, the circular keyspace is split into contiguous segments whose endpoints are the node identifiers. If i_1 and i_2 are two adjacent IDs, with a shorter clockwise distance from i_1 to i_2, then the node with ID i_2 owns all the keys that fall between i_1 and i_2.
Rendezvous hashing In rendezvous hashing, also called highest random weight (HRW) hashing, all clients use the same hash function h() (chosen ahead of time) to associate a key to one of the
n available servers. Each client has the same list of identifiers , one for each server. Given some key
k, a client computes
n hash weights . The client associates that key with the server corresponding to the highest hash weight for that key. A server with ID S_x owns all the keys k_m for which the hash weight h(S_x, k_m) is higher than the hash weight of any other node for that key.
Locality-preserving hashing Locality-preserving hashing ensures that similar keys are assigned to similar objects. This can enable a more efficient execution of range queries, however, in contrast to using consistent hashing, there is no more assurance that the keys (and thus the load) is uniformly randomly distributed over the key space and the participating peers. DHT protocols such as Self-Chord and Oscar address such issues. Self-Chord decouples object keys from peer IDs and sorts keys along the ring with a statistical approach based on the
swarm intelligence paradigm. Sorting ensures that similar keys are stored by neighbour nodes and that discovery procedures, including
range queries, can be performed in logarithmic time. Oscar constructs a navigable
small-world network based on
random walk sampling also assuring logarithmic search time.
Overlay network Each node maintains a set of
links to other nodes (its
neighbors or
routing table). Together, these links form the overlay network. A node picks its neighbors according to a certain structure, called the
network's topology. All DHT topologies share some variant of the most essential property: for any key , each node either has a node ID that owns or has a link to a node whose node ID is
closer to , in terms of the keyspace distance defined above. It is then easy to route a message to the owner of any key using the following
greedy algorithm (that is not necessarily globally optimal): at each step, forward the message to the neighbor whose ID is closest to . When there is no such neighbor, then we must have arrived at the closest node, which is the owner of as defined above. This style of routing is sometimes called
key-based routing. Beyond basic routing correctness, two important constraints on the topology are to guarantee that the maximum number of
hops in any route (route length) is low, so that requests complete quickly; and that the maximum number of neighbors of any node (maximum node
degree) is low, so that maintenance overhead is not excessive. Of course, having shorter routes requires higher
maximum degree. Some common choices for maximum degree and route length are as follows, where is the number of nodes in the DHT, using
Big O notation: The most common choice, O(\log n) degree/route length, is not optimal in terms of degree/route length tradeoff, but such topologies typically allow more flexibility in choice of neighbors. Many DHTs use that flexibility to pick neighbors that are close in terms of latency in the physical underlying network. In general, all DHTs construct navigable small-world network topologies, which trade-off route length vs. network degree. Maximum route length is closely related to
diameter: the maximum number of hops in any shortest path between nodes. Clearly, the network's worst case route length is at least as large as its diameter, so DHTs are limited by the degree/diameter tradeoff that is fundamental in
graph theory. Route length can be greater than diameter, since the greedy routing algorithm may not find shortest paths.
Algorithms for overlay networks Aside from routing, there exist many algorithms that exploit the structure of the overlay network for sending a message to all nodes, or a subset of nodes, in a DHT. These algorithms are used by applications to do
overlay multicast, range queries, or to collect statistics. Two systems that are based on this approach are Structella, which implements flooding and random walks on a Pastry overlay, and DQ-DHT, which implements a dynamic querying search algorithm over a Chord network. == Security ==