如何将Kademlia距离度量表示为整数 [英] How to represent Kademlia distance metric as integer

查看:136
本文介绍了如何将Kademlia距离度量表示为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是P2P网络的新手,目前我试图了解Kademlia论文中指定的一些基本知识.我无法理解的主要是Kademlia距离度量.所有论文都将距离定义为两个ID的XOR. ID大小为160位,因此结果也为160位. 问题:将距离表示为整数的便捷方法是什么? 我检查过的某些实现使用以下方法: distance = 160-前缀长度(其中前缀长度是前导零的数量). 这是正确的方法吗?

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?

推荐答案

我检查过的某些实现使用以下方法:distance = 160-前缀长度(其中前缀长度是前导零的数量).这是正确的方法吗?

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

该方法是基于对Kademlia论文的早期修订,不足以实施最终论文的某些后续章节.

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.

ID大小为160位,因此结果也为160位.问题:将距离表示为整数的便捷方法是什么?

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?

距离度量是160位整数.您可以使用大整数类,也可以基于数组滚动自己的类.要获得共享的前缀位数,您只需要计算前导零即可,前导零与网络大小成对数比例,完成后通常应以更小的整数为单位.

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.

这篇关于如何将Kademlia距离度量表示为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆