📝 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..
📝 All Kademlia protocol in P2P networks MCQs
Q1. What binary operation does Kademlia use to compute the distance between two node identifiers?
📖 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 and node Y has identifier . Which k‑bucket of X will contain Y based on the XOR distance?
📖 Explanation: The XOR of the two IDs is (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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 Explanation: For any two identifiers A and B, , establishing symmetry. Moreover, for any three identifiers A, B, and C, the bitwise differences obey 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 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?
📖 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 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 and node B has identifier . What is the XOR distance between them, and which k‑bucket index does B occupy relative to A?
📖 Explanation: Computing the XOR gives , 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.