torrent客户端:向p发送握手消息

2024-09-30 06:20:14 发布

您现在位置:Python中文网/ 问答频道 /正文

从我得到了peerlist并建立了到peer的tcp连接,我试图向他们发送握手消息,但他们似乎没有响应。在

以下是我的留言:

message = bytes(chr(19))+"BitTorrent protocol00000000"+self.getInfoHash(torrentCont)+self.peer_id

在self.getInfoHash(torrentCont)是torrent文件中的原始哈希

这就是我要传达的事实:

^{pr2}$

有什么关于我做错什么的建议吗?在


Tags: selfid消息messagebytestorrenttcpbittorrent
1条回答
网友
1楼 · 发布于 2024-09-30 06:20:14

你混淆了字节和字符。规范要求您发送8个空字节,而不是8倍于字符“0”(即chr(48)):

message = (chr(19) +
           "BitTorrent protocol" +
           8 * chr(0) +               # < - here
           self.getInfoHash(torrentCont) +
           self.peer_id)

# in case of doubt...
assert len(self.getInfoHash(torrentCont)) == 20
assert len(self.peer_id) == 20

相关问题 更多 >

    热门问题