通过NAT连接P2P吗? [英] Connecting P2P over NAT?

查看:144
本文介绍了通过NAT连接P2P吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始探索使用p2p连接与他人进行连接的选项,因此我在JAVA中为Android设备编写了一个简单的套接字程序,用户可以在其中共享简单的消息p2p(那时我对NAT一无所知).我对NAT有所了解,所以现在我需要与另一个使用服务器进行发现但将有效负载通过p2p传输的用户建立TCP连接.我还研究了XMPP(关于协议如何工作的非常详尽的解释是

I started to explore the option of connecting with other using a p2p connection, so I coded a simple socket program in JAVA for android devices in which the users can share simple messages p2p (I didn't have any idea about NAT then). I got to know about NAT, so I now need to establish a TCP connection with another user which uses a server for discovery but payload is transferred p2p. I have also looked at XMPP(a very good and detailed explanation of how protocol works is here) and UPnP but I dont know how to implement them.

另一个有趣的问题是BitTorrent,因为它们可以在任何设备上工作,甚至可以在NAT之后使用.我无法获得有关BitTorrent的工作原理的任何解释.

Another interesting question that arises is of BitTorrent because they can work on any device and even behind a NAT. I am not able to get any explanation of how BitTorrent works.

我研究了很多,但被困住了.

I have researched a lot but I am stuck.

我的问题是:

  1. BitTorrent的详细说明(例如此处 ,而不是Torrent的工作原理)以及如何在NAT周围工作?
  2. 有没有办法以编程方式创建NAT条目?
  3. 套接字编程足以满足p2p吗?
  4. 创建自己的协议有多困难,我该如何构建一个协议?
  5. 如果两个设备D1和D2要通信p2p,并且它们彼此知道IP. D1向D2发送一个请求,该请求无法通过D2的NAT,但是应在D1的NAT中创建一个条目.因此,当D2尝试发送某些内容时,D1的NAT应该发现具有D2的IP的条目.那为什么这个包不允许呢?
  1. A detailed explanation of BitTorrent(like here, not how torrents work) and how is it able to work around NAT ?
  2. Is there a way to make a NAT entry programmatically ?
  3. Is socket programming sufficient for p2p ?
  4. How difficult is it to create your own protocol and how can I build one ?
  5. If two devices D1 and D2 want to communicate p2p and they know each other's IP. D1 sends a request to D2 and that can't get through the D2's NAT, but there should be an entry created in D1's NAT. So when D2 tries to send something D1's NAT should discover an entry with D2's IP. Then why is the packet not allowed by it ?

推荐答案

另一个有趣的问题是BitTorrent,因为它们可以在任何设备上工作,甚至可以在NAT之后使用.我无法获得有关BitTorrent的工作原理的任何解释.

Another interesting question that arises is of BitTorrent because they can work on any device and even behind a NAT. I am not able to get any explanation of how BitTorrent works.

此语句看起来像您假设bittorrent需要完全连接才能运行.

This statement looks like you assume that bittorrent needs full connectivity to operate.

那是不正确的.

在NAT设备后面,您仍然可以建立传出 TCP连接.只要有其他未经过NAT的(或经过NAT但正确的 port-forwarded )可以接受传入连接的网络中的客户端.

Behind a NAT device you will still be able to establish outgoing TCP connections. Which generally is sufficient for bittorrent as long as there are other, non-NATed (or NATed but properly port-forwarded) clients in the network that can accept incoming connnections.

NAT对数据的流向没有影响,因为一旦建立连接,它们就是双向的.只是对于初始连接设置有问题.

NAT has no impact on the flow direction of the data because connections are bi-directional once they are established. It only is problematic for the initial connection setup.

这对于bittorrent非常有效,因为bittorent不在乎从哪个特定节点获取数据. 尽管更好的连接通常可以提高性能.

This works perfectly fine for bittorrent because bittorent does not care from which specific node you get your data. Although better connectivity generally does improve performance.

如果节点的身份很重要或一对一传输是重要的用例,则其他p2p协议通常会尝试

If the identity of the node matters or one-on-one transfers are an important use-case then other p2p protocols usually attempt NAT traversal first and if that fails rely on 3rd party nodes relaying traffic between those nodes who cannot connect to each other directly.

此外,由于越来越多的ISP开始推出

Additionally, IPv6 support will become essential in the future to maintain end-to-end connectivity because more and more ISPs are starting to roll out carrier-grade NAT for IPv4 while IPv6 will remain non-NATed

这篇关于通过NAT连接P2P吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆