- Reuse buffers and use rng.Read to cut per-iteration allocations in random echo test
- Separate RNG for payload length to keep data stream deterministic
- Optimize UDP source validation by comparing UDPAddr directly to avoid per-packet String allocation
Previously, the `readLoop` would lazily initialize the source address (`src`) based on the first incoming packet. This behavior meant that for a short window during initialization, the session might accept a packet from an arbitrary address, potentially allowing connection hijacking or address spoofing.
This change ensures that if `s.remote` is already known (e.g., in `Dial` mode), `src` is initialized immediately before entering the loop. This locks the session to the expected remote address from thefix: initialize source address in readLoop from remote addr
Previously, the `readLoop` would lazily initialize the source address (`src`) based on the first incoming packet. This behavior meant that for a short window during initialization, the session might accept a packet from an arbitrary address, potentially allowing connection hijacking or address spoofing.
This change ensures that if `s.remote` is already known (e.g., in `Dial` mode), `src` is initialized immediately before entering the loop. This locks the session to the expected remote address from the start.