简体   繁体   English

如何从 .torrent 文件中获取碎片值

[英]How to get pieces value from .torrent file

I am trying to build a .torrent file interpreter.我正在尝试构建一个.torrent文件解释器。 The problem is that I can't seem to understand how to go about interpreting the pieces value.问题是我似乎无法理解 go 如何解释件值。 I am aware that the pieces key contains a concatenation of the SHA-1 hashes for each piece and that SHA-1 contains 20 bytes.我知道片段键包含每个片段的 SHA-1 哈希值的串联,并且 SHA-1 包含 20 个字节。 A result of this is that the final output should be a multiple of 20 bytes.这样做的结果是最终的 output 应该是 20 字节的倍数。 However, after counting the bytes from the pieces value as a string or in hexadecimal form it still does not satisfy this.但是,在将片段值中的字节数作为字符串或十六进制形式之后,它仍然不能满足这一点。 How should I interpret the pieces key?我应该如何解释pieces的关键?

Here we use bencode and bdecode, and the pieces value can get easily.这里我们使用了bencode和bdecode,就可以轻松得到pieces的值。 I think you need to firstly read BEP for more details.我认为您需要首先阅读BEP以了解更多详细信息。 What's more, you can see this and use it as an example.更重要的是,你可以看到这个并将其用作示例。

From looking at a real torrent file, I found that the SHA-1 hashes had to be taken from its hexadecimal string format, but I previously thought that it was wrong because the byte length of the hash was not a multiple of 20. Turns out I forgot to add a trailing 0 to hexadecimals that were only 1 character (eg a had to be changed to 0a )通过查看真实的 torrent 文件,我发现 SHA-1 哈希必须取自其十六进制字符串格式,但我之前认为这是错误的,因为 hash 的字节长度不是 20 的倍数。原来我忘记在只有 1 个字符的十六进制中添加尾随0 (例如,必须将a更改为0a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM