HTTP subsystem refactoring, fixed possible crashes shortly after destroying daemon or self-select client.

This commit is contained in:
XMRig 2020-02-23 01:40:19 +07:00
parent 23c51c9a11
commit 1ee27a564b
No known key found for this signature in database
GPG key ID: 446A53638BE94409
16 changed files with 129 additions and 58 deletions

View file

@ -24,17 +24,13 @@
*/
#include <algorithm>
#include <cassert>
#include "base/net/stratum/DaemonClient.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/io/json/Json.h"
#include "base/io/json/JsonRequest.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/http/HttpClient.h"
#include "base/net/stratum/DaemonClient.h"
#include "base/net/stratum/SubmitResult.h"
#include "base/tools/Buffer.h"
#include "base/tools/Timer.h"
@ -50,6 +46,10 @@
#endif
#include <algorithm>
#include <cassert>
namespace xmrig {
static const char *kBlocktemplateBlob = "blocktemplate_blob";
@ -66,7 +66,8 @@ xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) :
BaseClient(id, listener),
m_monero(true)
{
m_timer = new Timer(this);
m_httpListener = std::make_shared<HttpListener>(this);
m_timer = new Timer(this);
}
@ -327,12 +328,12 @@ void xmrig::DaemonClient::send(int method, const char *url, const char *data, si
HttpClient *client;
# ifdef XMRIG_FEATURE_TLS
if (m_pool.isTLS()) {
client = new HttpsClient(method, url, this, data, size, m_pool.fingerprint());
client = new HttpsClient(method, url, m_httpListener, data, size, m_pool.fingerprint());
}
else
# endif
{
client = new HttpClient(method, url, this, data, size);
client = new HttpClient(method, url, m_httpListener, data, size);
}
client->setQuiet(isQuiet());

View file

@ -27,12 +27,15 @@
#define XMRIG_DAEMONCLIENT_H
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/net/http/HttpListener.h"
#include "base/net/stratum/BaseClient.h"
#include "base/tools/Object.h"
#include <memory>
namespace xmrig {
@ -74,6 +77,7 @@ private:
void setState(SocketState state);
bool m_monero;
std::shared_ptr<IHttpListener> m_httpListener;
String m_blocktemplate;
String m_prevHash;
String m_tlsFingerprint;

View file

@ -63,7 +63,8 @@ static const char * const required_fields[] = { kBlocktemplateBlob, kBlockhashin
xmrig::SelfSelectClient::SelfSelectClient(int id, const char *agent, IClientListener *listener) :
m_listener(listener)
{
m_client = new Client(id, agent, this);
m_httpListener = std::make_shared<HttpListener>(this);
m_client = new Client(id, agent, this);
}
@ -181,12 +182,12 @@ void xmrig::SelfSelectClient::send(int method, const char *url, const char *data
HttpClient *client;
# ifdef XMRIG_FEATURE_TLS
if (pool().daemon().isTLS()) {
client = new HttpsClient(method, url, this, data, size, String());
client = new HttpsClient(method, url, m_httpListener, data, size, String());
}
else
# endif
{
client = new HttpClient(method, url, this, data, size);
client = new HttpClient(method, url, m_httpListener, data, size);
}
client->setQuiet(isQuiet());

View file

@ -29,11 +29,14 @@
#include "base/kernel/interfaces/IClient.h"
#include "base/kernel/interfaces/IClientListener.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/net/http/HttpListener.h"
#include "base/net/stratum/Job.h"
#include "base/tools/Object.h"
#include <memory>
namespace xmrig {
@ -113,6 +116,7 @@ private:
int64_t m_sequence = 1;
Job m_job;
State m_state = IdleState;
std::shared_ptr<IHttpListener> m_httpListener;
uint64_t m_retryPause = 5000;
uint64_t m_timestamp = 0;
};