quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.76k stars 380 forks source link

Make `quinn-proto::{Connection, Endpoint}` deterministic #1691

Closed michael-yxchen closed 11 months ago

michael-yxchen commented 11 months ago

quinn-proto::{Connection, Endpoint} structs call StdRng::from_entropy() in their implementation. It makes it hard to reproduce errors in an otherwise deterministic test case.

This PR addresses the issue by adding a StdRng argument to the respective new functions. For other functions that may create an endpoint/connection, an argument of type impl FnOnce() -> StdRng is added. This avoids eager calls to generate fresh entropy. e.g. the Endpoint::handle function is frequently called but we'd only need the rng when handling a new incoming connection.

Fixes an unrelated lint error.

Closes #1684

michael-yxchen commented 11 months ago

Put up another version that always use Endpoint.rng to seed Connection.rng. Let me know if you like it this way, or prefer to obtain fresh randomness from the entropy pool if Endpoint.rng is not seeded