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
Add bind_addr for udp stream #2191
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,12 +264,25 @@ impl<S: UdpSocket + 'static> NextRandomUdpSocket<S> { | |
|
||
impl<S: DnsUdpSocket> NextRandomUdpSocket<S> { | ||
/// Create a future with generator | ||
#[allow(dead_code)] | ||
pub(crate) fn new_with_closure(name_server: &SocketAddr, func: UdpCreator<S>) -> Self { | ||
let bind_address = match *name_server { | ||
SocketAddr::V4(..) => SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0), | ||
SocketAddr::V6(..) => { | ||
SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), 0) | ||
} | ||
Self::new_with_bind_addr_and_closure(name_server, &None, func) | ||
} | ||
|
||
/// Create a future with generator | ||
pub(crate) fn new_with_bind_addr_and_closure( | ||
name_server: &SocketAddr, | ||
bind_addr: &Option<SocketAddr>, | ||
func: UdpCreator<S>, | ||
) -> Self { | ||
let bind_address = match bind_addr { | ||
Some(ba) => *ba, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I prefer more expressive names to shortening them like this, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the logic below, do we need to check that the bind_addr matches the family of the name_server? That is, if this is a v4 address, but the name_server is a v6 address, than this UDP socket will either fail, or never get a response, maybe it will fail quickly with a "no route to host", though I'm not sure off the top of my head. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I will take a look what other(such as std lib) do on this problem. |
||
None => match *name_server { | ||
SocketAddr::V4(..) => SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0), | ||
SocketAddr::V6(..) => { | ||
SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), 0) | ||
} | ||
}, | ||
}; | ||
Self { | ||
name_server: *name_server, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the discussion in #2190, this should probably be IPaddr instead. I do think we should still consider how we want to deal with IPv4 vs IPv6...