-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tweaks to std::net address types #923
Conversation
* Rename SocketAddr -> InetAddr * Add various proxy fns to IpAddr * Introduce `any*` functions to create unspecified inet addresses
Your other rfc for moving thread_local was included. On Mon, Mar 2, 2015, 11:34 AM Carl Lerche [email protected] wrote:
|
I removed it really fast but I guess you saw it! Thanks! |
|
||
```rust | ||
impl Ipv6Addr { | ||
fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr; |
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.
Is there a reason new
takes separate parameters instead of a [u16; 8]
?
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.
Only that this made it easier for users to switch from the old enum-based IpAddr::Ipv6Addr
. Otherwise they'd need to do more than a simple addition of ::new
. But that's not a good enough reason, and I think making callers pack the integers into a slice (just add brackets?) is better than making callers who already have a slice break that slice into separate arguments. So I'd change it to [u16; 8]
, as you said.
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.
... and the appropriate changes for Ipv4Addr
and the new_v4
-style functions.
fn is_unicast_global(&self) -> bool; | ||
fn multicast_scope(&self) -> Option<Ipv6MulticastScope>; | ||
fn is_multicast(&self) -> bool; | ||
fn to_ipv4(&self) -> Option<Ipv4Addr>; |
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.
If we're going to spell this out in the RFC I think we may want to hold off on some of these methods. These are pretty ambitious and a more conservative design would only have new
and segments
, for example. We can always add more over time but I think we may want to start off conservative.
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.
(same for the v4 addr)
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.
I would keep is_unspecific, to_ipv4 and maybe is_multicast, but +1 for marking the others as experimental or removing them, at least until more people can read through the IP RFCs and validate the code.
cc @ktossell |
@@ -1370,6 +1370,91 @@ The contents of `std::io::net` submodules `tcp`, `udp`, `ip` and | |||
the other modules are being moved or removed and are described | |||
elsewhere. | |||
|
|||
#### InetAddr |
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.
I don't like how similar IpAddr and InetAddr are, and I think it's not obvious which one is which, just from looking at the names.
Could we choose either Inet or Ip and have, say, InetAddr (host address) and InetSocketAddr?
After thinking about this some more, I think that we need some deeper changes to these type other than the cosmetic level. The recent rewrite created specific impl InetAddr {
pub fn new(addr: IpAddr, port: u16) -> InetAddr;
pub fn new_v4(addr: InetV4Addr) -> InetAddr;
pub fn new_v6(addr: InetV6Addr) -> InetAddr;
pub fn as_v4(&self) -> Option<&InetV4Addr>;
pub fn as_v6(&self) -> Option<&InetV6Addr>;
pub fn ip(&self) -> &IpAddr;
pub fn port(&self) -> u16;
}
impl InetV4Addr {
pub fn new(addr: Ipv4Addr, port: u16) -> InetV4Addr;
pub fn ip(&self) -> &Ipv4Addr;
pub fn port(&self) -> u16;
}
impl InetV6Addr {
pub fn new(addr: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> InetV6Addr;
pub fn ip(&self) -> &Ipv6Addr;
pub fn port(&self) -> u16;
pub fn flowinfo(&self) -> u32;
pub fn scope_id(&self) -> u32;
} The idea here is to expose all information inside of How does that sound? |
* Pare back the APIs * `inet_addr` methods to `local_addr` * `InetV{4,6}Addr` types * Remove `IpAddr` * Show impls of `ToInetAddrs`
Ok, I have pushed a large update to this RFC (@carllerche gave me push rights to his repo) with the following changes:
In general the API is probably even more conservative than it is today, but I believe it poises us for more advanced functionality such as the existing methods on IP addresses and getters/setters/mutators for socket addresses. It is intentional that it is not possible and/or is difficult to create an cc @ktossell, @carllerche, @jmesmon, curious what you guys think! |
One point @carllerche brings up is that this current proposal, as it stands, removes all matching on v4/v6 exhaustively. We could perhaps define enum InetAddr { V4(InetV4Addr), V6(InetV6Addr) } This would be an alternative to the |
The lack of a constructor for |
How likely is it that IPv9 or something is going to come out and cause sadness for an enum-based InetAddr? |
@sfackler I think that a new IP version is not worth worrying about. Rust will have to solve iterating std while maintaining backwards well before anything like that will become a reality. |
Aha interesting! This was precisely the use case I was looking for. Would you have a preference over
I'm not necessarily worried about something past IPv6, but I am not personally confident enough to say that we will never expose another "instance of I do agree though that this restriction may just be unnecessarily unergonomic and we may wish to expose the |
I don't feel strongly how an |
There are other |
|
While I don't personally mind the naming either way, but I would consider |
FYI, in Java (where folks love identifiers like AbstactXmlHttpSecureSocketFactoryCreator) similar class is called InetSocketAdress. I'm fine with I'm fine with I see no practical usefulness in (Disclaimer: my largest programming experience is in C++ and Java, and I'm biased towards decisions made by the authors of JDK, some of them I find good. (But not all of them: |
@stepancheg the I would be ok w/ |
@carllerche |
Like I said, I would also be ok w/ |
@stepancheg to be clear, the |
@alexcrichton internet address is an IP (without port). socket address (in internet) is IP+port. |
FWIW, I agree with @stepancheg that |
Can you elaborate on why this is the intent? What problem do you see with exposing constructor functions, for example? |
Given this, I would want to reconsider renaming
It is mainly motivated to stick to being conservative. Given @sfackler's use case though it may be best to just expose |
Sticking with
(I think @carllerche is raising these points as well). That said, (1) may not be so important since domain sockets would live in I guess this is what you mean about the "relative location"? Personally, I'm fine with basically any of the proposed names; we just need to ship. |
Yeah I'm thinking that |
I've pushed another update which goes back to |
Since I'm inclined to agree with @stepancheg that |
Tweaks to std::net address types
After discussion here and with the RFC author on IRC, we have decided to move forward with this RFC. In the end, this largely keeps the design of the |
SocketAddr
->InetAddr
(since there are other socket address types like unix domain socket addresses).InetAddr::is_unspecified()
andInetAddr::any_v*()
IpAddr
that proxy to the versioned ip address type.any_*
functions toIpAddr
and the versioned ip address types