You are on page 1of 30

Kademlia:APeertopeerInformationSystem

BasedontheXORMetric

BasedonslidesbyAmirH.Payberah(amir@sics.se)

1/31

2/31

KademliaBasics
Kademliaisakeyvalue(object)store.
Eachobjectisstoredatthekclosestnodestotheobject'sID.
Distancebetweenid1andid2:d(id1,id2)=id1XORid2
IfIDspaceis3bits:

d(1,4)=d(0012,1002)
=0012XOR1002
=1012
=5

3/31

KademliaRoutingTable
Kbucket:eachnodekeepsalistofreferencestonodes
(contacts)ofdistancebetween2iand2i+1fori=1toi=N.
EachKbuckethasmaxkentries.
KBucket List
KBucket

[1, 2)
[2, 4)

Node

[4, 8)

[8, 16)
[16, 32)
[32, 64)
[64, 128)
[128, 256)

4/31

KademliaTuningParameters
B is the size in bits of the keys used to identify nodes and store

and retrieve data; in basic Kademlia this is 160, the length of an


SHA1 digest (hash).
k is the maximum number of contacts stored in a Kbucket; this
is normally 20.
alpha () represents the degree of parallelism in network calls,
usually 3.

Other constants used in Kad:

tExpire = 86400s, the time after which a key/value pair expires; this is a time-to-live
(TTL) from the original publication date
tRefresh = 3600s, after which an otherwise unaccessed bucket must be refreshed
tReplicate = 3600s, the interval between Kademlia replication events, when a node
is required to publish its entire database
tRepublish = 86400s, the time after which the original publisher must republish a
key/value pair

5/31

FIND_NODEinKademlia

KBucket List

Lookup Q
Node

P
closestnodestoQ
arestoredhere

ClosestnodesinIDspace

6/31

FIND_NODEinKademlia

KBucketList

Lookup Q
Node

P
A

B C

closestnodestoQ
arestoredhere

...andselectnodesfrom
theappropriatekbucket
7/31

FIND_NODEinKademlia

A
FIND_NODE(Q)

FIND_NODE(Q)
FIND_NODE(Q)

8/31

FIND_NODEinKademlia
Find k closest
nodes to Q

Find k closest
nodes to Q

B
Find k closest
nodes to Q

9/31

FIND_NODEinKademlia

A
ReturnskclosestnodestoQ

ReturnskclosestnodestoQ

ReturnskclosestnodestoQ

10/31

FIND_NODEinKademlia,UpdateKbuckets
KBucket List

WhenPreceivesaresponsefromanode,it
updatestheappropriateKbucketforthe
sendersnodeID.

ReceivedresponsesfromA,B
andC

M
N
O

Pissuesuptonewrequeststonodesithasnotyetqueriedfromthesetofnodes
receivedintheresponses
11/31

FIND_NODEinKademlia

M
FIND_NODE(Q)

FIND_NODE(Q)
FIND_NODE(Q)

12/31

FIND_NODEinKademlia

P
Receivedinformationinroundn1
Receivedinformationinroundn

Repeatsthisprocedureiterativelyuntilreceivedinformationin
roundn1andnarethesame.

13/31

FIND_NODEinKademlia
PresendstheFIND_NODEtokclosestnodesithasnotalreadyqueried...

Receivedinformationinroundn

14/31

Let'sLookInside
Kademlia

15/31

NodeState
Kbucket:eachnodekeepsalistofinformationfornodesof
distancebetween2iand2i+1.
0<=i<160
Sortedbytimelastseen.
111

110

[1, 2)

101

100

011

010

[2, 4)
001

000

[4, 8)

16/31

NodeState
Kbucket:eachnodekeepsalistofinformationfornodesof
distancebetween2iand2i+1.
0<=i<160
Sortedbytimelastseen.
[1,2)Twofirstbitsincommon

111

110

101

100

011

010

[2,4)Firstbitincommon
001

000

[4,8)Nocommonprefix

17/31

KademliaRPCs
PING

Probesanodetoseeifitisonline.

STORE

Instructsanodetostorea<key,value>pair.

FIND_NODE

ReturnsinformationfortheknodesitknowsaboutclosesttothetargetID.
Itcanbefromonekbucketormore.

FIND_VALUE

LikeFIND_NODE,...
Butiftherecipienthasstoredthey<key,value>,itjustreturnsthestoredvalue.

18/31

StoreData
The<key,value>dataisstoredinkclosestnodestothekey.

19/31

LookupService
000

Step1

Step2

001

110

[1, 2)

010

011

110

100

[2, 4)
[4, 8)

111

111

[1, 2)

100

[2, 4)

011

010

001

000

101

Step3

100

[4, 8)

[1, 2)

111

110

001

000

[2, 4)
010

011

[4, 8)

20/31

MaintainingKbucketList(RoutingTable)
WhenaKademlianodereceivesanymessagefromanothernode,it
updatestheappropriatekbucketforthesendersnodeID.

21/31

MaintainingKbucketList(RoutingTable)
WhenaKademlianodereceivesanymessagefromanothernode,it
updatestheappropriatekbucketforthesendersnodeID.

Ifthesendingnodealreadyexistsinthekbucket:
Movesittothetailofthelist.

22/31

MaintainingKbucketList(RoutingTable)
WhenaKademlianodereceivesanymessagefromanothernode,it
updatestheappropriatekbucketforthesendersnodeID.

Ifthesendingnodealreadyexistsinthekbucket:
Movesittothetailofthelist.
Otherwise:
Ifthebuckethasfewerthankentries:

Insertsthenewsenderatthetailofthelist.
Otherwise:
Pingsthekbucketsleastrecentlyseennode:
Iftheleastrecentlyseennodefailstorespond:

itisevictedfromthekbucketandthenewsenderinsertedatthetail.
Otherwise:
itismovedtothetailofthelist,andthenewsenderscontactis
discarded.

23/31

MaintainingKbucketList(RoutingTable)
Bucketsshouldgenerallybekeptconstantlyfresh,duetotrafficof
requeststravellingthroughnodes.

Whenthereisnotraffic:eachpeerpicksarandomIDinkbucket'srange
andperformsanodesearchforthatID.

24/31

Join
NodePcontactsanalreadyparticipatingnodeQ.
PinsertsQintotheappropriatekbucket.
PthenperformsanodelookupforitsownnodeID.

25/31

LeaveAndFailure
Noaction!
IfanodedoesnotrespondtothePINGmessage,removeitfromthe
table.

26/31

Kademliavs.Chord

27/31

Kademliavs.Chord
likeChord
When =1thelookupalgorithmresemblesChord'sintermofmessage
cost.

UnlikeChord

XORmetricissymmetric,whileChord'smetricisasymmetric.

28/31

Summary
000

Step1

Step2

001

110

[1, 2)

010

011

110

100

[2, 4)
[4, 8)

111

111

[1, 2)

100

[2, 4)

011

010

001

000

101

Step3

100

[4, 8)

[1, 2)

111

110

001

000

[2, 4)
010

011

[4, 8)

29/31

References
Kademlia Specification

http://xlattice.sourceforge.net/components/protocol/kademlia/specs.html

Petar Maymounkov and David Mazieres, "Kademlia: A

Peer-to-Peer Information System Based on the XOR Metric",


IPTPS '02
http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf

Daniel Stutzbach and Reza Rejaie, "Improving Lookup

Performance over a Widely-Deployed DHT", INFOCOM '06


http://www.barsoom.org/~agthorr/papers/infocom-2006-kad.pdf

Raul Jimenez, Flutra Osmani and Bjorn Knutsson, Sub-Second


Lookups on a Large-Scale Kademlia-Based Overlay, P2P '11.
http://people.kth.se/~rauljc/p2p11/jimenez2011subsecond.pdf

30/31