http trackers (BitTorrent) 压缩响应对等解析

http trackers (BitTorrent) compact response peers parsing

我正在尝试在 dart 中创建一个 BitTorrent 客户端,但我阻止从压缩的 http 跟踪器响应中获取对等点。

d8:completei284e10:incompletei3e8:intervali1800e12:min intervali1800e5:peers300:����>���v�[�h��[�B�Z��dr+�N�x���ZR�M%�h���T��DN�R��չ]��'X<��Xy05��N�`���.�mkqA�[�5�d����՝�Wd�=P�ղ���� ��F��N�C�A�h��%�n��%;7������չ-øNB��㒡�@3U��Ú�]��%�p��չh���h��WA �e�[m��%��DN�0p�6&.���Q�}�������ZY�^уb՘���\��A�N�xu�%;'0�չ�:�X��Z6�R.�m�cs_�����e

我阅读了文档以了解压缩对等点列表的结构(4 个字节用于 ip,2 个字节用于端口)但我不知道如何读取这个 300 个字符长的对等点字符串( peers300:) 这是合乎逻辑的,因为它们是 50 个对等点 (50 * (4+2)),但它们在此字符串中是 557 个字符(在下面的 bold 中)。

[100, 56, 58, 99, 111, 109, 112, 108, 101, 116, 101, 105, 50, 56, 52, 101, 49, 48, 58, 105, 110, 99, 111, 109, 112, 108, 101, 116, 101, 105, 51, 101, 56, 58, 105, 110, 116, 101, 114, 118, 97, 108, 105, 49, 56, 48, 48, 101, 49, 50, 58, 109, 105, 110, 32, 105, 110, 116, 101, 114, 118, 97, 108, 105, 49, 56, 48, 48, 101, 53, 58, 112, 101, 101, 114, 115, 51, 48, 48, 58, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 62, 239, 191, 189, 239, 191, 189, 239, 191, 189, 25, 118, 6, 239, 191, 189, 91, 239, 191, 189, 104, 239, 191, 189, 239, 191, 189, 91, 239, 191, 189, 22, 66, 239, 191, 189, 90, 239, 191, 189, 239, 191, 189, 100, 114, 43, 239, 191, 189, 78, 239, 191, 189, 120, 239, 191, 189, 19, 239, 191, 189, 239, 191, 189, 90, 82, 239, 191, 189, 77, 37, 239, 191, 189, 104, 239, 191, 189, 239, 191, 189, 239, 191, 189, 84, 239, 191, 189, 239, 191, 189, 68, 6, 3, 78, 239, 191, 189, 82, 239, 191, 189, 239, 191, 189, 213, 185, 93, 2, 239, 191, 189, 26, 239, 191, 189, 5, 39, 88, 60, 239, 191, 189, 239, 191, 189, 88, 121, 48, 53, 239, 191, 189, 239, 191, 189, 78, 239, 191, 189, 96, 239, 191, 189, 239, 191, 189, 239, 191, 189, 46, 239, 191, 189, 109, 107, 242, 173, 176, 147, 113, 16, 65, 239, 191, 189, 91, 239, 191, 189, 53, 239, 191, 189, 25, 100, 239, 191, 189, 239, 191, 189, 18, 239, 191, 189, 239, 191, 189, 213, 157, 239, 191, 189, 87, 100, 239, 191, 189, 61, 80, 239, 191, 189, 213, 178, 239, 191, 189, 239, 191, 189, 5, 239, 191, 189, 239, 191, 189, 10, 26, 239, 191, 189, 5, 239, 191, 189, 70, 239, 191, 189, 239, 191, 189, 0, 78, 239, 191, 189, 67, 239, 191, 189, 65, 239, 191, 189, 104, 239, 191, 189, 239, 191, 189, 22, 37, 239, 191, 189, 110, 14, 239, 191, 189, 239, 191, 189, 37, 59, 55, 127, 239, 191, 189, 239, 191, 189, 5, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 213, 185, 45, 195, 184, 78, 66, 239, 191, 189, 239, 191, 189, 227, 146, 161, 239, 191, 189, 64, 20, 51, 85, 239, 191, 189, 239, 191, 189, 195, 154, 239, 191, 189, 93, 239, 191, 189, 239, 191, 189, 37, 239, 191, 189, 112, 239, 191, 189, 239, 191, 189, 213, 185, 104, 239, 191, 189, 5, 239, 191, 189, 239, 191, 189, 104, 239, 191, 189, 239, 191, 189, 82, 8, 87, 65, 10, 239, 191, 189, 101, 239, 191, 189, 91, 109, 239, 191, 189, 8, 239, 191, 189, 239, 191, 189, 37, 239, 191, 189, 17, 14, 239, 191, 189, 68, 78, 239, 191, 189, 48, 112, 22, 239, 191, 189, 54, 38, 46, 239, 191, 189, 239, 191, 189, 239, 191, 189, 81, 239, 191, 189, 125, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 19, 239, 191, 189, 90, 89, 239, 191, 189, 94, 209, 131, 98, 213, 152, 239, 191, 189, 239, 191, 189, 239, 191, 189, 24, 92, 239, 191, 189, 239, 191, 189, 29, 65, 239, 191, 189, 78, 239, 191, 189, 120, 117, 239, 191, 189, 19, 37, 59, 39, 48, 239, 191, 189, 213, 185, 21, 239, 191, 189, 58, 239, 191, 189, 88, 239, 191, 189, 239, 191, 189, 90, 54, 239, 191, 189, 82, 46, 239, 191, 189, 109, 239, 191, 189, 99, 115, 95, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 101]

我多次找到 3 个字符,但我不知道它们代表什么。

[239, 191, 189]

感谢您的回复。

不能有 557 个字符,因为编码清楚地表明它只有 300 个字节长。

造成这种不匹配的最可能原因是试图将二进制数据解释为字符串类型。 Bencoding 传送二进制数据,其中只有某些部分可以解释为字符串。紧凑型响应不是其中一种情况。

您需要一个 returns 二进制数据(而不是字符串)的 bdecoder,然后您可以将其切成表示 ipv4 地址和端口号的 6 字节块。

[239, 191, 189]

这是 unicode 替换字符 � (U+FFFD) 的 UTF8 表示。当尝试使用解码器将二进制数据解码为 utf8 时会发生这种情况,解码器不会出错,而是在遇到无效字节序列时插入这些字符,然后再次将生成的 unicode 代码点编码为 UTF 8,以将它们显示为数字数组。