Search Unity

  1. We have added dedicated sub-forums for UNet, the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

MLAPI.Puncher - NAT Punchthrough

Discussion in 'MLAPI' started by TwoTen, Jul 10, 2019.

  1. TwoTen

    TwoTen

    Unity Technologies

    Joined:
    May 25, 2016
    Posts:
    1,167
    To go along with the relay MLAPI.Relay, I have now released MLAPI.Puncher. A free and open source NAT punchthrough implementation. It's written in less than 500 lines, making it easy to work with. All the core implementation is in 2 files, one for the server and one for the client.

    It supports all cone types. FullCone, Address Restricted Cone, Port Restricted Cone and Symmetric Cone (if the symmetric cone has sequential port assignment). It's dependency free and should run everywhere with socket access. (For unity, everywhere except WebGL).

    Usage is super easy, the API is just a few method calls.

    If you want to check it out or just read more about it. Check the GitHub page out.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,364
    For anyone unfamiliar with the NAT "Cone" terminology, I believe their origin is RFC3489, which has clear definitions for them.

    https://tools.ietf.org/html/rfc3489
     
    TwoTen likes this.
  3. TwoTen

    TwoTen

    Unity Technologies

    Joined:
    May 25, 2016
    Posts:
    1,167
    Yes, that is correct.

    Just a note on the cones:
    We can trick every cone type except for symmetric cones (these are rare in home application afaik). This means that if one of the two parties have a symmetric cone but the other one does not, it will still work.

    If both people have symmetric cones, it will only work IF the router assigns the ports in sequential order. Because when you create a punch request, the clients actually send multiple punches on the base port + 8 by default. This can be changed ofcourse. Meaning that if they assign in sequential order, we can still trick symmetric nats.

    EDIT: I pushed a change that dramatically improves the success rate when one or both parties have symmetric NAT's: https://github.com/MidLevel/MLAPI.Puncher/commit/326776bd73e2ebc7ea15f943145138700622654f
     
    Last edited: Jul 11, 2019
    Joe-Censored likes this.
  4. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    Hello, I am going to try out your MLAPI nat punchthrough for a multiplayer game where one person acts as the host.

    What do you think the successrate is for your nat punchthrough implementation?

    (Previously I have used legacy Unity Network code and nat-faciliatator based on RakNet)
     
  5. TwoTen

    TwoTen

    Unity Technologies

    Joined:
    May 25, 2016
    Posts:
    1,167
    I have no data on this.

    But Fholm, who is pretty knowledgeable in this field told me he had read some data from Google stating 80%.

    You can expect a 0% rate in enterprise applications, and quite high in home applications.
     
    yoonitee likes this.
  6. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    Thanks, I think I might use the Steam transport for layer then. I'll give it a go anyway. Thanks! :)
     
  7. TwoTen

    TwoTen

    Unity Technologies

    Joined:
    May 25, 2016
    Posts:
    1,167
    If you are distributing through steam. The steam transport is great because it gives you free relaying which will work 100% of the time.
     
    yoonitee likes this.
unityunity