mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 21:52:53 +02:00
Merge bitcoin/bitcoin#34342: cli: Replace libevent usage with simple http client
d61053d97bbuild: Drop libevent from bitcoin-cli link libraries (Fabian Jahr)798d051c80cli: Remove libevent usage (Fabian Jahr)376e7ef07cutil: Expose IOErrorIsPermanent in sock header (Fabian Jahr)5d562430denetbase: Add timeout parameter to ConnectDirectly (Fabian Jahr)a988ac592fcli: Add HTTPResponseHeaders class for parsing response headers (Fabian Jahr)c471c5085bcommon: Add unused UrlEncode function (Fabian Jahr)9687ef1bd9ci: Tolerate unused free functions in intermediate commits (Fabian Jahr) Pull request description: Part of the effort to remove the libevent dependency altogether, see #31194 This takes the parsing logic from the [`HTTPHeaders` class](d549f01caa) from #32061 and puts it into `bitcoin-cli` as a small `HTTPResponseHeaders` class with a comment to revisit potentially sharing this code somehow. This decoupled the two pulls which seems like the most sensible way to deal with this since the actual overlap is very small compared to the impact of each of the pulls which should ideally not block each other. Otherwise the change itself replaces the libevent-based HTTP client with a simple synchronous implementation which uses the `Sock` class directly. ACKs for top commit: hodlinator: re-ACKd61053d97btheStack: re-ACKd61053d97bw0xlt: ACKd61053d97bTree-SHA512: a3580a45faf540ee844aac8cb1dc056a89e8e11b45781d2807baa4736d5c0934284c6066206101b6984111a48a186d67845545d07639b623cb35ccc2d85d3ab2
This commit is contained in:
@@ -587,7 +587,12 @@ static void LogConnectFailure(bool manual_connection, util::ConstevalFormatStrin
|
||||
}
|
||||
}
|
||||
|
||||
static bool ConnectToSocket(const Sock& sock, struct sockaddr* sockaddr, socklen_t len, const std::string& dest_str, bool manual_connection)
|
||||
static bool ConnectToSocket(const Sock& sock,
|
||||
struct sockaddr* sockaddr,
|
||||
socklen_t len,
|
||||
const std::string& dest_str,
|
||||
bool manual_connection,
|
||||
std::chrono::milliseconds timeout)
|
||||
{
|
||||
// Connect to `sockaddr` using `sock`.
|
||||
if (sock.Connect(sockaddr, len) == SOCKET_ERROR) {
|
||||
@@ -600,7 +605,7 @@ static bool ConnectToSocket(const Sock& sock, struct sockaddr* sockaddr, socklen
|
||||
// synchronously to check for successful connection with a timeout.
|
||||
const Sock::Event requested = Sock::RECV | Sock::SEND;
|
||||
Sock::Event occurred;
|
||||
if (!sock.Wait(std::chrono::milliseconds{nConnectTimeout}, requested, &occurred)) {
|
||||
if (!sock.Wait(timeout, requested, &occurred)) {
|
||||
LogInfo("wait for connect to %s failed: %s\n",
|
||||
dest_str,
|
||||
NetworkErrorString(WSAGetLastError()));
|
||||
@@ -643,6 +648,13 @@ static bool ConnectToSocket(const Sock& sock, struct sockaddr* sockaddr, socklen
|
||||
}
|
||||
|
||||
std::unique_ptr<Sock> ConnectDirectly(const CService& dest, bool manual_connection)
|
||||
{
|
||||
return ConnectDirectly(dest, manual_connection, std::chrono::milliseconds{nConnectTimeout});
|
||||
}
|
||||
|
||||
std::unique_ptr<Sock> ConnectDirectly(const CService& dest,
|
||||
bool manual_connection,
|
||||
std::chrono::milliseconds timeout)
|
||||
{
|
||||
auto sock = CreateSock(dest.GetSAFamily(), SOCK_STREAM, IPPROTO_TCP);
|
||||
if (!sock) {
|
||||
@@ -658,7 +670,7 @@ std::unique_ptr<Sock> ConnectDirectly(const CService& dest, bool manual_connecti
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!ConnectToSocket(*sock, (struct sockaddr*)&sockaddr, len, dest.ToStringAddrPort(), manual_connection)) {
|
||||
if (!ConnectToSocket(*sock, (struct sockaddr*)&sockaddr, len, dest.ToStringAddrPort(), manual_connection, timeout)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -687,7 +699,12 @@ std::unique_ptr<Sock> Proxy::Connect() const
|
||||
memcpy(addrun.sun_path, path.c_str(), std::min(sizeof(addrun.sun_path) - 1, path.length()));
|
||||
socklen_t len = sizeof(addrun);
|
||||
|
||||
if(!ConnectToSocket(*sock, (struct sockaddr*)&addrun, len, path, /*manual_connection=*/true)) {
|
||||
if (!ConnectToSocket(*sock,
|
||||
(struct sockaddr*)&addrun,
|
||||
len,
|
||||
path,
|
||||
/*manual_connection=*/true,
|
||||
std::chrono::milliseconds{nConnectTimeout})) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user