kinnay / NintendoClients

Python package to communicate with Switch, Wii U and 3DS servers
MIT License
547 stars 66 forks source link

Fix PRUDP sequence ID rollover to happen after ID 65535 #14

Closed tenda-gumi closed 5 years ago

tenda-gumi commented 5 years ago

Previously it rolled over at 0xffffffff but actually the sequence ID is a 2-byte field.

tenda-gumi commented 5 years ago

By the way, I think it's a slightly more complex thing to fix, but I think the sliding window might not handle the rollover perfectly with unreliable, out-of-order transport. Let's say that packet 0 arrives before packet 65535, we will discard it because it is less than the expected value. But -- we will ack the packet anyway, so the peer will never re-transmit it. Maybe the sliding window should accept rolled-over packets if we're close to the limit.

kinnay commented 5 years ago

Thanks, nice catch.

If you can think of a good way to fix the rollover issue, feel free to open another pull request. I don't think it'll ever be an issue under normal circumstances though. Even if you receive 10 packets per second it takes almost 2 hours until the sequence id wraps around. I'm not even sure if the real NEX handles it correctly.