A simple demo of P2P communication over middle boxes such as NAT
make p2pchat
./p2pchat/server port
./p2pchat/client server:port
>>> help
make test
./run_test.sh
This UDP hole punching demo only works on Cone NAT.
There is a simple python script to test your NAT type using RFC3489(the classic STUN protocol) in stun. You can simply check it by running:
cd stun
python3 classic_stun_client.py [your-local-ip]
And the result would be similar with:
INFO:root:running test I with stun.ideasip.com:3478
INFO:root:MAPPED_ADDRESS: 220.181.57.217:46208
INFO:root:running test II with stun.ideasip.com:3478
INFO:root:running test I with 217.116.122.138:3479
INFO:root:MAPPED_ADDRESS: 220.181.57.217:2732
NAT_TYPE: Symmetric NAT
If two of your peers are both behind the same NAT, this NAT must support LOOPBACK TRANSMISSION
to forward messages. You can test it by using the utils(udp_server/udp_client
) in tools
- https://www.pppan.net/blog/detail/2017-12-16-p2p-over-middle-box(up to date)
- http://jekyll.pppan.net/2015/10/31/p2p-over-middle-box/(original post)
NOTE: This is just a proof of concept project. If you want to build a stable P2P application, please refer to STUN/TURN and ICE protocol as well.