-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The only_v6
flag of the with_bind_address
method is not honoured
#50
Comments
Completely agree. Thanks for the feedback and I am going to change that. I cannot find any good reference/documentation for now (starting from https://man7.org/linux/man-pages/man7/ipv6.7.html), but not all configurations and platforms support In particular, I have found loopback binding ( Could you please confirm me that it instead works with |
I confirm that binding to
Notice the While I know that there exists the let mut addrs_iter = (host, port).to_socket_addrs()?; the So in reality my request would be to be able to bind to multiple addresses, as many as returned by |
This crate does not allow that directly, but yeah it is possible. Like its underlying transport, an However, nothing stops you from having multiple endpoints for your server. Something like: let socket_addresses = vec![
SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 4433),
SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 4433),
SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 4433),
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 4433),
];
// Vec<Endpoint<Server>>
let endpoints = socket_addresses
.into_iter()
.map(|address| {
let config = ServerConfig::builder()
.with_bind_address(address, false) // No dual stack, as we have multiple bindings
.with_certificate(Certificate::load("cert.pem", "key.pem")?)
.build();
Ok(Endpoint::server(config)?)
})
.collect::<Result<Vec<_>>>()?;
loop {
let (accepting, ..) = select_all(endpoints.iter().map(|ep| Box::pin(ep.accept()))).await;
accepting.await...
} Each |
True, but isn't building multiple sockets less efficient than having only one? |
I am not aware about any performance penalties about binding multiple sockets. And in any case, binding multiple addresses necessarily require binding multiple sockets (generally).
|
On further testing, binding with: let config = ServerConfig::builder()
.with_bind_config(wtransport::config::IpBindConfig::LocalDual, port)
.with_certificate(certificate)
.keep_alive_interval(Some(Duration::from_secs(3)))
.build(); the output of
So the EDIT: To calrify, I tested connecting from the browser using Thank you for the example code btw. |
I am not sure that could be classified as bug. As said, dual-stack is OS implementation details and might not be supported for localhost. In fact, I would change the API in this patch: #54 The dual-stack configuration will be more explicit: /// Configuration for IPv6 dual stack.
#[derive(Debug, Copy, Clone)]
pub enum Ipv6DualStackConfig {
/// Do not configure dual stack. Use OS's default.
OsDefault,
/// Deny dual stack. This is equivalent to `IPV6_V6ONLY`.
///
/// Socket will only bind for IPv6 (IPv4 port will still be available).
Deny,
/// Allow dual stack.
///
/// Please note that not all configurations/platforms support dual stack.
Allow,
} Where |
I have a ServerConfig builder that looks like this:
So the
only_v6
flag is false (side note: it's not good API design to pass boolean parameters to a function, because if I read that function without reading its documentation, what does false mean? It's better to use an enum in this case, but I digress).The output of the command
ss -ulpen
is as follows:Note the
v6only:1
part in the output.The text was updated successfully, but these errors were encountered: