gpt4 book ai didi

python - 没有从 bittorrent 对等握手中接收到任何数据

转载 作者:可可西里 更新时间:2023-11-01 02:42:16 25 4
gpt4 key购买 nike

我在 bit torrent 协议(protocol)上遇到了一些问题。我正在向一些同行发送握手消息。我让我的客户基本上连接到列表中的每个对等点,然后发送“握手”。代码如下 -

peer_id = 'autobahn012345678bit'
peer_id = peer_id.encode('utf-8')
pstr = 'BitTorrent protocol'
pstr = pstr.encode('utf-8')
pstrlen = chr(19)
pstrlen = pstrlen.encode('utf-8')
reserved = chr(0) * 8
reserved = reserved.encode('utf-8')

我正在发送我的变量。我的消息是 -

msg = (pstrlen + pstr + reserved + new.torrent_hash() + peer_id)

根据比特流规范,我的消息是 49 + len(pstr) 的适当长度 -

lenmsg = (pstrlen + reserved + new.torrent_hash() + peer_id)

print(lenmsg)
print(len(lenmsg))

已输出 -

b'\x13\x00\x00\x00\x00\x00\x00\x00\x00\x94z\xb0\x12\xbd\x1b\xf1\x1fO\x1d)\xf8\xfa\x1e\xabs\xa8_\xe7\x93autobahn012345678bit'
49

整个消息看起来像这样 -

b'\x13\x00\x00\x00\x00\x00\x00\x00\x00\x94z\xb0\x12\xbd\x1b\xf1\x1fO\x1d)\xf8\xfa\x1e\xabs\xa8_\xe7\x93autobahn012345678bit'

我的主要问题是我没有收到任何返回的数据。我有 socket.settimeout(4) 它会超时吗?

最佳答案

输出不正确,它遗漏了“BitTorrent 协议(protocol)”。
正确的握手字符串长度为 68 字节。

应该是:

\x13BitTorrent protocol\x00\x00\x00\x00\x00\x00\x00\x00\x94z\xb0\x12\xbd\x1b\xf1\x1fO\x1d)\xf8\xfa\x1e\xabs\xa8_\xe7\x93autobahn012345678bit

关于python - 没有从 bittorrent 对等握手中接收到任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40985955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com