Search Unity

MLAPI.Puncher - NAT Punchthrough

Discussion in 'Netcode for GameObjects' started by TwoTen, Jul 10, 2019.

  1. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    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,847
    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

    Joined:
    May 25, 2016
    Posts:
    1,168
    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,363
    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

    Joined:
    May 25, 2016
    Posts:
    1,168
    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,363
    Thanks, I think I might use the Steam transport for layer then. I'll give it a go anyway. Thanks! :)
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    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.
  8. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    @TwoTen I created basic multiplayer from code monkey video. Now i have Network Manager and Unity Transport. Where should i use this? I really didn't understand.
     
  9. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @segant the comment you replied to is 2 years old, nowadays you can use the Relay service for this
     
  10. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    I will just wait for Nat Punch