[英]The torrent info_hash parameter
How does one calculate the info_hash parameter ?如何计算info_hash 参数? Aka the hash corresponding to the info dictionar??
也就是对应于信息字典的哈希??
From official specs:从官方规格:
info_hash The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file.
info_hash元信息文件中信息值的编码形式的 20 字节 sha1 哈希。 Note that this is a substring of the metainfo file.
请注意,这是元信息文件的子字符串。 This value will almost certainly have to be escaped.
这个值几乎肯定会被转义。
Does this mean simply get the substring from the meta-info file and do a sha-1 hash on the reprezentative bytes??这是否意味着简单地从元信息文件中获取子字符串并对代表字节进行 sha-1 散列?
.... because this is how i tried 12 times but without succes meaning I have compared the resulting hash with the one i should end up with..and they differ ..that + tracker response is FAILURE, unknown torrent ...or something .... 因为这是我尝试了 12 次但没有成功的方式,这意味着我将结果散列与我最终应该得到的散列进行了比较..他们不同..那个 + 跟踪器响应是失败的,未知的洪流......或某物
So how do you calculate the info_hash?那么如何计算 info_hash 呢?
The metafile is already bencoded so I don't understand why you encode it again?元文件已经编码,所以我不明白你为什么再次编码?
I finally got this working in Java code, here is my code:我终于在 Java 代码中完成了这项工作,这是我的代码:
byte metaData[]; //the raw .torrent file
int infoIdx = ?; //index of 'd' right after the "4:info" string
info_hash = SHAsum(Arrays.copyOfRange(metaData, infoIdx, metaData.length-1));
This assumes the 'info' block is the last block in the torrent file (wrong?)这假设“信息”块是 torrent 文件中的最后一个块(错误?)
Don't sort or anything like that, just use a substring of the raw torrent file.不要排序或类似的东西,只需使用原始 Torrent 文件的子字符串。
Works for me.为我工作。
bdecode the metafile. bdecode 元文件。 Then it's simply
sha1(bencode(metadata['info']))
(ie bencode only the info dict again, then hash that).然后它只是
sha1(bencode(metadata['info']))
(即再次对 info dict 进行编码,然后散列)。
访问https://gist.github.com/shxsun/9085646 ,这是一个python代码,解释如何info_generate,祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.