0
votes

I am currently implementing a (UDP) p2p application in C using the "hole punching" method. I found really illustrating previous posts by J. Selbie where he explains the basics and proceeded accordingly (post1, post2) but probably i'm missing something and only one of the peers is receiving data while the other one is not.

Here are the steps i am taking:

  • Setup: One of the peers is connected to a 4G cellular dongle (NAT A) and the other one is connected to a router that goes to the ISP provider (NAT B). These are the results reported for stunclient (stuntman client) for both NATs.

    NAT A:
    Binding test: success
    Local address: X1:48383
    Mapped address: Y1:28265
    Behavior test: success
    Nat behavior: Endpoint Independent Mapping
    Filtering test: success
    Nat filtering: Address and Port Dependent Filtering
    
    NAT B:
    Binding test: success
    Local address: X2:49158
    Mapped address: Y2:49158
    Behavior test: success
    Nat behavior: Endpoint Independent Mapping
    Filtering test: success
    Nat filtering: Address and Port Dependent Filtering
    

Now, according to these results, it is my understanding, that both NATs have a reasonable behavior and hole punching might succeed (note that NAT A does not do port preservation).

  • Hole punching attempt: Both clients contact a public facing server (STUN/rendezvous) by means of UDP to discover/interchange ip:port pairs. When each of the clients receive the response from the server, they send a UDP datagram to the other peer (ip:port as seen by the contacted public server), and then proceed to send some more and receive and reply the message to the address from which it came. I am sending the datagrams using the same socket that contacted the public server, only changing destination ip:port on the sendto function.

The thing is, that the host behind NAT A (hooked up to the 4G dongle) always receives the message, and in spite of replying to the correct ip and port of destination, the other one behind (NAT B) never gets the message. Any ideas what i am missing here ? or how to diagnose the problem ??

Thanks in Advance.

1

1 Answers

-2
votes

This is standard and general scenario where p2p(peer-to-peer) call between cellular and wifi(ISP) network is not possible. Now why?

Why?: All of the cellular network uses a cost effective method where no user can have a dedicated public IP or NAT. Meaning mobiles public IP may change after a few hour or so. As a result cellular network provider can use less number of public IP for huge number of user. This process is done generally by assigning new ip:port for every request, which is a feature of symmetric NAT. So in your case as the NAT B is Nat filtering: Address and Port Dependent Filtering that means if the data comes from NAT A has unique ip:port for every send/request then the NAT B will filter the data and the call will fail.

Solution: In general you need a relay server hosted on public IP which will receive the data from A and forward it to B and B will also do so without doing any filtering. This kind of server is called TURN server.

Now I am not sure why your stuntman test client is detecting PRC NAT(Nat filtering: Address and Port Dependent Filtering) for both A and B. For A it must be Symmatric NAT as it is on cellular network.