zpl-c / enet

⚡️ ENet reliable UDP networking library
https://blog.zpl.pw
MIT License
650 stars 62 forks source link

Suggestion: Implement some kind (or various) of hole punching #40

Open Anyeos opened 1 year ago

Anyeos commented 1 year ago

I am actually developing a game that need to host game servers in user side and the NAT are a problem. UPnP does not work on all routers (no all CPE routers have a public IP neither), so UDP hole punching will be a solution that can works.

I am implementing my own code for that purpose but will be great to have that already included on the library itself simplyfing the things and adding that support out of the box.

I want to suggest:

Than you for reading and for the interest of making this project.

inlife commented 1 year ago

Hey @Anyeos !

Here is a small project showcasing how to achieve hole punching with an intermediate server: https://github.com/codecat/enet-p2p

Not exactly what you've asked, but might help!

Anyeos commented 1 year ago

Yes, and thank you for the link. But because hole punching is a low level thing, I think that it must be implemented directly on the ENET library.

ENET as is does not simplify hole punching because it cannot handle for example a kind of negotiation on peers, it directly listen or connects to. But if hole punching is implemented between ENET we can simply add the server (STUN or a custom one) as an extra parameter and all the rest remains the same.

Right now I need to implement a hole punching outside ENET (i.e.: using UDP socks directly) and next some kind of hacking to make ENET establish the connection. And it took me more than a week and still does not work.

There are various examples lying around but from that to real is a test and fail approach. If it is implemented directly on ENET it will not need the hacking part and it have more probability to work.

For now I will continue testig and trying to make it work outside of ENET because that is my only option.