【发布时间】:2017-02-11 22:14:50
【问题描述】:
我最近在学习Bit-torrent协议,我的脚本通过DHT协议成功获取了大量的peer地址,依赖于文档bep_0005:
http://www.bittorrent.org/beps/bep_0005.html
如果查询的节点有 infohash 的对等点,它们会以 键“值”作为字符串列表。每个包含“compact”的字符串 为单个对等体格式化对等体信息。
所以,我将这些“值”解码为 ip/port。
我尝试通过 TCP 套接字与他们连接,超时,网络无法访问,出现连接被拒绝错误。
我尝试通过 UDP 套接字发送依赖于 bep_0029 的握手消息,但没有一个回复。
谁能告诉我,有什么问题吗?连接这些对等点的正确方法是什么?还是正常的 99% 无法连接,我只是没有找到那 1% 的好同伴?
谢谢!
这是我从跟踪器获得的对等方的 TCP 响应
但 DHT 并不幸运。
# This is function I decode ip/port
def decode_peers(peers):
ret = []
for ipport in peers:
try:
ret.append((socket.inet_ntoa(ipport[:4]), unpack('>H', ipport[-2:])[0]))
except Exception as err:
logging.critical(err)
return ret
# This is an bdecoded example what I received from nodes, and I passed "value" part to the upon function.
[03:53:05](DEBUG): OrderedDict([(b'ip', b'n\xbc;,\xf1\x87'), (b'r', OrderedDict([(b'id', b'\xcf\x1c@\xfb\x86?\x17\xb0\x95\xd1\xb9:\x9a\xf1\x9c\xf1v\x03\xa82'), (b'nodes', b'\x85\xd7\x80\x1b\x8a"V\xd9>\xf8<\xa2\x0e2~\x84j\x94wIA\xb2\x19&\x8b\x0c\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde0\x05\xb2\xce\xe2\x0b8j\xd1\xd3.\x85\x8cH\x8c\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde0\x06\x8d\x81\x1f\xe4\xc5\x88\xec\xad\xfc\x1a\xcf\x9e\xa6\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde0\x07 \xbcR\x1d*u\x0e.\xa8E\x12G\xdb\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde1\x80r\xfdn\x8d!\r\x17\xbfU\xb5\x87\x81t\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde1\x81\x90\xc0\x13Pw\x91\x87\xc25\x9d1\x881\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde1\x82m"\x12-\x96\xc7\x1fY}\xe4_\x9f\xff\xcf\x1c@\xfb\x86?\x18\x93$\xdf\xde1\x83\x82\xdb\xf0\x10\xeb&I\xc5}\xece\x13\xc9'), (b'token', b'\na\xb8\x15'), (b'values', [b'9Bq\xf1X\xea', b'9\x07r7\x9a\xee', b'\x7fg\xb8\x17\x9e\x90', b'\xc1d\xfa\xa5\x01\x94', b'\x04r=!C\x9a', b'Fv\x7f\xa7\x86\x9e', b'\x89s\x7f\xf3\xc8\xa4'])])), (b't', b'\xc3\x8b\xc2\x9d'), (b'v', b'LT\x00\x11'), (b'y', b'r')])
# This is result I got from decode function, there is no difference when I compare to what Wireshark decode under DHT protocol.
[04:03:56](DEBUG): [('57.66.113.241', 22762), ('57.7.114.55', 39662), ('127.103.184.23', 40592), ('193.100.250.165', 404), ('4.114.61.33', 17306), ('70.118.127.167', 34462), ('137.115.127.243', 51364)]
【问题讨论】:
-
发布一些数据包捕获+您解码的内容。您可能想在流行的洪流上进行测试。并与现有的实现进行比较,看看它是否有效
-
你是否已经用非 DHT 对等体验证了你的 TCP 对等体协议实现?我最近正在测试一个新的 BitTorrent 实现的一些部分,我发现在本地运行客户端时,在已知端口上,然后尝试连接到 Internet 上的对等点时,它要容易得多。 (就我而言,我使用的是 docker 映像 (based on this),因此我可以轻松共享和重置我的测试对等方的状态。)
-
谢谢回复,我已经上传了Wireshark抓包截图。你可以看到我的 TCP 实现可能工作正常。但是我仍然无法从 DHT 中的同行那里得到任何回应,他们甚至都无法建立连接,这让我很沮丧
-
我在询问 DHT 消息的数据包捕获(响应
get_peers查询)和您的解码结果。我推测你解码不正确。 -
我更新了,我解码的和 Wireshark 做的没有区别。
标签: python bittorrent dht