Update base.
This commit is contained in:
parent
b38046db46
commit
46e49cde0b
40 changed files with 162 additions and 244 deletions
|
@ -5,8 +5,8 @@
|
|||
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 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
|
||||
|
@ -23,9 +23,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IDnsListener.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "base/kernel/interfaces/IDnsListener.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -35,10 +34,7 @@ namespace xmrig {
|
|||
|
||||
|
||||
xmrig::Dns::Dns(IDnsListener *listener) :
|
||||
m_hints(),
|
||||
m_listener(listener),
|
||||
m_status(0),
|
||||
m_resolver(nullptr)
|
||||
m_listener(listener)
|
||||
{
|
||||
m_key = m_storage.add(this);
|
||||
|
||||
|
@ -134,11 +130,11 @@ void xmrig::Dns::onResolved(int status, addrinfo *res)
|
|||
addrinfo *ptr = res;
|
||||
while (ptr != nullptr) {
|
||||
if (ptr->ai_family == AF_INET) {
|
||||
m_ipv4.push_back(ptr);
|
||||
m_ipv4.emplace_back(ptr);
|
||||
}
|
||||
|
||||
if (ptr->ai_family == AF_INET6) {
|
||||
m_ipv6.push_back(ptr);
|
||||
m_ipv6.emplace_back(ptr);
|
||||
}
|
||||
|
||||
ptr = ptr->ai_next;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 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
|
||||
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "base/net/dns/DnsRecord.h"
|
||||
#include "base/net/tools/Storage.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
|
@ -44,6 +45,8 @@ class IDnsListener;
|
|||
class Dns
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Dns)
|
||||
|
||||
Dns(IDnsListener *listener);
|
||||
~Dns();
|
||||
|
||||
|
@ -62,14 +65,14 @@ private:
|
|||
|
||||
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
|
||||
|
||||
addrinfo m_hints;
|
||||
addrinfo m_hints{};
|
||||
IDnsListener *m_listener;
|
||||
int m_status;
|
||||
int m_status = 0;
|
||||
std::vector<DnsRecord> m_ipv4;
|
||||
std::vector<DnsRecord> m_ipv6;
|
||||
String m_host;
|
||||
uintptr_t m_key;
|
||||
uv_getaddrinfo_t *m_resolver;
|
||||
uv_getaddrinfo_t *m_resolver = nullptr;
|
||||
|
||||
static Storage<Dns> m_storage;
|
||||
};
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
|
||||
|
||||
#include "base/net/http/Fetch.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "3rdparty/rapidjson/stringbuffer.h"
|
||||
#include "3rdparty/rapidjson/writer.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpClient.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include "rapidjson/writer.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
|
@ -45,7 +44,7 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
|
|||
}
|
||||
|
||||
|
||||
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls, bool quiet) :
|
||||
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
|
||||
quiet(quiet),
|
||||
tls(tls),
|
||||
method(method),
|
||||
|
@ -55,42 +54,10 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
|
|||
{
|
||||
assert(port > 0);
|
||||
|
||||
setBody(doc);
|
||||
setBody(value);
|
||||
}
|
||||
|
||||
|
||||
xmrig::FetchRequest::FetchRequest(int method, const Pool &pool, const String &path, bool quiet, const char *data, size_t size, const char *contentType) :
|
||||
quiet(quiet),
|
||||
tls(pool.isTLS()),
|
||||
method(static_cast<http_method>(method)),
|
||||
fingerprint(pool.fingerprint()),
|
||||
host(pool.host()),
|
||||
path(path),
|
||||
port(pool.port())
|
||||
{
|
||||
assert(pool.isValid());
|
||||
|
||||
setBody(data, size, contentType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
xmrig::FetchRequest::FetchRequest(int method, const Pool &pool, const String &path, const rapidjson::Document &doc, bool quiet) :
|
||||
quiet(quiet),
|
||||
tls(pool.isTLS()),
|
||||
method(static_cast<http_method>(method)),
|
||||
fingerprint(pool.fingerprint()),
|
||||
host(pool.host()),
|
||||
path(path),
|
||||
port(pool.port())
|
||||
{
|
||||
assert(pool.isValid());
|
||||
|
||||
setBody(doc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *contentType)
|
||||
{
|
||||
if (!data) {
|
||||
|
@ -110,7 +77,7 @@ void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *con
|
|||
}
|
||||
|
||||
|
||||
void xmrig::FetchRequest::setBody(const rapidjson::Document &doc)
|
||||
void xmrig::FetchRequest::setBody(const rapidjson::Value &value)
|
||||
{
|
||||
assert(method != HTTP_GET && method != HTTP_HEAD);
|
||||
|
||||
|
@ -122,7 +89,7 @@ void xmrig::FetchRequest::setBody(const rapidjson::Document &doc)
|
|||
|
||||
StringBuffer buffer(nullptr, 512);
|
||||
Writer<StringBuffer> writer(buffer);
|
||||
doc.Accept(writer);
|
||||
value.Accept(writer);
|
||||
|
||||
setBody(buffer.GetString(), buffer.GetSize(), HttpData::kApplicationJson.c_str());
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
#include <map>
|
||||
|
@ -35,7 +35,6 @@ namespace xmrig {
|
|||
|
||||
|
||||
class IHttpListener;
|
||||
class Pool;
|
||||
|
||||
|
||||
class FetchRequest
|
||||
|
@ -43,12 +42,10 @@ class FetchRequest
|
|||
public:
|
||||
FetchRequest() = default;
|
||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
|
||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls = false, bool quiet = false);
|
||||
FetchRequest(int method, const Pool &pool, const String &path, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
|
||||
FetchRequest(int method, const Pool &pool, const String &path, const rapidjson::Document &doc, bool quiet = false);
|
||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
|
||||
|
||||
void setBody(const char *data, size_t size, const char *contentType = nullptr);
|
||||
void setBody(const rapidjson::Document &doc);
|
||||
void setBody(const rapidjson::Value &value);
|
||||
|
||||
inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); }
|
||||
|
||||
|
|
|
@ -26,6 +26,19 @@ namespace xmrig {
|
|||
const std::string HttpData::kApplicationJson = "application/json";
|
||||
const std::string HttpData::kContentType = "Content-Type";
|
||||
const std::string HttpData::kContentTypeL = "content-type";
|
||||
const std::string HttpData::kTextPlain = "text/plain";
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
bool xmrig::HttpData::isJSON() const
|
||||
{
|
||||
if (!headers.count(kContentTypeL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto &type = headers.at(kContentTypeL);
|
||||
|
||||
return type == kApplicationJson || type == kTextPlain;
|
||||
}
|
||||
|
|
|
@ -46,12 +46,13 @@ public:
|
|||
static const std::string kApplicationJson;
|
||||
static const std::string kContentType;
|
||||
static const std::string kContentTypeL;
|
||||
static const std::string kTextPlain;
|
||||
|
||||
|
||||
inline HttpData(uint64_t id) : m_id(id) {}
|
||||
virtual ~HttpData() = default;
|
||||
|
||||
inline uint64_t id() const { return m_id; }
|
||||
inline uint64_t id() const { return m_id; }
|
||||
|
||||
virtual bool isRequest() const = 0;
|
||||
virtual const char *host() const = 0;
|
||||
|
@ -61,6 +62,8 @@ public:
|
|||
virtual uint16_t port() const = 0;
|
||||
virtual void write(std::string &&data, bool close) = 0;
|
||||
|
||||
bool isJSON() const;
|
||||
|
||||
int method = 0;
|
||||
int status = 0;
|
||||
int userType = 0;
|
||||
|
|
|
@ -27,11 +27,11 @@ void xmrig::HttpListener::onHttpData(const HttpData &data)
|
|||
{
|
||||
# ifdef APP_DEBUG
|
||||
if (!data.isRequest()) {
|
||||
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||
data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
|
||||
data.status >= 400 ? 31 : 32, data.status, data.body.size());
|
||||
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
|
||||
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
|
||||
|
||||
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.headers.count(HttpData::kContentTypeL) && data.headers.at(HttpData::kContentTypeL) == HttpData::kApplicationJson) {
|
||||
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
|
||||
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast<int>(data.body.size()), data.body.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,13 @@ namespace xmrig {
|
|||
class HttpListener : public IHttpListener
|
||||
{
|
||||
public:
|
||||
inline HttpListener(IHttpListener *listener) : 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:
|
||||
const char *m_tag;
|
||||
IHttpListener *m_listener;
|
||||
};
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 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
|
||||
|
@ -24,10 +24,10 @@
|
|||
|
||||
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "base/kernel/Env.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/Env.h"
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -328,7 +328,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
|
|||
|
||||
int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc)
|
||||
{
|
||||
FetchRequest req(HTTP_POST, m_pool, kJsonRPC, doc, isQuiet());
|
||||
FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet());
|
||||
fetch(std::move(req), m_httpListener);
|
||||
|
||||
return m_sequence++;
|
||||
|
@ -355,7 +355,7 @@ void xmrig::DaemonClient::retry()
|
|||
|
||||
void xmrig::DaemonClient::send(const char *path)
|
||||
{
|
||||
FetchRequest req(HTTP_GET, m_pool, path, isQuiet());
|
||||
FetchRequest req(HTTP_GET, m_pool.host(), m_pool.port(), path, m_pool.isTLS(), isQuiet());
|
||||
fetch(std::move(req), m_httpListener);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
|
||||
|
||||
#include "base/net/tls/TlsConfig.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/tls/TlsGen.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -86,7 +86,7 @@ xmrig::TlsConfig::TlsConfig(const rapidjson::Value &value)
|
|||
generate();
|
||||
}
|
||||
}
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
# ifdef XMRIG_FORCE_TLS
|
||||
else if (value.IsNull()) {
|
||||
generate();
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#define XMRIG_TLSCONFIG_H
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
#include "base/io/Env.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Env.h"
|
||||
#include "base/net/tls/TlsConfig.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
/* 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 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
|
@ -48,10 +42,10 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline static void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); }
|
||||
inline void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); }
|
||||
|
||||
|
||||
inline TYPE *get(const void *id) const { return get(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline TYPE *get(const void *id) const { return get(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline TYPE *get(uintptr_t id) const
|
||||
{
|
||||
assert(m_data.count(id) > 0);
|
||||
|
@ -63,19 +57,16 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline void remove(const void *id) { delete release(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline void remove(uintptr_t id) { delete release(id); }
|
||||
inline void remove(const void *id) { delete release(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline void remove(uintptr_t id) { delete release(id); }
|
||||
|
||||
|
||||
inline TYPE *release(const void *id) { release(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline TYPE *release(const void *id) { return release(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline TYPE *release(uintptr_t id)
|
||||
{
|
||||
TYPE *obj = get(id);
|
||||
auto obj = get(id);
|
||||
if (obj != nullptr) {
|
||||
auto it = m_data.find(id);
|
||||
if (it != m_data.end()) {
|
||||
m_data.erase(it);
|
||||
}
|
||||
m_data.erase(id);
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
@ -84,7 +75,7 @@ public:
|
|||
|
||||
private:
|
||||
std::map<uintptr_t, TYPE *> m_data;
|
||||
uint64_t m_counter = 0;
|
||||
uintptr_t m_counter = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue