Skip to content

[Netcode] Direct connections (NAT punching) fail often, players fall back to relays #119

Done

Description

@Greevee

Source: anonymous network statistics from players who opted in (first data since 0.6.0, Nov 25–26 – small sample).

What the numbers say

  • NAT hole punching (direct player-to-player connection) failed 28 times, while a direct connection worked 20 times.
  • The fallback works well: all 105 relay links had under 1 % packet loss.

So many players currently can't connect directly and play over a relay. That's fine for stability, but a direct connection usually has lower ping.

Goal
More players get a direct connection when it is possible; relays stay as a reliable fallback.

To do

  • Find out why punching fails (router type, timing, port handling).
  • Improve the punching strategy where possible.
  • Keep relay quality monitored as player numbers grow.

Lower priority than host loss and reconnect, since the relays already work.

Activity

  1. added
    enhancement
    game: LoC
    fixed-0.6.3
    on Nov 26, 2026
  2. Greevee commented on Nov 26, 2026

    @Greevee
    ContributorAuthor

    Thanks – the statistics were very helpful here.

    Why punching failed so often

    • The game tried for only three seconds and never again. If the other player's router answered a little late, the pair stayed on the relay for the whole session.
    • Some routers give each destination its own outgoing port. With those, only one direction got through: the other player could reach you, but you never punched back to the address you were actually seeing. In the worst case your side ended up with no path at all, and the connection never came up.
    • There was no IPv6. Many connections today share one IPv4 address with lots of other customers (carrier-grade NAT, DS-Lite, mobile) but have their own public IPv6 address. IPv6 usually has only a firewall in the way, not address translation.

    What changes in 0.6.3

    • IPv6 first: the game offers your own public IPv6 address to the players in your lobby and tries IPv6 before IPv4. The server only passes it on to your lobby; it is never logged or stored. The server doesn't need IPv6 for this. (Thanks to QuantX for the hint.)
    • Punching back: when a probe from the other player arrives from an unexpected address, the game now probes back to exactly that address.
    • Keep trying: the relay still starts after three seconds, so joining is just as fast. But punching keeps going for a while, then retries now and then in the background. If the direct path opens later, the game switches from the relay to direct during the match.
    • No more dead pairs: if only the other side gets through, your side uses the relay instead of waiting for a direct path that never comes.
    • All security rules stay as they are: probes are encrypted and authenticated, no bigger than the answer, and strictly limited in number.

    Lab test (simulated router types, 2 runs each, before → after): direct connections went from 4 to 16 out of 20 attempts.

    • Late answer: 0 → 2
    • One-way routers: 0 → 2. Before, the connection didn't come up at all.
    • Both sides behind the hardest NAT type, with IPv6: 0 → 2, also with a real public IPv6 address.
    • Switch from relay to direct in the middle of a session: 0 → 2

    Two players who are both behind the hardest NAT type and have no IPv6 still use the relay – that's expected, and the relays keep working well (all relay links under 1 % loss).

    The statistics now also count direct connections over IPv6 vs IPv4, late switches to direct, and how punching failed (one-way vs. no answer at all), so I'll see the effect after the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfixed-0.6.3game: LoC

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions