简体   繁体   English

如何与来自 DHT 网络的对等方通信?

[英]How can I communicate with peers get from DHT network?

I am learning Bit-torrent protocol recently, and I have made my script successfully get ton of peers address through DHT protocol depend on document bep_0005:我最近正在学习 Bit-torrent 协议,并且我已经使我的脚本通过 DHT 协议成功获取了大量对等地址,这取决于文档 bep_0005:

http://www.bittorrent.org/beps/bep_0005.html http://www.bittorrent.org/beps/bep_0005.html

If the queried node has peers for the infohash, they are returned in a key "values" as a list of strings.如果被查询的节点具有 infohash 的对等节点,它们将在键“值”中作为字符串列表返回。 Each string containing "compact" format peer information for a single peer.每个字符串包含单个对等点的“紧凑”格式对等点信息。

So, I decode those "values" to ip/port.因此,我将这些“值”解码为 ip/port。

I tried connect with them through TCP socket, timeout, network is unreachable, connection refused errors raised.我尝试通过 TCP 套接字与他们连接,超时,网络无法访问,出现连接拒绝错误。

I tried send handshake message depend on bep_0029 through UDP socket, but none of them replied.我尝试通过 UDP 套接字发送依赖于 bep_0029 的握手消息,但没有人回复。

Anyone can tell me, Is there anything wrong?谁能告诉我,有什么问题吗? What is the correct way to connect those peers?连接这些对等点的正确方法是什么? or Is that normal 99% of them are unable to connect, I just haven't get those 1% good peers?或者是正常的 99% 的人无法连接,我只是没有得到那些 1% 的好同行?

Thank you!谢谢!

This is TCP response of peers that I got from trackers这是我从跟踪器获得的对等方的 TCP 响应

But no lucky from DHT.但 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)]

('127.103.184.23', 40592) ('127.103.184.23', 40592)

This is clearly junk.这显然是垃圾。 The 127.0.0.0/8 block is not routed over the internet so no node should have any data containing an address in it. 127.0.0.0/8 块不通过互联网路由,因此任何节点都不应该有任何包含地址的数据。

I suggest you take a popular, known-good torrent, remove its announce URLs and put it into a client with DHT support.我建议你使用一个流行的、众所周知的种子文件,删除它的公告 URL 并将其放入一个支持 DHT 的客户端。 Then observe its behavior and compare it to your own implementation.然后观察它的行为并将其与您自己的实现进行比较。

Generally speaking some fraction of junk is expected since there are buggy or malicious implementations out there.一般来说,预计会有一部分垃圾,因为那里有错误或恶意的实现。 But generally that should only be a small fraction (smaller than 99%) and finding a single good address should be enough to connect to the swarm and then perform PEX to get more peers.但通常这应该只是一小部分(小于 99%),找到一个好的地址应该足以连接到群,然后执行 PEX 以获得更多的对等点。 If you have a malicious ISP that manipulates traffic to insert bogus data then that fraction may be much higher than normal.如果您有一个恶意 ISP 操纵流量以插入虚假数据,那么该比例可能比正常情况高得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM