简体   繁体   English

如果我有所有的ip信息,绕过P2P应用程序的NAT?

[英]Getting around NAT for P2P app if I have all ip info?

I am making a P2P android app. 我正在制作一个P2P安卓应用。 My current issue is that I am unable to get my devices to recognize each other unless they are on the same network and I use private IP addresses -- I have all public IPs/ports/private IP addresses stored in a database. 我目前的问题是,我无法让我的设备识别对方,除非他们在同一个网络上并使用私有IP地址 - 我将所有公共IP /端口/私有IP地址存储在数据库中。

How am I supposed to get one to contact the other, WITHOUT going into router settings and portforwarding, given that NAT blocks my attempts, and I can't specifically choose what private IP to choose from the public IP address... 考虑到NAT阻止我的尝试,我怎么能让一个人联系另一个,没有进入路由器设置和端口转发,我无法专门选择从公共IP地址中选择哪个私有IP ...

How am I supposed to go about successfully reaching my fellow device =] 我怎么能成功地到达我的同伴设备=]

Short answer: you can't 简短的回答:你做不到

Long answer: the problem of NAT traversal requires a 10+ man-year effort, and as far as i know there is no other product out there that does this reliably except for skype (skype allows you to write plugins which essentially use skype as a reliable P2P connection provider that you don't have to care about, see eg here and here ). 答案很长:NAT遍历的问题需要10年以上的工作量,据我所知,没有其他产品能够可靠地执行此操作除了skype(skype允许您编写基本上使用skype作为可靠的P2P连接提供程序,您不必关心,请参阅此处此处 )。 Sure enough, using skype as a "provide me a P2P connection please" service provider ties you to a proprietary and out-of-your-hands solution, so it's not really a... solution. 果然,使用skype作为“请给我提供P2P连接”服务提供商将您与专有和无法解决的解决方案联系起来,因此它不是真正的......解决方案。

Now, there's another problem which will only make things get tougher w/r to NAT traversal on IPv4 in the years to come: specifically, ISPs will start introducing what it's called "Carrier-Grade NATs" (CGN, see this for an intro) which use a different type of algorithms for port allocation than the home NATs use (plus, on top of this, you'll now have TWO cascaded NATs to deal with). 现在,还有另外一个问题,只会让未来几年内IPv4的NAT遍历更加艰难:具体来说,互联网服务提供商将开始推出所谓的“运营商级NAT”(CGN,请参阅此内容 )它使用不同类型的算法进行端口分配,而不是家庭NAT使用(另外,在这之上,你现在将有两个级联的NAT来处理)。 In a nutshell, w/o having a 10+ man-year developing resource at your hands, forget about ANYTHING P2P over IPv4. 简而言之,没有超过10人年的开发资源,忘记任何P2P over IPv4。 BTW, even skype is expected to succumb to CGNs (which are already THE NORM for mobile connections, ie there are almost no mobile carriers left that provide the handsets with a public IPv4 address), and this is (most likely IMHO) the reason why one of the first things that MS did after acquiring skype was to put thousand of RELAYS in place so that these will be able to deal with the impossibility to establish P2P connections over IPv4 in the coming years, see this (and forget about MS' reply at the end of the article, it's BS) 顺便说一下,即使是skype也会屈服于CGN(已经是移动连接的THE NORM,即几乎没有剩余的移动运营商为手机提供公共IPv4地址),这就是(最有可能是恕我直言)之所以如此获得Skype后,MS做的第一件事就是将数千个RELAYS放到适当的位置,以便能够处理未来几年在IPv4上建立P2P连接的不可能性,看到这一点 (忘掉MS的回复)在文章的最后,它是BS)

What you can do is to start learning some more about IPv6: with IPv6 things SHOULD be much easier because there will (allegedly) be no more NATs (there's something called NPT, but that's a P2P-friendly protocol). 你可以做的是开始学习更多关于IPv6的知识:使用IPv6的事情应该更容易,因为(据称)将不再有NAT(有一些叫做NPT,但这是一个P2P友好的协议)。 The problem with IPv6 routers is that there is (as-yet) no port control standard protocol, but there's something currently in the making, see this , so shoud/when this (or some other) protocol will become standardized AND adopted by CPE manufactures, then IPv6 router traversal will be next to trivial. IPv6路由器的问题在于(目前还没有)端口控制标准协议,但是目前正在制作中,看到这一点 ,所以当这个(或其他)协议将被标准化并由CPE制造商采用时,然后IPv6路由器遍历将是微不足道的。

So, either way, your best option right now is to FORGET ABOUT P2P for the next 3 to 5 years. 因此,无论哪种方式,您现在最好的选择是在接下来的3到5年内忘记P2P。 unfortunately... 不幸...

PS. PS。 2 more links: 1) This is my project, and believe me, it's a mess; 另外2个链接:1) 是我的项目,相信我,这是一个烂摊子; 2) CGNs in the wild . 2) 野外的CGN

The point is you can only connect to the other node, if there is some kind of port forwarding / NAT available via public internet. 关键是如果通过公共互联网提供某种端口转发/ NAT,则只能连接到其他节点。 Most likely there is, because for each of your private node (by private i mean one with a private ip address behind a public ip) it is still accessing internet, and that only happens when there is some rule already in place. 最有可能的是,因为对于每个私有节点(私有,我的意思是私有IP地址在公共IP后面),它仍然访问互联网,而这只有在已经存在某些规则时才会发生。 The only question is whether you can use that rule for your app. 唯一的问题是您是否可以将该规则用于您的应用。

The link i referred in comments above mentions some of the common techniques used. 我在上面的评论中提到的链接提到了一些常用的技术。

您必须使用STUN和/或UPnP等技术才能通过NAT路由器。

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

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