Utah Distributed Systems Meetup and Reading Group - Kademlia
Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair....
Transcript of Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair....
![Page 1: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/1.jpg)
1Kademlia, 18th Nov. 2008
Kademlia: A Peertopeer Information System Based on the XOR Metric
Petar Maymounkov and David Mazières New York University
(Presented In 1th International Workshop on P2P Systems 2002)
Presented by: Amir H. Payberah [email protected]
![Page 2: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/2.jpg)
2Kademlia, 18th Nov. 2008
![Page 3: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/3.jpg)
3Kademlia, 18th Nov. 2008
Core Idea
![Page 4: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/4.jpg)
4Kademlia, 18th Nov. 2008
Core Idea 1
P
Node
KBucket List
KBucket
![Page 5: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/5.jpg)
5Kademlia, 18th Nov. 2008
Core Idea 2
P
Node
KBucket List
Lookup Q
closest nodes to Q are stored here
•Closest nodes in ID space•Having more common bits in prefix (will be back to it)
![Page 6: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/6.jpg)
6Kademlia, 18th Nov. 2008
Core Idea 3
P
Node
KBucket List
closest nodes to Q are stored here
A B C
... and select nodes from the appropriate kbucket
Lookup Q
![Page 7: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/7.jpg)
7Kademlia, 18th Nov. 2008
Core Idea 4
FIND_NODE(Q)
P
A
B
C
FIND_NODE(Q)
FIND_NODE(Q)
![Page 8: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/8.jpg)
8Kademlia, 18th Nov. 2008
Core Idea 5
A
Find k closest nodes to Q
Find k closest nodes to Q
B
Find k closest nodes to Q
Find k closest nodes to Q
C
Find k closest nodes to Q
Find k closest nodes to Q
![Page 9: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/9.jpg)
9Kademlia, 18th Nov. 2008
Core Idea 6
Returns k closets nodes to Q
P
A
B
C
Returns k closets nodes to Q
Returns k closets nodes to Q
![Page 10: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/10.jpg)
10Kademlia, 18th Nov. 2008
Core Idea 7
Received information from A, B and C
P
P updates its kbucket list by received messages ...
KBucket List
M N O
... again select nodes from the received information
![Page 11: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/11.jpg)
11Kademlia, 18th Nov. 2008
Core Idea 8
FIND_NODE(Q)
P
M
N
O
FIND_NODE(Q)
FIND_NODE(Q)
![Page 12: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/12.jpg)
12Kademlia, 18th Nov. 2008
Core Idea 9
Repeats this procedure iteratively until ...
![Page 13: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/13.jpg)
13Kademlia, 18th Nov. 2008
Core Idea 10
Received information in round n1
P
Received information in round n
... until received information in round n1 and n are the same.
![Page 14: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/14.jpg)
14Kademlia, 18th Nov. 2008
Core Idea 11
P
P resends the FIND_NODE to k closest nodes it has not already queried ...
T S XReceived information in round n R
![Page 15: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/15.jpg)
15Kademlia, 18th Nov. 2008
Let's Look Inside of Kademlia
![Page 16: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/16.jpg)
16Kademlia, 18th Nov. 2008
System Description
•Each Kademlia node has a 160bit node ID.
•To publish and find <key,value> pairs, Kademlia relies on a notion of distance between two Ids.
•Distance between id1 and id2: d(id1, id2) = id1 XOR id2 If ID space is 3 bits:
d(1, 5) = d(0012, 1012) = 0012 XOR 1012
= 1002 = 4
![Page 17: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/17.jpg)
17Kademlia, 18th Nov. 2008
Node State
•Kbucket: each node keeps a list of information for nodes of distance between 2i and 2i+1.
0 <= i < 160
Sorted by time last seen.
110111
100101
000011 010 001
[1, 2)
[2, 4)
[4, 8)
![Page 18: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/18.jpg)
18Kademlia, 18th Nov. 2008
Node State
•Kbucket: each node keeps a list of information for nodes of distance between 2i and 2i+1.
0 <= i < 160
Sorted by time last seen.
110111
100101
000011 010 001
[1, 2) Two first bits in common
[2, 4) First bit in common
[4, 8) No common prefix
![Page 19: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/19.jpg)
19Kademlia, 18th Nov. 2008
Kademlia RPCs
•PING Probes a node to see if it is online.
•STORE Instructs a node to store a <key, value> pair.
•FIND_NODE Returns information for the k nodes it knows about closest to the target
ID. It can be from one kbucket or more.
•FIND_VALUE Like FIND_NODE, ... But if the recipient has stored they <key, value>, it just returns the stored
value.
![Page 20: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/20.jpg)
20Kademlia, 18th Nov. 2008
Store Data
•The <key, value> data is stored in k closest nodes to the key.
![Page 21: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/21.jpg)
21Kademlia, 18th Nov. 2008
Lookup Service
001000
011010
101110 100 111
[1, 2)
[2, 4)
[4, 8)
110111
100101
000011 010 001
[1, 2)
[2, 4)
[4, 8)
100101
110111
011001 000 010
[1, 2)
[2, 4)
[4, 8)
Step1
Step2
Step3
![Page 22: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/22.jpg)
22Kademlia, 18th Nov. 2008
Maintaining Kbucket List (Routing Table)
•When a Kademlia node receives any message from another node, it updates the appropriate kbucket for the sender’s node ID.
• If the sending node already exists in the kbucket: Moves it to the tail of the list.
•Otherwise: If the bucket has fewer than k entries:
• Inserts the new sender at the tail of the list. Otherwise:
• Pings the kbucket’s leastrecently seen node:• If the leastrecently seen node fails to respond:
– it is evicted from the kbucket and the new sender inserted at the tail.• Otherwise:
– it is moved to the tail of the list, and the new sender’s contact is discarded.
![Page 23: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/23.jpg)
23Kademlia, 18th Nov. 2008
Maintaining Kbucket List (Routing Table)
•Buckets will generally be kept constantly fresh, due to traffic of requests travelling through nodes.
•When there is no traffic: each peer picks a random ID in kbucket's range and performs a node search for that ID.
![Page 24: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/24.jpg)
24Kademlia, 18th Nov. 2008
Join
•Node P contacts to an already participating node Q.
•P inserts Q into the appropriate kbucket.
•P then performs a node lookup for its own node ID.
![Page 25: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/25.jpg)
25Kademlia, 18th Nov. 2008
Leave And Failure
•No action!
• If a node does not respond to the PING message, remove it from the table.
![Page 26: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/26.jpg)
26Kademlia, 18th Nov. 2008
DONE!
![Page 27: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/27.jpg)
27Kademlia, 18th Nov. 2008
A Page To Remember
001000
011010
101110 100 111
[1, 2)
[2, 4)
[4, 8)
110111
100101
000011 010 001
[1, 2)
[2, 4)
[4, 8)
100101
110111
011001 000 010
[1, 2)
[2, 4)
[4, 8)
Step1
Step2
Step3
![Page 28: Kademlia: A Peertopeer Information System Based on the ... · Instructs a node to store a pair. •FIND_NODE Returns information for the k nodes it knows about](https://reader034.fdocuments.net/reader034/viewer/2022042917/5f59530aa0c1a61a57020897/html5/thumbnails/28.jpg)
28Kademlia, 18th Nov. 2008
Question?