mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-11 05:14:40 +00:00
Update HTTP
This commit is contained in:
parent
63bd45c397
commit
86795aa5b7
11 changed files with 65 additions and 79 deletions
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -95,7 +95,7 @@ void xmrig::FetchRequest::setBody(const rapidjson::Value &value)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type)
|
||||
void xmrig::fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type, uint64_t rpcId)
|
||||
{
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||
|
@ -109,14 +109,15 @@ void xmrig::fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listen
|
|||
HttpClient *client;
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (req.tls) {
|
||||
client = new HttpsClient(std::move(req), listener);
|
||||
client = new HttpsClient(tag, std::move(req), listener);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
client = new HttpClient(std::move(req), listener);
|
||||
client = new HttpClient(tag, std::move(req), listener);
|
||||
}
|
||||
|
||||
client->userType = type;
|
||||
client->rpcId = rpcId;
|
||||
client->connect();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -58,10 +58,11 @@ public:
|
|||
String host;
|
||||
String path;
|
||||
uint16_t port = 0;
|
||||
uint64_t timeout = 0;
|
||||
};
|
||||
|
||||
|
||||
void fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type = 0);
|
||||
void fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type = 0, uint64_t rpcId = 0);
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -30,6 +24,7 @@
|
|||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
#include "base/tools/Timer.h"
|
||||
|
||||
|
||||
#include <sstream>
|
||||
|
@ -44,21 +39,20 @@ static const char *kCRLF = "\r\n";
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::HttpClient::HttpClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
|
||||
xmrig::HttpClient::HttpClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
|
||||
HttpContext(HTTP_RESPONSE, listener),
|
||||
m_tag(tag),
|
||||
m_req(std::move(req))
|
||||
{
|
||||
method = m_req.method;
|
||||
url = std::move(m_req.path);
|
||||
body = std::move(m_req.body);
|
||||
headers = std::move(m_req.headers);
|
||||
m_dns = new Dns(this);
|
||||
}
|
||||
m_dns = std::make_shared<Dns>(this);
|
||||
|
||||
|
||||
xmrig::HttpClient::~HttpClient()
|
||||
{
|
||||
delete m_dns;
|
||||
if (m_req.timeout) {
|
||||
m_timer = std::make_shared<Timer>(this, m_req.timeout, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,7 +68,7 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status)
|
|||
|
||||
if (status < 0 && dns.isEmpty()) {
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("[%s:%d] DNS error: \"%s\"", dns.host().data(), port(), uv_strerror(status));
|
||||
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(status));
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -91,6 +85,12 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::HttpClient::onTimer(const Timer *)
|
||||
{
|
||||
close(UV_ETIMEDOUT);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpClient::handshake()
|
||||
{
|
||||
headers.insert({ "Host", host() });
|
||||
|
@ -135,8 +135,12 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
|
|||
}
|
||||
|
||||
if (status < 0) {
|
||||
if (status == UV_ECANCELED) {
|
||||
status = UV_ETIMEDOUT;
|
||||
}
|
||||
|
||||
if (!client->isQuiet()) {
|
||||
LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(status));
|
||||
LOG_ERR("%s " RED("connect error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(status));
|
||||
}
|
||||
|
||||
return client->close(status);
|
||||
|
@ -151,7 +155,7 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
|
|||
client->read(buf->base, static_cast<size_t>(nread));
|
||||
} else {
|
||||
if (!client->isQuiet() && nread != UV_EOF) {
|
||||
LOG_ERR("[%s:%d] read error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(static_cast<int>(nread)));
|
||||
LOG_ERR("%s " RED("read error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(static_cast<int>(nread)));
|
||||
}
|
||||
|
||||
client->close(static_cast<int>(nread));
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,6 +23,7 @@
|
|||
|
||||
|
||||
#include "base/kernel/interfaces/IDnsListener.h"
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
#include "base/net/http/Fetch.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
@ -40,22 +35,24 @@ namespace xmrig {
|
|||
class String;
|
||||
|
||||
|
||||
class HttpClient : public HttpContext, public IDnsListener
|
||||
class HttpClient : public HttpContext, public IDnsListener, public ITimerListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpClient);
|
||||
|
||||
HttpClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
|
||||
~HttpClient() override;
|
||||
HttpClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
|
||||
~HttpClient() override = default;
|
||||
|
||||
inline bool isQuiet() const { return m_req.quiet; }
|
||||
inline const char *host() const override { return m_req.host; }
|
||||
inline const char *tag() const { return m_tag; }
|
||||
inline uint16_t port() const override { return m_req.port; }
|
||||
|
||||
bool connect();
|
||||
|
||||
protected:
|
||||
void onResolved(const Dns &dns, int status) override;
|
||||
void onTimer(const Timer *timer) override;
|
||||
|
||||
virtual void handshake();
|
||||
virtual void read(const char *data, size_t size);
|
||||
|
@ -66,8 +63,10 @@ protected:
|
|||
private:
|
||||
static void onConnect(uv_connect_t *req, int status);
|
||||
|
||||
Dns *m_dns;
|
||||
const char *m_tag;
|
||||
FetchRequest m_req;
|
||||
std::shared_ptr<Dns> m_dns;
|
||||
std::shared_ptr<Timer> m_timer;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,20 +29,13 @@ namespace xmrig {
|
|||
class HttpListener : public IHttpListener
|
||||
{
|
||||
public:
|
||||
inline HttpListener(IHttpListener *listener, const char *tag = nullptr) :
|
||||
# ifdef APP_DEBUG
|
||||
m_tag(tag),
|
||||
# endif
|
||||
m_listener(listener)
|
||||
{}
|
||||
inline HttpListener(IHttpListener *listener, const char *tag = nullptr) : m_tag(tag), m_listener(listener) {}
|
||||
|
||||
protected:
|
||||
void onHttpData(const HttpData &data) override;
|
||||
|
||||
private:
|
||||
# ifdef APP_DEBUG
|
||||
const char *m_tag;
|
||||
# endif
|
||||
IHttpListener *m_listener;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -39,8 +33,8 @@
|
|||
#endif
|
||||
|
||||
|
||||
xmrig::HttpsClient::HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
|
||||
HttpClient(std::move(req), listener)
|
||||
xmrig::HttpsClient::HttpsClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
|
||||
HttpClient(tag, std::move(req), listener)
|
||||
{
|
||||
m_ctx = SSL_CTX_new(SSLv23_method());
|
||||
assert(m_ctx != nullptr);
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -46,7 +40,7 @@ class HttpsClient : public HttpClient
|
|||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsClient)
|
||||
|
||||
HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
|
||||
HttpsClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
|
||||
~HttpsClient() override;
|
||||
|
||||
const char *tlsFingerprint() const override;
|
||||
|
|
|
@ -330,7 +330,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
|
|||
int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc)
|
||||
{
|
||||
FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet());
|
||||
fetch(std::move(req), m_httpListener);
|
||||
fetch(tag(), std::move(req), m_httpListener);
|
||||
|
||||
return m_sequence++;
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ void xmrig::DaemonClient::retry()
|
|||
void xmrig::DaemonClient::send(const char *path)
|
||||
{
|
||||
FetchRequest req(HTTP_GET, m_pool.host(), m_pool.port(), path, m_pool.isTLS(), isQuiet());
|
||||
fetch(std::move(req), m_httpListener);
|
||||
fetch(tag(), std::move(req), m_httpListener);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ void xmrig::SelfSelectClient::getBlockTemplate()
|
|||
JsonRequest::create(doc, m_sequence++, "getblocktemplate", params);
|
||||
|
||||
FetchRequest req(HTTP_POST, pool().daemon().host(), pool().daemon().port(), "/json_rpc", doc, pool().daemon().isTLS(), isQuiet());
|
||||
fetch(std::move(req), m_httpListener);
|
||||
fetch(tag(), std::move(req), m_httpListener);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ void xmrig::BenchClient::send(Request request)
|
|||
case GET_BENCH:
|
||||
{
|
||||
FetchRequest req(HTTP_GET, m_ip, BenchConfig::kApiPort, fmt::format("/1/benchmark/{}", m_job.id()).c_str(), BenchConfig::kApiTLS, true);
|
||||
fetch(std::move(req), m_httpListener);
|
||||
fetch(tag(), std::move(req), m_httpListener);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -336,7 +336,7 @@ void xmrig::BenchClient::send(Request request)
|
|||
doc.AddMember("cpu", Cpu::toJSON(doc), allocator);
|
||||
|
||||
FetchRequest req(HTTP_POST, m_ip, BenchConfig::kApiPort, "/1/benchmark", doc, BenchConfig::kApiTLS, true);
|
||||
fetch(std::move(req), m_httpListener);
|
||||
fetch(tag(), std::move(req), m_httpListener);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -375,6 +375,6 @@ void xmrig::BenchClient::update(const rapidjson::Value &body)
|
|||
FetchRequest req(HTTP_PATCH, m_ip, BenchConfig::kApiPort, fmt::format("/1/benchmark/{}", m_job.id()).c_str(), body, BenchConfig::kApiTLS, true);
|
||||
req.headers.insert({ "Authorization", fmt::format("Bearer {}", m_token)});
|
||||
|
||||
fetch(std::move(req), m_httpListener);
|
||||
fetch(tag(), std::move(req), m_httpListener);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue