mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-11 05:14:40 +00:00
New DNS implementation.
This commit is contained in:
parent
5b189696d7
commit
3e41bdc552
14 changed files with 357 additions and 121 deletions
|
@ -32,6 +32,7 @@ set(HEADERS_BASE
|
||||||
src/base/kernel/interfaces/IConfigListener.h
|
src/base/kernel/interfaces/IConfigListener.h
|
||||||
src/base/kernel/interfaces/IConfigTransform.h
|
src/base/kernel/interfaces/IConfigTransform.h
|
||||||
src/base/kernel/interfaces/IConsoleListener.h
|
src/base/kernel/interfaces/IConsoleListener.h
|
||||||
|
src/base/kernel/interfaces/IDnsBackend.h
|
||||||
src/base/kernel/interfaces/IDnsListener.h
|
src/base/kernel/interfaces/IDnsListener.h
|
||||||
src/base/kernel/interfaces/ILineListener.h
|
src/base/kernel/interfaces/ILineListener.h
|
||||||
src/base/kernel/interfaces/ILogBackend.h
|
src/base/kernel/interfaces/ILogBackend.h
|
||||||
|
@ -45,6 +46,8 @@ set(HEADERS_BASE
|
||||||
src/base/net/dns/Dns.h
|
src/base/net/dns/Dns.h
|
||||||
src/base/net/dns/DnsRecord.h
|
src/base/net/dns/DnsRecord.h
|
||||||
src/base/net/dns/DnsRecords.h
|
src/base/net/dns/DnsRecords.h
|
||||||
|
src/base/net/dns/DnsRequest.h
|
||||||
|
src/base/net/dns/DnsUvBackend.h
|
||||||
src/base/net/http/Http.h
|
src/base/net/http/Http.h
|
||||||
src/base/net/http/HttpListener.h
|
src/base/net/http/HttpListener.h
|
||||||
src/base/net/stratum/BaseClient.h
|
src/base/net/stratum/BaseClient.h
|
||||||
|
@ -102,6 +105,7 @@ set(SOURCES_BASE
|
||||||
src/base/net/dns/Dns.cpp
|
src/base/net/dns/Dns.cpp
|
||||||
src/base/net/dns/DnsRecord.cpp
|
src/base/net/dns/DnsRecord.cpp
|
||||||
src/base/net/dns/DnsRecords.cpp
|
src/base/net/dns/DnsRecords.cpp
|
||||||
|
src/base/net/dns/DnsUvBackend.cpp
|
||||||
src/base/net/http/Http.cpp
|
src/base/net/http/Http.cpp
|
||||||
src/base/net/stratum/BaseClient.cpp
|
src/base/net/stratum/BaseClient.cpp
|
||||||
src/base/net/stratum/Client.cpp
|
src/base/net/stratum/Client.cpp
|
||||||
|
|
54
src/base/kernel/interfaces/IDnsBackend.h
Normal file
54
src/base/kernel/interfaces/IDnsBackend.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright (c) 2016-2021 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_IDNSBACKEND_H
|
||||||
|
#define XMRIG_IDNSBACKEND_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/tools/Object.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class DnsRecords;
|
||||||
|
class DnsRequest;
|
||||||
|
class IDnsListener;
|
||||||
|
class String;
|
||||||
|
|
||||||
|
|
||||||
|
class IDnsBackend
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XMRIG_DISABLE_COPY_MOVE(IDnsBackend)
|
||||||
|
|
||||||
|
IDnsBackend() = default;
|
||||||
|
virtual ~IDnsBackend() = default;
|
||||||
|
|
||||||
|
virtual const DnsRecords &records() const = 0;
|
||||||
|
virtual std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif // XMRIG_IDNSBACKEND_H
|
|
@ -37,7 +37,7 @@ public:
|
||||||
IDnsListener() = default;
|
IDnsListener() = default;
|
||||||
virtual ~IDnsListener() = default;
|
virtual ~IDnsListener() = default;
|
||||||
|
|
||||||
virtual void onResolved(const DnsRecords &records, int status) = 0;
|
virtual void onResolved(const DnsRecords &records, int status, const char *error) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,74 +18,23 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
#include "base/kernel/interfaces/IDnsListener.h"
|
#include "base/net/dns/DnsUvBackend.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
Storage<Dns> Dns::m_storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
xmrig::Dns::Dns(IDnsListener *listener) :
|
std::map<String, std::shared_ptr<IDnsBackend> > Dns::m_backends;
|
||||||
m_listener(listener)
|
|
||||||
|
|
||||||
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<xmrig::DnsRequest> xmrig::Dns::resolve(const String &host, IDnsListener *listener, uint64_t ttl)
|
||||||
{
|
{
|
||||||
m_key = m_storage.add(this);
|
if (m_backends.find(host) == m_backends.end()) {
|
||||||
|
m_backends.insert({ host, std::make_shared<DnsUvBackend>() });
|
||||||
m_resolver = new uv_getaddrinfo_t;
|
|
||||||
m_resolver->data = m_storage.ptr(m_key);
|
|
||||||
|
|
||||||
m_hints.ai_family = AF_UNSPEC;
|
|
||||||
m_hints.ai_socktype = SOCK_STREAM;
|
|
||||||
m_hints.ai_protocol = IPPROTO_TCP;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
xmrig::Dns::~Dns()
|
|
||||||
{
|
|
||||||
m_storage.release(m_key);
|
|
||||||
|
|
||||||
delete m_resolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool xmrig::Dns::resolve(const String &host)
|
|
||||||
{
|
|
||||||
if (m_host != host) {
|
|
||||||
m_host = host;
|
|
||||||
|
|
||||||
m_records.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_status = uv_getaddrinfo(uv_default_loop(), m_resolver, Dns::onResolved, m_host.data(), nullptr, &m_hints);
|
return m_backends.at(host)->resolve(host, listener, ttl);
|
||||||
|
|
||||||
return m_status == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Dns::onResolved(int status, addrinfo *res)
|
|
||||||
{
|
|
||||||
m_status = status;
|
|
||||||
|
|
||||||
if (m_status < 0) {
|
|
||||||
return m_listener->onResolved(m_records, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_records.parse(res);
|
|
||||||
|
|
||||||
if (m_records.isEmpty()) {
|
|
||||||
m_status = UV_EAI_NONAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_listener->onResolved(m_records, m_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Dns::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res)
|
|
||||||
{
|
|
||||||
Dns *dns = m_storage.get(req->data);
|
|
||||||
if (dns) {
|
|
||||||
dns->onResolved(status, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
uv_freeaddrinfo(res);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,48 +20,28 @@
|
||||||
#define XMRIG_DNS_H
|
#define XMRIG_DNS_H
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
#include "base/tools/String.h"
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/dns/DnsRecords.h"
|
#include <map>
|
||||||
#include "base/net/tools/Storage.h"
|
#include <memory>
|
||||||
#include "base/tools/Object.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class DnsRequest;
|
||||||
|
class IDnsBackend;
|
||||||
class IDnsListener;
|
class IDnsListener;
|
||||||
|
|
||||||
|
|
||||||
class Dns
|
class Dns
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Dns)
|
static std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl = 60000);
|
||||||
|
|
||||||
Dns(IDnsListener *listener);
|
|
||||||
~Dns();
|
|
||||||
|
|
||||||
inline const String &host() const { return m_host; }
|
|
||||||
inline int status() const { return m_status; }
|
|
||||||
|
|
||||||
bool resolve(const String &host);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onResolved(int status, addrinfo *res);
|
static std::map<String, std::shared_ptr<IDnsBackend> > m_backends;
|
||||||
|
|
||||||
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
|
|
||||||
|
|
||||||
addrinfo m_hints{};
|
|
||||||
DnsRecords m_records;
|
|
||||||
IDnsListener *m_listener;
|
|
||||||
int m_status = 0;
|
|
||||||
String m_host;
|
|
||||||
uintptr_t m_key;
|
|
||||||
uv_getaddrinfo_t *m_resolver = nullptr;
|
|
||||||
|
|
||||||
static Storage<Dns> m_storage;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
50
src/base/net/dns/DnsRequest.h
Normal file
50
src/base/net/dns/DnsRequest.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright (c) 2016-2021 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_DNSREQUEST_H
|
||||||
|
#define XMRIG_DNSREQUEST_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/tools/Object.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class IDnsListener;
|
||||||
|
|
||||||
|
|
||||||
|
class DnsRequest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XMRIG_DISABLE_COPY_MOVE_DEFAULT(DnsRequest)
|
||||||
|
|
||||||
|
DnsRequest(IDnsListener *listener) : listener(listener) {}
|
||||||
|
~DnsRequest() = default;
|
||||||
|
|
||||||
|
IDnsListener *listener;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_DNSREQUEST_H */
|
130
src/base/net/dns/DnsUvBackend.cpp
Normal file
130
src/base/net/dns/DnsUvBackend.cpp
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright (c) 2016-2021 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/net/dns/DnsUvBackend.h"
|
||||||
|
#include "base/kernel/interfaces/IDnsListener.h"
|
||||||
|
#include "base/net/dns/DnsRequest.h"
|
||||||
|
#include "base/tools/Chrono.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
Storage<DnsUvBackend> DnsUvBackend::m_storage;
|
||||||
|
|
||||||
|
static addrinfo hints{};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::DnsUvBackend::DnsUvBackend()
|
||||||
|
{
|
||||||
|
if (!hints.ai_protocol) {
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_key = m_storage.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::DnsUvBackend::~DnsUvBackend()
|
||||||
|
{
|
||||||
|
m_storage.release(m_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<xmrig::DnsRequest> xmrig::DnsUvBackend::resolve(const String &host, IDnsListener *listener, uint64_t ttl)
|
||||||
|
{
|
||||||
|
auto req = std::make_shared<DnsRequest>(listener);
|
||||||
|
|
||||||
|
if (Chrono::currentMSecsSinceEpoch() - m_ts <= ttl && !m_records.isEmpty()) {
|
||||||
|
req->listener->onResolved(m_records, 0, nullptr);
|
||||||
|
} else {
|
||||||
|
m_queue.emplace(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_queue.size() == 1 && !resolve(host)) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::DnsUvBackend::resolve(const String &host)
|
||||||
|
{
|
||||||
|
m_req = std::make_shared<uv_getaddrinfo_t>();
|
||||||
|
m_req->data = m_storage.ptr(m_key);
|
||||||
|
|
||||||
|
m_status = uv_getaddrinfo(uv_default_loop(), m_req.get(), DnsUvBackend::onResolved, host.data(), nullptr, &hints);
|
||||||
|
|
||||||
|
return m_status == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::DnsUvBackend::done()
|
||||||
|
{
|
||||||
|
const char *error = m_status < 0 ? uv_strerror(m_status) : nullptr;
|
||||||
|
|
||||||
|
while (!m_queue.empty()) {
|
||||||
|
auto req = std::move(m_queue.front()).lock();
|
||||||
|
if (req) {
|
||||||
|
req->listener->onResolved(m_records, m_status, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_queue.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_req.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::DnsUvBackend::onResolved(int status, addrinfo *res)
|
||||||
|
{
|
||||||
|
m_ts = Chrono::currentMSecsSinceEpoch();
|
||||||
|
|
||||||
|
if ((m_status = status) < 0) {
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_records.parse(res);
|
||||||
|
|
||||||
|
if (m_records.isEmpty()) {
|
||||||
|
m_status = UV_EAI_NONAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::DnsUvBackend::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res)
|
||||||
|
{
|
||||||
|
auto backend = m_storage.get(req->data);
|
||||||
|
if (backend) {
|
||||||
|
backend->onResolved(status, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
uv_freeaddrinfo(res);
|
||||||
|
}
|
71
src/base/net/dns/DnsUvBackend.h
Normal file
71
src/base/net/dns/DnsUvBackend.h
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright (c) 2016-2021 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_DNSUVBACKEND_H
|
||||||
|
#define XMRIG_DNSUVBACKEND_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/kernel/interfaces/IDnsBackend.h"
|
||||||
|
#include "base/net/dns/DnsRecords.h"
|
||||||
|
#include "base/net/tools/Storage.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
|
||||||
|
using uv_getaddrinfo_t = struct uv_getaddrinfo_s;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class DnsUvBackend : public IDnsBackend
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XMRIG_DISABLE_COPY_MOVE(DnsUvBackend)
|
||||||
|
|
||||||
|
DnsUvBackend();
|
||||||
|
~DnsUvBackend() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
inline const DnsRecords &records() const override { return m_records; }
|
||||||
|
|
||||||
|
std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool resolve(const String &host);
|
||||||
|
void done();
|
||||||
|
void onResolved(int status, addrinfo *res);
|
||||||
|
|
||||||
|
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
|
||||||
|
|
||||||
|
DnsRecords m_records;
|
||||||
|
int m_status = 0;
|
||||||
|
std::queue<std::weak_ptr<DnsRequest> > m_queue;
|
||||||
|
std::shared_ptr<uv_getaddrinfo_t> m_req;
|
||||||
|
uint64_t m_ts = 0;
|
||||||
|
uintptr_t m_key;
|
||||||
|
|
||||||
|
static Storage<DnsUvBackend> m_storage;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_DNSUVBACKEND_H */
|
|
@ -23,11 +23,13 @@
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/Platform.h"
|
#include "base/kernel/Platform.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
|
#include "base/net/dns/DnsRecords.h"
|
||||||
#include "base/net/tools/NetBuffer.h"
|
#include "base/net/tools/NetBuffer.h"
|
||||||
#include "base/tools/Timer.h"
|
#include "base/tools/Timer.h"
|
||||||
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -48,7 +50,6 @@ xmrig::HttpClient::HttpClient(const char *tag, FetchRequest &&req, const std::we
|
||||||
url = std::move(m_req.path);
|
url = std::move(m_req.path);
|
||||||
body = std::move(m_req.body);
|
body = std::move(m_req.body);
|
||||||
headers = std::move(m_req.headers);
|
headers = std::move(m_req.headers);
|
||||||
m_dns = std::make_shared<Dns>(this);
|
|
||||||
|
|
||||||
if (m_req.timeout) {
|
if (m_req.timeout) {
|
||||||
m_timer = std::make_shared<Timer>(this, m_req.timeout, 0);
|
m_timer = std::make_shared<Timer>(this, m_req.timeout, 0);
|
||||||
|
@ -58,17 +59,20 @@ xmrig::HttpClient::HttpClient(const char *tag, FetchRequest &&req, const std::we
|
||||||
|
|
||||||
bool xmrig::HttpClient::connect()
|
bool xmrig::HttpClient::connect()
|
||||||
{
|
{
|
||||||
return m_dns->resolve(m_req.host);
|
m_dns = Dns::resolve(m_req.host, this);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::HttpClient::onResolved(const DnsRecords &records, int status)
|
void xmrig::HttpClient::onResolved(const DnsRecords &records, int status, const char *error)
|
||||||
{
|
{
|
||||||
this->status = status;
|
this->status = status;
|
||||||
|
m_dns.reset();
|
||||||
|
|
||||||
if (status < 0 && records.isEmpty()) {
|
if (status < 0 && records.isEmpty()) {
|
||||||
if (!isQuiet()) {
|
if (!isQuiet()) {
|
||||||
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(status));
|
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Dns;
|
class DnsRequest;
|
||||||
|
|
||||||
|
|
||||||
class HttpClient : public HttpContext, public IDnsListener, public ITimerListener
|
class HttpClient : public HttpContext, public IDnsListener, public ITimerListener
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
bool connect();
|
bool connect();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onResolved(const DnsRecords &records, int status) override;
|
void onResolved(const DnsRecords &records, int status, const char *error) override;
|
||||||
void onTimer(const Timer *timer) override;
|
void onTimer(const Timer *timer) override;
|
||||||
|
|
||||||
virtual void handshake();
|
virtual void handshake();
|
||||||
|
@ -65,7 +65,7 @@ private:
|
||||||
|
|
||||||
const char *m_tag;
|
const char *m_tag;
|
||||||
FetchRequest m_req;
|
FetchRequest m_req;
|
||||||
std::shared_ptr<Dns> m_dns;
|
std::shared_ptr<DnsRequest> m_dns;
|
||||||
std::shared_ptr<Timer> m_timer;
|
std::shared_ptr<Timer> m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,11 @@
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/interfaces/IClientListener.h"
|
#include "base/kernel/interfaces/IClientListener.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
|
#include "base/net/dns/DnsRecords.h"
|
||||||
#include "base/net/stratum/Socks5.h"
|
#include "base/net/stratum/Socks5.h"
|
||||||
#include "base/net/tools/NetBuffer.h"
|
#include "base/net/tools/NetBuffer.h"
|
||||||
#include "base/tools/Cvt.h"
|
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
|
#include "base/tools/Cvt.h"
|
||||||
#include "net/JobResult.h"
|
#include "net/JobResult.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,13 +87,11 @@ xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||||
{
|
{
|
||||||
m_reader.setListener(this);
|
m_reader.setListener(this);
|
||||||
m_key = m_storage.add(this);
|
m_key = m_storage.add(this);
|
||||||
m_dns = new Dns(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xmrig::Client::~Client()
|
xmrig::Client::~Client()
|
||||||
{
|
{
|
||||||
delete m_dns;
|
|
||||||
delete m_socket;
|
delete m_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,8 +294,10 @@ void xmrig::Client::tick(uint64_t now)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Client::onResolved(const DnsRecords &records, int status)
|
void xmrig::Client::onResolved(const DnsRecords &records, int status, const char *error)
|
||||||
{
|
{
|
||||||
|
m_dns.reset();
|
||||||
|
|
||||||
assert(m_listener != nullptr);
|
assert(m_listener != nullptr);
|
||||||
if (!m_listener) {
|
if (!m_listener) {
|
||||||
return reconnect();
|
return reconnect();
|
||||||
|
@ -304,7 +305,7 @@ void xmrig::Client::onResolved(const DnsRecords &records, int status)
|
||||||
|
|
||||||
if (status < 0 && records.isEmpty()) {
|
if (status < 0 && records.isEmpty()) {
|
||||||
if (!isQuiet()) {
|
if (!isQuiet()) {
|
||||||
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(status));
|
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return reconnect();
|
return reconnect();
|
||||||
|
@ -524,13 +525,7 @@ int xmrig::Client::resolve(const String &host)
|
||||||
m_failures = 0;
|
m_failures = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_dns->resolve(host)) {
|
m_dns = Dns::resolve(host, this);
|
||||||
if (!isQuiet()) {
|
|
||||||
LOG_ERR("%s " RED("getaddrinfo error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(m_dns->status()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ using BIO = struct bio_st;
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Dns;
|
class DnsRequest;
|
||||||
class IClientListener;
|
class IClientListener;
|
||||||
class JobResult;
|
class JobResult;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ protected:
|
||||||
void deleteLater() override;
|
void deleteLater() override;
|
||||||
void tick(uint64_t now) override;
|
void tick(uint64_t now) override;
|
||||||
|
|
||||||
void onResolved(const DnsRecords &records, int status) override;
|
void onResolved(const DnsRecords &records, int status, const char *error) override;
|
||||||
|
|
||||||
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
|
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
|
||||||
inline const char *mode() const override { return "pool"; }
|
inline const char *mode() const override { return "pool"; }
|
||||||
|
@ -132,10 +132,10 @@ private:
|
||||||
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
||||||
|
|
||||||
const char *m_agent;
|
const char *m_agent;
|
||||||
Dns *m_dns;
|
|
||||||
LineReader m_reader;
|
LineReader m_reader;
|
||||||
Socks5 *m_socks5 = nullptr;
|
Socks5 *m_socks5 = nullptr;
|
||||||
std::bitset<EXT_MAX> m_extensions;
|
std::bitset<EXT_MAX> m_extensions;
|
||||||
|
std::shared_ptr<DnsRequest> m_dns;
|
||||||
std::vector<char> m_sendBuf;
|
std::vector<char> m_sendBuf;
|
||||||
String m_rpcId;
|
String m_rpcId;
|
||||||
Tls *m_tls = nullptr;
|
Tls *m_tls = nullptr;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "base/io/log/Tags.h"
|
#include "base/io/log/Tags.h"
|
||||||
#include "base/kernel/interfaces/IClientListener.h"
|
#include "base/kernel/interfaces/IClientListener.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
|
#include "base/net/dns/DnsRecords.h"
|
||||||
#include "base/net/http/Fetch.h"
|
#include "base/net/http/Fetch.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
#include "base/net/http/HttpListener.h"
|
#include "base/net/http/HttpListener.h"
|
||||||
|
@ -185,13 +186,15 @@ void xmrig::BenchClient::onHttpData(const HttpData &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::BenchClient::onResolved(const DnsRecords &records, int status)
|
void xmrig::BenchClient::onResolved(const DnsRecords &records, int status, const char *error)
|
||||||
{
|
{
|
||||||
# ifdef XMRIG_FEATURE_HTTP
|
# ifdef XMRIG_FEATURE_HTTP
|
||||||
assert(!m_httpListener);
|
assert(!m_httpListener);
|
||||||
|
|
||||||
|
m_dns.reset();
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return setError(uv_strerror(status), "DNS error");
|
return setError(error, "DNS error");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ip = records.get().ip();
|
m_ip = records.get().ip();
|
||||||
|
@ -307,11 +310,7 @@ void xmrig::BenchClient::onGetReply(const rapidjson::Value &value)
|
||||||
|
|
||||||
void xmrig::BenchClient::resolve()
|
void xmrig::BenchClient::resolve()
|
||||||
{
|
{
|
||||||
m_dns = std::make_shared<Dns>(this);
|
m_dns = Dns::resolve(BenchConfig::kApiHost, this);
|
||||||
|
|
||||||
if (!m_dns->resolve(BenchConfig::kApiHost)) {
|
|
||||||
setError(uv_strerror(m_dns->status()), "getaddrinfo error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ protected:
|
||||||
void onBenchDone(uint64_t result, uint64_t diff, uint64_t ts) override;
|
void onBenchDone(uint64_t result, uint64_t diff, uint64_t ts) override;
|
||||||
void onBenchReady(uint64_t ts, uint32_t threads, const IBackend *backend) override;
|
void onBenchReady(uint64_t ts, uint32_t threads, const IBackend *backend) override;
|
||||||
void onHttpData(const HttpData &data) override;
|
void onHttpData(const HttpData &data) override;
|
||||||
void onResolved(const DnsRecords &records, int status) override;
|
void onResolved(const DnsRecords &records, int status, const char *error) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Mode : uint32_t {
|
enum Mode : uint32_t {
|
||||||
|
@ -110,7 +110,7 @@ private:
|
||||||
Pool m_pool;
|
Pool m_pool;
|
||||||
Request m_request = NO_REQUEST;
|
Request m_request = NO_REQUEST;
|
||||||
std::shared_ptr<BenchConfig> m_benchmark;
|
std::shared_ptr<BenchConfig> m_benchmark;
|
||||||
std::shared_ptr<Dns> m_dns;
|
std::shared_ptr<DnsRequest> m_dns;
|
||||||
std::shared_ptr<IHttpListener> m_httpListener;
|
std::shared_ptr<IHttpListener> m_httpListener;
|
||||||
String m_ip;
|
String m_ip;
|
||||||
String m_token;
|
String m_token;
|
||||||
|
|
Loading…
Reference in a new issue