build: target Windows 7 when building libevent and fix ipv6 usage#19375
build: target Windows 7 when building libevent and fix ipv6 usage#19375laanwj merged 2 commits intobitcoin:masterfrom
Conversation
libevent uses getaddrinfo when available, and falls back to gethostbyname Windows has both, but gethostbyname only supports IPv4 libevent fails to detect Windows's getaddrinfo due to not including the right headers This patches libevent's configure script to check it correctly
depends/packages/libevent.mk
Outdated
There was a problem hiding this comment.
I don't see how this can work... evutil.c #undef _WIN32_WINNT
There was a problem hiding this comment.
It's only undef'd after the inclusion of ws2tcpip.h which is where the AI_* definitions are.
In the ws2tcpip.h header on my machine I've got:
#define AI_PASSIVE 0x00000001
#define AI_CANONNAME 0x00000002
#define AI_NUMERICHOST 0x00000004
#if (_WIN32_WINNT >= 0x0600)
#define AI_NUMERICSERV 0x00000008
#define AI_ALL 0x00000100
#define AI_ADDRCONFIG 0x00000400
#define AI_V4MAPPED 0x00000800
#define AI_NON_AUTHORITATIVE 0x00004000
#define AI_SECURE 0x00008000
#define AI_RETURN_PREFERRED_NAMES 0x00010000
#endifThere was a problem hiding this comment.
Oh, weird. That seems like it's probably a bug, but not our problem.
There was a problem hiding this comment.
You might want to add a comment here in the makefile about why this is defined, and why it works.
There was a problem hiding this comment.
@laanwj I've added a comment here. These kinds of details probably deserve a separate document in depends (we could also add some of the macOS stuff there as well). I can follow up by writing up some more extensive docs.
|
tACK b440aca96a338f16ca664065821b980c4b0537ae. Adjusted test commands: Relevant parts of bitcoind console messages: |
|
Just a clarification to "how" this is working, and follow up to the comments above. By default, the mingw32 compiler, (on my machine, So the fix here isn't just that we are overriding libevents internal The seconds point is header include order. Because the #define AI_PASSIVE 0x00000001
#define AI_CANONNAME 0x00000002
#define AI_NUMERICHOST 0x00000004
#if (_WIN32_WINNT >= 0x0600)
#define AI_NUMERICSERV 0x00000008
#define AI_ALL 0x00000100
#define AI_ADDRCONFIG 0x00000400
#define AI_V4MAPPED 0x00000800
#define AI_NON_AUTHORITATIVE 0x00004000
#define AI_SECURE 0x00008000
#define AI_RETURN_PREFERRED_NAMES 0x00010000
#endifis included before libevent #undefs |
Gitian builds
|
This enables of the use of AI_* definitions in the Windows headers, specifically AI_ADDRCONFIG, which fixes an issue with libevent and ipv6 on Windows. It also aligns with what we define in configure when building Core.
b440aca to
eb6b735
Compare
|
ACK eb6b735 |
|
Post-merge ACK eb6b735 . |
This enables of the use of AI_* definitions in the Windows headers, specifically AI_ADDRCONFIG, which fixes an issue with libevent and ipv6 on Windows. It also aligns with what we define in configure when building Core. Github-Pull: bitcoin#19375 Rebased-From: eb6b735
Summary: Fix for ipv6 on Windows. Backport of core [[bitcoin/bitcoin#19375 | PR19375]]. Depends on D7742. Test Plan: make build-win64 cmake -GNinja .. \ -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/Win64.cmake \ -DBUILD_BITCOIN_SEEDER=OFF ninja Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D7743
TLDR: This poaches a commit from #18287 and adds one more to adjust the Windows version targeted when building libevent. These changes combined should fully fix ipv6 usage with the RPC server on Windows.
Binding the RPC server to a ipv6 address does not currently work on Windows.
We currently try and bind to
127.0.0.1and::1by default.On Windows you'll see lines like this in debug.log:
This issue was bought up in, and supposedly fixed by #18287, however the two people that tested it, both said that it didn't fix the problem. I think I now understand why that change alone is incomplete.
Our call into libevent starts with evhttp_bind_socket_with_handle():
The problem is falling into "#ifndef AI_ADDRCONFIG":
When this occurs, hints end up being adjusted, and it seems that ipv6 addresses end up being mis-identified as ipv4?
However this shouldn't happen, as these
AI_definitions are available on Windows.The issue is that in evutil.c,
_WIN32_WINNTis set to0x501(XP).This obviously predates Vista (
0x0600), which is when theAI_ADDRCONFIGdefinition (and others) became available.The change here will override libevents internal D_WIN32_WINNT defines. This should be ok, because it's only making "more" of the Windows API available. It's also aligned with what we do in our own configure, we pass
D_WIN32_WINNT=0x0601. We also now use linker flags to restrict our binary from running on a Windows version earlier than Windows 7.The combined fixes can be tested by running:
bitcoind -rpcbind=::1 rpcallowip='0.0.0.0/0' -debug=httpand then querying it using:
bitcoin-cli -rpcconnect=::1 getblockchaininfoTODO: