win: map 0.0.0.0 and :: addresses to localhost#1515
win: map 0.0.0.0 and :: addresses to localhost#1515bzoz wants to merge 10 commits intolibuv:v1.xfrom
Conversation
On Linux when connecting IP addresses 0.0.0.0 and :: are automatically converted to localhost. This adds same functionality to Windows.
|
Another run, with correct Makefile: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/420/ |
|
Ideally I'd go the other way and throw on So I'm +1 on this |
|
Some bots had failed with Jenkins issues, I retriggered the build: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/421/ |
|
I'm +1 on this, as long as all Unixen behave like Linux. |
bnoordhuis
left a comment
There was a problem hiding this comment.
I don't know if we should adopt this behavior on Windows because I don't know if it is universal across Unices.
| uv_inet_pton(AF_INET6, "::1", &(dest->sin6_addr)); | ||
| addr = (const struct sockaddr*) dest; | ||
| } | ||
| } |
There was a problem hiding this comment.
} else {
abort();
// or:
// return UV_EINVAL;
}There is no need for this function to return a pointer, it could return an int. In fact, I'd argue it somewhat obscures the fact that the second argument is used as an out parameter.
| dest = (struct sockaddr_in*) storage; | ||
| if (src->sin_addr.S_un.S_addr == 0) { | ||
| memcpy(dest, src, sizeof(struct sockaddr_in)); | ||
| uv_inet_pton(AF_INET, "127.0.0.1", &(dest->sin_addr.s_addr)); |
There was a problem hiding this comment.
Superfluous parens. Ditto a few lines below.
| src = (const struct sockaddr_in6*) addr; | ||
| dest = (struct sockaddr_in6*) storage; | ||
| if (memcmp(src->sin6_addr.u.Byte, | ||
| uv_addr_ip6_any_.sin6_addr.u.Byte, |
There was a problem hiding this comment.
Just &src->sin6_addr and &uv_addr_ip6_any_.sin6_addr? Or is there some subtlety I'm missing?
|
|
||
| uv_tcp_init(loop, &socket4); | ||
| uv_ip4_addr("0.0.0.0", 80, &addr4); | ||
| uv_tcp_connect(&connect4, &socket4, (const struct sockaddr*)&addr4, connect_4); |
|
Updated, PTAL. New CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/434/ |
|
The failures are unrelated, and the automatic mapping of |
saghul
left a comment
There was a problem hiding this comment.
I'd say this needs a mention in the docs.
| struct sockaddr_in* dest; | ||
| src = (const struct sockaddr_in*) addr; | ||
| dest = (struct sockaddr_in*) storage; | ||
| memcpy(dest, src, sizeof(struct sockaddr_in)); |
| src = (const struct sockaddr_in*) addr; | ||
| dest = (struct sockaddr_in*) storage; | ||
| memcpy(dest, src, sizeof(struct sockaddr_in)); | ||
| if (src->sin_addr.S_un.S_addr == 0) { |
There was a problem hiding this comment.
src->sin_addr.s_addr intead of the union.
| dest = (struct sockaddr_in6*) storage; | ||
| memcpy(dest, src, sizeof(struct sockaddr_in6)); | ||
| if (memcmp(&src->sin6_addr, | ||
| &uv_addr_ip6_any_.sin6_addr, |
| sizeof(struct in6_addr)) == 0) { | ||
| uv_inet_pton(AF_INET6, "::1", &dest->sin6_addr); | ||
| } | ||
| return 0; |
| } | ||
| return 0; | ||
| } else { | ||
| return UV_EINVAL; |
|
|
||
| loop = uv_default_loop(); | ||
|
|
||
| uv_tcp_init(loop, &socket4); |
|
Updated, PTAL. CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/442/ |
|
ping? |
bnoordhuis
left a comment
There was a problem hiding this comment.
Left some comments. I still don't know if this is something we should actually do.
|
|
||
| :returns: 0 on success, or an error code < 0 on failure. | ||
|
|
||
| .. versionchanged:: 1.15.0 added ``0.0.0.0`` to ``localhost`` mapping |
| } | ||
|
|
||
| int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr, | ||
| struct sockaddr_storage* storage) { |
| struct sockaddr_in* dest; | ||
| src = (const struct sockaddr_in*) addr; | ||
| dest = (struct sockaddr_in*) storage; | ||
| memcpy(dest, src, sizeof(struct sockaddr_in)); |
There was a problem hiding this comment.
sizeof(*src) or sizeof(dest).
| dest = (struct sockaddr_in*) storage; | ||
| memcpy(dest, src, sizeof(struct sockaddr_in)); | ||
| if (src->sin_addr.s_addr == 0) { | ||
| uv_inet_pton(AF_INET, "127.0.0.1", &dest->sin_addr.s_addr); |
There was a problem hiding this comment.
dest->sin_addr.s_addr = INADDR_LOOPBACK;? Or doesn't that exist on Windows? You could use htonl(0x7F000001) instead.
| struct sockaddr_in6* dest; | ||
| src = (const struct sockaddr_in6*) addr; | ||
| dest = (struct sockaddr_in6*) storage; | ||
| memcpy(dest, src, sizeof(struct sockaddr_in6)); |
There was a problem hiding this comment.
sizeof(*src) or sizeof(dest).
| memcpy(dest, src, sizeof(struct sockaddr_in6)); | ||
| if (memcmp(&src->sin6_addr, | ||
| &uv_addr_ip6_any_.sin6_addr, | ||
| sizeof(struct in6_addr)) == 0) { |
| if (memcmp(&src->sin6_addr, | ||
| &uv_addr_ip6_any_.sin6_addr, | ||
| sizeof(struct in6_addr)) == 0) { | ||
| uv_inet_pton(AF_INET6, "::1", &dest->sin6_addr); |
There was a problem hiding this comment.
IN6ADDR_LOOPBACK_INIT or in6addr_loopback?
| #include "uv.h" | ||
| #include "task.h" | ||
|
|
||
| void connect_4(uv_connect_t* req, int status) { |
| ASSERT(status != UV_EADDRNOTAVAIL); | ||
| } | ||
|
|
||
| void connect_6(uv_connect_t* req, int status) { |
|
Updated, PTAL |
|
ping |
|
ping? |
|
ping? |
|
@bzoz I've dismissed my review but like I said, I don't know if I agree that this is a change for the better. I won't block this PR but I can't say I wholeheartedly endorse it either. @libuv/collaborators WDYT? |
|
I'm conflicted as well. server.bind(0, '0.0.0.0');
client.connect(server.port, server.address);pattern which is useful for IPC (and testing which is also nice)... |
| } | ||
| } | ||
|
|
||
| int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr, |
There was a problem hiding this comment.
Couldnt this method could be cleaned up using a union and switch similar to the code found here?
|
@imran-iq I've followed up on your suggestion, I think that indeed it looks simpler now. PTAL |
|
Fixed the test, new CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/539/, PTAL |
|
@libuv/collaborators ping? I know it might be controversial. But it eases out differences between platforms, and fixes real world use case. CI, since last 404ed: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/555/ |
|
ping? |
bnoordhuis
left a comment
There was a problem hiding this comment.
I guess I'll sign off on this because it brings Windows closer to the out-of-the-box behavior on Linux.
| The callback is made when the connection has been established or when a | ||
| connection error happened. | ||
|
|
||
| .. versionchanged:: 1.15.0 added ``0.0.0.0`` and ``::`` to ``localhost`` |
There was a problem hiding this comment.
Version number needs an update.
|
|
||
| :returns: 0 on success, or an error code < 0 on failure. | ||
|
|
||
| .. versionchanged:: 1.15.0 added ``0.0.0.0`` and ``::`` to ``localhost`` |
|
CI after rebase: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/641 |
On Linux when connecting IP addresses 0.0.0.0 and :: are automatically converted to localhost. This adds same functionality to Windows. PR-URL: #1515 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
|
Landed in 2b32e77 |
|
Ho @bzoz, there's still a -1 from a collaborator. You'll have to revert this. |
|
@saghul commented he is generally +1 on the change and I've addressed his feedback here |
|
Should I make a PR for revert or just push a revert commit? Also, @saghul did not respond to my pings for some time now, how can I get this merged then? |
On Linux when connecting, IP addresses
0.0.0.0and::are automatically converted tolocalhost. This adds the same functionality to Windows.Ref: nodejs/node#14900
Ref: nodejs/node#14111