【问题标题】:torrent client: sending handshake message to peer洪流客户端:向对等方发送握手消息
【发布时间】:2012-11-27 06:22:20
【问题描述】:

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

这是我在代码中的信息:

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

self.getInfoHash(torrentCont) 是种子文件的原始哈希

这是我实际发送的内容:

BitTorrent protocol00000000ŒïƒœÝtDØ´öÙÄ×àŠD³T4F11T6ZGBQK2Y5LB8I4

关于我做错了什么的任何建议?

【问题讨论】:

    标签: python bittorrent handshake


    【解决方案1】:

    您混淆了字节和字符。规范说的是你应该发送八个空字节,而不是字符“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
    

    【讨论】:

      猜你喜欢
      • 2023-01-30
      • 1970-01-01
      • 2015-04-07
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      相关资源
      最近更新 更多