🎓 BookMCQ
← Back to 29. Peer to Peer Paradigm

📝 Kademlia protocol in P2P networks (9 MCQs)

Distributed Lookup Using XOR Distance

Kademlia is a structured peer-to-peer system for locating nodes and key-value data through an XOR-based identifier metric. Nodes and keys occupy a binary identifier space, and the XOR of two identifiers defines their distance. The symmetric metric supports lookup routing and allows messages to improve a node's knowledge of other participants. XOR ordering controls lookup decisions regardless of physical network distance between peers.

Node IDs, Keys, and K-Bucket Routing State

In the original design, identifiers are 160 bits. Each node maintains k-buckets containing contact information for peers at particular XOR-distance ranges. Buckets are organized by distance class, and contacts include a node identifier and network endpoint. The value k limits the number of contacts retained in each bucket. Bucket structure bounds state while covering distinct XOR distance ranges around each node.

Iterative Lookup with Parallel Queries

A lookup begins with the closest contacts already known to the requester. It sends FIND_NODE or a value lookup request to selected peers, receives closer contacts in responses, and updates its candidate list. Several queries may run concurrently; the process repeats until no closer useful contacts are discovered or the result is found. Responses can add closer contacts before the next query round.

Finding the Closest Nodes to a Key

Suppose the target key is 1010 and candidate node IDs are 1000, 1011, and 0010. XOR gives distances 0010, 0001, and 1000 respectively. The node with ID 1011 is closest under this metric, even though its ordinary numerical difference from the key is not the rule being applied. XOR values, not decimal subtraction, determine which candidate is nearer here.

Fault Tolerance and Routing Knowledge

Kademlia can tolerate unavailable peers by querying several candidates and retaining multiple contacts in each distance range. Lookups also reveal useful node information, helping maintain routing state. Applications use the DHT for distributed indexes and peer discovery, while replication and data validation remain responsibilities of the application or implementation. Availability still depends on replicas and reachable contacts near the key.

XOR Distance Is Not Ordinary Subtraction

'The nearest node is the numerically nearest ID' is false because Kademlia compares XOR values. 'Each lookup contacts only one peer' ignores parallelism. 'Every peer stores the requested value' confuses routing contacts with key-value responsibility; the lookup seeks nodes close to the target key. Distance measures identifiers, not latency, ownership, or physical separation between peers.

XOR Calculations and Lookup Sequences

Students should calculate bitwise XOR, compare resulting distances as unsigned values, and trace how a lookup improves its candidate set. Identify the roles of k, the parallelism parameter, and contact information. Distinguish FIND_NODE from a value lookup, and explain why failed contacts do not necessarily end the search. Write each XOR result before ranking candidate contacts for lookup.

Kademlia XOR Lookup Terminology

  • XOR distance - Bitwise exclusive OR between two identifiers..
  • Node ID - Binary identifier assigned to a node..
  • Key - Identifier locating a stored value..
  • k-bucket - Bounded contacts for one distance range..
  • FIND_NODE - Request seeking nodes near a target ID..
  • Parallel lookup - Concurrent queries to candidate peers..
3
Easy
4
Medium
2
Hard

📝 All Kademlia protocol in P2P networks MCQs

Q1. What binary operation does Kademlia use to compute the distance between two node identifiers?

A.XOR ✅
B.AND
C.OR
D.Addition
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Kademlia defines the distance between identifiers as the bitwise exclusive‑or (XOR) of the two IDs. XOR highlights the positions where the bits differ, producing a numeric value that can be ordered to guide routing. Because XOR is fast to compute and yields a symmetric metric, it is the operation used throughout the protocol.

Q2. Node X has identifier 0x1A30x1A3 and node Y has identifier 0x1B70x1B7. Which k‑bucket of X will contain Y based on the XOR distance?

A.Bucket 2
B.Bucket 3
C.Bucket 4 ✅
D.Bucket 5
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The XOR of the two IDs is 0x1A3⊕0x1B7=0x140x1A3 \oplus 0x1B7 = 0x14 (decimal 20). The most significant set bit of 20 is at position 4, so the distance falls into bucket 4 (bucket indices start at 0). Consequently, Y is stored in X’s bucket 4.

Q3. Compare two pairs of nodes: Pair 1 differs only in the most‑significant bit of their IDs, while Pair 2 differs only in the least‑significant bit. Which statement correctly describes the bucket each pair would occupy?

A.Both pairs are placed in bucket 0
B.Pair 1 goes to a higher‑index bucket than Pair 2 ✅
C.Both pairs go to the highest‑index bucket
D.Pair 2 goes to a higher‑index bucket than Pair 1
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: In Kademlia, the bucket index corresponds to the position of the highest differing bit. A difference in the most‑significant bit yields the largest possible index (the highest bucket), whereas a difference in the least‑significant bit yields index 0, the lowest bucket. Thus Pair 1 resides in a higher‑index bucket than Pair 2.

Q4. If the bucket size k is increased from 10 to 20 while keeping the network size constant, what is the most likely effect on lookup latency and network overhead?

A.Latency tends to decrease, but overhead increases ✅
B.Both latency and overhead decrease
C.Latency increases and overhead stays the same
D.There is no noticeable effect
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Larger k allows each bucket to hold more contacts, giving the routing algorithm more choices for each hop. With more options, the algorithm can often find a node that is closer to the target, reducing the number of hops (lower latency). However, maintaining additional contacts requires extra ping/refresh traffic, raising overall overhead.

Q5. A node has five full k‑buckets. During a lookup for target ID T, the XOR distance to T is smaller than any distance represented by bucket 3. Which buckets can supply the initial candidate nodes?

A.Only bucket 0
B.Buckets 0 through 2 ✅
C.Buckets 3 and 4
D.All five buckets
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The node selects candidates from buckets that contain IDs closer to the target than the bucket being considered. Since the target distance is smaller than any entry in bucket 3, only the buckets that store nearer distances—buckets 0, 1, and 2—can provide nodes that are potentially closer to T. Buckets 3 and 4 hold IDs that are farther away, so they are excluded.

Q6. How does a non‑uniform distribution of node identifiers affect the population of k‑buckets and overall routing efficiency in Kademlia?

A.Some buckets become overfull, causing longer lookup paths and higher churn ✅
B.Underfull buckets improve efficiency by reducing maintenance traffic
C.Bucket sizes remain balanced regardless of identifier distribution
D.All buckets experience equal load, so efficiency is unchanged
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When identifiers cluster, the buckets that correspond to the dense region receive more entries than their capacity k, forcing older contacts to be evicted. Overfull buckets may contain stale or less optimal peers, which can increase the number of hops needed to reach a target and amplify maintenance messages as nodes constantly refresh their tables. This degrades routing efficiency compared with a uniformly random ID space.

Q7. Explain why the XOR metric used in Kademlia satisfies symmetry and the triangle inequality, making it a valid distance function?

A.XOR is not symmetric and violates triangle inequality
B.XOR is symmetric but does not satisfy triangle inequality
C.XOR is symmetric and fulfills triangle inequality ✅
D.None of the above
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: For any two identifiers A and B, A⊕B=B⊕AA \oplus B = B \oplus A, establishing symmetry. Moreover, for any three identifiers A, B, and C, the bitwise differences obey (A⊕B)≤(A⊕C)+(C⊕B)(A \oplus B) \le (A \oplus C) + (C \oplus B) because each differing bit contributes at most once to the combined distance, ensuring the triangle inequality holds. These properties qualify XOR as a proper metric for routing decisions.

Q8. In a network of 2102^{10} nodes where each k‑bucket stores at most 3 contacts, what is the worst‑case number of hops required to locate a specific target node using Kademlia’s lookup algorithm?

A.5 hops
B.7 hops
C.10 hops ✅
D.12 hops
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Kademlia guarantees that each hop reduces the XOR distance to the target by at least one bit, effectively halving the remaining search space. With 2102^{10} possible identifiers, the maximum number of distinct bit positions is 10, so in the worst case the algorithm may need one hop per bit, resulting in 10 hops. The bucket size does not change this logarithmic bound.

Q9. Node A has identifier 0x0F0F0x0F0F and node B has identifier 0xF0F00xF0F0. What is the XOR distance between them, and which k‑bucket index does B occupy relative to A?

A.Bucket 7
B.Bucket 12
C.Bucket 15 ✅
D.Bucket 8
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Computing the XOR gives 0x0F0F⊕0xF0F0=0xFFFF0x0F0F \oplus 0xF0F0 = 0xFFFF, which in binary is fifteen consecutive 1s. The most significant set bit is at position 15 (counting from 0), so the distance falls into bucket 15. This is the highest possible bucket for a 16‑bit identifier space, indicating that B is maximally distant from A according to the Kademlia metric.

🔗 Related Topics (MCQs)