3

I am making a P2P android app. 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.

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...

How am I supposed to go about successfully reaching my fellow device =]

Paul
  • 375
  • 1
  • 5
  • 17

3 Answers3

3

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 e.g. here and here). 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.

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). In a nutshell, w/o having a 10+ man-year developing resource at your hands, forget about ANYTHING P2P over IPv4. BTW, even skype is expected to succumb to CGNs (which are already THE NORM for mobile connections, i.e. 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)

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). 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.

So, either way, your best option right now is to FORGET ABOUT P2P for the next 3 to 5 years. unfortunately...

PS. 2 more links:

  1. This is my project, and believe me, it's a mess;
  2. CGNs in the wild.
Community
  • 1
  • 1
Gyll
  • 351
  • 2
  • 6
0

The point is you can only connect to the other node, if there is some kind of port forwarding / NAT available via public internet. 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. 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.

fkl
  • 5,412
  • 4
  • 28
  • 68
0

You have to use technologies like STUN and/or UPnP to get through the NAT router.

Sarel Botha
  • 12,419
  • 7
  • 54
  • 59