DHT 节点 ID 生成?

发布于 2024-10-26 06:20:59 字数 112 浏览 5 评论 0原文

我刚刚开始研究 DHT 实现和理论,并专注于节点启动并连接到网络时如何生成节点 id。我读到 ID 是来自某些哈希范围的随机哈希,但是它是唯一的哈希吗?哈希生成的数据是否接近该节点存储的数据?帮我解决这个问题。

I just start studying DHT implementation and theory and stuck on on part, how generates node id when node startup and connect to network. I read that ID is random hash from some hashes range but, is it unique hash? and is hash generates close no the data which this node store? Help me with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岛歌少女 2024-11-02 06:20:59

在大的值空间上使用良好的散列函数自行生成节点 ID 是 DHT/P2P 系统中使用的常用技术。由于哈希保证了良好的随机分布,因此发生冲突的概率很小。从统计上看,ID(几乎总是)是唯一的。

该哈希值独立于节点存储的数据。

Self-generation of the node ID using a good hash function over a large space of values is a common technique used in DHT/P2P systems. Since the hash guarantees good random distribution, the probability of a collision is very small. Statistically, the ID will (almost always) be unique.

That hash is independent from the data stored of the node.

倒带 2024-11-02 06:20:59
import random
import hashlib

def newID():
  s = ""
  for i in range(20):
    s += chr(random.randint(0, 255))
  m = hashlib.sha1()
  m.update(s)
  return m.digest()
import random
import hashlib

def newID():
  s = ""
  for i in range(20):
    s += chr(random.randint(0, 255))
  m = hashlib.sha1()
  m.update(s)
  return m.digest()
好菇凉咱不稀罕他 2024-11-02 06:20:59

正如前面的答案中所述,节点的 ID 是通过对其 IP 地址进行散列生成的(一般来说,DHT 中就是这种情况,例如 Chord) 或其他唯一可识别信息。

由于它在节点加入或离开 n 网络时使用一致性哈希,因此仅 1/n密钥需要重新映射,因此它适合高度动态的网络拓扑,例如点对点。

从技术上讲,生成的哈希并不传达有关存储在该节点上的数据的任何信息。相反,某个键(或数据存储中的条目,如果用于此目的)的散列源自对关键字(或文件名或文件内容)进行散列。

作为一致性哈希的直接结果,出现了键之间距离的抽象概念。 (如此处所述)节点拥有其标识密钥 (ID) 的所有密钥根据距离度量最接近。

As said in the previous answers, the ID of a node is generated by hashing it's IP address (generally speaking, such is the case in a DHT like Chord) or other uniquely identifiable information.

And since it uses Consistent Hashing when a node will join or leave the n-network, only 1/nkeys needs to be remapped, thus it lends itself to highly dynamic network topologies, such as peer-to-peer.

Technically, the hash generated doesn't convey any information about the data that is stored on this node. Rather the hash for a certain key (or entry in a data store, if used for such purpose) originates from hashing the keyword (or the filename or the file contents).

As a direct consequence of the Consistent Hashing, the abstract concept of distance between keys emerges. (As stated here) A node owns all the keys for which its identifying key (ID) is the closest to according to the distance metric.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文