python - 为 torrent 创建对等请求

标签 python p2p bittorrent handshake torrent

我在 python 中创建了一个 torrent 跟踪器,它返回所有播种地址的列表和它们正在播种的端口

我想与他们握手,这样我就可以开始获取碎片并创建 block (下载文件)

到目前为止,我的握手已被拒绝并出现以下错误,因为我发送给对等方的消息不正确。

ConnectionRefusedError: [Errno 111] Connection refused

到目前为止,我有以下用于创建握手的代码

 25 def genhand(t : torrent):
 26   temp = b'\x13'
 27   temp += b'BitTorrent protocol'
 28   temp += b'\x00'*8
 29   temp += torrent.info_hash
 30   temp += t.peer_id.encode('utf8')
 31   return temp

作为 hexdump 这是:

00000000: 13 42 69 74 54 6F 72 72  65 6E 74 20 70 72 6F 74  .BitTorrent prot
00000010: 6F 63 6F 6C 00 00 00 00  00 00 00 00 55 8C F1 4F  ocol........U..O
00000020: 80 A2 D0 BC A6 FB 90 8C  62 90 76 55 F1 84 A6 59  ........b.vU...Y
00000030: 2D 50 59 30 30 30 31 2D  38 38 39 34 31 38 30 32  -PY0001-88941802
00000040: 33 31 38 30                                       3180

创建握手的格式可以是found here根据第 6.2 节。 据我所知,我的握手格式是正确的。我做错了什么?

谢谢

最佳答案

玩了一会儿,发现我的实现是正确的,但是有些小伙伴不太好意思回复。在浏览了我的种子列表后,我发现有些人重置了我的连接,有些人会用握手回复

例子:

sent
00000000: 13 42 69 74 54 6F 72 72  65 6E 74 20 70 72 6F 74  .BitTorrent prot
00000010: 6F 63 6F 6C 00 00 00 00  00 00 00 00 55 8C F1 4F  ocol........U..O
00000020: 80 A2 D0 BC A6 FB 90 8C  62 90 76 55 F1 84 A6 59  ........b.vU...Y
00000030: 2D 50 59 30 30 30 31 2D  30 35 30 36 30 34 34 34  -PY0001-05060444
00000040: 30 38 32 38                                       0828


back
00000000: 13 42 69 74 54 6F 72 72  65 6E 74 20 70 72 6F 74  .BitTorrent prot
00000010: 6F 63 6F 6C 00 00 00 00  00 18 00 05 55 8C F1 4F  ocol........U..O
00000020: 80 A2 D0 BC A6 FB 90 8C  62 90 76 55 F1 84 A6 59  ........b.vU...Y
00000030: 2D 46 57 36 37 33 46 2D  56 78 57 35 56 76 5F 30  -FW673F-VxW5Vv_0
00000040: 28 54 49 7E                                       (TI~

我仍在努力获取位域有效负载,例如 article所以我实际上可以找到他们有哪些作品

关于python - 为 torrent 创建对等请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53512912/

相关文章:

ruby - 使用 ruby​​ 连接到 torrent "swarm"或 DHT

Python 生成器,将另一个可迭代对象分组为 N 组

android - 将 android framebuffer 传输到其他设备

frameworks - 互联网范围的点对点应用程序的软件框架

math - BitTorrent 群中的最佳节点数是多少?

bittorrent - 使用 netcat ping router.utorrent.com DHT 节点

python请求POST 400错误

python - Flask-SQLAlchemy:尝试以相反的顺序使用 query.paginate()

python - 是否有一个开关可以忽略 LXML 中未定义的 namespace 前缀?

android - 直接连接2个或更多安卓客户端