【问题标题】:Why my GET request to a torrent tracker doesn't work?为什么我对 torrent 跟踪器的 GET 请求不起作用?
【发布时间】:2016-10-12 11:36:31
【问题描述】:

我绝对是 Bittorrent 协议的新手,我试图向跟踪器请求文件。 为此,我使用 C# 程序解析并打印了一个工作的 .torrent 文件,然后我使用 PostMan 请求跟踪器提供这些信息

提取的信息有:

- announce :
http://bt1.archive.org:6969/announce

- announce-list
http://bt1.archive.org:6969/announce
http://bt2.archive.org:6969/announce

- comment :
This content hosted at the Internet Archive at https://archive.org/details/6201484321_f1a88ca2cb_b
Files may have changed, which prevents torrents from downloading correctly or completely; please check for an updated torrent at https://archive.org/download/6201484321_f1a88ca2cb_b/6201484321_f1a88ca2cb_b_archive.torrent
Note: retrieval usually requires a client that supports webseeding (GetRight style).
Note: many Internet Archive torrents contain a 'pad file' directory. This directory and the files within it may be erased once retrieval completes.
Note: the file 6201484321_f1a88ca2cb_b_meta.xml contains metadata about this torrent's contents.

- created by :
ia_make_torrent

- creation date :
1462999235

- info
- collections
org.archive.6201484321_f1a88ca2cb_b

- crc32 :
6dbd08b2

- length :
970

- md5 :
96951c7834ee105660e0447e00ec4b31

- mtime :
1462999235

- path
6201484321_f1a88ca2cb_b_meta.xml

- sha1 :
cc69b6337b4e459ec9428629ca49fb65a6249ee8

- name :
6201484321_f1a88ca2cb_b

- piece length :
524288

- pieces :
üyR¨ÆôO2¿Ù'ù'┼0ö


- locale :
en

- title :
6201484321_f1a88ca2cb_b

- url-list
https://archive.org/download/
http://ia600704.us.archive.org/24/items/
http://ia800704.us.archive.org/24/items/

所以我有这个请求要发送:

http://bt1.archive.org:6969/announce?info_hash=cc69b6337b4e459ec9428629ca49fb65a6249ee8&peer_id=ABCDEFGHIJKLMNOPQRST&ip=80.11.255.166&port=6881&downloaded=0&left=970

怎么了?

编辑:

我用 WireShark 跟踪了 uTorrent 在这个 torrent 上发出的请求,hash_info 是:%ac%c3%b2%e43%d7%c7GZ%bbYA%b5h%1c%b7%a1%ea%26%e2

但是,如果我 sha1 信息值的编码形式是 collectionsl35:org.archive.6201484321_f1a88ca2cb_be5:filesld5:crc328:262eacb06:lengthi346936e3:md532:48ab0840ed6501c37072b261fd52bcde5:mtime10:13176646104:pathl27:6201484321_f1a88ca2cb_b.jpge4:sha140:6ce409c363e038a57c79ed17ee97571058101575ed5:crc328:6dbd08b26:lengthi970e3:md532:96951c7834ee105660e0447e00ec4b315:mtime10:14629992354:pathl32:6201484321_f1a88ca2cb_b_meta.xmle4:sha140:cc69b6337b4e459ec9428629ca49fb65a6249ee8ed5:crc328:f94424566:lengthi5253e3:md532:9d665d42153c0b27b5eb4922c4ddef685:mtime10:13176646704:pathl33:6201484321_f1a88ca2cb_b_thumb.jpge4:sha140:e5e775116512cebdc0ad048ce3a0e3dd100becf0ee4:name23:6201484321_f1a88ca2cb_b12:piece lengthi524288e6:pieces20:üyR¨Æô;O2¿Ù‚ù‘†0ö

我没有相同的哈希

【问题讨论】:

  • 这个问题与 C# 有什么关系?
  • @Firebug 给出 400 无效请求
  • 我用C#程序解析了文件,可能是因为这个:/是的,我知道返回的Http状态码是400,我的问题是为什么请求错误?
  • @LeCintas 你能给个种子文件的链接吗
  • @MiguelSanchez 是的,当然:link

标签: http bittorrent tracker libtorrent


【解决方案1】:

有两个问题:

  1. 您发送的哈希不是info_hash。您以某种方式从 .torrent 文件中的元数据中获取了 torrent 中一个文件的 SHA1 哈希值。
    https://archive.org/download/6201484321_f1a88ca2cb_b/6201484321_f1a88ca2cb_b_archive.torrent 检索 .torrent 文件显示十六进制编码的 info_hashACC3B2E433D7C7475ABB5941B5681CB7A1EA26E2
  2. 您在请求中发送的info_hash 是十六进制编码的。它必须像这样进行 URL 编码:
    %ac%c3%b2%e43%d7%c7GZ%bbYA%b5h%1c%b7%a1%ea%26%e2

更正并发送:
http://bt1.archive.org:6969/announce?info_hash=%ac%c3%b2%e43%d7%c7GZ%bbYA%b5h%1c%b7%a1%ea%26%e2&peer_id=ABCDEFGHIJKLMNOPQRST&ip=80.11.255.166&port=6881&downloaded=0&left=970

给出答案:
d8:completei0e10:downloadedi2e10:incompletei2e8:intervali1950e12:min intervali975e5:peers12:************e

【讨论】:

    【解决方案2】:

    您需要对哈希进行URL 编码,而不是以原始十六进制发送。

    来自BitTorrent Tracker Protocol

    基本跟踪器公告请求

    info_hash 元信息文件中信息值的编码形式的 20 字节 sha1 散列。请注意,这是元信息文件的子字符串。 不要忘记对其进行 URL 编码。

    更新

    BencodeNET library 似乎在做什么你为什么不试试呢? 这些例子清楚地展示了如何计算种子的哈希

    // Parse torrent by specifying the file path
    var parser = new BencodeParser(); // Default encoding is Encoding.UT8F, but you can specify another if you need to
    var torrent = parse.Parse<Torrent>("C:\ubuntu.torrent");
    
    // Alternatively, handle the stream yourself
    using (var stream = File.OpenRead("C:\ubuntu.torrent"))
    {
        torrent = parse.Parse<Torrent>(stream);
    }
    
    // Calculate the info hash
    string infoHash = torrent.GetInfoHash();
    // "B415C913643E5FF49FE37D304BBB5E6E11AD5101"
    
    // or as bytes instead of a string
    byte[] infoHashBytes = torrent.GetInfoHashBytes();
    
    // Get Magnet link
    string magnetLink = torrent.GetMagnetLink();
    // magnet:?xt=urn:btih:1CA512A4822EDC7C1B1CE354D7B8D2F84EE11C32&dn=ubuntu-14.10-desktop-amd64.iso&tr=http://torrent.ubuntu.com:6969/announce&tr=http://ipv6.torrent.ubuntu.com:6969/announce
    
    // Convert Torrent to it's BDictionary representation
    BDictionary bencode = torrent.ToBDictionary();
    

    【讨论】:

    • 我已经这样做了,编码的哈希与未编码的哈希没有什么不同。目前,我使用torrent中包含的文件的sha1字段,但是经过更多研究我发现我必须使用pieces字段(stackoverflow.com/questions/28348678/…)但是,看看字段内容,这不是很好编码,我不知道使用什么编码编辑:字符集是 UTF-8
    • @LeCintas 文档说hash of the bencoded form of the info value from the metainfo file
    猜你喜欢
    • 1970-01-01
    • 2018-06-05
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2017-01-17
    • 2011-07-28
    • 2018-04-10
    相关资源
    最近更新 更多