Skip to content
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 core->requestHTTP4. Force IPV4 requests for announce. Use bind address if provided #786

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions SDK/include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ struct ICore : public IExtensible, public ILogger
network->update();
}
}

/// Launch an HTTP request (IPV4) and read the response
/// @param handler The handler that will handle the response
/// @param type The request type
/// @param url The URL
/// @param[opt] data The POST data
virtual void requestHTTP4(HTTPResponseHandler* handler, HTTPRequestType type, StringView url, StringView data = StringView()) = 0;
AmyrAhmady marked this conversation as resolved.
Show resolved Hide resolved
};

/// Helper class to get streamer config properties
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/LegacyNetwork/legacy_network_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void RakNetLegacyNetwork::start()
if (*config.getBool("announce"))
{
const String get = "https://api.open.mp/0.3.7/announce/" + std::to_string(port);
core->requestHTTP(new AnnounceHTTPResponseHandler(core), HTTPRequestType::HTTPRequestType_Get, get.data());
core->requestHTTP4(new AnnounceHTTPResponseHandler(core), HTTPRequestType::HTTPRequestType_Get, get.data());
}
}

Expand Down
21 changes: 19 additions & 2 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,13 @@ class Config final : public IEarlyConfig
class HTTPAsyncIO
{
public:
HTTPAsyncIO(HTTPResponseHandler* handler, HTTPRequestType type, StringView url, StringView data)
HTTPAsyncIO(HTTPResponseHandler* handler, HTTPRequestType type, StringView url, StringView data, bool force_v4 = false, StringView bindAddr = "")
: handler(handler)
, type(type)
, url(url)
, data(data)
, force_v4(force_v4)
, bindAddr(bindAddr)
, finished(false)
, response(0)
{
Expand Down Expand Up @@ -903,6 +905,12 @@ class HTTPAsyncIO
request.set_write_timeout(Seconds(5));
request.set_keep_alive(true);

if (params->force_v4)
request.set_address_family(AF_INET);

if (!params->bindAddr.empty())
request.set_interface(params->bindAddr);

// Run request
httplib::Result res(nullptr, httplib::Error::Canceled);
switch (type)
Expand Down Expand Up @@ -937,6 +945,9 @@ class HTTPAsyncIO
String url;
String data;

bool force_v4;
String bindAddr;

std::atomic_bool finished;
int response;
String body;
Expand Down Expand Up @@ -2091,4 +2102,10 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
}
return false;
}
};

void requestHTTP4(HTTPResponseHandler* handler, HTTPRequestType type, StringView url, StringView data) override
{
HTTPAsyncIO* httpIO = new HTTPAsyncIO(handler, type, url, data, true, config.getString("network.bind"));
httpFutures.emplace(httpIO);
}
};
Loading