feat: allow passing a known port for first endpoint, and random for subsequent.
dan-da opened this issue · 1 comments
Presently, QuicP2p::with_config() contains this logic:
let (port, allow_random_port) = cfg
.port
.map(|p| (p, false))
.unwrap_or((DEFAULT_PORT_TO_TRY, true));
Thus allow_random_port
is set to false if caller specifies a port, and is set to true otherwise.
However, esp when using ::send_uni(), a caller may need to be listening on one port and sending on another. So it can make sense to specify a port for listening, and then request a random port for sending.
Presently, if the caller specifies a known port in config, eg 10000 and then calls ::new_endpoint() twice, the second call will fail/error because the port is already in use. That seems a little bit broken-by-design.
As such, I am thinking that perhaps new_endpoint() should take an Option argument that allows to override the config defaults. Or failing that, a way to specify in the config "random port for any endpoints after the first".
The API was changed in #309. The local address is no longer part of Config
, but rather a separate argument for Endpoint::new
or Endpoint::new_client
.
I think that closes this issue: it's now possible to reuse Config
and still specify different local addresses for separate Endpoint
s.