How to represent Kademlia distance metric as integer

安稳与你 提交于 2019-12-11 12:58:09

问题


I'm new in P2P networking and currently I try to understand some basic things specified by Kademlia papers. The main thing that I cannot understand is Kademlia distance metric. All papers define the distance as XOR of two IDs. The ID size is 160 bits, so the result is also has 160 bits. The question: what is a convenient way to represent this distance as integer? Some implementations, that I checked, use the following: distance = 160 - prefix length (where prefix length is number of leading zeros). Is it correct approach?


回答1:


Some implementations, that I checked, use the following: distance = 160 - prefix length (where prefix length is number of leading zeros). Is it correct approach?

That approach is based on an early revision of the kademlia paper and is insufficient to implement some of the later chapters of the final paper.

A full-fledged implementation should use a tree-like routing table that orders buckets by their absolute position in the keyspace which can be resized when bucket splitting happens.

The ID size is 160 bits, so the result is also has 160 bits. The question: what is a convenient way to represent this distance as integer?

The distance metrics are 160bit integers. You can use a big-integer class or roll your own based on arrays. To get shared prefix bit counts you just have to count the leading zeroes, which scale logarithmically with the network size and should normally fit in much smaller integers once you're done.



来源:https://stackoverflow.com/questions/48602172/how-to-represent-kademlia-distance-metric-as-integer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!