【发布时间】:2012-11-20 04:07:07
【问题描述】:
如何在 torrent 文件上生成 torrent 哈希信息。
我一直在看这个例子:How to calculate the hash value of a torrent using Java 并试图将其转换为 C++。这是我到目前为止的代码:
void At::ReadTorrent::TorrentParser::create_hash(std::string torrentstub)
{
std::string info;
int counter = 0;
while(info.find("4:info") == -1)
{
info.push_back(torrentstub[counter]);
counter++;
}
unsigned char array[torrentstub.size()];
int test = 0;
for(int data; (data = torrentstub[counter]) > -1;)
{
array[test++] = data;
counter++;
}
std::cout << array << std::endl;
//SHA-1 some value here to generate the hash.
}
torrentstub 参数是表示为字符串的 torrent 文件。
据我了解,我必须获得4:info 之后的信息。我认为这行得通,例如:
d6:lengthi2847431620e4:name8:filename12:piece lengthi1143252e6:pieces50264
在这之后只有我无法读取的信息,我猜这是一些二进制数据?
所以我的问题实际上归结为:
应该对 4:info 之后的所有信息进行哈希处理,我应该在哪里停止收集哈希数据?
【问题讨论】:
-
嗨,我正在尝试在 C++ 中做同样的事情,你能发布最终对你有用的东西吗?
标签: c++ bittorrent info-hash