lucaspoffo / renet

Server/Client network library for multiplayer games with authentication and connection management made with Rust
Apache License 2.0
662 stars 68 forks source link

Per-packet overhead can easily push packet size over SLICE_LENGTH #83

Closed NiseVoid closed 1 year ago

NiseVoid commented 1 year ago

When sending small packets, they get grouped into one big packet if possible, however the overhead is not taken into consideration. This means if we send many small packets, for example 255 packets of 4 bytes, goes over SLICE_LENGTH. Sending even more even smaller packets, like 1000 of 1 byte, also over the buffer size (1400), and even the maximum MTU (1500). These messages then get dropped by either the transport's max packet size, or it gets truncated to the buffer length, resulting in a corrupt packet.

lucaspoffo commented 1 year ago

Fixed by 6d65002e0bd1a10959b9bff6ac723ea4e55b26bf

The unreliable channel was not considering the message length for packet size calculation. The reliable channel was doing it correctly already. Added tests to make sure we are covering this case.